SUMMARY="An open source library to talk to FTDI chips"
DESCRIPTION="libFTDI is an open source library to talk to FTDI chips: FT232BM, FT245BM, \
FT2232C, FT2232D, FT245R and FT232H including the popular bitbang mode. The \
library is linked with your program in userspace, no kernel driver required.\
libFTDI works perfectly with Linux, Windows, MacOS X and BSD variants thanks to \
libusb."
HOMEPAGE="https://www.intra2net.com/en/developer/libftdi/index.php"
COPYRIGHT="2003-2020 Intra2net AG and the libftdi developers"
LICENSE="GNU LGPL v2.1
	GNU GPL v2"
REVISION="2"
SOURCE_URI="https://www.intra2net.com/en/developer/libftdi/download/libftdi1-$portVersion.tar.bz2"
CHECKSUM_SHA256="7c7091e9c86196148bd41177b4590dccb1510bfe6cea5bf7407ff194482eb049"
SOURCE_DIR="libftdi1-$portVersion"
PATCHES="libftdi-$portVersion.patchset"

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

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

PROVIDES="
	libftdi$secondaryArchSuffix = $portVersion
	cmd:ftdi_eeprom
	lib:libftdi1$secondaryArchSuffix = $libVersionCompat
	lib:libftdipp1$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libconfuse$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libusb_1.0$secondaryArchSuffix
	"

PROVIDES_devel="
	libftdi${secondaryArchSuffix}_devel = $portVersion
	cmd:libftdi1_config
	devel:libftdi1$secondaryArchSuffix = $libVersionCompat
	devel:libftdipp1$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	libftdi$secondaryArchSuffix == $portVersion base
	devel:libusb_1.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libboost_unit_test_framework$secondaryArchSuffix >= 1.70.0
	devel:libconfuse$secondaryArchSuffix
	devel:libusb_1.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	rm -rf build
	mkdir build
	cd build
	cmake -DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX:PATH=$prefix \
		-DEXAMPLES=OFF \
		-DFTDIPP=ON \
		-DLIB_SUFFIX=$secondaryArchSubDir \
		-DINC_SUFFIX=$secondaryArchSubDir \
		-DCMAKE_INSTALL_DOCDIR=$docDir \
		..
	make
}

INSTALL()
{
	cd build
	make install
	prepareInstalledDevelLibs libftdi1 libftdipp1
	fixPkgconfig

	# fixPkgconfig
	if [ -n "$secondaryArchSuffix" ]; then
		sed -i 's,\/headers/x86,\/headers/x86/libftdi1,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libftdi1.pc
		sed -i 's,\/headers/x86,\/headers/x86/libftdi1,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libftdipp1.pc
	else
		sed -i 's,\/headers,\/headers/libftdi1,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libftdi1.pc
		sed -i 's,\/headers,\/headers/libftdi1,g' \
			$prefix/$relativeDevelopLibDir/pkgconfig/libftdipp1.pc
	fi

	packageEntries devel $developDir \
		$prefix/bin/libftdi1-config \
		$libDir/cmake
}
