APP=docbook
VERSION=1.0
BUILD=1sml
HOMEPAGE='https://docbook.org'
DOWNLOAD=''
DOCBOOKV="4.5"
XSLV="1.79.2"
DESC="DocBook DTD for XML"
REQUIRES="libxslt libxml2"

build() {
  mkandenterbuilddir
  rm -rf $APP-$VERSION

tar xf $SRCDIR/docbook-xml-$DOCBOOKV.tar.?z*
cd docbook-xml-$DOCBOOKV
  fixbuilddirpermissions

XML_CATALOG="$PKG/etc/xml/catalog"
XML_DOCBOOK="$PKG/etc/xml/docbook"

cd docbook-4.5

install -d -m755 "$PKG"/share/xml/docbook/xml-dtd-4.5 
install -d -m755 "$PKG"/etc/xml 
#rm -rf /etc/xml

chown -R root:root . 
cp -v -af docbook.cat *.dtd ent/ *.mod \
    "$PKG"/share/xml/docbook/xml-dtd-"$DOCBOOKV"

# Create the docbook and catalog
xmlcatalog --noout --create "$XML_DOCBOOK"
xmlcatalog --noout --create "$XML_CATALOG" 

xmlcatalog --noout --add "public" \
    "-//OASIS//DTD DocBook XML V"$DOCBOOKV"//EN" \
    "http://www.oasis-open.org/docbook/xml/"$DOCBOOKV"/docbookx.dtd" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "public" \
    "-//OASIS//DTD DocBook XML CALS Table Model V"$DOCBOOKV"//EN" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"/calstblx.dtd" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "public" \
    "-//OASIS//DTD XML Exchange Table Model 19990315//EN" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"/soextblx.dtd" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "public" \
    "-//OASIS//ELEMENTS DocBook XML Information Pool V"$DOCBOOKV"//EN" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"/dbpoolx.mod" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "public" \
    "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V"$DOCBOOKV"//EN" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"/dbhierx.mod" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "public" \
    "-//OASIS//ELEMENTS DocBook XML HTML Tables V"$DOCBOOKV"//EN" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"/htmltblx.mod" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "public" \
    "-//OASIS//ENTITIES DocBook XML Notations V"$DOCBOOKV"//EN" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"/dbnotnx.mod" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "public" \
    "-//OASIS//ENTITIES DocBook XML Character Entities V"$DOCBOOKV"//EN" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"/dbcentx.mod" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "public" \
    "-//OASIS//ENTITIES DocBook XML Additional General Entities V"$DOCBOOKV"//EN" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"/dbgenent.mod" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "rewriteSystem" \
    "http://www.oasis-open.org/docbook/xml/"$DOCBOOKV"" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"" \
    "$XML_DOCBOOK"
xmlcatalog --noout --add "rewriteURI" \
    "http://www.oasis-open.org/docbook/xml/"$DOCBOOKV"" \
    "file:///share/xml/docbook/xml-dtd-"$DOCBOOKV"" \
    "$XML_DOCBOOK"


xmlcatalog --noout --add "delegatePublic" \
    "-//OASIS//ENTITIES DocBook XML" \
    "file:///etc/xml/docbook" \
    "$XML_CATALOG"
xmlcatalog --noout --add "delegatePublic" \
    "-//OASIS//DTD DocBook XML" \
    "file:///etc/xml/docbook" \
    "$XML_CATALOG"
xmlcatalog --noout --add "delegateSystem" \
    "http://www.oasis-open.org/docbook/" \
    "file:///etc/xml/docbook" \
    "$XML_CATALOG"
xmlcatalog --noout --add "delegateURI" \
    "http://www.oasis-open.org/docbook/" \
    "file:///etc/xml/docbook" \
    "$XML_CATALOG"


# Prep the older versions too
for DTDDOCBOOKV in 4.1.2 4.2 4.3 4.4
do
  xmlcatalog --noout --add "public" \
    "-//OASIS//DTD DocBook XML V$DTDDOCBOOKV//EN" \
    "http://www.oasis-open.org/docbook/xml/$DTDDOCBOOKV/docbookx.dtd" \
    "$XML_DOCBOOK"
  xmlcatalog --noout --add "rewriteSystem" \
    "http://www.oasis-open.org/docbook/xml/$DTDDOCBOOKV" \
    "file:///share/xml/docbook/xml-dtd-$DOCBOOKV" \
    "$XML_DOCBOOK"
  xmlcatalog --noout --add "rewriteURI" \
    "http://www.oasis-open.org/docbook/xml/$DTDDOCBOOKV" \
    "file:///share/xml/docbook/xml-dtd-$DOCBOOKV" \
    "$XML_DOCBOOK"
  xmlcatalog --noout --add "delegateSystem" \
    "http://www.oasis-open.org/docbook/xml/$DTDDOCBOOKV/" \
    "file:///etc/xml/docbook" \
    "$XML_CATALOG"
  xmlcatalog --noout --add "delegateURI" \
    "http://www.oasis-open.org/docbook/xml/$DTDDOCBOOKV/" \
    "file:///etc/xml/docbook" \
    "$XML_CATALOG"
done


tar xf $SRCDIR/docbook-xsl-nons-$XSLV.tar.?z*
cd docbook-xsl-nons-$XSLV
  fixbuilddirpermissions


patch -p1 < $SRCDIR/non-recursive-string-subst.patch

install -v -m755 -d "$PKG"/share/xml/docbook/xsl-stylesheets-"$XSLV"

cp -v -R VERSION common eclipse epub extensions fo highlighting html \
	 htmlhelp images javahelp lib manpages params profiling \
	 roundtrip slides template tests tools webhelp website \
	 xhtml xhtml-1_1 \
	 "$PKG/share/xml/docbook/xsl-stylesheets-$XSLV" &&
(
  cd "$PKG/share/xml/docbook/xsl-stylesheets-$XSLV" 
  ln -s VERSION VERSION.xsl
)

install -v -m644 -D README \
  "$PKG"/share/doc/docbook-xsl-"$XSLV"/README.txt
install -v -m644 RELEASE-NOTES* NEWS* \
  "$PKG"/share/doc/docbook-xsl-"$XSLV"

xmlcatalog --noout --add "rewriteSystem" \
	"http://cdn.docbook.org/release/xsl-nons/"$XSLV"" \
	"/share/xml/docbook/xsl-stylesheets-$XSLV" \
	"$XML_CATALOG" &&

xmlcatalog --noout --add "rewriteURI" \
	"http://cdn.docbook.org/release/xsl-nons/"$XSLV"" \
	"/share/xml/docbook/xsl-stylesheets-$XSLV" \
	"$XML_CATALOG" 

xmlcatalog --noout --add "rewriteSystem" \
	"http://cdn.docbook.org/release/xsl-nons/current" \
	"/share/xml/docbook/xsl-stylesheets-$XSLV" \
	"$XML_CATALOG" &&

xmlcatalog --noout --add "rewriteURI" \
	"http://cdn.docbook.org/release/xsl-nons/current" \
	"/share/xml/docbook/xsl-stylesheets-$XSLV" \
	"$XML_CATALOG"

xmlcatalog --noout --add "rewriteSystem" \
	"http://docbook.sourceforge.net/release/xsl/"$XSLV"" \
	"/share/xml/docbook/xsl-stylesheets-$XSLV" \
	"$XML_CATALOG" &&

xmlcatalog --noout --add "rewriteURI" \
	"http://docbook.sourceforge.net/release/xsl/"$XSLV"" \
	"/share/xml/docbook/xsl-stylesheets-$XSLV" \
	"$XML_CATALOG" 

xmlcatalog --noout --add "rewriteSystem" \
	"http://docbook.sourceforge.net/release/xsl/current" \
	"/share/xml/docbook/xsl-stylesheets-$XSLV" \
	"$XML_CATALOG" &&

xmlcatalog --noout --add "rewriteURI" \
	"http://docbook.sourceforge.net/release/xsl/current" \
	"/share/xml/docbook/xsl-stylesheets-$XSLV" \
	"$XML_CATALOG"

  mkfinalpkg
}

SHA512SUMS="
2408f9444d84490d31914dfe03ed53199012b9ac42f4562165c099b1e5af1a6a99037f16521b829f5833d5fc2d340cf590f48116aa856e6913f2b880d0ea56d3  docbook-xml-4.5.tar.lz
cfa54a7c499d9d964970cfdde065307a113965bac527445b87c52c32b361ca1a7e33b2611a81166ca75c223d6fed84fdec468d4deb6a6097b970dedfa110bf47  docbook-xsl-nons-1.79.2.tar.lz
3199de6b5a61ed25defa50a55fa3d138b60e1f5e4c2e3b9a14e169099189794adc3ac079fa3f62debc682f4840c6dadff40f8bd5a07fdba34fe1016ce885b9e2  non-recursive-string-subst.patch
"
