# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contriutor: Eric Belanger <eric@archlinux.org>
# Contributor: Jo Christian Bergskås <jcberg@gmail.com>

pkgname=fceux
pkgver=2.4.0
pkgrel=1
url='https://fceux.com/'
pkgdesc='Fast and ultra-compatible NES/Famicom emulator'
arch=(x86_64)
license=(GPL)
depends=(gd minizip qt5-base sdl2)
makedepends=(cmake git glu mesa-libgl ninja setconf scons)
source=("git+https://github.com/TASVideos/fceux#commit=941da60ecb283263a3810ed199d80abf94bd6494") # fceux-2.4.0
b2sums=('SKIP')

prepare() {
  cd $pkgname
  sed -i 's/-interim git//g' src/version.h
  setconf scripts/genGitHdr.sh GIT_URL "'""${source:4:34}""'"
  setconf scripts/genGitHdr.sh GIT_REV "${source#*=}"
}

build() {
  mkdir -p build
  cd build
  cmake ../$pkgname \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_C_FLAGS="$CFLAGS -fPIC -w" \
    -DCMAKE_CXX_FLAGS="$CXXFLAGS -fPIC -w" \
    -G Ninja
  ninja
}

package() {
  DESTDIR="$pkgdir" ninja -C build install
  install -d "$pkgdir/usr/share/doc/$pkgname"
  cp -r $pkgname/documentation/* "$pkgdir/usr/share/doc/$pkgname/"
  install -Dm644 $pkgname/changelog.txt "$pkgdir/usr/share/doc/$pkgname/"
}
