SUMMARY="A cross-platform C++ GUI toolkit for X11, MS Windows, OSX and Haiku"
DESCRIPTION="FLTK (pronounced \"fulltick\") is a cross-platform C++ GUI \
toolkit for UNIX®/Linux® (X11), Microsoft® Windows®, and MacOS® X. \
FLTK provides modern GUI functionality without the bloat and \
supports 3D graphics via OpenGL® and its built-in GLUT emulation.
NOTE: OpenGL is not supported yet.

FLTK is designed to be small and modular enough to be statically linked, \
but works fine as a shared library. \
FLTK also includes an excellent UI builder called FLUID that can be used \
to create applications in minutes."
HOMEPAGE="https://www.fltk.org/"
COPYRIGHT="1998-2019 by Bill Spitzak and others."
LICENSE="FLTK
	GNU LGPL v2"
REVISION="3"
SOURCE_URI="https://github.com/mmuman/fltk/archive/haiku-1.3-final.tar.gz"
CHECKSUM_SHA256="5ea5eb6f4028534bb911a61ad3df7dbfa1274dd200a03be441b75b691f79d7f1"
SOURCE_DIR="fltk-haiku-1.3-final"
PATCHES="fltk-$portVersion.patchset"

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

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

libVersion="1.3"

PROVIDES="
	fltk$secondaryArchSuffix = $portVersion
	lib:libfltk$secondaryArchSuffix = $libVersion
	lib:libfltk_forms$secondaryArchSuffix = $libVersion
	lib:libfltk_images$secondaryArchSuffix = $libVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	#lib:libgl$secondaryArchSuffix
	#lib:libglu$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	fltk${secondaryArchSuffix}_devel = $portVersion
	devel:libfltk$secondaryArchSuffix = $libVersion
	devel:libfltk_forms$secondaryArchSuffix = $libVersion
	devel:libfltk_images$secondaryArchSuffix = $libVersion
	cmd:fltk_config$commandSuffix = 1.3.5
	cmd:fluid$commandSuffix = 1.3.5
	"
REQUIRES_devel="
	fltk$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	#lib:libgl$secondaryArchSuffix
	#lib:libglu$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng16$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	#devel:libgl$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	#devel:libgl$secondaryArchSuffix
	#devel:libglu$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:automake
	cmd:awk
	cmd:doxygen
	cmd:g++$secondaryArchSuffix
	cmd:grep
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:man
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

defineDebugInfoPackage fltk$secondaryArchSuffix \
	"$libDir"/libfltk.so.$libVersion \
	"$libDir"/libfltk_forms.so.$libVersion \
	"$libDir"/libfltk_images.so.$libVersion \
	"$(getPackagePrefix devel)/bin"/fluid

BUILD()
{
	NOCONFIGURE=1 sh ./autogen.sh
	runConfigure --omit-dirs "docDir binDir" ./configure \
		--bindir=$commandBinDir \
		--docdir=$developDocDir \
		--enable-shared \
		--disable-gl \
		--disable-localjpeg \
		--disable-localpng \
		--disable-localzlib \
		--enable-debug
	make $jobArgs
}

INSTALL()
{
	make install

	prepareInstalledDevelLibs \
		libfltk libfltk_forms libfltk_images
	fixPkgconfig

	# install does not copy attributes and strips resources!?
	copyattr -d fluid/fluid $commandBinDir/fluid

	addAppDeskbarSymlink $commandBinDir/fluid "FLUID"

	# extract the FLTK license, we already have the GPLv2 text
	# XXX: haikuporter does not like it, wants the licence beforehand anyway.
	#sed -n '/^------/q;p' < COPYING > $dataDir/licenses/FLTK

	packageEntries devel \
		$developDir \
		$commandBinDir \
		$manDir \
		${dataDir}/deskbar
}
