SUMMARY="A makefile framework for writing simple makefiles for complex tasks"
DESCRIPTION="kBuild is a build framework derived from GNU make that delivers \
power and flexibility using makefiles that are easy to write and maintain. \
Its features include a template mechanism that simplifies configuration and \
a set of supporting tools that provide consistent behavior across multiple \
platforms."
HOMEPAGE="https://trac.netlabs.org/kbuild/"
COPYRIGHT="2005-2018 Knut St. Osmundsen"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://salsa.debian.org/pkg-virtualbox-team/kbuild/-/archive/upstream/0.1.9998svn3296+dfsg/kbuild-upstream-0.1.9998svn3296+dfsg.tar.bz2"
CHECKSUM_SHA256="30c025d076f561984932801c143d57e833386f6e96bf244d57d0f9074e59f683"
SOURCE_DIR="kbuild-upstream-0.1.9998svn3296+dfsg"
PATCHES="
	kbuild-0.1.9998svn3296-distribution.patch
	kbuild-0.1.9998svn3296-haiku.patch
	"

ARCHITECTURES="all !x86_gcc2"
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
fi

PROVIDES="
	kbuild$secondaryArchSuffix = $portVersion
	cmd:kDepIDB$secondaryArchSuffix  = $portVersion
	cmd:kDepObj$secondaryArchSuffix  = $portVersion
	cmd:kDepPre$secondaryArchSuffix  = $portVersion
	cmd:kmk$secondaryArchSuffix = $portVersion
	cmd:kmk_append$secondaryArchSuffix = $portVersion
	cmd:kmk_ash$secondaryArchSuffix = $portVersion
	cmd:kmk_cat$secondaryArchSuffix = $portVersion
	cmd:kmk_chmod$secondaryArchSuffix = $portVersion
	cmd:kmk_cmp$secondaryArchSuffix = $portVersion
	cmd:kmk_cp$secondaryArchSuffix = $portVersion
	cmd:kmk_echo$secondaryArchSuffix = $portVersion
	cmd:kmk_expr$secondaryArchSuffix = $portVersion
	cmd:kmk_gmake$secondaryArchSuffix = $portVersion
	cmd:kmk_install$secondaryArchSuffix = $portVersion
	cmd:kmk_ln$secondaryArchSuffix = $portVersion
	cmd:kmk_md5sum$secondaryArchSuffix = $portVersion
	cmd:kmk_mkdir$secondaryArchSuffix = $portVersion
	cmd:kmk_mv$secondaryArchSuffix = $portVersion
	cmd:kmk_printf$secondaryArchSuffix = $portVersion
	cmd:kmk_redirect$secondaryArchSuffix = $portVersion
	cmd:kmk_rm$secondaryArchSuffix = $portVersion
	cmd:kmk_rmdir$secondaryArchSuffix = $portVersion
	cmd:kmk_sed$secondaryArchSuffix = $portVersion
	cmd:kmk_sleep$secondaryArchSuffix = $portVersion
	cmd:kmk_test$secondaryArchSuffix = $portVersion
	cmd:kmk_time$secondaryArchSuffix = $portVersion
	cmd:kmk_touch$secondaryArchSuffix = $portVersion
	cmd:kObjCache$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autopoint
	cmd:autoreconf
	cmd:find
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:makeinfo
	cmd:yacc
	"

defineDebugInfoPackage kbuild$secondaryArchSuffix \
	$binDir/kDepIDB \
	$binDir/kDepObj \
	$binDir/kDepPre \
	$binDir/kmk \
	$binDir/kmk_append \
	$binDir/kmk_ash \
	$binDir/kmk_cat \
	$binDir/kmk_chmod \
	$binDir/kmk_cmp \
	$binDir/kmk_cp \
	$binDir/kmk_echo \
	$binDir/kmk_expr \
	$binDir/kmk_gmake \
	$binDir/kmk_install \
	$binDir/kmk_ln \
	$binDir/kmk_md5sum \
	$binDir/kmk_mkdir \
	$binDir/kmk_mv \
	$binDir/kmk_printf \
	$binDir/kmk_redirect \
	$binDir/kmk_rm \
	$binDir/kmk_rmdir \
	$binDir/kmk_sed \
	$binDir/kmk_sleep \
	$binDir/kmk_test \
	$binDir/kmk_time \
	$binDir/kmk_touch \
	$binDir/kObjCache

# Map our target architecture's name to the corresponding name used by kBuild
case $targetArchitecture in
	x86_gcc2) kbuildArch=x86;;
	x86_64) kbuildArch=amd64;;
	*) kbuildArch=$targetArchitecture;;
esac

BUILD()
{
	kBuild/env.sh --full make $jobArgs -f bootstrap.gmk
}

INSTALL()
{
	mkdir -p $binDir $dataDir/kBuild $dataDir/profile.d

	cp -R kBuild/bin/haiku.${kbuildArch}/* $binDir
	cp -R kBuild/{tools,units,*.kmk} $dataDir/kBuild

	kbuildProfile=$dataDir/profile.d/kbuild.sh
	echo "export KBUILD_PATH=$dataDir/kBuild" > $kbuildProfile
	echo "export KBUILD_BIN_PATH=$binDir" >> $kbuildProfile
}
