# -*- 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           github 1.0
PortGroup           xmlcatalog 1.0

github.setup        docbook xslt10-stylesheets 1.79.2 release/
name                docbook-xsl
categories          textproc
platforms           any
maintainers         {ryandesign @ryandesign} openmaintainer
license             MIT Permissive
supported_archs     noarch

homepage            http://docbook.org/
github.tarball_from releases
use_bzip2           yes

set srcxslpaths     "assembly catalog.xml common eclipse epub epub3 extensions \
                    fo highlighting html htmlhelp images javahelp lib manpages \
                    params profiling roundtrip slides template tools webhelp \
                    website xhtml xhtml-1_1 xhtml5 VERSION VERSION.xsl"
set srcdocpaths     "AUTHORS BUGS README RELEASE-NOTES.html RELEASE-NOTES.txt \
                    TODO VERSION NEWS COPYING"
set instxsldir      share/xsl/${subport}
set instdocdir      share/doc/${subport}

if {${subport} eq ${name}} {
    PortGroup       obsolete 1.0
    replaced_by     ${name}-nons
    version         1.79.2
    revision        4
    description     The DocBook XSL stylesheets
    livecheck.type  regex
    livecheck.url   ${github.homepage}
    livecheck.regex {/release/(\d+(?:\.\d+)+)}
}

subport ${name}-nons {
    revision        1
    description     Non-namespaced version of the DocBook XSL stylesheets
    distname        ${subport}-${version}
    checksums       rmd160  63bae43e79c3b8bc3dac66711eb8c9e5ae3e4a32 \
                    sha256  ee8b9eca0b7a8f89075832a2da7534bce8c5478fc8fc2676f512d5d87d832102 \
                    size    23400667
}

subport ${name}-ns {
    revision        1
    description     Namespaced version of the DocBook XSL stylesheets
    distname        ${name}-${version}
    checksums       rmd160  425ca8723443bcd45c23d33df26e13b930b2ce42 \
                    sha256  316524ea444e53208a2fb90eeb676af755da96e1417835ba5f5eb719c81fa371 \
                    size    23404486
}

subport ${name}-docs {
    revision        1
    description     Documentation for the DocBook XSL stylesheets
    distname        ${name}-doc-${version}
    worksrcdir      ${name}-${version}
    checksums       rmd160  f0937514b2eaff60cdeca60b7dc1e86b07bf1e09 \
                    sha256  9bc38a3015717279a3a0620efb2d4bcace430077241ae2b0da609ba67d8340bc \
                    size    534208

    destroot {
        copy ${worksrcpath}/doc ${destroot}${prefix}/${instdocdir}
    }
}

long_description    ${description} -- the official stylesheets for transforming\
                    DocBook XML documents into other document formats via XSLT.

use_configure       no

build               {}

if {${subport} in [list "${name}-nons" "${name}-ns"]} {
    # Non-recursive string.subst that doesn't kill smb.conf.5 generation
    # See: https://trac.macports.org/ticket/72362
    patchfiles-append   patch-libxsl.diff

    xml.catalog     ${prefix}/${instxsldir}/catalog.xml \
                    ${prefix}/${instxsldir}/catalog.sf.xml

    destroot {
        foreach pathname "${instxsldir} ${instdocdir}" {
            xinstall -m 755 -d ${destroot}${prefix}/${pathname}
        }
        foreach pathname ${srcxslpaths} {
            copy ${worksrcpath}/${pathname} ${destroot}${prefix}/${instxsldir}
        }
        foreach pathname ${srcdocpaths} {
            copy ${worksrcpath}/${pathname} ${destroot}${prefix}/${instdocdir}
        }

        # Also register docbook.sourceforge.net URIs for backward compatibility
        copy ${destroot}${prefix}/${instxsldir}/catalog.xml ${destroot}${prefix}/${instxsldir}/catalog.sf.xml
        if {${subport} eq "${name}-ns"} {
            reinplace {s|/cdn\.docbook\.org/release/xsl/|/docbook.sourceforge.net/release/xsl-ns/|g} ${destroot}${prefix}/${instxsldir}/catalog.sf.xml
        } else {
            reinplace {s|/cdn\.docbook\.org/release/xsl-nons/|/docbook.sourceforge.net/release/xsl/|g} ${destroot}${prefix}/${instxsldir}/catalog.sf.xml
        }
    }

    if {${registry.format} eq "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 remove nextCatalog ${prefix}/${instxsldir}/catalog.xml\".
# \"xmlcatmgr remove nextCatalog ${prefix}/${instxsldir}/catalog.sf.xml\".
######################################################################"
    }
}

if {${subport} ne ${name}} {
    livecheck.type  none
}
