%define Name docbook-dtd41-xml
%define Version 1.0

Name        	: %{Name}
Version     	: %{Version}
Release     	: 9
Group       	: Textprocessing/Tools

Summary     	: XML document type definition for DocBook 4.1.

Copyright   	: 1992-2000 HaL Computer Systems, Inc., O'Reilly & Associates, Inc., ArborText, Inc., Fujitsu Software Corporation, Norman Walsh, and the Organization for the Advancement of Structured Information Standards (OASIS); distributable
Packager    	: Eric Bischoff <eric@caldera.de>, Mark Galassi <rosalia@galassi.org>
URL         	: http://www.oasis-open.org/docbook/

Provides        : docbook-dtd-sgml
Requires    	: sgml-common >= 0.6.3
Prereq		: sgml-common

BuildRoot   	: /tmp/%{Name}-%{Version}

BuildArch	: noarch
Source0		: http://www.oasis-open.org/docbook/xml/4.1/docbkx41.zip
Source1		: %{Name}-%{Version}.Makefile
Patch0		: %{Name}-%{Version}.catalog.patch
Patch1		: %{Name}-%{Version}.dbcentx.patch


%Description
The DocBook Document Type Definition (DTD) describes the syntax of
technical documentation texts (articles, books and manual pages).
This syntax is XML-compliant and is developped by the OASIS consortium.
This is the version 4.1 of this DTD.


%Prep
%setup -c -T
unzip %{SOURCE0}
if [ `id -u` -eq 0 ]; then
  chown -R root.root .
  chmod -R a+rX,g-w,o-w .
fi
cp %{SOURCE1} Makefile
%patch0
%patch1


%Build


%Install
DESTDIR=$RPM_BUILD_ROOT
make install DESTDIR=$DESTDIR/usr/share/sgml/docbook/xml-dtd-4.1


%Clean
DESTDIR=$RPM_BUILD_ROOT
rm -rf $DESTDIR


%Files
%defattr (-,root,root)
%doc *.txt
/usr/share/sgml/docbook/xml-dtd-4.1/dbgenent.ent
/usr/share/sgml/docbook/xml-dtd-4.1/catalog
/usr/share/sgml/docbook/xml-dtd-4.1/*.dtd
/usr/share/sgml/docbook/xml-dtd-4.1/*.mod


%Post
# Avoid adding things when updating (postuninstall of old package is called *after* postinstall of new package)
if [ $1 -gt 1 ]; then exit 0; fi

# Update the centralized catalog corresponding to this version of the DTD
/usr/bin/install-catalog --add /etc/sgml/xml-docbook-4.1.cat /usr/share/sgml/sgml-iso-entities-8879.1986/catalog
/usr/bin/install-catalog --add /etc/sgml/xml-docbook-4.1.cat /usr/share/sgml/docbook/xml-dtd-4.1/catalog

# The following lines are for the case in which the style sheets were installed after another DTD but before this DTD
STYLESHEETS=`rpm -q docbook-style-dsssl 2> /dev/null | sed 's/^docbook-style-dsssl-\(.*\)-.*$/\1/'`
if [ -n "$STYLESHEETS" ]; then
    /usr/bin/install-catalog --add /etc/sgml/xml-docbook-4.1.cat /usr/share/sgml/jade-1.2.1/catalog
    /usr/bin/install-catalog --add /etc/sgml/xml-docbook-4.1.cat /usr/share/sgml/docbook/dsssl-stylesheets-$STYLESHEETS/catalog
fi

# Update the link to the current version of the DTD
ln -s -f /etc/sgml/xml-docbook-4.1.cat /etc/sgml/xml-docbook.cat


%Postun
# Avoid removing things when updating (postuninstall of old package is called *after* postinstall of new package)
if [ $1 -gt 1 ]; then exit 0; fi

# Update the centralized catalog corresponding to this version of the DTD
/usr/bin/install-catalog --remove /etc/sgml/xml-docbook-4.1.cat /usr/share/sgml/sgml-iso-entities-8879.1986/catalog
/usr/bin/install-catalog --remove /etc/sgml/xml-docbook-4.1.cat /usr/share/sgml/docbook/xml-dtd-4.1/catalog

# The following lines are for the case in which the style sheets were not uninstalled because there is still another DTD
STYLESHEETS=`rpm -q docbook-style-dsssl 2> /dev/null | sed 's/^docbook-style-dsssl-\(.*\)-.*$/\1/'`
if [ -n "$STYLESHEETS" ]; then
    /usr/bin/install-catalog --remove /etc/sgml/xml-docbook-4.1.cat /usr/share/sgml/jade-1.2.1/catalog
    /usr/bin/install-catalog --remove /etc/sgml/xml-docbook-4.1.cat /usr/share/sgml/docbook/dsssl-stylesheets-$STYLESHEETS/catalog
fi

# Update the link to the current version of the DTD
if [ ! -e /etc/sgml/xml-docbook-4.1.cat ]; then
    rm -f /etc/sgml/xml-docbook.cat
    OTHERCAT=`ls /etc/sgml/xml-docbook-?.?.cat 2> /dev/null | head --lines 1`
    if [ -n "$OTHERCAT" ]; then ln -s $OTHERCAT /etc/sgml/xml-docbook.cat; fi
fi