SUMMARY="Open Source library project"
DESCRIPTION="FreeImage is an Open Source library project for developers \
who would like to support popular graphics image formats like PNG, BMP, \
JPEG, TIFF and others as needed by today's multimedia applications"
HOMEPAGE="http://freeimage.sourceforge.net"
COPYRIGHT="2003-2018 FreeImage Project"
LICENSE="GNU GPL v2
	GNU GPL v3"
REVISION="2"
SOURCE_URI="https://downloads.sourceforge.net/freeimage/FreeImage${portVersion//.}.zip"
CHECKSUM_SHA256="f41379682f9ada94ea7b34fe86bf9ee00935a3147be41b6569c9605a53e438fd"
SOURCE_DIR="FreeImage"
PATCHES="freeimage-$portVersion.patchset"

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

PROVIDES="
	freeimage$secondaryArchSuffix = $portVersion
	lib:libfreeimage$secondaryArchSuffix = 3
	lib:libfreeimage_$portVersion$secondaryArchSuffix
	lib:libfreeimageplus$secondaryArchSuffix = 3
	lib:libfreeimageplus_$portVersion$secondaryArchSuffix

	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	freeimage${secondaryArchSuffix}_devel = $portVersion
	devel:libfreeimage$secondaryArchSuffix = 3
	devel:libfreeimage_$portVersion$secondaryArchSuffix
	devel:libfreeimageplus$secondaryArchSuffix = 3
	devel:libfreeimageplus_$portVersion$secondaryArchSuffix
	"
REQUIRES_devel="
	freeimage$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	make -f Makefile.gnu \
		INCDIR=$includeDir \
		INSTALLDIR=$libDir

	make -f Makefile.fip \
		INCDIR=$includeDir \
		INSTALLDIR=$libDir
}

INSTALL()
{
	make -f Makefile.gnu install \
		INCDIR=$includeDir \
		INSTALLDIR=$libDir

	make -f Makefile.fip install \
		INCDIR=$includeDir \
		INSTALLDIR=$libDir

	prepareInstalledDevelLibs libfreeimage libfreeimage-$portVersion \
		libfreeimageplus libfreeimageplus-$portVersion

	ln -s $libDir/libfreeimage-"$portVersion".so \
		$libDir/libfreeimage.so.${portVersion%.*.*}
	ln -s $libDir/libfreeimageplus-"$portVersion".so \
		$libDir/libfreeimageplus.so.${portVersion%.*.*}

	mkdir -p "$developLibDir"/pkgconfig
	cat > "$developLibDir"/pkgconfig/freeimage.pc << EOF
prefix=${prefix}
exec_prefix=${prefix}
libdir=${libDir}
includedir=${includeDir}

Name: freeimage
Description: FreeImage
Version: ${portVersion}
Libs: -L${developLibDir} -lfreeimage
Cflags: -I${includeDir}
EOF

	packageEntries devel \
		$developDir
}
