### this file is sourced not run
PKGBUILD=1
PKGARCH=x86_64

# source: james
# website tarball
#TARBALL=pcsx2-1.6.0-source.zip
#MD5SUM=7a768d3a48b39e063612b8b2ebc1b061
#SRC_URL=http://distro.ibiblio.org/fatdog/source/800/$TARBALL

# release tarball
#PKGVER=1.6.0
#TARBALL=pcsx2-$PKGVER.tar.gz
#MD5SUM=51185d06f77b39df03e42fc68710c174
#SRC_URL=https://github.com/PCSX2/pcsx2/archive/v${PKGVER}.tar.gz
#BUNDLE=

# git-master tarball
PKGVER=1.6.0.2020.09 # or 1.7.0pre
MD5SUM=b2ea09351eca1ea4d6a3802de6a6c73e
hash=fd4f9aacf00102d5cb041ba59d99b10413f040e9
hash7=${hash#???????}; hash7=${hash%$hash7}
TARBALL=pcsx2-$PKGVER-$hash7.tar.gz
SRC_URL=https://github.com/PCSX2/pcsx2/archive/$hash.tar.gz

# we need specific version because wxwidgets 3.0.4 is compiled with SDL 1.2
SLACKREQ='wxwidgets >= 3.0.5
libaio libsoundtouch libSDL2
alsa-lib libportaudio gtk2 harfbuzz
eudev libX11 libpcap libxml2 freetype2 libpng32 xz'
# and opengl - Mesa or otherwise
# build-time: ninja and perl

SLACKDESC="pcsx2_64: pcsx2_64 $PKGVER (Playstation2 Emulator)
pcsx2_64: 
pcsx2_64: PCSX2 is a Playstation 2 'emulator', a free program that tries to 
pcsx2_64: replicate the Playstation 2 console to enable you to play PS2 games 
pcsx2_64: on your PC.
pcsx2_64: 
pcsx2_64: Note: You need BIOS file to use this, which is not included because 
pcsx2_64: it is copyrighted by Sony. Get it from your Playstation2 console.
pcsx2_64: 
pcsx2_64: https://pcsx2.net/
pcsx2_64: https://github.com/PCSX2/pcsx2
"
SLACKCONF='pcsx2'

### default pkg_download
### prepare
pkg_prepare() {

### This is when we use the zip file
#	if pkg_check $SRC_DIR $TARBALL $MD5SUM; then
#		unzip $SRC_DIR/$TARBALL -d tmp &&
#	else
#		return 1
#	fi

	pkg_prepare_default &&
	cd tmp/pcsx2-* &&

	# make sure we find the correct wx-config
	patch -Np1 < ../pkg/wx-config.patch	&&

	# make sure wx_sdl check is correct
	sed -i -e 's|"0"|"0\n"|' cmake/ApiValidation.cmake &&

	# SDL 1.2 compat patch if wxwidgets is compiled with SDL 1.2
	#sed -i -e '/SDL_GetNumAudioDrivers/ s|^|//|' \
	#	-e '/SDL_GetAudioDriver/ s|.*|m_sdl.Add("SDL Default");|' \
	#	plugins/spu2-x/src/wx/wxConfig.cpp

	true
}

### default pkg_package
### build
pkg_build() {
	cd tmp/pcsx2* &&

	# removing the PACKAGE_MODE resuls in portable-mode build
	# DCMAKE_INSTALL_PREFIX & DPLUGIN_DIR only works if PACKAGE_MODE=TRUE
	# --sdl12 is required if wxwidgets is compiled with SDL 1.2

	./build.sh --release --no-cross-multilib  \
		-DCMAKE_INSTALL_PREFIX=/usr           \
		-DPLUGIN_DIR=/usr/$LIBDIR/games/PCSX2 \
		-DDISABLE_PCSX2_WRAPPER=TRUE          \
		-DPACKAGE_MODE=TRUE && # --sdl12 &&

	pkg_build_slackdesc
}
