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

name                fop
version             1.1
revision            1
categories          textproc java
license             Apache-2
maintainers         {@mascguy} \
                    openmaintainer
platforms           darwin
supported_archs     noarch

description         Apache FOP Java XSL-FO Print Formatter
long_description    Apache FOP is the world's first print formatter driven by \
                    XSL formatting objects. It is a Java application that \
                    reads a formatting object tree conforming to the XSL 1.0 \
                    Recommendation (15 October 2001) and then turns it into a \
                    PDF document, certain other output formats or allows you \
                    to preview it directly on screen. Some parts of the XSL \
                    1.1 specification (work in progress!) have also been \
                    implemented.
homepage            https://xmlgraphics.apache.org/fop/

# Apache recommends at present that FOP be linked to FOP-specific versions of
# the Java libraries that it depends on (which are distributed with FOP), as
# both it and some of those libraries are undergoing a lot of changes, and they
# do not guarantee that FOP will work with any other versions.  We therefore
# might as well only use the binary distribution, unless anyone else comes up
# with a compelling reason to change this.  For the same reason, we also stick
# to the directory structure within the archive, since it isolates FOP and its
# libraries from conflicts with other versions.

if {${name} eq ${subport}} {
    checksums       rmd160  fdeee43b73f0b005738661bb9b86d9f9a4434f63 \
                    sha256  0697a90c2f0b0602bf707070267caecc59638a8bf7a719d5950acff764f57b8e \
                    size    22490250

    patchfiles      patch-fop-java_home.diff

    livecheck.type  none
}

subport ${name}2 {
    version         2.1

    checksums       rmd160  0b261f214c2d841147f84a76ce14c78d473d1b59 \
                    sha256  a93b59aa4d0b6d573c9090d8f21dee6c7d0c449a4bd2d48a1723e233dfb423ea \
                    size    18424515

    livecheck.type  regex
    livecheck.url   https://www.apache.org/dist/xmlgraphics/fop/binaries/
    livecheck.regex "${name}-(\\d+(?:\\.\\d+)*)-bin${extract.suffix}"

    notes {
        fop2 is now run via command 'fop2', rather than 'fop'.
    }
}

distname            ${name}-${version}-bin
master_sites        apache:xmlgraphics/fop/binaries/

worksrcdir          ${name}-${version}

use_configure       no
build   {}
pre-destroot {
    delete ${worksrcpath}/fop.bat
    delete ${worksrcpath}/fop.cmd
    delete ${worksrcpath}/fop.js
}
destroot    {
    xinstall -m 755 -d ${destroot}${prefix}/share/java/fop/${version}

    set foppaths [glob ${worksrcpath}/*]
    foreach foppath ${foppaths} {
        copy $foppath ${destroot}${prefix}/share/java/fop/${version}
    }

    # Ensure soft link name corresponds to port, to avoid conflicts
    ln -fs ${prefix}/share/java/fop/${version}/fop \
        ${destroot}${prefix}/bin/${subport}

    xinstall -m 755 -d ${destroot}${prefix}/share/doc/fop/${version}

    foreach fopdoc {KEYS LICENSE README NOTICE status.xml} {
        # Ensure soft links are only created for files that exist.
        # Necessary, as not all are provided with both versions.
        set src ${destroot}${prefix}/share/java/fop/${version}/${fopdoc}
        if {[file exists ${src}]} {
            ui_debug "destroot: fopdoc: linking to file: ${fopdoc}"
            ln -fs ${prefix}/share/java/fop/${version}/${fopdoc} \
                ${destroot}${prefix}/share/doc/fop/${version}/${fopdoc}
        } else {
            ui_debug "destroot: fopdoc: file doesn't exist, ignoring: ${fopdoc}"
        }
    }

    foreach docdir {docs javadocs} {
        # Ensure soft links are only created for directories that exist.
        # Necessary, as not all are provided with both versions.
        set src ${destroot}${prefix}/share/java/fop/${version}/${docdir}
        if {[file exists ${src}]} {
            ui_debug "destroot: docdir: linking to directory: ${docdir}"
            ln -fs ${prefix}/share/java/fop/${version}/${docdir} \
                ${destroot}${prefix}/share/doc/fop/${version}/${docdir}
        } else {
            ui_debug "destroot: docdir: directory doesn't exist, ignorning: ${docdir}"
        }
    }
}

# Skeleton of a source variant, despite the comments above, just in case it
# proves useful to have one in the future :-)
#
#variant source description {Build FOP from source instead} {
#    distname            ${name}-${version}-src
#    master_sites        apache:xmlgraphics/fop/source/
#    checksums           md5 184c578a6269a8287ed150e0fc12868d \
#                        sha1 3efc0020fdbf14a12851acf6020ea723aebe2af6 \
#                        rmd160 c047f7512a08120cfed07536c0849b2a999e96d4
#
#    depends_build       bin:ant:apache-ant
#    build.env-append    JAVA_HOME=/Library/Java/Home
#    build.cmd           ant
#    # Re-building local docs requires forrest, for which we don't yet have a
#    # port.
#    #build.target       all docs javadocs
#    build.target        all javadocs
#}
