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

# 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='wxwidgets32 >= 3.0.5
libaio32 libsoundtouch32 libSDL2_32
alsa-lib32 libportaudio32 gtk2_32 harfbuzz32
eudev32 libX11_32 libpcap32 libxml2_32 freetype2_32 libpng32 xz32'
# and opengl - Mesa or otherwise
# build-time: ninja and perl32

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

### 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
	#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() {
	# patch FindGTK2 so it doesn't grab lib64
	# do it here because this is a temporary patch
	sed -i -e '/lib64/d' /usr/share/cmake*/Modules/FindGTK2.cmake &&

	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 &&

	# delete our temporary patch
	rm -rf /usr/share/cmake* &&
	
	# all good
	pkg_build_slackdesc
}
