# Maintainer: PktSurf <smlinux@pktsurf.in>
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"

prepbuilddir() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/docbook-xml-$docbookv.tar.?z*
  cd docbook-xml-$docbookv
  fixbuilddirpermissions
}

build() {
  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 

  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

  applypatch $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
"
