SUMMARY="Professional Pascal compiler"
DESCRIPTION="Free Pascal is a 32, 64 and 16 bit professional Pascal compiler. \
It can target many processor architectures: Intel x86 (including 8086), AMD64\
/x86-64, PowerPC, PowerPC64, SPARC, ARM, AArch64, MIPS and the JVM. \
Supported operating systems include Linux, FreeBSD, Haiku, Mac OS X/iOS/\
iPhoneSimulator/Darwin, DOS (16 and 32 bit), Win32, Win64, WinCE, OS/2, \
MorphOS, Nintendo GBA, Nintendo DS, Nintendo Wii, Android, AIX and AROS. \
Additionally, support for the Motorola 68k architecture is available in the \
development versions."
HOMEPAGE="https://freepascal.org/"
COPYRIGHT="1993-2020 Florian Klaempfl and others"
LICENSE="GNU LGPL v3
	GNU GPL v3"
REVISION="2"
if [ "$targetArchitecture" = x86_gcc2 ]; then
	BINARY_ARCH=i386
	CHECKSUM_SHA256="686fb58bd8939ab7ca41e3b9b518f3d187b9ee1fd14367dea63bc55564617fa2"
else
	BINARY_ARCH=x86_64
	CHECKSUM_SHA256="7a0ab7a480c5e2fed30396b9f80ca94154ee1f4e8508f071fa95b2fed6d941e7"
fi
SOURCE_URI="https://sourceforge.net/projects/freepascal/files/Haiku/$portVersion/fpc-$portVersion.$BINARY_ARCH-haiku.tar"
SOURCE_DIR="fpc-$portVersion.$BINARY_ARCH-haiku"

ARCHITECTURES="all"
DISABLE_SOURCE_PACKAGE="YES"

POST_INSTALL_SCRIPTS="
	boot/post-install/createcfg.sh
	"

PROVIDES="
	fpc_bin = $portVersion
	cmd:bin2obj = $portVersion
	cmd:chmcmd = $portVersion
	cmd:chmls = $portVersion
	cmd:compileserver = $portVersion
	cmd:cvsco.tdf = $portVersion
	cmd:cvsdiff.tdf = $portVersion
	cmd:cvsup.tdf = $portVersion
	cmd:data2inc = $portVersion
	cmd:delp = $portVersion
	cmd:fd2pascal = $portVersion
	cmd:fp = $portVersion
	cmd:fp.ans = $portVersion
	cmd:fp.rsj = $portVersion
	cmd:fpc = $portVersion
	cmd:fpcjres = $portVersion
	cmd:fpclasschart = $portVersion
	cmd:fpclasschart.rsj = $portVersion
	cmd:fpcmake = $portVersion
	cmd:fpcmkcfg = $portVersion
	cmd:fpcmkcfg.rsj = $portVersion
	cmd:fpcres = $portVersion
	cmd:fpcsubst = $portVersion
	cmd:fpcsubst.rsj = $portVersion
	cmd:fpdoc = $portVersion
	cmd:fppkg = $portVersion
	cmd:fprcp = $portVersion
	cmd:gplprog.pt = $portVersion
	cmd:gplunit.pt = $portVersion
	cmd:grep.tdf = $portVersion
	cmd:h2pas = $portVersion
	cmd:h2paspp = $portVersion
	cmd:instantfpc = $portVersion
	cmd:makeskel = $portVersion
	cmd:makeskel.rsj = $portVersion
	cmd:mkarmins = $portVersion
	cmd:mkinsadd = $portVersion
	cmd:mkx86ins = $portVersion
	cmd:pas2fpm = $portVersion
	cmd:pas2jni = $portVersion
	cmd:pas2ut = $portVersion
	cmd:pas2ut.rsj = $portVersion
	cmd:plex = $portVersion
	cmd:postw32 = $portVersion
	cmd:ppdep = $portVersion
	cmd:ppudump = $portVersion
	cmd:ppufiles = $portVersion
	cmd:ppumove = $portVersion
	cmd:program.pt = $portVersion
	cmd:ptop = $portVersion
	cmd:ptop.rsj = $portVersion
	cmd:pyacc = $portVersion
	cmd:rmcvsdir = $portVersion
	cmd:rstconv = $portVersion
	cmd:rstconv.rsj = $portVersion
	cmd:tpgrep.tdf = $portVersion
	cmd:unit.pt = $portVersion
	cmd:unitdiff = $portVersion
	cmd:unitdiff.rsj = $portVersion
	cmd:json2pas = $portVersion
	cmd:mka64ins = $portVersion
	cmd:pas2js = $portVersion
	cmd:webidl2pas = $portVersion
	lib:libpas2jslib = $portVersion
	"
if [ "$targetArchitecture" = x86_gcc2 ]; then
	PROVIDES="$PROVIDES
		cmd:ppc386 = $portVersion
		"
else
	PROVIDES="$PROVIDES
		cmd:ppcx64 = $portVersion
		"
fi
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libncurses >= 6.0
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	binutils
	cmd:tar
	"

BUILD()
{
	true
}

INSTALL()
{
	for f in `tar tf binary.$BINARY_ARCH-haiku.tar`; do
		tar -xOf binary.$BINARY_ARCH-haiku.tar $f | tar -C $prefix -xzf -
	done

	mkdir -p $docDir $prefix/lib/fpc/$portVersion/etc
	mv $prefix/doc/fpc-$portVersion/fpc/* $docDir
	rm -dR $prefix/{doc,share}

	if [ "$targetArchitecture" = x86_gcc2 ]; then
		ln -s $prefix/lib/fpc/$portVersion/ppc386 $prefix/bin/ppc386
	else
		ln -s $prefix/lib/fpc/$portVersion/ppcx64 $prefix/bin/ppcx64
	fi

	# create post script
	mkdir -p $prefix/boot/post-install
	echo "#!/bin/sh" > $postInstallDir/createcfg.sh
	echo "/boot/system/lib/fpc/$portVersion/samplecfg \
/boot/system/lib/fpc/$portVersion /etc" >> $postInstallDir/createcfg.sh
	chmod 755 $postInstallDir/createcfg.sh
}
