# -*- 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            launch4j
version         3.50
revision        0
categories      java
maintainers     {amake @amake} openmaintainer
license         GPL-2
description     Cross-platform Java executable wrapper
long_description \
                Launch4j is a cross-platform tool for wrapping Java \
                applications distributed as jars in lightweight Windows \
                native executables. The executable can be configured to \
                search for a certain JRE version or use a bundled one, \
                and it's possible to set runtime options, like the \
                initial/max heap size. The wrapper also provides better \
                user experience through an application icon, a native \
                pre-JRE splash screen, a custom process name, and a Java \
                download page in case the appropriate JRE cannot be found.
homepage        http://launch4j.sourceforge.net/
platforms       darwin
supported_archs x86_64

master_sites    sourceforge
distname        launch4j-${version}-macosx-x86
extract.suffix  .tgz
checksums       md5     118752bf66fa488c352135b9718644cc \
                sha1    570357fa07432359b522e9d53f13f8a137436b0b \
                rmd160  51d698a36cb9589f6c5d4d097ca516e30ed0bf2d \
                sha256  e251cf9dc77a90b5a0af7854525dd66adceea762b30551d0458571e8e380c018 \
                size    7938201

# A binary copy of windres (from GNU bintools) is included; it links to
# /opt/local/lib/libgcc/libggc_s.1.dylib for some reason. Upstream only has the
# binary, not source, so we can't rebuild it. Instead we relink to our own
# library in case the prefix is not the default.
depends_lib-append \
                path:share/doc/libgcc/README:libgcc

use_configure   no
build           {}

worksrcdir      launch4j

post-extract {
    reinplace "s|\r||g; s|^LAUNCH4J=.*|LAUNCH4J=${prefix}/share/launch4j/launch4j.jar|" ${worksrcpath}/launch4j
    system -W ${worksrcpath} "install_name_tool -change \
           /opt/local/lib/libgcc/libgcc_s.1.dylib \
           ${prefix}/lib/libgcc/libgcc_s.1.dylib \
           bin/windres"
}

destroot {
    set sharedir ${destroot}${prefix}/share
    set l4jdir ${sharedir}/launch4j
    set l4jdoc ${sharedir}/doc/launch4j

    xinstall -d -m 0755 ${l4jdoc}
    file rename ${worksrcpath}/web ${l4jdoc}
    file rename ${worksrcpath}/demo ${l4jdoc}
    file rename ${worksrcpath}/LICENSE.txt ${l4jdoc}
    file rename ${worksrcpath}/w32api/MinGW.LICENSE.txt ${l4jdoc}
    foreach doc {JGoodies.Forms ant flatlaf} {
        file rename ${worksrcpath}/lib/${doc}.LICENSE.txt ${l4jdoc}
    }
    file rename ${worksrcpath}/bin/COPYING ${l4jdoc}/bin.COPYING
    file rename ${worksrcpath}/head/LICENSE.txt ${l4jdoc}/head.LICENSE.txt
    file rename ${worksrcpath}/head_jni_BETA/LICENSE.txt ${l4jdoc}/head_jni_BETA.LICENSE.txt

    file delete -force ${worksrcpath}/head_src
    file delete -force ${worksrcpath}/src
    file delete -force ${worksrcpath}/maven
    file delete ${worksrcpath}/build.xml
    file delete ${worksrcpath}/launch4j.jfpr
    file delete ${worksrcpath}/.classpath
    file delete ${worksrcpath}/.project
    file delete -force ${worksrcpath}/.settings
    file delete -force ${worksrcpath}/.vscode

    xinstall -d -m 0755 ${sharedir}
    file copy ${worksrcpath} ${sharedir}
    ln -s ../share/launch4j/launch4j ${destroot}${prefix}/bin/launch4j
}

livecheck.type  regex
livecheck.regex {launch4j-[0-9]+/([a-zA-Z0-9.]+\.[a-zA-Z0-9.]+)}