SUMMARY="A library for manipulating disk image files"
DESCRIPTION="LIBDSK is a library for accessing discs and disc image files. \
It is intended for use in:
* Emulator tools - converting between real floppy discs and disc images, as \
CPCTRANS / PCWTRANS do under DOS.
* Filesystem utilities - CPMTOOLS is configurable to use LIBDSK, thus allowing \
the use of CPMTOOLS on emulator .DSK images. To do this, install LIBDSK and \
then build CPMTOOLS, using \"./configure --with-libdsk\". For CPMTOOLS 1.9 or \
2.0, you will also need to apply this patch.
* Emulators - it is possible to use LIBDSK as part of an emulator's floppy \
controller emulation, thus giving the emulator transparent access to .DSK \
files or real discs."
HOMEPAGE="http://www.seasip.info/Unix/LibDsk/"
COPYRIGHT="2010-2018 John Elliott"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="http://www.seasip.info/Unix/LibDsk/libdsk-$portVersion.tar.gz"
CHECKSUM_SHA256="0d3b4dbe1986682bd38fa3cb50aa6f37190f8adac32e0b9f88644df9ccbcbeb9"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

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

PROVIDES="
	libdsk$secondaryArchSuffix = $portVersion
	lib:libdsk$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

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

if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES_tools="
		libdsk_tools = $portVersion
		cmd:apriboot = $portVersion
		cmd:dskconv = $portVersion
		cmd:dskdump = $portVersion
		cmd:dskform = $portVersion
		cmd:dskid = $portVersion
		cmd:dskscan = $portVersion
		cmd:dsktrans = $portVersion
		cmd:dskutil = $portVersion
		cmd:md3serial = $portVersion
		"
	REQUIRES_tools="
		libdsk == $portVersion base
		haiku
		lib:libbz2
		lib:libdsk
		lib:libz
		"
fi

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	"

defineDebugInfoPackage libdsk$secondaryArchSuffix \
	"$libDir"/libdsk.so.$libVersion

BUILD()
{
	runConfigure ./configure
	make $jobArgs
}

INSTALL()
{
	make install

	# remove command for secondary architecture
	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf "$binDir"
	fi

	rm -f "$libDir"/libdsk.la

	prepareInstalledDevelLib libdsk

	mkdir -p "$developLibDir"/pkgconfig
	cat > "$developLibDir"/pkgconfig/libdsk.pc << EOF
prefix=${prefix}
exec_prefix=${prefix}
libdir=${libDir}
includedir=${includeDir}

Name: libdsk
Description: Library for accessing discs and disc image files
Version: $portVersion
Libs: -L${developLibDir} -ldsk
Cflags: -I${includeDir}
EOF

	packageEntries devel \
		"$developDir"

	if [ -z "$secondaryArchSuffix" ]; then
		packageEntries tools \
			"$binDir"
	fi
}

TEST()
{
	make check
}
