SUMMARY="Automatically generate compilation database for Clang tooling"
DESCRIPTION="Bear records the flags passed to the compiler for each translation unit and \
stores them in a JSON file. This file can be used by Clang's tooling interface \
and programs like clang-check to process a translation unit.\
\
cmake supports the generation of JSON compilation databases out of the box. \
For any other build system that does not support this, Bear can be used \
instead to intercept the invocation of the compiler."
HOMEPAGE="https://github.com/rizsotto/Bear"
COPYRIGHT="2012-2022 by László Nagy"
LICENSE="GNU GPL v3"
REVISION="1"
SOURCE_URI="https://github.com/rizsotto/Bear/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="ae94047c79b4f48462b66981f66a67b6a833d75d4c40e7afead491b1865f1142"
SOURCE_DIR="Bear-$portVersion"
PATCHES="bear-$portVersion.patchset"

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

PROVIDES="
	bear$secondaryArchSuffix = $portVersion
	cmd:bear = $portVersion compat >= 3
	cmd:citnames = $portVersion compat >= 3
	cmd:intercept = $portVersion compat >= 3
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libabsl_bad_optional_access$secondaryArchSuffix
	lib:libabsl_bad_variant_access$secondaryArchSuffix
	lib:libabsl_base$secondaryArchSuffix
	lib:libabsl_city$secondaryArchSuffix
	lib:libabsl_civil_time$secondaryArchSuffix
	lib:libabsl_cord$secondaryArchSuffix
	lib:libabsl_debugging_internal$secondaryArchSuffix
	lib:libabsl_demangle_internal$secondaryArchSuffix
	lib:libabsl_exponential_biased$secondaryArchSuffix
	lib:libabsl_graphcycles_internal$secondaryArchSuffix
	lib:libabsl_hash$secondaryArchSuffix
	lib:libabsl_hashtablez_sampler$secondaryArchSuffix
	lib:libabsl_int128$secondaryArchSuffix
	lib:libabsl_log_severity$secondaryArchSuffix
	lib:libabsl_malloc_internal$secondaryArchSuffix
	lib:libabsl_raw_hash_set$secondaryArchSuffix
	lib:libabsl_raw_logging_internal$secondaryArchSuffix
	lib:libabsl_spinlock_wait$secondaryArchSuffix
	lib:libabsl_stacktrace$secondaryArchSuffix
	lib:libabsl_status$secondaryArchSuffix
	lib:libabsl_statusor$secondaryArchSuffix
	lib:libabsl_strings$secondaryArchSuffix
	lib:libabsl_strings_internal$secondaryArchSuffix
	lib:libabsl_str_format_internal$secondaryArchSuffix
	lib:libabsl_symbolize$secondaryArchSuffix
	lib:libabsl_synchronization$secondaryArchSuffix
	lib:libabsl_throw_delegate$secondaryArchSuffix
	lib:libabsl_time$secondaryArchSuffix
	lib:libabsl_time_zone$secondaryArchSuffix
	lib:libaddress_sorting$secondaryArchSuffix
	lib:libcares$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libfmt$secondaryArchSuffix
	lib:libgpr$secondaryArchSuffix
	lib:libgrpc++$secondaryArchSuffix
	lib:libgrpc$secondaryArchSuffix
	lib:libprotobuf$secondaryArchSuffix
	lib:libre2$secondaryArchSuffix
	lib:libspdlog$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libupb$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfmt$secondaryArchSuffix
	devel:libgrpc$secondaryArchSuffix
	devel:libgtest$secondaryArchSuffix
	devel:libspdlog$secondaryArchSuffix
	devel:nlohmann_json$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	cmake -B build -S . -DCMAKE_INSTALL_PREFIX=$prefix \
		-DCMAKE_BUILD_TYPE=Release
	unset -f cmake
	cmake --build build $jobArgs
}

INSTALL()
{
	unset -f cmake
	cmake --install build

	mkdir -vp $manDir
	cp -vrd $prefix/share/man/man1 $manDir

	mkdir -p $dataDir
	mv -v $prefix/share $dataDir
}
