# -*- 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 98891 2012-10-20 01:07:42Z takeshi@macports.org $

PortSystem          1.0

name                berkeley_upc
version             2.14.2
revision            2
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     32362938755ae031ff2a607be36bcc19 \
                    sha1    8e83af6ad7efb943201a25da5364d28422ec0599 \
                    rmd160  63513bd91381ec38a899a2347c224251e9b14a22

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

use_parallel_build  yes
universal_variant   no

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.cc        ${prefix}/lib/upc/bin/gcc
configure.cxx       ${prefix}/lib/upc/bin/g++
configure.env       MPI_CC=${prefix}/lib/openmpi/bin/mpicc \
                    MPI_CFLAGS="-O3" \
                    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_gupc/gasnet/other/amudp/Makefile
    reinplace "s|-L. -lamudp|./libamudp.a|g" ${worksrcpath}/dbg_gupc/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_gupc/bin/${f} ${destroot}${prefix}/bin/${f}
    }
}

variant gcc44 conflicts gcc45 description {deprecated dummy variant} {
}

variant gcc45 conflicts gcc44 description {deprecated dummy variant} {
}

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