SUMMARY="CD (Canvas Draw) is a platform-independent graphics library."
HOMEPAGE="http://www.tecgraf.puc-rio.br/cd/"
SRC_URI="http://heanet.dl.sourceforge.net/project/canvasdraw/5.6.1/Docs%20and%20Sources/cd-5.6.1_Sources.zip"
	# They have a tar.gz but the permissions are broken inside it (will create unreadable files)
CHECKSUM_MD5="0953b2d9a094a14608f73561038ad84d"
REVISION="1"
ARCHITECTURES="x86_gcc2"
SECONDARY_ARCHITECTURES="x86"
PROVIDES="
	cd$secondaryArchSuffix = $portVersion
	lib:libcd$secondaryArchSuffix = $portVersion
	lib:libcdgl$secondaryArchSuffix = $portVersion
	lib:libcdlua51$secondaryArchSuffix = $portVersion
	lib:libcdlua52$secondaryArchSuffix = $portVersion
	lib:libcdluagl51$secondaryArchSuffix = $portVersion
	lib:libcdluagl52$secondaryArchSuffix = $portVersion
	lib:libcdluaim51$secondaryArchSuffix = $portVersion
	lib:libcdluaim52$secondaryArchSuffix = $portVersion
	lib:libcdluapdf51$secondaryArchSuffix = $portVersion
	lib:libcdluapdf52$secondaryArchSuffix = $portVersion
	lib:libcdpdf$secondaryArchSuffix = $portVersion

	lib:libftgl$secondaryArchSuffix = $portVersion
	lib:libpdflib$secondaryArchSuffix = $portVersion
	"

REQUIRES="
	haiku$secondaryArchSuffix >= $haikuVersion
	lib:libGLU$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libim$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
"

BUILD_REQUIRES="
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libglu$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libim$secondaryArchSuffix
	devel:liblua$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
"

BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel >= $haikuVersion
	cmd:make
	cmd:gcc$secondaryArchSuffix
	cmd:as$secondaryArchSuffix
	cmd:pkg_config
	cmd:which
"

SOURCE_DIR="cd"
PATCHES="cd-5.6.patchset"
BUILD()
{
	export PKG_CONFIG_PATH=`finddir B_SYSTEM_DEVELOP_DIRECTORY`/lib$secondaryArchSubDir/pkgconfig

	cd src
	make

	cd ..
}

INSTALL()
{
	mkdir -p $developLibDir
	mkdir -p $libDir
	mkdir -p $includeDir

	cp lib/Haiku11/* $libDir
	cp include/* $includeDir

	prepareInstalledDevelLibs libcd libcdgl libcdlua51 libcdlua52 libcdluagl51 \
		libcdluagl52 libcdluaim51 libcdluaim52 libcdluapdf51 libcdluapdf52 \
		libcdpdf libftgl libpdflib
		
	packageEntries devel $developDir
}

TEST()
{
	export PKG_CONFIG_PATH=`finddir B_SYSTEM_DEVELOP_DIRECTORY`/lib$secondaryArchSubDir/pkgconfig

	# Make sure the tests can link against the built libs
	mkdir -p bin/Haiku11
	ln -sf ../../lib/Haiku11 bin/Haiku11/lib

	cd test

	make -f ../tecmake.mak MF=metafile
	../bin/Haiku11/metafile

	# needs IUP
	#make -f ../tecmake.mak MF=screencapture
	#../bin/Haiku11/screencapture

	# needs IUP
	#pushd cdtest
	#make -f ../../tecmake.mak
	#popd
	#../bin/Haiku11/cdtest
}

PROVIDES_devel="
	cd${secondaryArchSuffix}_devel = $portVersion
	devel:libcd$secondaryArchSuffix = $portVersion
	devel:libcdgl$secondaryArchSuffix = $portVersion
	devel:libcdlua51$secondaryArchSuffix = $portVersion
	devel:libcdlua52$secondaryArchSuffix = $portVersion
	devel:libcdluagl51$secondaryArchSuffix = $portVersion
	devel:libcdluagl52$secondaryArchSuffix = $portVersion
	devel:libcdluaim51$secondaryArchSuffix = $portVersion
	devel:libcdluaim52$secondaryArchSuffix = $portVersion
	devel:libcdluapdf51$secondaryArchSuffix = $portVersion
	devel:libcdluapdf52$secondaryArchSuffix = $portVersion
	devel:libcdpdf$secondaryArchSuffix = $portVersion

	devel:libftgl$secondaryArchSuffix = $portVersion
	devel:libpdflib$secondaryArchSuffix = $portVersion
"

LICENSE="MIT"
COPYRIGHT="1994-2013 Tecgraf, PUC-Rio."
DESCRIPTION="
CD (Canvas Draw) is a platform-independent graphics library. It is implemented \
in several platforms using native graphics libraries: Microsoft Windows (GDI) \
and X-Windows (XLIB).
The library contains functions to support both vector and image applications, \
and the visualization surface can be either a window or a more abstract \
surface, such as Image, Clipboard, Metafile, PS, and so on.
"
