# $Id: Portfile 86410 2011-10-25 11:15:36Z dports@macports.org $

PortSystem 1.0
name		iso8879
version		1986
revision	1
categories	textproc
license		Permissive
maintainers	nomaintainer
description	Character entity sets from ISO 8879:1986 (SGML)
platforms	darwin

long_description $description

master_sites	freebsd

distname	isoENTS
checksums	md5 c8a9561212c1a2ec6e48919640de9c67

use_zip		yes

depends_run	port:xmlcatmgr

use_configure	no
build		{}

set install_dir	${prefix}/share/sgml/${name}

# 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	{
	xinstall -m 755 -d ${destroot}${install_dir}
	xinstall -m 644 ${portpath}/${filesdir}/catalog ${destroot}${install_dir}
	eval xinstall -m 644 [glob ${workpath}/ISO*] ${destroot}${install_dir}
}

destroot.args	prefix=${destroot}${prefix}

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}/catalog}]} {
        system "xmlcatmgr ${xmlcatmgr.args} add CATALOG ${install_dir}/catalog"
    }
}

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