# -*- 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 88165 2011-12-21 07:55:35Z dports@macports.org $

PortSystem 1.0

name            openjade
version         1.3.2
revision        3
categories      textproc
license         MIT
maintainers     nomaintainer
description     James Clark's implementation of DSSSL
homepage        http://openjade.sourceforge.net/
platforms       darwin freebsd

long_description OpenJade is an implementation of ISO/IEC 10179:1996 \
                 standard DSSSL language.

master_sites   sourceforge

checksums       md5 7df692e3186109cc00db6825b777201e

patchfiles      patch-Makefile.lib.in \
                patch-Makefile.prog.in \
                patch-ltmain.sh \
                patch-configure \
                patch-GroveApp.h \
                patch-GroveBuilder.cxx \
                patch-Node.h

depends_lib     port:opensp
depends_run     port:xmlcatmgr

if {${configure.compiler} == "clang"} { 
    configure.compiler llvm-gcc-4.2 
} 

# xmlcatmgr as installed by MacPorts defaults to using
# ${prefix}/etc/sgml/catalog (for XML) and ${prefix}/etc/sgml/catalog (for
# SGML). For historic reasons, openjade expects the catalog to be in
# share/sgml/catalog. To avoid breaking existing setup, we simply add
# a reference to the root catalog (/etc/sgml/catalog) to openjade's
# catalog (/share/sgml/catalog)
set catalog.sgml      ${prefix}/etc/sgml/catalog
set catalog.openjade  ${prefix}/share/sgml/catalog
 
configure.args  --enable-http --enable-html --enable-mif \
                --disable-dependency-tracking \
                --enable-default-catalog=${catalog.openjade} \
                --datadir=${prefix}/share/sgml/openjade \
                --mandir=${prefix}/share/man

configure.env-append        LIBS="-L${prefix}/lib"
configure.cxxflags-append   "-isystem ${prefix}/include -fno-rtti"
configure.ldflags-delete    "-L${prefix}/lib"

post-configure  {
    reinplace "s|^#pragma implementation||g" ${worksrcpath}/grove/Node.cxx
    reinplace "s|^#pragma implementation||g" ${worksrcpath}/msggen.pl
    reinplace "s|^#pragma implementation||g" ${worksrcpath}/spgrove/GroveApp.cxx
    reinplace "s|^#pragma implementation||g" ${worksrcpath}/style/MessageModule.cxx
    reinplace "s|^#pragma interface||g" ${worksrcpath}/generic/EventGenerator.h
    reinplace "s|^#pragma interface||g" ${worksrcpath}/generic/ParserEventGeneratorKit.h
    reinplace "s|^#pragma interface||g" ${worksrcpath}/generic/SGMLApplication.h
    reinplace "s|^#pragma interface||g" ${worksrcpath}/grove/Node.h
    reinplace "s|^#pragma interface||g" ${worksrcpath}/msggen.pl
    reinplace "s|^#pragma interface||g" ${worksrcpath}/spgrove/GroveApp.h
    reinplace "s|^CXX=.*$|CXX='${configure.cxx} [get_canonical_archflags]'|g" ${worksrcpath}/libtool 
 	reinplace "s|^CC=.*$|CC='${configure.cc} [get_canonical_archflags]'|g" ${worksrcpath}/libtool 
}

destroot.target install install-man

post-destroot   {
    system "install -d -m 755 ${destroot}${prefix}/share/sgml/openjade"
    system "install -m 644 ${worksrcpath}/dsssl/* ${destroot}${prefix}/share/sgml/openjade"
}

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 root catalog file if it doesn't exist
    if {![file exists ${catalog.sgml}]} {
        system "xmlcatmgr -s -c ${catalog.sgml} create"
    }

    # Create the openjade catalog file if it doesn't exist
    if {![file exists ${catalog.openjade}]} {
        system "xmlcatmgr -s -c ${catalog.openjade} create"
    }

    # Add the root catalog to openjade's catalog
    if {[catch {exec xmlcatmgr -s -c ${catalog.openjade} lookup ${catalog.sgml}}]} {
        system "xmlcatmgr -s -c ${catalog.openjade} add CATALOG ${catalog.sgml}"
    }

    # And add openjade's catalog to the root catalog
    if {[catch {exec xmlcatmgr -s -c ${catalog.sgml} lookup ${prefix}/share/sgml/openjade/catalog}]} {
        system "xmlcatmgr -s -c ${catalog.sgml} add CATALOG ${prefix}/share/sgml/openjade/catalog"
    }
}

# This will remove the catalog entry for this port.
post-deactivate {
    # Remove the CATALOG entry from the catalog
    system "xmlcatmgr -s -c ${catalog.sgml} remove CATALOG ${prefix}/share/sgml/openjade/catalog"
}
