SUMMARY="A port of PicoDrive, a Sega 16bit emulator to the libretro API"
DESCRIPTION="PicoDrive is a Megadrive / Genesis / Sega CD / Mega CD / 32X \
emulator, focusing on performance."
HOMEPAGE="http://notaz.gp2x.de/pico.php"
COPYRIGHT="2005-2018 notaz, the libretro team"
LICENSE="GNU LGPL v2.1"
REVISION="1"
srcGitRev="d44605c269e645a6734089ac1f95116a5ce57e0b"
SOURCE_URI="https://github.com/libretro/picodrive/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="4d37ff162d1aa646a41f0de9bc8549d7d1562c6182e4536d788a2c1a7ea14e96"
SOURCE_FILENAME="libretro-picodrive-${portVersion/_/-}-$srcGitRev.tar.gz"
SOURCE_DIR="picodrive-$srcGitRev"
srcGitRev_2="94a9d9a888e72cbfa4db12113cd113cf5e154f7f"
SOURCE_URI_2="https://github.com/notaz/cyclone68000/archive/$srcGitRev_2.tar.gz"
CHECKSUM_SHA256_2="1bd2f6558b3cf276ed6d895df303c3e8fc45e501017b10c2f96b35a73d052401"
SOURCE_FILENAME_2="cyclone68000-$srcGitRev_2.tar.gz"
SOURCE_DIR_2="cyclone68000-$srcGitRev_2"
srcGitRev_3="ff3175ddb040b1a967c665a28868b16bf5aa97dd"
SOURCE_URI_3="https://github.com/irixxxx/libchdr-picodrive/archive/$srcGitRev_3.tar.gz"
CHECKSUM_SHA256_3="0684ee076fb288cf52fcf4451463043c23db3e37dc43b478ca7f80196803bded"
SOURCE_FILENAME_3="libchdr-picodrive-$srcGitRev_3.tar.gz"
SOURCE_DIR_3="libchdr-picodrive-$srcGitRev_3"
srcGitRev_4="9f1dcf848d0e33e775e49352f7bc83a9c0e87a81"
SOURCE_URI_4="https://github.com/digital-sound-antiques/emu2413/archive/$srcGitRev_4.tar.gz"
CHECKSUM_SHA256_4="e8341a5dad1d9eb1f6c0acb9fbdc7d41e2739699e568a60da8a00d9e628ce351"
SOURCE_FILENAME_4="emu2413-$srcGitRev_4.tar.gz"
SOURCE_DIR_4="emu2413-$srcGitRev_4"
srcGitRev_5="d57c9992201e065f8caf6ce68247195ff98e8420"
SOURCE_URI_5="https://github.com/irixxxx/libpicofe/archive/$srcGitRev_5.tar.gz"
CHECKSUM_SHA256_5="4e5172e2374aee49d65e7283fa88ee4ff17e145721e2dd98468d1b6db4a7851d"
SOURCE_FILENAME_5="libpicofe-$srcGitRev_5.tar.gz"
SOURCE_DIR_5="libpicofe-$srcGitRev_5"
srcGitRev_6="343aa923439e59e7a9f7726f70edc77a4500bdec"
SOURCE_URI_6="https://github.com/mackron/dr_libs/archive/$srcGitRev_6.tar.gz"
CHECKSUM_SHA256_6="02066f139aa14c1aa986b103624e36493d6a895125a565e770709754196362f0"
SOURCE_FILENAME_6="dr_libs-$srcGitRev_6.tar.gz"
SOURCE_DIR_6="dr_libs-$srcGitRev_6"
srcGitRev_7="95864e8e0d3b34402a49ae9af6c66f7e98c13c35"
SOURCE_URI_7="https://github.com/lieff/minimp3/archive/$srcGitRev_7.tar.gz"
CHECKSUM_SHA256_7="033fd7eab9ab2fbf70070e76c85d41cecaab6e1d59c52725f8b6bbcc453282ee"
SOURCE_FILENAME_7="minimp3-$srcGitRev_7.tar.gz"
SOURCE_DIR_7="minimp3-$srcGitRev_7"
ADDITIONAL_FILES="picodrive_libretro.info.in"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	picodrive_libretro$secondaryArchSuffix = $portVersion
	addon:picodrive_libretro$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	retroarch$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:awk
	cmd:find
	"

BUILD()
{
	sed -e "s/@DISPLAY_VERSION@/v${portVersion/_/-}/" \
		$portDir/additional-files/picodrive_libretro.info.in \
		> picodrive_libretro.info
	# Remove directories from submodules and copy them
	rm -rf cpu/cyclone
	cp -r $sourceDir2 cpu/cyclone
	rm -rf pico/cd/libchdr
	cp -r $sourceDir3 pico/cd/libchdr
	rm -rf pico/sound/emu2413
	cp -r $sourceDir4 pico/sound/emu2413
	rm -rf platform/libpicofe
	cp -r $sourceDir5 platform/libpicofe
	rm -rf platform/common/dr_libs
	cp -r $sourceDir6 platform/common/dr_libs
	rm -rf platform/common/minimp3
	cp -r $sourceDir7 platform/common/minimp3
	# Build the core
	make -f Makefile.libretro $jobArgs

}

INSTALL()
{
	install -m 0755 -d "$docDir"
	install -m 0644 -t "$docDir" AUTHORS COPYING README
	install -m 0755 -d "$addOnsDir"/libretro
	install -m 0644 -t "$addOnsDir"/libretro \
		picodrive_libretro.info \
		picodrive_libretro.so
}
