#!/bin/sh
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

PKGNAME=docbook-xml
PKGVERSION=4.5
PKGREVISION=1
PKGLICENSE="CUSTOM"
PKGSUMMARY="DocBook XML DTD"
PKGDOWNLOAD="https://docbook.org/xml/4.2/docbook-xml-4.2.zip
             https://docbook.org/xml/4.3/docbook-xml-4.3.zip
             https://docbook.org/xml/4.4/docbook-xml-4.4.zip
             https://docbook.org/xml/4.5/docbook-xml-4.5.zip"
PKGDEPENDS="unzip:build libxml2:build"

build_version()
{
	rm -rf docbook
	unzip $PKGNAME-$1.zip -d docbook

	install -dm755 $DESTDIR/share/xml/docbook/xml-dtd-$1
	cp -af \
		docbook/docbook.cat \
		docbook/*.dtd \
		docbook/ent/ \
		docbook/*.mod \
		$DESTDIR/share/xml/docbook/xml-dtd-$1
	xmlcatalog --noout --add "public" \
		"-//OASIS//DTD DocBook XML V$1//EN" \
		"http://www.oasis-open.org/docbook/xml/$1/docbookx.dtd" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "public" \
		"-//OASIS//DTD DocBook XML CALS Table Model V$1//EN" \
		"file:///share/xml/docbook/xml-dtd-$1/calstblx.dtd" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "public" \
		"-//OASIS//DTD XML Exchange Table Model 19990315//EN" \
		"file:///share/xml/docbook/xml-dtd-$1/soextblx.dtd" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "public" \
		"-//OASIS//ELEMENTS DocBook XML Information Pool V$1//EN" \
		"file:///share/xml/docbook/xml-dtd-$1/dbpoolx.mod" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "public" \
		"-//OASIS//ELEMENTS DocBook XML Document Hierarchy V$1//EN" \
		"file:///share/xml/docbook/xml-dtd-$1/dbhierx.mod" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "public" \
		"-//OASIS//ELEMENTS DocBook XML HTML Tables V$1//EN" \
		"file:///share/xml/docbook/xml-dtd-$1/htmltblx.mod" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "public" \
		"-//OASIS//ENTITIES DocBook XML Notations V$1//EN" \
		"file:///share/xml/docbook/xml-dtd-$1/dbnotnx.mod" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "public" \
		"-//OASIS//ENTITIES DocBook XML Character Entities V$1//EN" \
		"file:///share/xml/docbook/xml-dtd-$1/dbcentx.mod" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "public" \
		"-//OASIS//ENTITIES DocBook XML Additional General Entities V$1//EN" \
		"file:///share/xml/docbook/xml-dtd-$1/dbgenent.mod" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "rewriteSystem" \
		"http://www.oasis-open.org/docbook/xml/$1" \
		"file:///share/xml/docbook/xml-dtd-$1" \
		$DESTDIR/etc/xml/docbook &&
	xmlcatalog --noout --add "rewriteURI" \
		"http://www.oasis-open.org/docbook/xml/$1" \
		"file:///share/xml/docbook/xml-dtd-$1" \
		$DESTDIR/etc/xml/docbook
	rm -rf docbook
}

build()
{
	install -dm755 $DESTDIR/etc/xml
	xmlcatalog --noout --create $DESTDIR/etc/xml/docbook

	for v in 4.2 4.3 4.4 4.5; do
		build_version $v
	done
}
