SUMMARY="Library and tool for working with Microsoft cabinet archives"
DESCRIPTION="gcab is command line tool that can list, extract and create \
cabinet (.cab) archives. The Cabinet format is often used on Microsoft Windows \
but it can also be used on other systems with open source software such as \
cabextract, lcab and gcab. Unlike cabextract and lcab, which can only list \
and extract cabinet archives, gcab can also create them.
gcab also includes a GObject shared library, libgcab, which provides all the \
functionality available to the command line tool."
HOMEPAGE="https://wiki.gnome.org/msitools"
COPYRIGHT="2000-2002 Stuart Caie
	2002 Patrik Stridvall
	2003 Greg Turner
	2012 Marc-André Lureau
	2017 Richard Hughes"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://download.gnome.org/sources/gcab/$portVersion/gcab-$portVersion.tar.xz"
CHECKSUM_SHA256="67a5fa9be6c923fbc9197de6332f36f69a33dadc9016a2b207859246711c048f"

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

# 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

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

PROVIDES="
	gcab$secondaryArchSuffix = $portVersion
	cmd:gcab$commandSuffix = $portVersion
	lib:libgcab_1.0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix >= 0.4600.2
	lib:libintl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	gcab${secondaryArchSuffix}_devel = $portVersion
	devel:libgcab_1.0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	gcab$secondaryArchSuffix == $portVersion base
	devel:libglib_2.0$secondaryArchSuffix >= 0.4600.2
	devel:libintl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libgettextlib$secondaryArchSuffix >= 0.14.1
	devel:libglib_2.0$secondaryArchSuffix >= 0.4600.2
	devel:libintl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:gtkdoc_scan
	cmd:ld$secondaryArchSuffix
	cmd:meson
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage gcab$secondaryArchSuffix \
	"$libDir"/libgcab-1.0.so.$libVersion

BUILD()
{
	export CFLAGS=-fno-stack-protector
	meson build -Dintrospection=false \
		--buildtype=release --prefix=$prefix \
		--libdir=$libDir --includedir=$includeDir
	ninja -C build
}

INSTALL()
{
	ninja -C build install

	mkdir -p $dataDir
	mv $prefix/share/gtk-doc $dataDir
	rm -rf $prefix/share

	prepareInstalledDevelLibs \
		libgcab-1.0
	fixPkgconfig

	packageEntries devel \
		$developDir \
		$dataDir/gtk-doc
}

TEST()
{
	meson test -C build
}
