# -*- 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
# $Id: Portfile 92833 2012-05-08 23:46:29Z ryandesign@macports.org $

PortSystem          1.0

name                berkeley_upc
version             2.14.0
categories          lang science parallel
maintainers         takeshi
description         Unified Parallel C runtime
license             BSD LGPL GPL-3
long_description    \
    This is the runtime component of the Berkeley UPC compiler. \
    It also contains the 'upcc' front end to the UPC compilation system.
homepage            http://upc.lbl.gov/
platforms           darwin
master_sites        ${homepage}/download/release/

checksums           md5     0ddc685c1d42b028de2dce5fb44fd95e \
                    sha1    4f40fd448a2b9b0ba06d8b1ed31d5546f2f6ac16 \
                    rmd160  300b0d0006c6dd0ebd04f2b786993005e3883106

depends_lib         port:openmpi \
                    port:upc \
                    bin:perl:perl5

use_parallel_build  yes
universal_variant   no

patchfiles          patch-configure.diff
post-patch {
    reinplace "s|/usr/local/upc/bin/upc|${prefix}/lib/upc/bin/upc|" ${worksrcpath}/multiconf.conf.in
    reinplace "s|\$opt{'gccupc'}|1|g" ${worksrcpath}/multiconf.conf.in
}

configure.env       MPI_CC=${prefix}/lib/openmpi/bin/mpicc \
                    GCCUPC_TRANS=${prefix}/lib/upc/bin/upc
              
configure.args-append \
                    --prefix=${prefix}/lib/${name} \
                    --mandir=${prefix}/share/man \
                    --disable-elan \
                    --disable-gm \
                    --disable-lapi \
                    --disable-vapi \
                    --disable-ibv \
                    --disable-shmem \
                    --disable-portals \
                    --disable-dcmf \
                    --disable-sci \
                    --enable-mpi \
                    --enable-udp \
                    --enable-smp \
                    --disable-pshm \
                    --enable-sptr-packed \
                    --disable-aligned-segments \
                    --with-multiconf=dbg_gccupc,opt_gccupc

post-configure {
    reinplace "s|-L\$(top_builddir) -lgasnet_tools-seq|\$(top_builddir)/libgasnet_tools-seq.a|" ${worksrcpath}/dbg_gccupc/gasnet/other/amudp/Makefile
    reinplace "s|-L. -lamudp|./libamudp.a|g" ${worksrcpath}/dbg_gccupc/gasnet/other/amudp/Makefile
}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/${name}
    file copy ${worksrcpath}/upc-examples ${destroot}${prefix}/share/${name}/
    file copy ${worksrcpath}/upc-tests ${destroot}${prefix}/share/${name}/
    file delete -force ${destroot}${prefix}/lib/${name}/man
    ln -s ${prefix}/lib/${name}/bin/upcc ${destroot}${prefix}/bin/upcc
    foreach f "upc_trace upcdecl upcrun" {
        ln -s ${prefix}/lib/${name}/opt_gccupc/bin/${f} ${destroot}${prefix}/bin/${f}
    }
}

if {![variant_isset gcc44]} {
    default_variants +gcc45
}

variant gcc44 conflicts gcc45 description {build with gcc44} {
    depends_lib-append  port:gcc44
    configure.compiler  macports-gcc-4.4
}

variant gcc45 conflicts gcc44 description {build with gcc45} {
    depends_lib-append  port:gcc45
    configure.compiler  macports-gcc-4.5
}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     {Berkeley UPC version ([0-9]+.[0-9]+.[0-9]+)}
