##
##  docbook.spec -- OpenPKG RPM Specification
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  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.
##

%define       V_dtd_sgml       4.2
%define       V_dtd_xml        4.2
%define       V_ss_dsssl       1.77
%define       V_ss_xsl         1.58.1

#   package information
Name:         docbook
Summary:      DocBook SGML DTD and Tools
URL:          http://www.oasis-open.org/docbook/
Vendor:       OASIS
Packager:     The OpenPKG Project
Distribution: OpenPKG [PLUS]
Group:        SGML
License:      BSD
Version:      4.2
Release:      20021129

#   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/sgml/%{V_dtd_sgml}/docbook-%{V_dtd_sgml}.zip
Source2:      http://fallout.campusview.indiana.edu/ports/distfiles/isoENTS.zip
Source3:      http://osdn.dl.sourceforge.net/sourceforge/docbook/docbook-xsl-%{V_ss_xsl}.tar.gz
Source4:      http://osdn.dl.sourceforge.net/sourceforge/docbook/docbook-dsssl-%{V_ss_dsssl}.tar.gz
Source5:      isoENTS.catalog

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20020206, infozip, sgml
PreReq:       OpenPKG, openpkg >= 20020206, sgml
AutoReq:      no
AutoReqProv:  no

%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.

%prep
    rm -rf docbook-%{version}
    mkdir docbook-%{version}
    cd docbook-%{version}
    for zip in %{SOURCE0} %{SOURCE1} %{SOURCE2}; do
        base=`echo $zip | sed -e 's;^.*/\([^/]*\)\.zip$;\1;'`
        mkdir $base
        (cd $base; %{l_prefix}/bin/unzip -q -x $zip)
    done
    for tgz in %{SOURCE3} %{SOURCE4}; do
        base=`echo $tgz | sed -e 's;^.*/\([^/]*\)\.tar.gz$;\1;'`
        %{l_gzip} -d -c $tgz | %{l_tar} -xf -
    done

%build
    :

%install
    rm -rf $RPM_BUILD_ROOT
    cd docbook-%{version}

    %{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 -rp * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-xml/
    )

    #   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 -rp * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-dtd-sgml/
    )
    ( cd isoENTS
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/iso8879-sgml
      cp -rp * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/iso8879-sgml/
      %{l_shtool} install -c -m 644 \
          %{SOURCE isoENTS.catalog} \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/iso8879-sgml/catalog
    )

    #   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
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-ss-xsl
      cp -rp * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-ss-xsl/
    )

    #   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 -rp * $RPM_BUILD_ROOT%{l_prefix}/share/sgml/docbook-ss-dsssl/
    )

    cd ..
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%not %dir %{l_prefix}/share/sgml'

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
    if [ $1 -eq 1 ]; then
        $RPM_INSTALL_PREFIX/bin/mkcatalog -q install iso8879-sgml
        $RPM_INSTALL_PREFIX/bin/mkcatalog -q install docbook-dtd-xml
        $RPM_INSTALL_PREFIX/bin/mkcatalog -q install docbook-dtd-sgml
        $RPM_INSTALL_PREFIX/bin/mkcatalog -q install docbook-ss-dsssl
    fi

%preun
    if [ $1 -eq 0 ]; then
        $RPM_INSTALL_PREFIX/bin/mkcatalog -q deinstall iso8879-sgml
        $RPM_INSTALL_PREFIX/bin/mkcatalog -q deinstall docbook-dtd-xml
        $RPM_INSTALL_PREFIX/bin/mkcatalog -q deinstall docbook-dtd-sgml
        $RPM_INSTALL_PREFIX/bin/mkcatalog -q deinstall docbook-ss-dsssl
    fi

