##
##  docbook.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and 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.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package versions
%define       V_dtd_sgml       4.5
%define       V_dtd_sgml_old   4.2
%define       V_dtd_xml        4.5
%define       V_dtd_xml_old    4.2
%define       V_dtd_simple     1.0
%define       V_ss_dsssl       1.79
%define       V_ss_xsl         1.79.1

#   package information
Name:         docbook
Summary:      DocBook SGML DTD and Tools
URL:          http://www.oasis-open.org/docbook/
Vendor:       OASIS
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        XML
License:      BSD
Version:      %{V_dtd_xml}
Release:      20171212

#   list of sources
Source0:      http://www.oasis-open.org/docbook/xml/%{V_dtd_xml}/docbook-xml-%{V_dtd_xml}.zip
Source1:      http://www.oasis-open.org/docbook/xml/%{V_dtd_xml_old}/docbook-xml-%{V_dtd_xml_old}.zip
Source2:      http://www.oasis-open.org/docbook/xml/simple/%{V_dtd_simple}/docbook-simple-%{V_dtd_simple}.zip
Source3:      http://www.oasis-open.org/docbook/sgml/%{V_dtd_sgml}/docbook-%{V_dtd_sgml}.zip
Source4:      http://www.oasis-open.org/docbook/sgml/%{V_dtd_sgml_old}/docbook-%{V_dtd_sgml_old}.zip
Source5:      http://fallout.campusview.indiana.edu/ports/distfiles/isoENTS.zip
Source6:      http://download.sourceforge.net/docbook/docbook-xsl-%{V_ss_xsl}.tar.bz2
Source7:      http://download.sourceforge.net/docbook/docbook-dsssl-%{V_ss_dsssl}.tar.gz
Source8:      isoENTS.catalog
Source9:      simple.catalog

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, infozip, sgml
PreReq:       OpenPKG, openpkg >= 20160101, sgml

%description
    DocBook is a Document Type Description (DTD) for both XML and
    SGML, maintained by the DocBook Technical Committee of OASIS. It
    is particularly well suited to books and papers about computer
    hardware and software (though it is by no means limited to these
    applications). Output can be rendered with SGML/DSSSL and XML/XSL
    stylesheets. This package contains DTDs and stylesheets for
    SGML/DSSSL and XML/XSL only.

%track
    prog docbook:docbook-dsssl = {
        version   = %{V_ss_dsssl}
        url       = http://sourceforge.net/projects/docbook/files/
        regex     = docbook-dsssl-(__VER__)\.tar\.gz
    }
    prog docbook:docbook-sgml = {
        version   = %{V_dtd_sgml}
        url       = http://docbook.org/sgml/4.2/
        regex     = docbook-(__VER__)\.zip
    }
    prog docbook:docbook-simple = {
        version   = %{V_dtd_simple}
        url       = http://www.oasis-open.org/docbook/xml/simple/1.0/
        regex     = docbook-simple-(__VER__)\.zip
    }
    prog docbook:docbook-xml = {
        version   = %{V_dtd_xml}
        url       = http://docbook.org/xml/4.5/
        regex     = docbook-xml-(__VER__)\.zip
    }
    prog docbook:docbook-xsl = {
        version   = %{V_ss_xsl}
        url       = http://sourceforge.net/projects/docbook/files/
        regex     = docbook-xsl-(__VER__)\.tar\.gz
    }

%prep
    %setup -c -T
    for zip in %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5}; do
        base=`echo $zip | sed -e 's;^.*/\([^/]*\)\.zip$;\1;'`
        mkdir $base
        ( cd $base; %{l_prefix}/bin/unzip -q -x $zip ) || exit $?
    done
    for tgz in %{SOURCE6}; do
        %{l_bzip2} -d -c $tgz | %{l_tar} -xf -
    done
    for tgz in %{SOURCE7}; do
        %{l_gzip} -d -c $tgz | %{l_tar} -xf -
    done

%build

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/share/sgml

    #   install DocBook XML DTD
    ( cd docbook-xml-%{V_dtd_xml}
      mv docbook.cat catalog
      rm -f ChangeLog README
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-xml
      cp -r * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-xml/
    ) || exit $?
    ( cd docbook-xml-%{V_dtd_xml_old}
      mv docbook.cat catalog
      rm -f ChangeLog README
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-xml-old
      cp -r * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-xml-old/
    ) || exit $?

    #   install Simplified DocBook DTD
    ( cd docbook-simple-%{V_dtd_simple}
      cp %{SOURCE simple.catalog} catalog
      rm -f ChangeLog README
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-simple
      cp -r * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-simple/
    ) || exit $?

    #   install DocBook SGML DTD
    ( cd docbook-%{V_dtd_sgml}
      mv docbook.cat catalog
      rm -f ChangeLog README
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-sgml
      cp -r * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-sgml/
    ) || exit $?
    ( cd docbook-%{V_dtd_sgml_old}
      mv docbook.cat catalog
      rm -f ChangeLog README
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-sgml-old
      cp -r * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-sgml-old/
    ) || exit $?
    ( cd isoENTS
      cp %{SOURCE isoENTS.catalog} catalog
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/iso8879-sgml
      chmod 644 *
      cp * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/iso8879-sgml/
    ) || exit $?

    #   install DocBook XSL Stylesheets (for XML)
    ( cd docbook-xsl-%{V_ss_xsl}
      rm -f [A-UW-Z]*
      rm -rf extensions doc docsrc
      find . -name ChangeLog -print | xargs rm -f
      find . -name "*.bak" -print | xargs rm -f
      find . -name README -print | xargs rm -f
      rm -f fo/pdf2index
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-ss-xsl
      chmod 644 params/*
      cp -r * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-ss-xsl/
    ) || exit $?

    #   install DocBook DSSSL Stylesheets (for SGML)
    ( cd docbook-dsssl-%{V_ss_dsssl}
      rm -f [A-UW-Z]*
      rm -rf bin doc docsrc debian
      find . -name ChangeLog -print | xargs rm -f
      find . -name "*.bak" -print | xargs rm -f
      find . -name README -print | xargs rm -f
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-ss-dsssl
      cp -r * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-ss-dsssl/
    ) || exit $?

    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std}

%files -f files

%clean

%post
    if [ $1 -eq 1 ]; then
        $RPM_INSTALL_PREFIX/bin/sgmlcatalog \
            -p "ISO 8879:1986" \
            -s "ISO 8879:1986//ENTITIES" \
            -i iso8879-sgml \
            -p "-//OASIS//DTD DocBook XML V4.2" \
            -p "-//OASIS//ENTITIES DocBook XML V4.2" \
            -S "http://www.oasis-open.org/docbook/xml/4.2" \
            -U "http://www.oasis-open.org/docbook/xml/4.2" \
            -x \
            -i docbook-dtd-xml-old \
            -p "-//OASIS//ELEMENTS DocBook XML Information Pool V4.5" \
            -p "-//OASIS//DTD DocBook XML V4.5" \
            -p "-//OASIS//ENTITIES DocBook XML Character Entities V4.5" \
            -p "-//OASIS//ENTITIES DocBook XML Notations V4.5" \
            -p "-//OASIS//ENTITIES DocBook XML Additional General Entities V4.5" \
            -p "-//OASIS//ENTITIES DocBook XML Document Hierarchy V4.5" \
            -p "-//OASIS//DTD XML Exchange Table Model 19990315" \
            -p "-//OASIS//DTD DocBook XML CALS Table Model V4.5" \
            -p "-//OASIS//ENTITIES DocBook XML" \
            -p "-//OASIS//DTD DocBook XML" \
            -S "http://www.oasis-open.org/docbook/xml/4.5" \
            -S "http://www.oasis-open.org/docbook/" \
            -U "http://www.oasis-open.org/docbook/xml/4.5" \
            -U "http://www.oasis-open.org/docbook/" \
            -i docbook-dtd-xml \
            -p "-//OASIS//DTD Simplified DocBook XML V1.0" \
            -p "-//OASIS//DTD Simplified DocBook RefEntry XML V1.0" \
            -i docbook-dtd-simple \
            -p "-//OASIS//DTD DocBook V4.5" \
            -i docbook-dtd-sgml-old \
            -p "-//OASIS//DTD DocBook V4.2" \
            -i docbook-dtd-sgml \
            -p "-//Norman Walsh//DOCUMENT DocBook " \
            -p "-//Norman Walsh//DOCUMENT DSSSL " \
            -p "-//Norman Walsh//DOCUMENT OLink " \
            -p "+//IDN nwalsh.com//DTD DocBook" \
            -p "-//Norman Walsh//DTD DocBook" \
            -p "-//Norman Walsh//DTD Image Library" \
            -i docbook-ss-dsssl \
            -S "http://docbook.sourceforge.net/release/xsl/current" \
            -S "http://docbook.sourceforge.net/release/xsl/1.39" \
            -S "http://docbook.sourceforge.net/release/xsl/1.40" \
            -S "http://docbook.sourceforge.net/release/xsl/1.41" \
            -S "http://docbook.sourceforge.net/release/xsl/1.42" \
            -S "http://docbook.sourceforge.net/release/xsl/1.43" \
            -S "http://docbook.sourceforge.net/release/xsl/1.44" \
            -S "http://docbook.sourceforge.net/release/xsl/1.45" \
            -S "http://docbook.sourceforge.net/release/xsl/1.46" \
            -S "http://docbook.sourceforge.net/release/xsl/1.47" \
            -S "http://docbook.sourceforge.net/release/xsl/1.48" \
            -S "http://docbook.sourceforge.net/release/xsl/1.49" \
            -S "http://docbook.sourceforge.net/release/xsl/1.50" \
            -U "http://docbook.sourceforge.net/release/xsl/current" \
            -U "http://docbook.sourceforge.net/release/xsl/1.39" \
            -U "http://docbook.sourceforge.net/release/xsl/1.40" \
            -U "http://docbook.sourceforge.net/release/xsl/1.41" \
            -U "http://docbook.sourceforge.net/release/xsl/1.42" \
            -U "http://docbook.sourceforge.net/release/xsl/1.43" \
            -U "http://docbook.sourceforge.net/release/xsl/1.44" \
            -U "http://docbook.sourceforge.net/release/xsl/1.45" \
            -U "http://docbook.sourceforge.net/release/xsl/1.46" \
            -U "http://docbook.sourceforge.net/release/xsl/1.47" \
            -U "http://docbook.sourceforge.net/release/xsl/1.48" \
            -U "http://docbook.sourceforge.net/release/xsl/1.49" \
            -U "http://docbook.sourceforge.net/release/xsl/1.50" \
            -S "http://docbook.sourceforge.net/release/xsl/" \
            -U "http://docbook.sourceforge.net/release/xsl/" \
            -i docbook-ss-xsl
    fi

%preun
    if [ $1 -eq 0 ]; then
        $RPM_INSTALL_PREFIX/bin/sgmlcatalog \
            -d iso8879-sgml \
            -x \
            -d docbook-dtd-xml-old \
            -d docbook-dtd-xml \
            -d docbook-dtd-simple \
            -d docbook-dtd-sgml \
            -d docbook-ss-dsssl \
            -d docbook-ss-xsl
    fi

