# -*- 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 98259 2012-10-01 05:34:33Z pixilla@macports.org $

PortSystem          1.0

name                docbook-utils
version             0.6.14
revision            1
categories          textproc
platforms           darwin
license             GPL-2+
maintainers         fourpalms.org:lockhart openmaintainer
homepage            http://sources.redhat.com/docbook-tools/
description         Shell scripts for managing DocBook documents
long_description    This package contains scripts are for easy conversion from DocBook \
                    files to other formats (for example, HTML, RTF, and PostScript), and \
                    for comparing SGML files. \
                    Transcribed from the Fedora 15 RPM written originally by \
                    Tim Waugh <twaugh@redhat.com> based on work by Eric Bischoff \
                    and with recent maintenance by Ondrej Vasik <ovasik@redhat.com>.
master_sites        ftp://sources.redhat.com/pub/docbook-tools/new-trials/SOURCES/

checksums           rmd160  710fe047ea8a794cc6c0d944521184375a666e6b \
                    sha256  48faab8ee8a7605c9342fb7b906e0815e3cee84a489182af38e8f7c0df2e92e9

conflicts           docbook2X

depends_lib         port:sgml-common \
                    port:p5.12-sgmlspm \
                    port:openjade \
                    port:docbook-dsssl \
                    port:docbook-sgml-4.2

configure.args-append --mandir=${prefix}/share/man

post-extract {
    copy ${filespath}/docbook2man-spec.pl \
        ${worksrcpath}/bin/
}

patch.pre_args      -p1
patchfiles          docbook-utils-spaces.patch \
                    docbook-utils-2ndspaces.patch \
                    docbook-utils-w3mtxtconvert.patch \
                    docbook-utils-grepnocolors.patch \
                    docbook-utils-sgmlinclude.patch \
                    docbook-utils-rtfmanpage.patch \
                    docbook-utils-papersize.patch \
                    docbook-utils-nofinalecho.patch \
                    docbook-utils-newgrep.patch


post-patch {
    reinplace -E "s|^docdir=.+$|docdir='${prefix}/share/doc'|" \
        ${worksrcpath}/configure
    reinplace -E "s|^(htmldir = .+)(/html)(.+)$|\\1\\3\\2|" \
        ${worksrcpath}/doc/HTML/Makefile.in

    reinplace "s|/etc/sgml|${prefix}/etc/sgml|" \
        ${worksrcpath}/bin/jw.in \
        ${worksrcpath}/doc/man/Makefile.in \
        ${worksrcpath}/doc/HTML/Makefile.in
    reinplace "s|jade|openjade|" \
        ${worksrcpath}/doc/man/Makefile.in \
        ${worksrcpath}/doc/HTML/Makefile.in
    reinplace "s|nsgmls|onsgmls|" \
        ${worksrcpath}/doc/man/Makefile.in \
        ${worksrcpath}/doc/HTML/Makefile.in

    # Update content to docbook-4.x since we do not have 3.x available in MacPorts
    reinplace "s|V3.1|V4.2|" ${worksrcpath}/doc/docbook-utils.sgml
    reinplace "s|docinfo|chapterinfo|" \
        ${worksrcpath}/doc/docbook-utils.sgml
    reinplace "s|docinfo|refentryinfo|" \
        ${worksrcpath}/doc/refentry/docbook2man-spec.pl.sgml \
        ${worksrcpath}/doc/refentry/jw.sgml \
        ${worksrcpath}/doc/refentry/frontend-spec.sgml \
        ${worksrcpath}/doc/refentry/backend-spec.sgml \
        ${worksrcpath}/doc/refentry/sgmldiff.sgml
    reinplace "s|<Comment>|<!-- |" \
        ${worksrcpath}/doc/refentry/docbook2man-spec.pl.sgml
    reinplace "s|</Comment>| -->|" \
        ${worksrcpath}/doc/refentry/docbook2man-spec.pl.sgml
}
