# Maintainer: bill-auger <bill-auger@programmer.net>
# Maintainer (AUR): MCMic <come.bernigaud@laposte.net>


pkgname=puzzlemoppet-git
pkgver=r64.d79b10e
pkgrel=3
pkgdesc="Guide your moppet through the ethereal void in this mellow and sublime 3D puzzle game"
arch=('i686' 'x86_64')
url=https://bitbucket.org/Knitter/puzzlemoppet/overview
license=('WTFPL')

depends=('irrlicht' 'libxrandr' 'ode' 'openal')
makedepends=('cmake' 'git')
conflicts=('puzzle-moppet-bin')

source=(${pkgname}::git+https://bitbucket.org/Knitter/puzzlemoppet.git)
md5sums=('SKIP')


_version_constraint() # (dep_pkgname)
{
  local dep_pkgname=$1
  local version=$(pacman -S --print-format='%v' ${dep_pkgname} | tail -n 1)
  version=${version%-*}
  local version_inc=${version%.*}.$(( ${version##*.} + 1 ))

  echo -n "${dep_pkgname}>=${version}" "${dep_pkgname}<${version_inc}"
}

pkgver()
{
  cd "${srcdir}/${pkgname}"

  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare()
{
  cd "${srcdir}/${pkgname}/puzzlemoppet"

  sed -i 's|/licences/|/licenses/|' ./CMakeLists.txt
}

build()
{
  cd "${srcdir}/${pkgname}/puzzlemoppet"

  cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_FOR_INSTALL=ON .
  make
}

package()
{
  cd "${srcdir}/${pkgname}/puzzlemoppet"

  depends+=( $(_version_constraint 'ode') )

  make install DESTDIR=$pkgdir
}
