# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer:  Brenton Horne <brentonhorne77@gmail.com>
# Contributor: Sven-Hendrik Haase <sh@lutzhaase.com>
# Contributor: t3ddy  <t3ddy1988 "at" gmail {dot} com>
# Contributor: AdriÃ¡n Chaves FernÃ¡ndez (Gallaecio) <adriyetichaves@gmail.com>
pkgname=('0ad' '0ad-data')
pkgver=0.23+20190814
pkgrel=2
arch=(x86_64 powerpc64le)
url="http://play0ad.com/"
license=('GPL2' 'CCPL')
depends=('binutils' 'boost-libs' 'curl' 'enet' 'libogg' 'libpng' 'libvorbis'
         'libxml2' 'openal' 'sdl2' 'wxgtk' 'zlib' 'libgl' 'glu'
         'gloox' 'miniupnpc' 'icu' 'nspr' 'nvidia-texture-tools' 'libsodium')
makedepends=('boost' 'cmake' 'mesa' 'zip' 'python2' 'libsm' 'git')
commit=1880cabf79f6f3bb594eae1b922acd6206c1373c
source=("${pkgname}::git+https://github.com/0ad/0ad.git#commit=${commit}"
	spidermonkey-powerpc.patch
        spidermonkey-patchset.patch
        0ad-powerpc64-support.patch)
sha512sums=('SKIP'
	    '3a1de09a0d6c084292d3914cd39638e9fa09fbef6f8993147528c39abdae20d77496d5bab6416fe5e4b49593eb5cf74e899d96066847ce76a6156af44f429a91'
	    '9892fddf043b42103501d5bbf054a39fa377f8ca9e94b0adfaa2f06ac50d91b66d3faee5196fb24d85929bfb4a98b8af9152da92e95611ad586c6da30ad7b7ca'
	    '02907941146ce066b4dcafc9dc6c4e987686aa26abbec9f4cab5f8ba425d00354f31af148c4b9d6c8f1133a923262a7d187ec8c51898144e24398ae20a60d16a')

prepare() {
  cd "${srcdir}/${pkgname}"
  sed -i "s/env python/env python2/g" libraries/source/cxxtest-4.4/bin/cxxtestgen
  patch -Np0 -i "${srcdir}/spidermonkey-patchset.patch"
  patch -Np1 -i "${srcdir}/0ad-powerpc64-support.patch"
}

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

  unset CPPFLAGS # for le spidermonkey
  export SDL2_CONFIG="pkg-config sdl2"
  export HOSTTYPE=${CARCH}

  ./update-workspaces.sh \
      --bindir=/usr/bin \
      --libdir=/usr/lib/0ad \
      --datadir=/usr/share/${pkgname}/data \
      --with-system-nvtt

  cd "${srcdir}/${pkgname}/libraries/source/fcollada/src"
  make config=release

  cd "${srcdir}/${pkgname}/build/workspaces/gcc"
  make config=release
}

package_0ad() {
  pkgdesc="Cross-platform, 3D and historically-based real-time strategy game"
  depends=('0ad-data')
  provides=('0ad')

  install -d "${pkgdir}"/usr/{bin,lib/${pkgname}}
  cd "${srcdir}/${pkgname}"

  install -Dm755 binaries/system/pyrogenesis "${pkgdir}/usr/bin"
  install -Dm755 binaries/system/*.so "${pkgdir}/usr/lib/${pkgname}"
  install -Dm755 build/resources/${pkgname}.sh "${pkgdir}/usr/bin/${pkgname}"
  install -Dm644 build/resources/${pkgname}.desktop \
    "${pkgdir}/usr/share/applications/${pkgname}.desktop"
  install -Dm644 build/resources/${pkgname}.png \
    "${pkgdir}/usr/share/pixmaps/${pkgname}.png"
}

package_0ad-data() {
  pkgdesc="Data package for 0ad"
  depends=('0ad')
  provides=('0ad-data')

  mkdir -p ${pkgdir}/usr/share/${pkgbase}
  cp -r ${srcdir}/${pkgbase}/binaries/data ${pkgdir}/usr/share/${pkgbase}
}
