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-2017 Florian Klaempfl and others"
LICENSE="GNU LGPL v3
	GNU GPL v3"
REVISION="3"
SOURCE_URI="https://downloads.sourceforge.net/freepascal/fpcbuild-$portVersion.tar.gz"
CHECKSUM_SHA256="f9b914eace989a023fb953da203dc0d973b44487568b4138c7d5b9613d7d6838"
SOURCE_URI_2="https://sourceforge.net/projects/freepascal/files/Documentation/$portVersion/doc-pdf.tar.gz#noarchive"
CHECKSUM_SHA256_2="5c4efe4709c387182d6da214bdd159f503ae9aa65c5c3e47c299cd7a03ed8de1"
SOURCE_DIR="fpcbuild-$portVersion"

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

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel >= r1~alpha4_pm_hrev51411
	"
BUILD_PREREQUIRES="
	binutils$secondaryArchSuffix
	cmd:tar
	cmd:make
	cmd:diff
	cmd:find
	cmd:which
	cmd:gcc
	fpc_bin == 3.0.4
	"


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

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

	export CHECKLIBGDB=false
	install/makepack
}

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

	cd $prefix

	mkdir -p $docDir/examples
	mkdir -p $binDir

	# on x86, we have to move binaries in the right directory
	if [ "$targetArchitecture" = x86 ]; then
		find bin -maxdepth 1 -type f -name "*" -exec mv {} $binDir \;
		ren $binDir/bin2obj $binDir/bin2obj$secondaryArchSuffix

		mkdir -p $libDir
		if [ -d lib/fpc ] ; then
			mv lib/fpc $libDir
		fi
	fi

	ln -s $libDir/fpc/$portVersion/ppc386 $binDir/ppc386
	mkdir -p $libDir/fpc/etc
	rm -dR $prefix/{doc,share}

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

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