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

name                berkeley_upc
version             2.22.3
revision            1
categories          lang science parallel
maintainers         {takeshi @tenomoto}
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           rmd160  36bf86a35a8e20c19bae6225cadbc885db0016db \
                    sha256  013a47a7f94a2435845338a9a06043cc58662f61faff005514902cf38dedee83

compilers.choose    cc cxx
mpi.setup

depends_lib         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.env       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 \
                    --disable-mpi \
                    --enable-udp \
                    --enable-smp \
                    --disable-pshm \
                    --enable-sptr-packed \
                    --disable-aligned-segments \
                    --with-multiconf=dbg_gccupc,opt_gccupc

pre-configure {
    if {[mpi_variant_isset]} {
        configure.args-delete   --disable-mpi
        configure.args-append   --enable-mpi
        configure.env-append    MPI_CC=${mpi.cc}
    }
}

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}
    }
}

notes               "Choose openmpi or mpich to use MPI"

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