description="Tools for maintaining centralized SGML catalogs."
url="http://www.docbook.org/xml/"

packager="Great-OS Team"
maintainer="Great-OS Team"

name=sgml-common
version=0.6.3
release=3

source=(http://anduin.linuxfromscratch.org/BLFS/sgml-common/sgml-common-$version.tgz
        http://www.linuxfromscratch.org/patches/blfs/svn/sgml-common-$version-manpage-1.patch)

build(){
    cd $name-$version

    patch -Np1 -i ../sgml-common-$version-manpage-1.patch &&

    autoreconf -fiv

    ./configure --prefix=/usr \
                --sysconfdir=/etc

    make
    make DESTDIR=$PKG install

    # fix doc dir
    mv $PKG/usr/doc $PKG/usr/share/doc

    mkdir -p $PKG/usr/bin
    cat > $PKG/usr/bin/rebuild-sgml-common << EOF
#!/usr/bin/env bash
if [ -e /etc/sgml/sgml-ent.cat ]; then
  install-catalog --remove /etc/sgml/sgml-ent.cat \
    /usr/share/sgml/sgml-iso-entities-8879.1986/catalog

  install-catalog --remove /etc/sgml/sgml-docbook.cat \
    /etc/sgml/sgml-ent.cat
fi
  
install-catalog --add /etc/sgml/sgml-ent.cat \
    /usr/share/sgml/sgml-iso-entities-8879.1986/catalog

install-catalog --add /etc/sgml/sgml-docbook.cat \
    /etc/sgml/sgml-ent.cat
EOF

chmod +x $PKG/usr/bin/rebuild-sgml-common
}
