# $Id: Portfile 80952 2011-07-21 23:51:47Z jmr@macports.org $

PortSystem 1.0

name        docbook-sgml-4.2
version     [strsed ${name} {s/docbook-sgml-//}]
description Version ${version} of the DocBook SGML DTDs
long_description \
    Version ${version} of the DocBook SGML DTDs, which provide a structured,\
    semantic markup format for books and documentation, especially for\
    computer hardware and software.
categories  textproc
license     MIT Permissive
platforms   darwin
maintainers phlo.org:fgp
supported_archs noarch
distname    docbook-${version}

homepage    http://www.docbook.org/sgml/${version}/
master_sites    http://www.oasis-open.org/docbook/sgml/${version}/
checksums   md5 0dfeb94569334dd22a62d90d99fc0630 \
            sha1 98afcae616ed24edb30e40baa4ddd8cd8731f2c7
worksrcdir  ${distname}

depends_run port:xmlcatmgr port:docbook-dsssl port:iso8879

use_zip     yes

extract.mkdir   yes

use_configure   no
build       {}

set install_dir    ${prefix}/share/sgml/docbook/${version}

# xmlcatmgr as installed by MacPorts defaults to using
# ${prefix}/etc/sgml/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 catalog.sgml ${prefix}/etc/sgml/catalog
set xmlcatmgr.args "-s -c ${catalog.sgml}"

destroot {
    set destroot_dir    ${destroot}${install_dir}
    set destroot_files  [readdir ${worksrcpath}]
    xinstall -m 755 -d ${destroot_dir}
    foreach file ${destroot_files} {
        copy ${worksrcpath}/${file} ${destroot_dir}
    }
}

post-activate {
    # Make the directory if it doesn't exist
    if {![file exists ${prefix}/etc/sgml]} {
        xinstall -m 755 -d ${prefix}/etc/sgml
    }

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

    # Add the CATALOG entry to the catalog if it doesn't exist
    if {[catch {exec xmlcatmgr ${xmlcatmgr.args} lookup ${install_dir}/docbook.cat}]} {
        system "xmlcatmgr ${xmlcatmgr.args} add CATALOG ${install_dir}/docbook.cat"
    }
}

if {${registry.format} == "receipt_flat"} {
    notes \
"######################################################################
# As the flat registry format does not support post-deactivate hooks,
# you will need to ensure that you manually remove the catalog
# entry for this port when you uninstall it.  To do so, run
# \"xmlcatmgr ${xmlcatmgr.args} remove CATALOG ${install_dir}/docbook.cat\".
######################################################################"
}

# This will remove the catalog entry for this port.
post-deactivate {
    # Remove the CATALOG entry from the catalog
    system "xmlcatmgr ${xmlcatmgr.args} remove CATALOG ${install_dir}/docbook.cat"
}
