# $Id$

PortSystem          1.0

name                jython
version             2.7.0
revision            1
categories          lang python java
platforms           darwin
maintainers         nomaintainer
description         Python implementation in pure Java
long_description    \
    Jython is an implementation of the high-level, \
    dynamic, object-oriented language Python written in \
    100% Pure Java, and seamlessly integrated with the \
    Java platform. It thus allows you to run Python on any \
    Java platform.
license             PSF

homepage            http://www.jython.org/
master_sites        http://search.maven.org/remotecontent?filepath=org/python/jython-installer/${version}
fetch.type          hg
hg.url              https://hg.python.org/jython
hg.tag              v${version}

depends_build       bin:ant:apache-ant
depends_lib         bin:java:kaffe

use_configure       no
build.cmd           ant
build.target        developer-build
set java_ver        1.7
set have_java       [catch { exec /usr/libexec/java_home -F -v ${java_ver} } java_home ]
build.env           JAVA_HOME=${java_home}

pre-fetch {
    if {![variant_isset installer] && ${have_java} == 1} {
       return -code error "Java ${java_ver} is required to build from source"
    }
}

set bin_name        jython.py

destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/java/
    copy ${worksrcpath}/dist \
        ${destroot}${prefix}/share/java/${name}
}

post-destroot {
    set fp [open ${destroot}${prefix}/bin/${name} w]
    puts $fp "#!/bin/sh"
    puts $fp "${prefix}/share/java/${name}/bin/${bin_name} \\"
    puts $fp "  -Dpython.cachedir=\"\$HOME/.jython_cachedir\" \"\$@\""
    close $fp
    system "chmod +x ${destroot}${prefix}/bin/${name}"
}

pre-activate {
    # Delete cache files left over from old installation
    file delete -force -- ${prefix}/share/java/${name}/cachedir
}

variant installer description {Use installer, rather than building from source} {
    fetch.type      standard
    distname        ${name}-installer-${version}
    worksrcdir
    extract.suffix  .jar
    distfiles       ${distname}${extract.suffix}
    extract.cmd     cp
    extract.args    ${worksrcpath}
    extract.pre_args
    extract.post_args ${worksrcpath}
    depends_build-delete bin:ant:apache-ant
    checksums           rmd160  4f9cf193cc9a41b1fc603d02932778d3fbeb3e11 \
                        sha256  b44352ece72382268a60e2848741c96609a91d796bb9a9c6ebeff62f0c12c9cf

    pre-build {
        xinstall -m 755 -d ${destroot}${prefix}/share/java/${name}
    }

    build.cmd       java
    build.target
    build.env
    build.args      -jar ${distname}${extract.suffix}
    build.post_args -s -d ${destroot}${prefix}/share/java/${name}

    set bin_name    jython

    destroot {}
}

default_variants +installer

livecheck.type      regex
livecheck.url       ${homepage}downloads.html
livecheck.regex     "Jython (\\d+(?:\\.\\d+)*)"