SUMMARY="A Scheme interpreter and native Scheme to C compiler"
DESCRIPTION="CHICKEN is a compiler for the Scheme programming language. \
CHICKEN produces portable and efficient C, supports almost all of the R5RS \
Scheme language standard, and includes many enhancements and extensions. \
CHICKEN runs on Linux, MacOS X, Windows, and many Unix flavours."
HOMEPAGE="http://www.call-cc.org/"
COPYRIGHT="2008-2020 The Chicken Team
	2000-2007 Felix L. Winkelmann"
LICENSE="BSD (2-clause)"
REVISION="1"
SOURCE_URI="http://code.call-cc.org/releases/$portVersion/chicken-$portVersion.tar.gz"
CHECKSUM_SHA256="819149c8ce7303a9b381d3fdc1d5765c5f9ac4dee6f627d1652f47966a8780fa"

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

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

GLOBAL_WRITABLE_FILES="
	non-packaged/lib/chicken/11 directory keep-old
	"

PROVIDES="
	chicken$secondaryArchSuffix = $portVersion
	cmd:csi$commandSuffix = $portVersion
	cmd:csc$commandSuffix = $portVersion
	cmd:chicken$commandSuffix = $portVersion
	cmd:chicken_install$commandSuffix = $portVersion
	cmd:chicken_profile$commandSuffix = $portVersion
	cmd:chicken_status$commandSuffix = $portVersion
	cmd:chicken_uninstall$commandSuffix = $portVersion
	cmd:chicken_do$commandSuffix = $portVersion
	cmd:feathers$commandSuffix = $portVersion
	lib:libchicken$secondaryArchSuffix = 11 compat >= 11
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	chicken${secondaryArchSuffix}_devel = $portVersion
	devel:libchicken$secondaryArchSuffix = 11 compat >= 11
	"
REQUIRES_devel="
	chicken$secondaryArchSuffix == $portVersion base
	"

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

PATCH()
{
if [ "$effectiveTargetArchitecture" = x86_gcc2 ]; then
	echo "Removing -fwrapv flag for gcc2 build"
	sed -i 's/-fwrapv//' Makefile.haiku
fi
	echo "Removing git check"
	sed -i 's/sh $(SRCDIR)identify.sh/echo/' rules.make
}

TEST_REQUIRES="
	cmd:diff
	"

BUILD()
{
	# odd timestamp issue
	touch build-version.c

	make PLATFORM=haiku \
		PREFIX=$prefix \
		BINDIR=$commandBinDir \
		LIBDIR=$libDir \
		SHAREDIR=$dataDir \
		MANDIR=$manDir \
		DOCDIR=$docDir \
		INCLUDEDIR=$includeDir \
		EGGDIR=$prefix/non-packaged/lib/chicken/11 \
		HOSTNAME=shredder
}

INSTALL()
{
	mkdir -p $prefix/non-packaged/lib/chicken/11

	make install PLATFORM=haiku \
		PREFIX=$prefix \
		BINDIR=$commandBinDir \
		LIBDIR=$libDir \
		SHAREDIR=$dataDir \
		MANDIR=$manDir \
		DOCDIR=$docDir \
		INCLUDEDIR=$includeDir \
		HOSTNAME=shredder

	prepareInstalledDevelLibs libchicken
	fixPkgconfig

	packageEntries devel \
		$developDir
}

TEST()
{
	if ! type -p csi > /dev/null;then
		echo "ERROR: Chicken must be installed before running the test suite"
		exit 1
	fi
	make PLATFORM=haiku PREFIX=$prefix check
}
