SUMMARY="A software construction tool"
DESCRIPTION="SCons is an open-source software construction tool - that is, a \
next-generation build tool. Think of SCons as an improved, cross-platform \
substitute for the classic Make utility with integrated functionality similar \
to autoconf/automake and compiler caches such as ccache. In short, SCons is \
an easier, more reliable and faster way to build software."
HOMEPAGE="https://www.scons.org/"
COPYRIGHT="2001-2019 The SCons Foundation"
LICENSE="MIT"
REVISION="4"
SOURCE_URI="https://github.com/scons/scons/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="f758368332adb4436a2ede6340e95922f1c62a6dc03609dad376b22aa47ae3d8"
SOURCE_FILENAME="scons-$portVersion.tar.gz"
PATCHES="scons-$portVersion.patchset"

ARCHITECTURES="all"

PROVIDES="
	scons = $portVersion compat >= 3
	cmd:scons = $portVersion compat >= 3
	cmd:scons_$portVersion = $portVersion compat >= 3
	cmd:scons_configure_cache = $portVersion compat >= 3
	cmd:scons_configure_cache_$portVersion = $portVersion compat >= 3
	cmd:scons_time = $portVersion compat >= 3
	cmd:scons_time_$portVersion = $portVersion compat >= 3
	cmd:sconsign = $portVersion compat >= 3
	cmd:sconsign_$portVersion = $portVersion compat >= 3
	"
REQUIRES="
	haiku
	cmd:python3
	"

BUILD_REQUIRES="
	haiku_devel
	"
BUILD_PREREQUIRES="
	cmd:python3
	cmd:sed
	"
TEST_REQUIRES="
	cmd:gcc
	"

PATCH()
{
	copyright='Copyright (c) 2001 - 2019 The SCons Foundation'
	release='2019-12-17'
	for file in `find . -iname "*.py" -type f`; do
		sed -i \
		-e "s|__COPYRIGHT__|$copyright|g" \
		-e "s|__DATE__|$release|g" \
		-e "s|__BUILDSYS__|none|g" \
		-e "s|__DEVELOPER__|none|g" \
		-e "s|__REVISION__|none|g" \
		-e "s|__FILE__|$file|g" \
		-e "s|__VERSION__|$portVersion|g" \
		$file
	done
}

BUILD()
{
	# prepare scripts
	for _script in scons{,ign,-time,-configure-cache}; do
		cp src/script/${_script}.py src/script/${_script}
	done
	(
		python3 bootstrap.py SConstruct doc
	)
	(
		cd src
		python3 setup.py build
	)
}

INSTALL()
{
	cd src
	python3 setup.py install \
		--prefix="$prefix" \
		--install-data="$documentationDir" \
		--symlink-scons \
		--standard-lib \
		--no-install-bat \
		--no-install-man
	sed -i s/python/python3/ $binDir/scons
}

TEST()
{
	python3 ./runtest.py -a -t
}
