SUMMARY="A meta-build system that generates build files for Ninja"
DESCRIPTION="GN is a meta-build system that generates build files for Ninja"
HOMEPAGE="https://gn.googlesource.com/"
COPYRIGHT="2008-2019 The Chromium Authors."
LICENSE="BSD (3-clause)"
REVISION="1"
srcGitRev="5ed3c9cc67b090d5e311e4bd2aba072173e82db9"
SOURCE_URI="https://github.com/korli/gn/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="b018b5dbb484997dc0c0c693c4d7efbec76b8e26e845465c3cb7aba0e3d3db6c"
SOURCE_FILENAME="gn-$portVersion-$srcGitRev.tar.gz"
SOURCE_DIR="gn-$srcGitRev"
PATCHES="gn-$portVersion.patchset"

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

commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandBinDir=$prefix/bin
fi

PROVIDES="
	gn1731$secondaryArchSuffix = $portVersion
	cmd:gn = 1731 compat >= 1731
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"
CONFLICTS="
	gn$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:g++$secondaryArchSuffix
	cmd:ninja
	cmd:python2
	cmd:sed
	"

BUILD()
{
	export CC=gcc
	export CXX=g++

	GN_COMMIT_VERSION_SHORT=`echo $srcGitRev | cut -c 1-7`

	sed  -i \
		"s/(999999, 999999, \"091169b\")/(\"1731\", \"1731\", \"$GN_COMMIT_VERSION_SHORT\")/g" \
		build/gen.py

	python2 build/gen.py --host haiku --platform=haiku -d
	ninja -C out $jobArgs
}

INSTALL()
{
	mkdir -p $commandBinDir
	cp out/gn $commandBinDir
}

TEST()
{
	./out/gn_unittests
}
