# $Id: Portfile 71533 2010-09-15 20:26:12Z ryandesign@macports.org $
PortSystem 1.0

name 		docbook-dsssl
version		1.79
categories	textproc
description	the docbook dsssl stylesheets
platforms	darwin
depends_run	port:xmlcatmgr
maintainers     decibel.org:decibel
master_sites	sourceforge:docbook
homepage	http://docbook.sf.net/
checksums	md5 8459913bbd8a5724a6fe4b9ed5bab5af
use_configure 	no
build		{}

set things_to_install	"common contrib dtds frames html images lib olink print catalog VERSION"
set install_dir		${prefix}/share/dsssl/${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	{
    # Docs
	xinstall -m 755 -d ${destroot}${install_dir} \
		${destroot}${prefix}/share/doc/${name} \
		${destroot}${prefix}/share/${name}
    
    # bin
	xinstall -m 755 -W ${worksrcpath} bin/collateindex.pl \
		${destroot}${prefix}/bin
    # man
	xinstall -m 644 -W ${worksrcpath} bin/collateindex.pl.1 \
		${destroot}${prefix}/share/man/man1

    # everything else
	xinstall -m 644 -W ${worksrcpath} BUGS ChangeLog README \
		RELEASE-NOTES.html RELEASE-NOTES.xml RELEASE-NOTES.txt WhatsNew \
		${destroot}${prefix}/share/doc/${name}
	foreach dirname $things_to_install {
		file copy ${worksrcpath}/${dirname} ${destroot}${install_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}/catalog}]} {
        system "xmlcatmgr ${xmlcatmgr.args} add CATALOG ${install_dir}/catalog"
    }
}

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