# -*- 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 86420 2011-10-25 13:54:14Z dports@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
homepage        http://www.docbook.org/sgml/${version}/

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

master_sites    http://www.oasis-open.org/docbook/sgml/${version}/
distname        docbook-${version}
worksrcdir      ${distname}

checksums       rmd160  f97bf5c595f1f28d0bb4be6549b27f701da7c9f8 \
                sha256  67ebd2c94b342718c6865d2de60f5d4ff02d77a7e4b0d9e72a48c45f2b2635c3

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"
    }
}

# 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"
}
