SUMMARY="The Device Tree Compiler"
DESCRIPTION="The Device Tree Compiler (DTC) is the toolchain for building \
device tree source files (*.dts) into the binary format (*.dtb)."
HOMEPAGE="https://git.kernel.org/cgit/utils/dtc/dtc.git"
COPYRIGHT="2005 David Gibson, IBM Corporation"
LICENSE="GNU GPL v2"
REVISION="2"
SOURCE_URI="https://www.kernel.org/pub/software/utils/dtc/dtc-$portVersion.tar.xz"
CHECKSUM_SHA256="6643e8f00ff86350f465bb54b2185058b5b1b7bac01a0842c81a52b86589cde7"
PATCHES="dtc-$portVersion.patchset"

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

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

libVersion=$portVersion
libVersionCompat=${libVersion%%.*}

PROVIDES="
	dtc$secondaryArchSuffix = $portVersion
	cmd:convert_dtsv0$commandSuffix = $portVersion
	cmd:dtc$commandSuffix = $portVersion
	cmd:dtdiff$commandSuffix = $portVersion
	cmd:fdtdump$commandSuffix = $portVersion
	cmd:fdtget$commandSuffix = $portVersion
	cmd:fdtoverlay$commandSuffix = $portVersion
	cmd:fdtput$commandSuffix = $portVersion
	lib:libfdt$secondaryArchSuffix = $libVersion compat >= $libVersionCompat
	lib:libfdt_$portVersion$secondaryArchSuffix = $libVersion compat >= $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	dtc${secondaryArchSuffix}_devel = $portVersion
	devel:libfdt$secondaryArchSuffix
	devel:libfdt_$portVersion$secondaryArchSuffix
	"
REQUIRES_devel="
	dtc$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:bison >= 2.5
	cmd:cmp
	cmd:flex
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

defineDebugInfoPackage dtc$secondaryArchSuffix \
	$commandBinDir/convert-dtsv0 \
	$commandBinDir/dtc \
	$commandBinDir/fdtdump \
	$commandBinDir/fdtget \
	$commandBinDir/fdtoverlay \
	$commandBinDir/fdtput \
	$libDir/libfdt-$portVersion.so

BUILD()
{
	make PREFIX=$prefix $jobArgs NO_PYTHON=TRUE
}

INSTALL()
{
	make install \
		PREFIX=$prefix \
		BINDIR=$commandBinDir \
		INCLUDEDIR=$includeDir \
		LIBDIR=$libDir \
		NO_PYTHON=1

	prepareInstalledDevelLibs libfdt

	packageEntries devel $developDir

	ln -r -s $libDir/libfdt-$portVersion.so \
		$libDir/libfdt.so.$libVersionCompat
}

TEST()
{
	make check
}
