# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 99124 2012-10-27 19:39:14Z ryandesign@macports.org $

PortSystem          1.0

name                sgml-common
version             0.6.3
set openjade_version 1.3.2
categories          textproc
platforms           darwin
license             GPL-2+
maintainers         fourpalms.org:lockhart openmaintainer
supported_archs     noarch

# Actually - there is no homepage of this project, on that URL
# page you could get complete ISO 8879 listing as was on the
# old page - only part of it is included in sgml-common package.
homepage            http://www.w3.org/2003/entities/
description         A collection of entities and DTDs common to multiple packages.
long_description    The sgml-common package contains a collection of entities and DTDs \
                    that are useful for processing SGML, but that don't need to be \
                    included in multiple packages.  Sgml-common also includes an \
                    up-to-date Open Catalog file. \
                    Transcribed from the Fedora 15 RPM written originally by \
                    Tim Waugh <twaugh@redhat.com> based on work by Eric Bischoff \
                    and with recent maintenance by Ondrej Vasik <ovasik@redhat.com>.

master_sites        ftp://sources.redhat.com/pub/docbook-tools/new-trials/SOURCES/:redhat \
                    sourceforge:project/openjade/openjade/${openjade_version}:openjade

extract.suffix      .tgz
set openjade        openjade-${openjade_version}

distfiles           ${distname}${extract.suffix}:redhat \
                    ${openjade}.tar.gz:openjade

checksums           ${distname}${extract.suffix} \
                    rmd160  246d01272f70cd8382a7d596392e61d7dc0eec78 \
                    sha256  7dc418c1d361123ffc5e45d61f1b97257940a8eb35d0bfbbc493381cc5b1f959 \
                    ${openjade}.tar.gz \
                    rmd160  3b12f6596a42c49a60cc07cd9b8f4c5fdf3bafd2 \
                    sha256  1d2d7996cc94f9b87d0c51cf0e028070ac177c4123ecbfd7ac1cb8d0b7d322d1

depends_lib         port:perl5 \
                    port:libxml2 \
                    port:openjade \
                    port:docbook-dsssl \
                    port:docbook-sgml-4.2

depends_run         port:xmlcatmgr

set bindir ${prefix}/bin
set confdir ${prefix}/etc
set datadir ${prefix}/share
set sgmldir ${datadir}/sgml
set sgmlcatalog ${confdir}/sgml/catalog
set xmldir ${datadir}/xml
set xmlcatalog ${confdir}/xml/catalog
# xmlcatmgr as installed by MacPorts defaults to using
# ${prefix}/etc/xml/catalog (for XML) and ${prefix}/etc/sgml/catalog (for
# SGML) if no catalog is specified, but we'll specify the path just in case
# users have another installation of xmlcatmgr and happen to have it before
# ${prefix}/bin in their PATH.
set xml.args       "-c ${xmlcatalog}"
set sgml.args      "-s -c ${sgmlcatalog}"

patch.pre_args      -p1
patchfiles          patch-bin-install-catalog.in.diff \
                    patch-config-sgml.conf.diff \
                    patch-xml-iso-entities-Makefile.am.diff \
                    patch-xml-iso-entities-Makefile.in.diff

post-patch {
    reinplace "s|@PREFIX@|${prefix}|" \
        ${worksrcpath}/config/sgml.conf
}

use_configure       no

build {
    # XML catalog
    # Make the directory if it doesn't exist
    if {![file exists ${confdir}/xml]} {
        xinstall -m 755 -d ${confdir}/xml
    }

    # Create the catalog file if it doesn't exist
    if {![file exists ${xmlcatalog}]} {
        system "xmlcatmgr ${xml.args} create"
    }

    # SGML catalog
    # Make the directory if it doesn't exist
    if {![file exists ${confdir}/sgml]} {
        xinstall -m 755 -d ${confdir}/sgml
    }

    # Create the catalog file if it doesn't exist
    if {![file exists ${sgmlcatalog}]} {
        system "xmlcatmgr ${sgml.args} create"
    }

    # Now put the common DocBook entries in it
    # system "${bindir}/xmlcatalog --noout --add 'delegatePublic' \
    #     '-//OASIS//ENTITIES DocBook XML' \
    #     'file://${confdir}/sgml/docbook/xmlcatalog' ${worksrcpath}${xmlcatalog}"
    # system "${bindir}/xmlcatalog --noout --add 'delegatePublic' \
    #     '-//OASIS//DTD DocBook XML' \
    #     'file://${confdir}/sgml/docbook/xmlcatalog' ${worksrcpath}${xmlcatalog}"
    # system "${bindir}/xmlcatalog --noout --add 'delegatePublic' \
    #     'ISO 8879:1986' \
    #     'file://${confdir}/sgml/docbook/xmlcatalog' ${worksrcpath}${xmlcatalog}"
    # system "${bindir}/xmlcatalog --noout --add 'delegateSystem' \
    #     'http://www.oasis-open.org/docbook/' \
    #     'file://${confdir}/sgml/docbook/xmlcatalog' ${worksrcpath}${xmlcatalog}"
    # system "${bindir}/xmlcatalog --noout --add 'delegateURI' \
    #     'http://www.oasis-open.org/docbook/' \
    #     'file://${confdir}/sgml/docbook/xmlcatalog'
	# ${worksrcpath}${xmlcatalog}"
    # Also create the common DocBook catalog
    # xinstall -d ${worksrcpath}${confdir}/sgml/docbook
    # system "${bindir}/xmlcatalog --noout --create \
    #     ${worksrcpath}${confdir}/sgml/docbook/xmlcatalog"
}

destroot {
    xinstall -d ${destroot}${confdir}/sgml
    xinstall ${worksrcpath}/config/sgml.conf ${destroot}${prefix}/etc/sgml/sgml.conf
    xinstall -d ${destroot}${sgmldir}
    # Following 4 from openjade/pubtext - same maintainer as in SGML-common, so up2date:
    xinstall -W ${workpath}/${openjade}/pubtext xml.dcl xml.soc html.dcl html.soc ${destroot}${sgmldir}
}
