SUMMARY="Library for reading and processing of RAW digicam images"
DESCRIPTION="LibRaw is a library for reading RAW files from digital photo \
cameras (CRW/CR2, NEF, RAF, DNG, MOS, KDC, DCR, etc, virtually all RAW \
formats are supported).
It pays special attention to correct retrieval of data required for subsequent \
RAW conversion.
The library is intended for embedding in RAW converters, data analyzers, and \
other programs using RAW files as the initial data."
HOMEPAGE="https://www.libraw.org/"
COPYRIGHT="2008-2018 LibRaw LLC"
LICENSE="GNU LGPL v2.1
	CDDL v1"
REVISION="1"
SOURCE_URI="https://www.libraw.org/data/LibRaw-$portVersion.tar.gz"
CHECKSUM_SHA256="dc1b486c2003435733043e4e05273477326e51c3ea554c6864a4eafaff1004a6"
SOURCE_DIR="LibRaw-$portVersion"
PATCHES="libraw-$portVersion.patchset"

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

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

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

PROVIDES="
	libraw$secondaryArchSuffix = $portVersion compat >= 0
	lib:libraw$secondaryArchSuffix = $libVersionCompat
	lib:libraw_r$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	lib:libjasper$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblcms2$secondaryArchSuffix
	"

PROVIDES_devel="
	libraw${secondaryArchSuffix}_devel = $portVersion compat >= 0
	devel:libraw$secondaryArchSuffix = $libVersionCompat
	devel:libraw_r$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	libraw$secondaryArchSuffix == $portVersion base
	"

SUMMARY_tools="The libraw tools"
PROVIDES_tools="
	libraw${secondaryArchSuffix}_tools = $portVersion
	cmd:4channels$commandSuffix = $portVersionCompat
	cmd:dcraw_emu$commandSuffix = $portVersionCompat
	cmd:dcraw_half$commandSuffix = $portVersionCompat
	cmd:half_mt$commandSuffix = $portVersionCompat
	cmd:mem_image$commandSuffix = $portVersionCompat
	cmd:multirender_test$commandSuffix = $portVersionCompat
	cmd:postprocessing_benchmark$commandSuffix = $portVersionCompat
	cmd:raw_identify$commandSuffix = $portVersionCompat
	cmd:rawtextdump$commandSuffix = $portVersionCompat
	cmd:simple_dcraw$commandSuffix = $portVersionCompat
	cmd:unprocessed_raw$commandSuffix = $portVersionCompat
	"
REQUIRES_tools="
	libraw$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	lib:libgomp$secondaryArchSuffix
	lib:libjasper$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:liblcms2$secondaryArchSuffix
	"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
	REQUIRES_tools+="
			"
fi

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libjasper$secondaryArchSuffix
	devel:liblcms2$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:cmp
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

debugList=(
	"$libDir"/libraw.so.$libVersion
	"$libDir"/libraw_r.so.$libVersion
	)
librawTools="
	4channels
	dcraw_emu
	dcraw_half
	half_mt
	mem_image
	multirender_test
	postprocessing_benchmark
	raw-identify
	rawtextdump
	simple_dcraw
	unprocessed_raw
	"
for i in $librawTools; do
	debugList+=("${commandBinDir/libraw$secondaryArchSuffix/libraw${secondaryArchSuffix}_tools}"/$i)
done
defineDebugInfoPackage libraw$secondaryArchSuffix "${debugList[@]}"

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

INSTALL()
{
	make install

	rm $libDir/lib*.la

	prepareInstalledDevelLibs libraw libraw_r
	fixPkgconfig

	pushd "$developLibDir"
	if [ -f libraw_r.a -a -f libraw.a ] && cmp libraw_r.a libraw.a; then
		rm libraw_r.a
		ln -s libraw.a libraw_r.a
	fi
	popd

	# devel package
	packageEntries devel \
		$developDir

		# tools package
	packageEntries tools \
		"$commandBinDir"

}

TEST()
{
	make check
}
