SUMMARY="A free, high-quality, and portable font engine"
DESCRIPTION="FreeType is written in C, designed to be small, efficient, \
highly customizable, and portable while capable of producing high-quality \
output (glyph images) of most vector and bitmap font formats."
HOMEPAGE="http://www.freetype.org"
LICENSE="FreeType"
COPYRIGHT="1996-2013 David Turner, Robert Wilhelm, Werner Lemberg, et al."
SOURCE_URI="http://download.savannah.gnu.org/releases/freetype/freetype-$portVersion.tar.bz2"
CHECKSUM_SHA256="8469fb8124764f85029cc8247c31e132a2c5e51084ddce2a44ea32ee4ae8347e"
REVISION="1"
ARCHITECTURES="x86_gcc2 x86 x86_64 arm"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

#   Uncomment next line to enable subpixel rendering and subpixel hinting
#PATCHES="freetype-$portVersion.patchset"

PROVIDES="
	freetype$secondaryArchSuffix = $portVersion
	lib:libfreetype$secondaryArchSuffix = 6.12.0 compat >= 6
	"
PROVIDES_devel="
	freetype${secondaryArchSuffix}_devel = $portVersion
	cmd:freetype_config${secondaryArchSuffix} = $portVersion
	devel:libfreetype${secondaryArchSuffix} = 6.12.0 compat >= 6
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix >= 1
	lib:libpng16$secondaryArchSuffix
	"
REQUIRES_devel="
	freetype${secondaryArchSuffix} == $portVersion base
	devel:libbz2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	devel:libpng16$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtool >= 2.4.2
	cmd:make
	cmd:which
	"

BUILD()
{
	./autogen.sh
	runConfigure ./configure
	make $jobArgs
}

INSTALL()
{
	make install

	prepareInstalledDevelLibs libfreetype
	fixPkgconfig

	# Freetype headers are in a freetype2 subdirectory, but fixPkgconfig removes
	# that from the pkg-config file, making it difficult for other ports to use
	# freetype with pkg-config.
	sed -i -e "s,^includedir=.*,includedir=$prefix/$relativeIncludeDir/freetype2," \
		$developLibDir/pkgconfig/freetype2.pc

	# The libtool files reference other libraries using the wrong paths, which
	# creates a lot of confusion. Fix them so correct paths are used.
	local develPackageName="${portName}_devel-$portFullVersion"
	local packageLinksDir=$(dirname $portPackageLinksDir)
	local linksDir="$packageLinksDir/${develPackageName}/devel~libpng16$secondaryArchSuffix/$relativeDevelopLibDir"
	sed -i -e "s,^\(Libs.private.*\)-L.* \(-l.*\)$,\1-L$linksDir \2," \
		$developLibDir/pkgconfig/freetype2.pc
	sed -i -e "s,^\(dependency_libs.*\)-L.* \(-l.*\)$,\1-L$linksDir $linksDir/libpng16.la \2," \
		$developLibDir/libfreetype.la

	# devel package
	packageEntries devel \
		$binDir \
		$dataRootDir/aclocal \
		$developDir
}
