# $Id: Portfile 91257 2012-03-27 18:44:47Z mww@macports.org $

PortSystem 1.0

name			openmpi
version			1.5.5
set branch		[join [lrange [split ${version} .] 0 1] .]
categories		science parallel net
platforms		darwin
license			BSD
maintainers		mww openmaintainer
description		A High Performance Message Passing Library
long_description	Open MPI is a project combining technologies and resources \
			from several other projects (FT-MPI, LA-MPI, LAM/MPI, and \
			PACX-MPI) in order to build the best MPI library available. A \
			completely new MPI-2 compliant implementation, Open MPI offers \
			advantages for system and software vendors, application developers \
			and computer science researchers.

homepage		http://www.open-mpi.org/
set subdir		ompi/v${branch}/downloads/
master_sites		http://www.open-mpi.org/software/${subdir} \
			http://www.open-mpi.de/software/${subdir} \
			http://icl.cs.utk.edu/open-mpi/${subdir} \
			freebsd
checksums           md5     f882fd61ff89db856bfd8f0dfa42e1bd \
                    sha1    206e555f6d376443f2342f721d944e67dd1a04ef \
                    rmd160  6e7648ec0fa553c16b40f886b397d11863039eb2
use_bzip2		yes

pre-extract { file mkdir ${workpath}/build }

configure.dir	${workpath}/build
configure.cmd	${worksrcpath}/configure
configure.args	--disable-mpi-f77 --disable-mpi-f90 \
		--with-xgrid \
		--sysconfdir=${prefix}/etc/${name} \
		--includedir=${prefix}/include/${name} \
		--bindir=${prefix}/lib/${name}/bin \
		--mandir=${prefix}/share/man

if {${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler clang
}

build.dir	${configure.dir}

destroot.dir	${build.dir}
set wrappers	{mpicc mpicxx mpic++}
post-destroot {
	foreach bin {mpirun mpiexec} {
		system -W ${destroot}${prefix}/bin \
			"ln -sf ${prefix}/lib/${name}/bin/orterun open${bin}"
	}
	foreach bin ${wrappers} {
		system -W ${destroot}${prefix}/bin \
			"ln -sf ${prefix}/lib/${name}/bin/opal_wrapper open${bin}"
		system -W ${destroot}${prefix}/share/${name} \
			"ln -sf ${prefix}/share/${name}/${bin}-wrapper-data.txt \
			open${bin}-wrapper-data.txt"
	}
}

variant threads description {enable threads for MPI applications} {
	configure.args-append --enable-mpi-threads
}

variant progressthreads description {enable threads asynchronous communication progress} {
	configure.args-append --enable-progress-threads
}

variant valgrind description {enable valgrind support} {
	depends_lib-append    port:valgrind
	configure.args-append --enable-debug --enable-memchecker --with-valgrind=${prefix}
}

variant gcc42 description {build mpif77 and mpif90 using gcc42} conflicts gcc43 gcc44 gcc45 gcc46 g95 {
	configure.args-delete --disable-mpi-f77 --disable-mpi-f90
	configure.args-append --enable-mpi-f77 --enable-mpi-f90
	configure.f77	      ${prefix}/bin/gfortran-mp-4.2
	configure.fc	      ${prefix}/bin/gfortran-mp-4.2
	depends_lib-append    port:gcc42
	lappend wrappers mpif77 mpif90
}

variant gcc43 description {build mpif77 and mpif90 using gcc43} conflicts gcc42 gcc44 gcc45 gcc46 g95 {
	configure.args-delete --disable-mpi-f77 --disable-mpi-f90
	configure.args-append --enable-mpi-f77 --enable-mpi-f90
	configure.f77	      ${prefix}/bin/gfortran-mp-4.3
	configure.fc	      ${prefix}/bin/gfortran-mp-4.3
	depends_lib-append    port:gcc43
	lappend wrappers mpif77 mpif90
}

variant gcc44 description {build mpif77 and mpif90 using gcc44} conflicts gcc42 gcc43 gcc45 gcc46 g95 {
	configure.args-delete --disable-mpi-f77 --disable-mpi-f90
	configure.args-append --enable-mpi-f77 --enable-mpi-f90
	configure.f77	      ${prefix}/bin/gfortran-mp-4.4
	configure.fc	      ${prefix}/bin/gfortran-mp-4.4
	depends_lib-append    port:gcc44
	lappend wrappers mpif77 mpif90
}

variant gcc45 description {build mpif77 and mpif90 using gcc45} conflicts gcc42 gcc43 gcc44 gcc46 g95 {
	configure.args-delete --disable-mpi-f77 --disable-mpi-f90
	configure.args-append --enable-mpi-f77 --enable-mpi-f90
	configure.f77	      ${prefix}/bin/gfortran-mp-4.5
	configure.fc	      ${prefix}/bin/gfortran-mp-4.5
	depends_lib-append    port:gcc45
	lappend wrappers mpif77 mpif90
}

variant gcc46 description {build mpif77 and mpif90 using gcc46} conflicts gcc42 gcc43 gcc44 gcc45 g95 {
	configure.args-delete --disable-mpi-f77 --disable-mpi-f90
	configure.args-append --enable-mpi-f77 --enable-mpi-f90
	configure.f77	      ${prefix}/bin/gfortran-mp-4.6
	configure.fc	      ${prefix}/bin/gfortran-mp-4.6
	depends_lib-append    port:gcc46
	lappend wrappers mpif77 mpif90
}

variant g95 description {build mpif77 and mpif90 using g95} conflicts gcc42 gcc43 gcc44 gcc45 gcc46 {
	configure.args-delete --disable-mpi-f77 --disable-mpi-f90
	configure.args-append --enable-mpi-f77 --enable-mpi-f90
	configure.f77	      ${prefix}/bin/g95
	configure.fc	      ${prefix}/bin/g95
	depends_lib-append    port:g95
	lappend wrappers mpif77 mpif90
}

# dependents like netcdf need some form of fortran
if {![variant_isset gcc42] && ![variant_isset gcc43] && ![variant_isset gcc44] && ![variant_isset gcc46] && ![variant_isset g95]} {
    default_variants +gcc45
}

livecheck.type	regex
livecheck.url	http://www.open-mpi.org/software/ompi/v1.5/
livecheck.regex	openmpi-(\[0-9\.\]+).tar.bz2

universal_variant no

# remove -arch from ldflags, ticket #22833
configure.ld_archflags
# avoid building against older installed version, ticket #23864
configure.cppflags-delete -I${prefix}/include
configure.ldflags-delete -L${prefix}/lib
