SUMMARY="Tool and library to extract CAB files from InstallShield installers"
DESCRIPTION="Unshield extracts CAB files from InstallShield installers, \
used to install software on Microsoft Windows based machines."
HOMEPAGE="https://github.com/twogood/unshield"
COPYRIGHT="2017 David Eriksson"
LICENSE="MIT"
REVISION="2"
SOURCE_URI="https://github.com/twogood/unshield/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="aa8c978dc0eb1158d266eaddcd1852d6d71620ddfc82807fe4bf2e19022b7bab"
SOURCE_FILENAME="unshield-$portVersion.tar.gz"

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

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

PROVIDES="
	unshield$secondaryArchSuffix = $portVersion
	cmd:unshield$secondaryArchSuffix = $portVersion
	lib:libunshield$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	unshield${secondaryArchSuffix}_devel = $portVersion
	devel:libunshield$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	unshield$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:c++$secondaryArchSuffix
	cmd:cc$secondaryArchSuffix
	cmd:cmake
	cmd:make
	"

TEST_REQUIRES="
	cmd:curl
	cmd:diff
	cmd:find
	cmd:unzip
	cmd:xargs
	"

BUILD()
{
	cmake . \
		$cmakeDirArgs \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_EXE_LINKER_FLAGS="-liconv"
	make $jobArgs
}

INSTALL()
{
	make install

	install -d -m 755 "$docDir" "$manDir" "$dataDir/expander/rules"
	install -t "$docDir" ChangeLog

	mv "$dataDir/man/man1" "$manDir/man1"
	rm -rf "$dataDir/man"

	cat > "$dataDir/expander/rules/unshield-expander-rules" << EOF
"application/x-installshield-cab"	.cab	"unshield$secondaryArchSuffix l %s"	"unshield$secondaryArchSuffix x %s"
EOF

	prepareInstalledDevelLib libunshield
	fixPkgconfig
	packageEntries devel "$developDir"
}

# The scripts called by run-tests.sh download a few files from the internet.
# The total size is currently around 10 MB.
TEST()
{
	LC_ALL=en_US UNSHIELD="$sourceDir"/src/unshield ./run-tests.sh
}
