# -*- 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 108404 2013-07-22 20:22:02Z eborisch@macports.org $

PortSystem          1.0
PortGroup           compiler_blacklist_versions 1.0

name                mpich
version             3.0.4
revision            0

license             BSD
categories          science parallel net
platforms           darwin
maintainers         eborisch \
                    openmaintainer

description         Message Passing Interface (MPI) Library

long_description    MPICH is a high-performance and widely portable\
                    implementation of the Message Passing Interface (MPI) \
                    standard (MPI-1, MPI-2 and MPI-3). The goals of MPICH are:\
                    (1) to provide an MPI implementation that efficiently\
                    supports different computation and communication platforms\
                    including commodity clusters (desktop systems,\
                    shared-memory systems, multicore architectures), high-speed\
                    networks (10 Gigabit Ethernet, InfiniBand, Myrinet,\
                    Quadrics) and proprietary high-end computing systems (Blue\
                    Gene, Cray) and (2) to enable cutting-edge research in MPI\
                    through an easy-to-extend modular framework for other\
                    derived implementations. \n\
                    \n\
                    The mpich port follows the latest mpich 3.x line, and is \
                    the successor to the mpich2 port. Starting with the major \
                    release in November 2012, the project is renamed back to \
                    MPICH (from MPICH2) with a version number of 3.0. 
homepage            http://www.mpich.org/

checksums \
    rmd160  c14b3b335be863dd36c0a58630c969719d8ef217 \
    sha256  cf638c85660300af48b6f776e5ecd35b5378d5905ec5d34c3da7a27da0acf0b3

configure.args      --disable-dependency-tracking \
                    --disable-f77 \
                    --disable-fc \
                    --disable-silent-rules \
                    --enable-base-cache \
                    --enable-cache \
                    --enable-cxx \
                    --enable-fast=O2 \
                    --enable-shared \
                    --enable-smpcoll \
                    --with-device=ch3:nemesis \
                    --with-pm=hydra \
                    --with-thread-package=posix \
                    --enable-versioning \
                    "F90FLAGS='' F90=''"

subport mpich-devel {
    conflicts           mpich
#    version             3.0.1
}

if {${subport} == ${name}} {
    conflicts           mpich-devel
}

master_sites        ${homepage}static/tarballs/${version}/

conflicts-append    mpich2 \
                    mpich2-devel \
                    lammpi \
                    openmpi

universal_variant   no

depends_lib-append  port:libxml2

# Linker for Apple clang version 431.11.66 currently segfaults 
# See https://trac.macports.org/ticket/36654#comment:9 
compiler.blacklist-append   {clang >= 421.11.66 < 425.0.24} 

platform darwin {
    configure.args-append   --enable-timer-type=mach_absolute_time
}

# We're making compiler wrappers here... don't default to -O2 for wrappers.
# Actual library code is compiled with -O2 via --enable-fast=O2 configure arg
configure.cflags-delete     -O2
configure.cxxflags-delete   -O2
configure.fflags-delete     -O2
configure.fcflags-delete    -O2
configure.cppflags-delete   -I${prefix}/include

# As MPICH creates compiler wrappers, there are lots of
# variants for what compiler the user would like to wrap.

# Compiler variant set
#   name     depends_lib    configure.compiler  Description
array set clist {
    clang   {""             clang               "Apple native"}
    clang31 {port:clang-3.1 macports-clang-3.1  "MacPorts' version"}
    clang32 {port:clang-3.2 macports-clang-3.2  "MacPorts' version"}
    clang33 {port:clang-3.3 macports-clang-3.3  "MacPorts' version"}
    clang34 {port:clang-3.4 macports-clang-3.4  "MacPorts' version"}
    gcc43   {port:gcc43     macports-gcc-4.3    "enables Fortran wrappers"}
    gcc44   {port:gcc44     macports-gcc-4.4    "enables Fortran wrappers"}
    gcc45   {port:gcc45     macports-gcc-4.5    "enables Fortran wrappers"}
    gcc46   {port:gcc46     macports-gcc-4.6    "enables Fortran wrappers"}
    gcc47   {port:gcc47     macports-gcc-4.7    "enables Fortran wrappers"}
    gcc48   {port:gcc48     macports-gcc-4.8    "enables Fortran wrappers"}
    gcc49   {port:gcc49     macports-gcc-4.9    "enables Fortran wrappers"}
    llvm    {""             llvm-gcc-4.2        "Apple native"}
}

# Alphabetized list of compiler variants
set clist_keys [lsort [array names clist]]

foreach clist_item $clist_keys {
    # Conflict with everyone else (remove ourselves from full list)
    set this_key [lsearch $clist_keys $clist_item]
    set conf_list [lreplace $clist_keys $this_key $this_key]
    
    # Describe variant
    variant $clist_item \
        description "Wraps $clist_item -- [lindex $clist($clist_item) 2]" \
        conflicts $conf_list "
            depends_lib-append  [lindex $clist($clist_item) 0]
            configure.compiler  [lindex $clist($clist_item) 1] 
        "
}

if {[ variant_isset gcc43 ] ||
    [ variant_isset gcc44 ] ||
    [ variant_isset gcc45 ] ||
    [ variant_isset gcc46 ] ||
    [ variant_isset gcc47 ] ||
    [ variant_isset gcc48 ] ||
    [ variant_isset gcc49 ]} {
    configure.args-append   --enable-f77 --enable-fc
    configure.args-delete   --disable-f77 --disable-fc
}

variant gforker description {
    Use gforker process manager instead of the default hydra
} {
    configure.args-append   --with-pm=gforker
    configure.args-delete   --with-pm=hydra
}

variant tuned description {Build with more optimizations} {
    configure.args-delete       --enable-fast=O2
    configure.args-append       --enable-fast=all \
                                MPICHLIB_CFLAGS='-fomit-frame-pointer -O2'
}

if {[regexp -all -- {\yclang\y} ${compiler.blacklist}] != 0 &&
    [variant_isset clang]} {
    ui_error \
        "The linker called from this version of clang segfaults."
    return -code error "Unsupported clang version. Use +clang31 or +clang32"
}

livecheck.type      regex
livecheck.regex     ${name}-(\[0-9.pbrc\]+)${extract.suffix}
livecheck.url       ${homepage}downloads/index.php?s=downloads
