SUMMARY="A fast compiler cache"
DESCRIPTION="ccache speeds up recompilation by caching previous \
compilations and detecting when same compilation is being done again. \
Supported languages are C, C++, Objective-C and Objective-C++."
HOMEPAGE="https://ccache.samba.org/"
COPYRIGHT="2002-2007 Andrew Tridgell
	2009-2021 Joel Rosdahl and other contributors"
LICENSE="GNU GPL v3
	GNU LGPL v3"
REVISION="1"
SOURCE_URI="https://github.com/ccache/ccache/releases/download/v$portVersion/ccache-$portVersion.tar.xz"
CHECKSUM_SHA256="9200cafbaa5fd62c2600fccb40a18214e57747825e6cdcd76688b4b61c2dcba0"
PATCHES="ccache-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

GLOBAL_WRITABLE_FILES="settings/ccache.conf keep-old"
USER_SETTINGS_FILES="settings/ccache.conf"

# 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

PROVIDES="
	ccache$secondaryArchSuffix = $portVersion
	cmd:ccache$commandSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libhiredis$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libzstd$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libhiredis$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libzstd$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:xargs
	"

TEST_REQUIRES="
	cmd:awk
	cmd:cmp
	cmd:dirname
	cmd:head
	cmd:perl
	cmd:sed
	"

BUILD()
{
	cmake -B build -S . \
		$cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_BINDIR=$commandBinDir
	make -C build $jobArgs
}

INSTALL()
{
	make -C build install
	echo "# System-wide configuration for ccache" > $settingsDir/ccache.conf
}

TEST()
{
	make -C build check
}
