SUMMARY="A lightweight pkg-config replacement"
DESCRIPTION="A program which helps to configure compiler and linker flags for \
development libraries. It is similar to pkg-config from freedesktop.org."
HOMEPAGE="http://pkgconf.org/"
COPYRIGHT="2011-2018 pkgconf authors"
LICENSE="ISC"
REVISION="1"
SOURCE_URI="https://distfiles.dereferenced.org/pkgconf/pkgconf-$portVersion.tar.xz"
CHECKSUM_SHA256="d3468308553c94389dadfd10c4d1067269052b5364276a9d24a643c88485f715"
ADDITIONAL_FILES="pkgconf-gcc2.sh"

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

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

libVersion="3.0.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

GLOBAL_WRITABLE_FILES="
	$relativeSettingsDir/pkgconfig/personality.d directory
	"

PROVIDES="
	pkgconf$secondaryArchSuffix = $portVersion
	cmd:pkg_config$secondaryArchSuffix = $portVersion
	cmd:pkgconf$secondaryArchSuffix = $portVersion
	lib:libpkgconf$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"
CONFLICTS="
	pkgconfig$secondaryArchSuffix
	"

if [ "$targetArchitecture" = "x86_gcc2" ]; then
	PROVIDES+="
		cmd:pkg_config = $portVersion
		cmd:pkgconf = $portVersion
		"
	CONFLICTS+="
		pkgconfig
		"
fi

PROVIDES_devel="
	pkgconf${secondaryArchSuffix}_devel = $portVersion
	devel:libpkgconf$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	pkgconf$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:cmp
	cmd:diff
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:make
	cmd:sed
	"

TEST_REQUIRES="
	cmd:kyua$commandSuffix
	devel:libatf_c$secondaryArchSuffix
	"

defineDebugInfoPackage pkgconf$secondaryArchSuffix \
	"$binDir/pkgconf" \
	"$libDir/libpkgconf.so.$libVersion"

BUILD()
{
	runConfigure ./configure

	make $jobArgs
}

INSTALL()
{
	make install

	install -d -m 755 "$docDir" "$developDocDir"
	install -t "$docDir" -m 644 AUTHORS NEWS
	install -t "$developDocDir" -m 644 doc/*.rst

	ln -s pkgconf "$binDir/pkg-config"
	ln -s pkgconf.1 "$manDir/man1/pkg-config.1"

	if [ "$targetArchitecture" = "x86_gcc2" ]; then
		install -d -m 755 "$commandBinDir"
		install -m 755 "$portDir/additional-files/pkgconf-gcc2.sh" \
			"$commandBinDir/pkgconf"
		ln -s pkgconf "$commandBinDir/pkg-config"
	fi

	rm -f "$libDir"/*.la

	prepareInstalledDevelLib libpkgconf
	fixPkgconfig
	packageEntries devel \
		"$developDir"
}

TEST()
{
	make check
}
