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

# source: james

# the source tarball is created this one:
# 1. Clone https://github.com/libretro/libretro-super libretro-super
# 2. cd libretro-super
# 3. SHALLOW_CLONE=1 ./libretro-fetch.sh
# 4. cd ..; tar -czvf libretro-super-$PKGVER.tar.gz libretro-super

# release tarball
PKGVER=1.9.0.2020.09
TARBALL=libretro-super-20200930.tar.gz
MD5SUM=620c7f3c45a0403923c162132b00521a
SRC_URL=http://distro.ibiblio.org/fatdog/source/800/$TARBALL
#BUNDLE=

SLACKREQ='ffmpeg libvulkan openal openssl libSDL2 libSDL-net' # and opengl / mesa

SLACKDESC="retroarch: retroarch $PKGVER (RetroArch multi-system emulator)
retroarch: 
retroarch: RetroArch is the reference frontend for the libretro API. Popular 
retroarch: examples of implementations for this API includes video game system 
retroarch: emulators and game engines as well as more generalized 3D programs.
retroarch: 
retroarch: https://www.libretro.com/
retroarch: https://github.com/libretro/RetroArch
retroarch: 
retroarch: 
retroarch: 
"

# other configurations
USE_EXPANDED_SOURCES=yes

### default pkg_download
### prepare
pkg_prepare() {
	if [ $USE_EXPANDED_SOURCES ]; then
		mkdir -p tmp/libretro-super &&
		mount -o bind /mnt/sda5/0test/libretro-super tmp/libretro-super
	else
		pkg_prepare_default
	fi
}

### default pkg_package

### build
pkg_build() {
	echo nameserver 8.8.8.8 > /etc/resolv.conf
	
	cd /tmp
	#return 1

	# clear our flags to avoid interference
	unset CFLAGS CXXFLAGS
	
	# from here: https://github.com/libretro/docs/blob/master/docs/development/retroarch/compilation/linux-and-bsd.md
	# modified for our use
	
	# default is to install to /usr/local, configure it to /usr instead	
	cd libretro-super*/retroarch  &&
	./configure --prefix=/usr --sysconfdir=/etc && cd .. &&

	# then build
	NOCLEAN=1 ./retroarch-build.sh &&
	NOCLEAN=1 ./libretro-build.sh  &&

	# then install
	cd retroarch &&
	make install &&
	cd ..        &&
	mkdir -p /usr/share/retroarch/cores              &&
	./libretro-install.sh /usr/share/retroarch/cores &&

	# finally install additional stuff - these install to /usr by default
	cd retroarch/media &&
	for p in shaders_cg libretrodb autoconfig; do
		cd $p &&
		make install &&
		cd ..
	done &&
	cp -a overlays /usr/share/retroarch &&

	pkg_build_slackdesc &&
	RET=$?

	rm -f /etc/resolv.conf

	if [ $USE_EXPANDED_SOURCES ]; then
		cd /tmp 
		umount /tmp/libretro-super
	fi
	return $RET
}
