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

github.setup        yui yuicompressor 2.4.8 v
categories          www
license             BSD
maintainers         {amake @amake} openmaintainer

description         The Yahoo! JavaScript and CSS Compressor
long_description    \
    The YUI Compressor is a JavaScript compressor which, in addition to removing \
    comments and white-spaces, obfuscates local variables using the smallest \
    possible variable name. This obfuscation is safe, even when using constructs \
    such as 'eval' or 'with' (although the compression is not optimal in those \
    cases) Compared to jsmin, the average savings is around 20%.

platforms           any
supported_archs     noarch

use_configure       no

set jar             ${name}-${version}.jar
set jarpath         ""
set sharepath       ${prefix}/share/java/${name}

variant source description "Build from source" {
    depends_build   bin:ant:apache-ant

    checksums       rmd160  9e26866b5ff2de40c2c57720fbb4bdfba35986a2 \
                    sha256  a5885eabfe4d030061210a0204bc8bbd318ca1f0aae1dc7348dae41e6f3b7fa5 \
                    size    1254366

    java.version    1.8

    build.cmd       ant
    build.target    build.jar

    set jarpath    ${worksrcpath}/build
}

if {![variant_isset source] } {
    github.tarball_from  releases

    extract.only

    distfiles       ${jar}

    checksums       rmd160  d870a9db48dc21436d8fc5ac82a852f5240f20d9 \
                    sha256  30371db57285e490c761f1cca52527e697fe09077a16da46fb892e98a6a25de2 \
                    size    787524

    build           {}

    set jarpath    ${distpath}
}

destroot        {
    xinstall -m 0755 -d ${destroot}${sharepath}
    xinstall -m 0644 -W ${jarpath} ${jar} ${destroot}${sharepath}

    set cli_script ${destroot}${prefix}/bin/${name}
    set fp [open $cli_script w]
    puts $fp "#!/bin/sh"
    puts $fp "exec java -jar \"${sharepath}/${jar}\" \"$@\""
    close $fp
    system "chmod +x ${cli_script}"
}
