SUMMARY="The XML C parser and toolkit of Gnome"
HOMEPAGE="http://www.xmlsoft.org/"
LICENSE="MIT"
COPYRIGHT="1998-2013 Daniel Veillard.  All Rights Reserved."
SRC_URI="ftp://xmlsoft.org/libxml2/libxml2-2.9.1.tar.gz"
CHECKSUM_SHA256="fd3c64cb66f2c4ea27e934d275904d92cec494a8e8405613780cbc8a71680fdb"
REVISION="2"
ARCHITECTURES="!x86_gcc2 !x86 x86_64"
SECONDARY_ARCHITECTURES="!x86_gcc2 !x86"

PATCHES="libxml2-2.9.1.patchset"

# build the python module only for the primary architecture
pythonModuleEnabled=false
if [ -z "$secondaryArchSuffix" ]; then
	pythonModuleEnabled=true
fi

PROVIDES="
	libxml2$secondaryArchSuffix = $portVersion compat >= 2
	lib:libxml2$secondaryArchSuffix = $portVersion compat >= 2
	"
if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES="$PROVIDES
		cmd:xmlcatalog = $portVersion compat >= 2
		cmd:xmllint = $portVersion compat >= 2
		"
fi

REQUIRES="
	haiku$secondaryArchSuffix >= $haikuVersion
	lib:libz$secondaryArchSuffix
	"
BUILD_REQUIRES="
	devel:libz$secondaryArchSuffix
	"
if $pythonModuleEnabled; then
	BUILD_REQUIRES="$BUILD_REQUIRES
		python >= 2.7
		"
			# Note: We don't use "cmd:python" here to avoid issues with the
			# python search path.
fi

BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel >= $haikuVersion
	haiku_devel >= $haikuVersion
	lib:libicudata$secondaryArchSuffix
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize
	cmd:make
	cmd:sed
	"

PATCH()
{
	# replace hard-coded references to the development documentation dir
	sed -i "s,^DEVHELP_DIR=\(.*\),DEVHELP_DIR=${developDocDir}," \
		doc/devhelp/Makefile.am
	sed -i "s,%{_datadir}/gtk-doc/html/libxml2,${developDocDir},g" \
		libxml.spec.in
}

BUILD()
{
	libtoolize --force --copy --install
	aclocal
	autoconf
	automake

	withPython=
	if $pythonModuleEnabled; then
		# We symlink python's directories into our packaging directory and tell
		# configure that it can find python there. This way the correct
		# installation directory for the python module is determined.
		pythonDir="$portPackageLinksDir/python"
		ln -s $pythonDir/bin $pythonDir/develop $pythonDir/lib $prefix
		withPython="--with-python=$prefix"
	fi

	runConfigure ./configure LDFLAGS="-lnetwork"  \
		--with-html-dir=$docDir/html \
		--with-html-subdir="" \
		$withPython
	make $jobArgs
}

INSTALL()
{
	if $pythonModuleEnabled; then
		# Unfortunately we can't just remove the in symlinks we created in
		# BUILD() and install normally, since then make detects that the
		# Python.h is missing and tries to rebuild the module. So we leave
		# things as is and use DESTDIR to install the everything in a subdir.
		# Then we remove the symlinks and move everything where it belongs.
		make DESTDIR=$prefix install
		rm -f $prefix/bin $prefix/develop $prefix/lib
		mv $prefix/$prefix/* $prefix
		rm -r $prefix/packages
	else
		make install
	fi

	# prepare develop/lib
	prepareInstalledDevelLibs libxml2
	fixPkgconfig
	mv $libDir/xml2Conf.sh $developLibDir/
	fixDevelopLibDirReferences $developLibDir/xml2Conf.sh $binDir/xml2-config

	# python package
	if $pythonModuleEnabled; then
		packageEntries python \
			$libDir/python* \
			${docDir}_python*
	fi

	# devel package
	packageEntries devel \
		$binDir/xml2-config \
		$dataDir \
		$developDir \
		$docDir \
		$manDir/man1/xml2-config.1 \
		$manDir/man3

	# Remove stuff we don't need in the secondary architecture base package.
	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf $binDir
		rm -rf $documentationDir
	else
		# left-over since all contents has been moved to other packages
		rmdir $(dirname $docDir)
	fi
}

TEST()
{
	make tests
}

# ----- devel package ---------------------------------------------------------

PROVIDES_devel="
	libxml2${secondaryArchSuffix}_devel = $portVersion
	cmd:xml2_config$secondaryArchSuffix = $portVersion compat >= 2
	devel:libxml2$secondaryArchSuffix = $portVersion compat >= 2
	"
REQUIRES_devel="
	libxml2$secondaryArchSuffix == $portVersion base
	"

# ----- python package -------------------------------------------------------

if $pythonModuleEnabled; then
	SUMMARY_python="The python module for libxml2"
	PROVIDES_python="
		libxml2_python = $portVersion
		"
	REQUIRES_python="
		libxml2 == $portVersion base
		cmd:python
		"
fi

# ----- DESCRIPTION -----------------------------------------------------------

DESCRIPTION="
	Libxml2 is the XML C parser and toolkit developed for the Gnome project
	(but usable outside of the Gnome platform), it is free software available
	under the MIT License. XML itself is a metalanguage to design markup
	languages, i.e. text language where semantic and structure are added to
	the content using extra "markup" information enclosed between angle
	brackets. HTML is the most well-known markup language. Though the library
	is written in C a variety of language bindings make it available in other
	environments.

	Libxml2 implements a number of existing standards related to markup
	languages:

    - the XML standard: http://www.w3.org/TR/REC-xml
    - Namespaces in XML: http://www.w3.org/TR/REC-xml-names/
    - XML Base: http://www.w3.org/TR/xmlbase/
    - RFC 2396 : Uniform Resource Identifiers
    - XML Path Language (XPath) 1.0: http://www.w3.org/TR/xpath
    - HTML4 parser: http://www.w3.org/TR/html401/
    - XML Pointer Language (XPointer) Version 1.0: http://www.w3.org/TR/xptr
    - XML Inclusions (XInclude) Version 1.0: http://www.w3.org/TR/xinclude/
    - ISO-8859-x encodings, as well as rfc2044 [UTF-8] and rfc2781 [UTF-16]
      Unicode encodings, and more if using iconv support part of SGML Open
      Technical Resolution TR9401:1997
    - XML Catalogs Working Draft 06 August 2001:
      http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
    - Canonical XML Version 1.0:
      http://www.w3.org/TR/xml-c14n and the Exclusive XML Canonicalization
      CR draft http://www.w3.org/TR/xml-exc-c14n
    - Relax NG, ISO/IEC 19757-2:2003,
      http://www.oasis-open.org/committees/relax-ng/spec-20011203.html
    - W3C XML Schemas Part 2: Datatypes REC 02 May 2001
    - W3C xml:id Working Draft 7 April 2004

	In most cases libxml2 tries to implement the specifications in a
	relatively strictly compliant way. As of release 2.4.16, libxml2 passed
	all 1800+ tests from the OASIS XML Tests Suite.

	To some extent libxml2 provides support for the following additional
	specifications but doesn't claim to implement them completely:

    - Document Object Model (DOM) http://www.w3.org/TR/DOM-Level-2-Core/
      the document model, but it doesn't implement the API itself, gdome2
      does this on top of libxml2
    - RFC 959 : libxml2 implements a basic FTP client code
    - RFC 1945 : HTTP/1.0, again a basic HTTP client code
    - SAX: a SAX2 like interface and a minimal SAX1 implementation compatible
      with early expat versions

	A partial implementation of XML Schemas Part 1: Structure is being worked
	on but it would be far too early to make any conformance statement about
	it at the moment.
	"
