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/" 
SRC_URI="http://code.call-cc.org/releases/4.8.0/chicken-4.8.0.5.tar.gz"
CHECKSUM_SHA256="5b9192951bc61cc19dd4963cceb93908bff46b6868d7927f19850e8973c430fb"
REVISION="1"
LICENSE="BSD (2-clause)"
COPYRIGHT="2008-2013 The Chicken Team
		2000-2007 Felix L. Winkelmann"

ARCHITECTURES="?x86 ?x86_gcc2"

PROVIDES="
	chicken = $portVersion compat >= 4.8
	cmd:csi = $portVersion compat >= 4.8
	cmd:csc = $portVersion compat >= 4.8
	cmd:chicken = $portVersion compat >= 4.8
	cmd:chicken_bug = $portVersion compat >= 4.8
	cmd:chicken_install = $portVersion compat >= 4.8
	cmd:chicken_profile = $portVersion compat >= 4.8
	cmd:chicken_status = $portVersion compat >= 4.8
	cmd:chicken_uninstall = $portVersion compat >= 4.8
	lib:libchicken = $portVersion compat >= 4.8
	"

REQUIRES="
	haiku >= $haikuVersion
	cmd:gcc
	cmd:ld
	"

BUILD_REQUIRES="
	"

BUILD_PREREQUIRES="
	haiku_devel >= $haikuVersion
	cmd:gcc
	cmd:make
	cmd:ld
	"

PROVIDES_devel="
	chicken_devel = $portVersion
	devel:libchicken = $portVersion
	"

REQUIRES_devel="
	chicken == $portVersion
	"


PATCH()
{
if [ "$targetArchitecture" = 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
}

PATCHES="chicken-4.8.0.5.patchset"

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

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

	make PLATFORM=haiku PREFIX=$prefix \
	MANDIR=$manDir/man1 \
	DOCDIR=$docDir \
	DATADIR=$dataDir/chicken \
	INCDIR=$includeDir/chicken \
	HOSTNAME=shredder
}

INSTALL()
{
	make install PLATFORM=haiku PREFIX=$prefix \
	MANDIR=$manDir/man1 \
	DOCDIR=$docDir \
	DATADIR=$dataDir/chicken \
	INCDIR=$includeDir/chicken \
	HOSTNAME=shredder

	prepareInstalledDevelLibs libchicken
	packageEntries devel $developDir
	
	rm -rf $prefix/share
}

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
}
