SUMMARY="MTP initiator library"
DESCRIPTION="libmtp implements an MTP initiator, which means it initiates MTP \
sessions with devices. The devices responding are known as MTP responders. \
libmtp runs on something with a USB host controller interface, using libusb to \
access the host controller."
HOMEPAGE="http://libmtp.sourceforge.net/"
COPYRIGHT="2006-2011 Linus Walleij
	2006-2010 Richard Low
	2006-2009 Marcus Meissner
	2006 Mariusz Woloszyn"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://downloads.sourceforge.net/libmtp/libmtp-$portVersion.tar.gz"
CHECKSUM_SHA256="deb4af6f63f5e71215cfa7fb961795262920b4ec6cb4b627f55b30b18aa33228"
PATCHES="libmtp-$portVersion.patchset"

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

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

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

PROVIDES="
	libmtp$secondaryArchSuffix = $portVersion compat >= 1.0
	cmd:mtp_albumart$commandSuffix = $portVersion
	cmd:mtp_albums$commandSuffix = $portVersion
	cmd:mtp_connect$commandSuffix = $portVersion
	cmd:mtp_delfile$commandSuffix = $portVersion
	cmd:mtp_detect$commandSuffix = $portVersion
	cmd:mtp_emptyfolders$commandSuffix = $portVersion
	cmd:mtp_files$commandSuffix = $portVersion
	cmd:mtp_filetree$commandSuffix = $portVersion
	cmd:mtp_folders$commandSuffix = $portVersion
	cmd:mtp_format$commandSuffix = $portVersion
	cmd:mtp_getfile$commandSuffix = $portVersion
	cmd:mtp_getplaylist$commandSuffix = $portVersion
	cmd:mtp_newfolder$commandSuffix = $portVersion
	cmd:mtp_newplaylist$commandSuffix = $portVersion
	cmd:mtp_playlists$commandSuffix = $portVersion
	cmd:mtp_reset$commandSuffix = $portVersion
	cmd:mtp_sendfile$commandSuffix = $portVersion
	cmd:mtp_sendtr$commandSuffix = $portVersion
	cmd:mtp_thumb$commandSuffix = $portVersion
	cmd:mtp_tracks$commandSuffix = $portVersion
	cmd:mtp_trexist$commandSuffix = $portVersion
	lib:libmtp$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgcrypt$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libusb_1.0$secondaryArchSuffix
	# required by libgcrypt
	lib:libgpg_error$secondaryArchSuffix
	"

PROVIDES_devel="
	libmtp${secondaryArchSuffix}_devel = $portVersion compat >= 1.0
	devel:libmtp$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	libmtp$secondaryArchSuffix == $portVersion base
	devel:libusb_1.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libgcrypt$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libusb_1.0$secondaryArchSuffix
	# required by libgcrypt
	devel:libgpg_error$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal >= 1.15
	cmd:autoconf
	cmd:automake
#	cmd:doxygen
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:gettext$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage libmtp$secondaryArchSuffix \
	"$commandBinDir"/mtp-albumart \
	"$commandBinDir"/mtp-albums \
	"$commandBinDir"/mtp-connect \
	"$commandBinDir"/mtp-detect \
	"$commandBinDir"/mtp-emptyfolders \
	"$commandBinDir"/mtp-files \
	"$commandBinDir"/mtp-filetree \
	"$commandBinDir"/mtp-folders \
	"$commandBinDir"/mtp-format \
	"$commandBinDir"/mtp-getplaylist \
	"$commandBinDir"/mtp-newplaylist \
	"$commandBinDir"/mtp-playlists \
	"$commandBinDir"/mtp-reset \
	"$commandBinDir"/mtp-thumb \
	"$commandBinDir"/mtp-tracks \
	"$commandBinDir"/mtp-trexist \
	"$libDir"/libmtp.so.$libVersion

BUILD()
{
	autoreconf -fi
	runConfigure --omit-dirs binDir ./configure --bindir=$commandBinDir \
		# --enable-doxygen
	make $jobArgs
}

INSTALL()
{
	make install

	rm $libDir/libmtp.la

	prepareInstalledDevelLib libmtp
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir # $docDir
}

TEST()
{
	make check
}
