# Maintainer: Eric DeStefano <eric at ericdestefano dot com>

pkgbase=sheepshaver-git
pkgname=(basiliskii-git sheepshaver-git sheepnet-dkms-git)
epoch=4
pkgver=r3551.g55ac71ba
pkgrel=2
pkgdesc="An Open Source PowerMac and Classic Macintosh Emulator"
arch=('x86_64')
url="http://sheepshaver.cebix.net"
license=('GPL')
depends=('gtk2' 'sdl2' 'vde2')
options=('!makeflags' '!buildflags')
source=('git+https://github.com/kanjitalk755/macemu'
        'SheepShaver.sysctl'
        'SheepShaver.desktop'
        'SheepShaver.png'
        'BasiliskII.desktop'
        'BasiliskII.png'
        'sheep_net.patch')
makedepends=('git')
sha256sums=('SKIP'
            'a4aa858b95d29906873693988d5db42d5a4da8aa94a72c79374f59fc488efd51'
            'fa5e3828b40dfa5196c4b801b9a6761f57dde47756734f37bdd3c8333eec5670'
            'b7f67b1f8424f3e0ffa1a5e57597f368c4c4f93ea1f871ec0a76700b7519b241'
            '435c68f045cff3a8e407a13bf6d25f81a045cb6477bf3d116ec7e83c0218668d'
            '66635f63471e314fcc587d1a14b6caf87ed582ba80525e12462da0dba87eec60'
            '27e63a5d9a9d86b66ac7884b9ca2923b398deacb5c7f44758ea71c0d10d25a4b')

pkgver() {
  cd macemu
  echo "r$(git rev-list --count HEAD).g$(git rev-parse --short HEAD)"
}

prepare() {
  cd macemu
  patch -p0 -i ../sheep_net.patch
  cd SheepShaver/src/Unix
  sed -i "s/#error \"You don't have ANSI C header files.\"//g" sysdeps.h 
}

build() {
  cd macemu/SheepShaver/src/Unix
  NO_CONFIGURE=1 ./autogen.sh
  ./configure \
    --prefix=/usr \
    --enable-standalone-gui \
    --with-bincue \
    --enable-sdl-video \
    --enable-sdl-audio

  make -j1

  cd $srcdir/macemu/BasiliskII/src/Unix
#  sed -i 's/I_PUSH/TIOCPKT/g' sshpty.c

  NO_CONFIGURE=1 ./autogen.sh
  #sed -i 's/config.rpath //g' configure
  ./configure \
		--prefix=/usr \
    --enable-standalone-gui \
		--enable-jit-compiler \
		--with-bincue \
		--with-vdeplug \
    --enable-sdl-video \
    --enable-sdl-audio

	make -j1
}

package_basiliskii-git() {
  cd macemu/BasiliskII/src/Unix
	make DESTDIR="$pkgdir/" install
  cd ${srcdir}
  install -Dm644 BasiliskII.desktop "$pkgdir"/usr/share/applications/BasiliskII.desktop
  install -Dm644 BasiliskII.png     "$pkgdir"/usr/share/pixmaps/BasiliskII.png
}

package_sheepshaver-git() {
  provides=("sheepshaver=$pkgver")
  conflicts=("sheepshaver")

  install -Dm755 macemu/SheepShaver/src/Unix/SheepShaver    "$pkgdir"/usr/bin/SheepShaver
  install -Dm755 macemu/SheepShaver/src/Unix/SheepShaverGUI    "$pkgdir"/usr/bin/SheepShaverGUI

  mkdir -p "$pkgdir"/usr/share/doc
  cp -a macemu/SheepShaver/doc/Linux "$pkgdir"/usr/share/doc/SheepShaver

  install -Dm644 SheepShaver.desktop "$pkgdir"/usr/share/applications/SheepShaver.desktop
  install -Dm644 SheepShaver.png     "$pkgdir"/usr/share/pixmaps/SheepShaver.png
  install -Dm644 SheepShaver.sysctl  "$pkgdir"/etc/sysctl.d/90-SheepShaver.conf
}

package_sheepnet-dkms-git() {
  depends=('dkms')
  provides=("sheepnet-dkms=$pkgver")
  conflicts=("sheepnet-dkms")

  mkdir -p "$pkgdir"/usr/src
  cp -rL macemu/SheepShaver/src/Unix/Linux/NetDriver "$pkgdir"/usr/src/sheepnet-$pkgver

  cat > "$pkgdir"/usr/src/sheepnet-$pkgver/dkms.conf <<EOF
PACKAGE_NAME="sheepnet"
PACKAGE_VERSION="$pkgver"
AUTOINSTALL=yes
BUILT_MODULE_NAME="sheep_net"
DEST_MODULE_LOCATION="/kernel/net"
EOF
}

# vim: ts=2:sw=2:et:
