# -*- 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

PortSystem      1.0
PortGroup       xmlcatalog 1.0

name            openjade
version         1.3.2
revision        11
categories      textproc
license         MIT
maintainers     {gmail.com:tlockhart1976 @lockhart} openmaintainer
description     James Clark’s implementation of DSSSL
long_description \
    OpenJade is an implementation of ISO/IEC 10179:1996 \
    standard DSSSL language.
homepage        http://openjade.sourceforge.net/
platforms       darwin freebsd
master_sites    sourceforge

checksums       rmd160  3b12f6596a42c49a60cc07cd9b8f4c5fdf3bafd2 \
                sha256  1d2d7996cc94f9b87d0c51cf0e028070ac177c4123ecbfd7ac1cb8d0b7d322d1 \
                size    894834

patchfiles      patch-clang.diff \
                patch-GroveApp.h.diff \
                patch-GroveBuilder.cxx.diff \
                patch-Node.h.diff \
                patch-openjade-getoptperl.diff \
                patch-delete_la_files.diff

depends_lib-append  port:opensp

set openjade.catalog ${prefix}/share/sgml/catalog
set openjade.rootcatalog ${prefix}/share/sgml/openjade/catalog

sgml.catalog ${openjade.rootcatalog}
# Add the root catalog to the openjade catalog
sgml.addtocatalog "${openjade.catalog}" "${sgml.rootcatalog}"

configure.args  --enable-http --enable-html --enable-mif \
                --disable-dependency-tracking \
                --enable-default-catalog=${openjade.catalog} \
                --datadir=${prefix}/share/sgml/openjade \
                --mandir=${prefix}/share/man

# Fix build failure on Tiger due to use of -isystem
compiler.blacklist      gcc-4.0 gcc-3.3

set cxx_stdlibflags {}
if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    set cxx_stdlibflags "-stdlib=${configure.cxx_stdlib}"
}

configure.env-append        LIBS=-L${prefix}/lib
# Note: Cxx98 necessary due to OpenSP
configure.cxxflags-append   "-isystem ${prefix}/include -fno-rtti -std=c++98"
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] ${cxx_stdlibflags}'|g" ${worksrcpath}/libtool
    reinplace "s|^CC=.*$|CC='${configure.cc} [get_canonical_archflags]'|g" ${worksrcpath}/libtool
}

destroot.target install install-man

post-destroot {
    xinstall -d ${destroot}${prefix}/share/sgml/openjade
    xinstall -m 644 {*}[glob ${worksrcpath}/dsssl/*] ${destroot}${prefix}/share/sgml/openjade
}
