# Template file for 'docbook-xml'
pkgname=docbook-xml
version=4.5
wrksrc="docbook"
distfiles="
http://www.oasis-open.org/docbook/xml/$version/$pkgname-$version.zip
http://www.oasis-open.org/docbook/xml/4.4/$pkgname-4.4.zip
http://www.oasis-open.org/docbook/xml/4.3/$pkgname-4.3.zip
http://www.oasis-open.org/docbook/xml/4.2/$pkgname-4.2.zip"
build_style=custom-install
short_desc="XML DTD designed for computer documentation"
maintainer="Juan RP <xtraeme@gmail.com>"
checksum="
4e4e037a2b83c98c6c94818390d4bdd3f6e10f6ec62dd79188594e26190dc7b4
02f159eb88c4254d95e831c51c144b1863b216d909b5ff45743a1ce6f5273090
23068a94ea6fd484b004c5a73ec36a66aa47ea8f0d6b62cc1695931f5c143464
acc4601e4f97a196076b7e64b368d9248b07c7abf26b34a02cca40eeebe60fa2"
long_desc="
 DocBook provides a system for writing structured documents using
 SGML or XML. It is particularly well-suited to books and papers
 about computer hardware and software, though it is by no means
 limited to them.

 In short, DocBook is an easy-to-understand and widely used DTD.
 Dozens of organizations use DocBook for millions of pages of
 documentation, in various print and online formats, worldwide."

noarch=yes
noextract=yes

Add_dependency full xmlcatmgr
Add_dependency build unzip

do_install()
{
	local versions="4.2 4.3 4.4 4.5"
	local ver dir

	cd $wrksrc
	for ver in ${versions}; do
		dir=${DESTDIR}/usr/share/xml/docbook/${ver}
		install -d -m755 ${dir}
		unzip -q -x ${XBPS_SRCDISTDIR}/docbook-xml-${ver}.zip \
			-d ${dir} && mv ${dir}/catalog.xml ${dir}/catalog \
			|| return 1
	done
	dir=${DESTDIR}/usr/share/xml/docbook/4.2
	sed -e 's|V4.2|V4.1.2|g' < ${dir}/catalog > ${dir}/catalog-4.1.2
	chmod 644 ${dir}/catalog-4.1.2
}

post_install()
{
	local versions="4.2 4.3 4.4 4.5"
	local uri="http://www.oasis-open.org/docbook/xml"
	local ver dir

	for ver in ${versions}; do
		dir=/usr/share/xml/docbook/${ver}
		xml_catalogs="${xml_catalogs} ${dir}/catalog"
		xml_entries="${xml_entries} rewriteSystem ${uri}/${ver} ${dir}"
	done

	#
	# 4.2 is backwards-compatible with 4.1.2, so just make 4.1.2 be
	# an alias for 4.2.
	#
	dir=/usr/share/xml/docbook/4.2
	xml_catalogs="${xml_catalogs} ${dir}/catalog-4.1.2"
	xml_entries="${xml_entries} rewriteSystem ${uri}/4.1.2 ${dir}"

	export xml_catalogs="${xml_catalogs}"
	export xml_entries="${xml_entries}"
	export sgml_catalogs="${sgml_catalogs}"
	export sgml_entries="${sgml_entries}"
	#
	# Run the trigger to register its XML catalog entries.
	#
	cd ${XBPS_MASTERDIR}
	${XBPS_TRIGGERSDIR}/xml-catalog run post-install
}
