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, macOS/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-2021 Florian Klaempfl and others"
LICENSE="GNU LGPL v3
	GNU GPL v3"
REVISION="1"
SOURCE_URI="https://downloads.sourceforge.net/freepascal/fpcbuild-$portVersion.tar.gz"
CHECKSUM_SHA256="85ef993043bb83f999e2212f1bca766eb71f6f973d362e2290475dbaaf50161f"
SOURCE_URI_2="https://sourceforge.net/projects/freepascal/files/Documentation/$portVersion/doc-pdf.tar.gz#noarchive"
CHECKSUM_SHA256_2="4dccbd4210995a94b76d1624a796c0abcf5118c0b92c487ab35a9d5a8bc68138"
SOURCE_FILENAME_2="doc-pdf-$portVersion.tar.gz"
SOURCE_DIR="fpcbuild-$portVersion"

ARCHITECTURES="all ?x86_gcc2"
SECONDARY_ARCHITECTURES="x86"
DISABLE_SOURCE_PACKAGE="yes"

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

PROVIDES="
	fpc$secondaryArchSuffix = $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$secondaryArchSuffix  >= 6.0
	"
PROVIDES_examples="
	fpc${secondaryArchSuffix}_examples
	"
REQUIRES_examples="
	fpc$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	binutils$secondaryArchSuffix
	cmd:tar
	cmd:make
	cmd:diff
	cmd:find
	cmd:which
	cmd:gcc$secondaryArchSuffix
	fpc_bin == 3.2.0
	"

if [ "$targetArchitecture" = x86_gcc2 ]; then
	BINARY_ARCH=i386
else
	BINARY_ARCH=x86_64
fi

BUILD()
{
	cp $sourceDir2/doc-pdf-$portVersion.tar.gz $sourceDir/doc-pdf.tar.gz

	rm -rf ${sourceDir}/fpc-${portVersion}.$BINARY_ARCH-haiku

	export CHECKLIBGDB=false
	install/makepack
}

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

#	cd $prefix

	mkdir -p $docDir/examples $prefix/lib/fpc/$portVersion/etc
	mv $prefix/doc/fpc-$portVersion/fpc/* $docDir
	mv $prefix/share/doc/fpc-$portVersion/* $docDir/examples
	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

	packageEntries examples \
		$docDir/examples
}
