SUMMARY="USB CEC Adapter communication Library"
DESCRIPTION="This library provides support for CEC capable hardware"
HOMEPAGE="http://libcec.pulse-eight.com/"
COPYRIGHT="2011-2015 Pulse-Eight Limited"
LICENSE="GNU GPL v2"
REVISION="2"

srcGitRev="$portVersion"
SOURCE_URI="https://github.com/Pulse-Eight/libcec/archive/libcec-$srcGitRev.tar.gz"
CHECKSUM_SHA256="ef90d6e4cf9d5847c14d3ff21b71579e5110643f31e8574766d3fa6c89c6239c"
SOURCE_DIR="libcec-libcec-$srcGitRev"
PATCHES="libcec-$srcGitRev.patchset"
srcGitRev2="63ec40a9e2dbe26d49dba0a73071a410dcc6b73b"
SOURCE_URI_2="https://github.com/Pulse-Eight/libcec-support/archive/$srcGitRev2.tar.gz"
CHECKSUM_SHA256_2="752695072aaf45de54d4edf46f415f836834500d03739a4dc56cd922065a75dc"
SOURCE_FILENAME_2="libcec-support-$srcGitRev2.tar.gz"
SOURCE_DIR_2="libcec-support-$srcGitRev2"
srcGitRev3="180cbe2b4e2b2d6a58c4b22d09760aba4b67a8e5"
SOURCE_URI_3="https://github.com/Pulse-Eight/cec-dotnet/archive/$srcGitRev3.tar.gz"
CHECKSUM_SHA256_3="1c542d1f07841aa7de85f21ee0157f413ad8e7043eef525f4c10b6111fa3aef9"
SOURCE_FILENAME_3="cec-dotnet-$srcGitRev3.tar.gz"
SOURCE_DIR_3="cec-dotnet-$srcGitRev3"
srcGitRev4="6535e48d68d69264c32d46ab9386ac18f77da5f7"
SOURCE_URI_4="https://github.com/Pulse-Eight/platform/archive/$srcGitRev4.tar.gz"
CHECKSUM_SHA256_4="2fa23d6242c249ba257b3ad8cbf8104ca816685c5567cf56e304b707ebd12d22"
SOURCE_FILENAME_4="platform-$srcGitRev4.tar.gz"
SOURCE_DIR_4="platform-$srcGitRev4"
PATCHES_4="platform-$srcGitRev4.patchset"
srcGitRev5="1149a12c79595a03a1915585159d5e6952484325"
SOURCE_URI_5="https://github.com/Pulse-Eight/libcec-support/archive/$srcGitRev5.tar.gz"
CHECKSUM_SHA256_5="39fd78a0f08ba7ad97e9be6339a6f7ba4e667ab5d050d35904012aebb77b7262"
SOURCE_FILENAME_5="libcec-support-$srcGitRev5.tar.gz"
SOURCE_DIR_5="libcec-support-$srcGitRev5"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

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

PROVIDES="
	libcec$secondaryArchSuffix = $portVersion
	cmd:cec_client = $portVersion
	cmd:cec_client_$portVersion = $portVersion
	cmd:cecc_client = $portVersion
	cmd:cecc_client_$portVersion = $portVersion
	cmd:pycecclient
	lib:libcec$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libp8_platform$secondaryArchSuffix
	lib:libpython3.7m$secondaryArchSuffix
	"
PROVIDES_devel="
	libcec${secondaryArchSuffix}_devel = $portVersion
	devel:libcec$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	libcec$secondaryArchSuffix == $portVersion base
	devel:libp8_platform$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libncurses$secondaryArchSuffix
	devel:libp8_platform$secondaryArchSuffix
	devel:libpython3.7m$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:swig
	"

BUILD()
{
	# submodules
	ln -sfn $sourceDir2 support
	ln -sfn $sourceDir3 src/dotnet
	ln -sfn $sourceDir4 src/platform
	ln -sfn $sourceDir5 src/platform/support
	# building
	mkdir -p build && cd build
	cmake -DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=$prefix \
		-DCMAKE_INSTALL_LIBDIR=$libDir \
		-DCMAKE_INSTALL_INCLUDEDIR=$includeDir ..
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	prepareInstalledDevelLib libcec
	fixPkgconfig
	packageEntries devel $developDir
}
