# $Id: Portfile 115967 2014-01-15 17:10:34Z blair@macports.org $

PortSystem 1.0

name                    apache-ant
version                 1.9.3
categories              devel java
license                 Apache-2 W3C
maintainers             openmaintainer blair
supported_archs         noarch

description             Java opensource build system
long_description        Ant is a Java based build tool.  In theory it is \
                        kind of like make without make's wrinkles.  Ant \
                        uses XML build files that define a set of targets.  \
                        Each target has dependencies (other targets) and \
                        contains a set of tasks to perform.
homepage                http://ant.apache.org/

platforms               darwin freebsd

distname                ${name}-${version}-bin
master_sites            apache:ant/
master_sites.mirror_subdir        binaries
checksums               md5    6e6d888140858f3926c34081c4bd2227 \
                        sha1   efcf206e24b0dd1583c501182ad163af277951a4 \
                        sha512 b7a31651ed11a68991c4508e60e7c4b59c2a0412f4c078f2c036fb9c80247542ca89d634e8d19ebcdf700cb148fed254804d493f9e2dff518834ac912aff16e3

worksrcdir              ${name}-${version}
set workTarget          ""

use_bzip2               yes
use_configure           no

build.cmd               true

platform darwin {
    build.env           JAVA_HOME=/Library/Java/Home
}

# Ant is installed from the binary (jar) distribution by default. Due to
# bootstrapping issues, the source variant generally doesn't build a very
# usable ant: the ant tasks (such as junit) are non-functional as their
# dependent support isn't available when ant is built, due to circular
# dependencies back to ant.
variant source description "build from source; not recommended" {
        distname                        ${name}-${version}-src
        master_sites.mirror_subdir      source
        checksums                       md5    c474fa9d0c35a24037c23b6e476862c1 \
                                        sha1   fe01edd5acb221485d86e74411365cc139e1c87c \
                                        sha512 7dbbdcd31f5fd498cbbe7f125451899320e5e9c2396b80f1f90d18943f8ef066a75198edfdba0edf96b1e0b5b84cb049b5281403180a7a6924ebfb077930e307
        set workTarget                  /${name}

        build.cmd                       ./build.sh
        build.args                      -Dchmod.fail=false -Ddist.name=${name}
        build.target                    dist
}

post-patch {
        reinplace "s|/System/Library/Frameworks/JavaVM.framework/Home|`/usr/libexec/java_home`|g" "${worksrcpath}/bin/ant"
}

pre-destroot {
        delete \
                ${worksrcpath}${workTarget}/bin/ant.bat \
                ${worksrcpath}${workTarget}/bin/ant.cmd \
                ${worksrcpath}${workTarget}/bin/antRun.bat \
                ${worksrcpath}${workTarget}/bin/antenv.cmd \
                ${worksrcpath}${workTarget}/bin/envset.cmd \
                ${worksrcpath}${workTarget}/bin/lcp.bat \
                ${worksrcpath}${workTarget}/bin/runrc.cmd
}

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

        xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
        foreach f {INSTALL
                   KEYS
                   LICENSE
                   NOTICE
                   README
                   WHATSNEW
                   manual} {
            file rename ${destroot}${prefix}/share/java/${name}/${f} \
                ${destroot}${prefix}/share/doc/${name}/${f}
        }

        ln -s ../share/java/${name}/bin/ant ${destroot}${prefix}/bin/ant
}

universal_variant       no

livecheck.type          regex
livecheck.url           http://www.apache.org/dist/ant/binaries/
livecheck.regex         {apache-ant-(\d+(?:\.\d+)*)-bin.tar.bz2}
