# -*- 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 68471 2010-06-04 09:16:10Z ryandesign@macports.org $

PortSystem          1.0

name                upc
version             4.3.2.5
categories          lang parallel science
maintainers         takeshi openmaintainer
description         Unified Parallel C
license             GPLv3
long_description    \
    The GCC UPC toolset provides a compilation and execution environment \
    for programs written in the UPC (Unified Parallel C) language. 
homepage            http://www.gccupc.org/
platforms           darwin
master_sites        ftp://ftp.gccupc.org/pub/upc/rls/${name}-${version}/
distname            ${name}-${version}.src

checksums           md5     3bbb45a8d8da96714f97e2eb95eb4822 \
                    sha1    4c3e8a60abf2f60d38b1aa48a521306e75294da3 \
                    rmd160  939daf3f707f8f320380bef626785cfe604a9e6b

depends_lib         port:gmp port:mpfr port:libiconv

worksrcdir          build

post-extract {
    file mkdir ${worksrcpath}
}

post-patch {
    reinplace {s|i\[356]86|x86_64|} ${workpath}/${name}-${version}/gcc/upc/config-lang.in
}

if {[info exists build_arch] && ${os.platform} == "darwin"} {
    configure.cc_archflags
    configure.cxx_archflags
    configure.objc_archflags
    configure.pre_args-append --build=${build_arch}-apple-darwin${os.major}
}

pre-configure {
    if {${os.platform} == "darwin" && ${os.arch} == "powerpc"} {
        ui_error "PowerPC is not supported"
    }
}

configure.cmd       ../${name}-${version}/configure
configure.args      --bindir=${prefix}/lib/${name}/bin \
                    --libdir=${prefix}/lib/${name} \
                    --libexecdir=${prefix}/libexec/${name} \
                    --infodir=${prefix}/share/info \
                    --mandir=${prefix}/share/man \
                    --with-local-prefix=${prefix} \
                    --with-system-zlib \
                    --disable-nls \
                    --without-gnuld \
                    --disable-multilib \
                    --with-gmp=${prefix} \
                    --with-mpfr=${prefix}
if {${os.platform} == "darwin" && ${build_arch} == "x86_64"} {
    configure.args-append   --build=${build_arch}-apple-${os.platform}${os.major}
}
use_parallel_build  yes
universal_variant   no

post-destroot {
    set man [glob ${destroot}${prefix}/share/man/man1/*]
    set i [lsearch $man ${destroot}${prefix}/share/man/man1/upc.1]
    foreach f [lreplace $man $i $i] {
        file delete $f
    }
    file delete -force ${destroot}${prefix}/share/man/man7
    file delete -force ${destroot}${prefix}/share/info
    xinstall -d 755 -m ${destroot}${prefix}/share/${name}
    file copy ${workpath}/${name}-${version}/upc_test ${destroot}${prefix}/share/${name}
    system "cd ${destroot}${prefix}/bin; \
            ln -s ${prefix}/lib/${name}/bin/${name} ${name};"
}

# Error: cannot check if upc was updated (The requested URL returned error: 406)
#livecheck.type      regex
#livecheck.url       ${homepage}
#livecheck.regex     {The current version of GCC/UPC compiler is ([0-9]+.[0-9]+.[0-9]+.[0-9]+)}
