# $Id: Portfile 90820 2012-03-15 03:13:40Z jmr@macports.org $

PortSystem   1.0

name         adaptor
version      12.0
revision     2
platforms    darwin
categories   lang
maintainers  nomaintainer
description  Parallel Fortran compiliation system
long_description ADAPTOR is a Fortran Compilation System              \
    that supports the analysis, translation and optimization of       \
    Fortran 90 programs with parallel and/or optimization directives. \
    It generates new Fortran sources that will be linked with runtime \
    libraries supporting the needed functionality.
homepage  http://www.scai.fraunhofer.de/EP-CACHE/adaptor/www/adaptor_home.html
master_sites http://www.scai.fraunhofer.de/EP-CACHE/adaptor/www/
distfiles    adp_${version}.tar.gz
checksums    md5 5cd6677f7f66a1f33246d5ed4bdface2            \
             sha1 6bbcb22e32afbc26a1f3f59ef963a8213c377180   \
             rmd160 97cb37a397f68bae98853b11413b867b3d400efa

depends_lib port:openmpi port:libtool
configure.env F77_OPT=-O3 F77_MP="" THR_LIB=-lpthread \
    F77_OPENMP=-fopenmp THR_LIB=-lpthread                   \
    MPI_INC="-I${prefix}/include -I${prefix}/include/openmpi" \
    MPI_LIB="-L${prefix}/lib -lmpi_f90 -lmpi_f77 -lmpi"
configure.args --prefix=${prefix}/lib/${name}

extract.mkdir yes

pre-configure {
    reinplace "s|NAME|FILE|g" ${worksrcpath}/config_tools/fmpi.f
    file copy -force ${prefix}/share/libtool/config/config.guess ${worksrcpath}/config_tools
}

post-configure {
    if {![variant_isset g95]} {
        reinplace "s|FFUNCTION(iargc)|_gfortran_iargc|g" ${worksrcpath}/dalib/finit.m4
        reinplace "s|FFUNCTION(getarg)|_gfortran_getarg_i4|g" ${worksrcpath}/dalib/finit.m4
    } else {
        reinplace "s|FFUNCTION(iargc)|iargc_|g" ${worksrcpath}/dalib/finit.m4
        reinplace "s|FFUNCTION(getarg)|getarg_|g" ${worksrcpath}/dalib/finit.m4
    }
}

pre-destroot {
    file mkdir ${destroot}${prefix}/lib/${name}
    file mkdir ${destroot}${prefix}/share/${name}
    file mkdir ${destroot}${prefix}/share/doc/${name}
}

post-destroot {
    file copy ${worksrcpath}/doc ${destroot}${prefix}/share/doc/${name}
    file copy ${worksrcpath}/hpf_examples ${destroot}${prefix}/share/${name}/
    file copy ${worksrcpath}/test_examples ${destroot}${prefix}/share/${name}/
    puts stdout "Set PHOME to ${prefix}/lib/${name} and add \$PHOME/bin to PATH."
}

destroot.destdir PREFIX=${destroot}${prefix}/lib/${name}

variant gcc43 conflicts g95 gcc44 gcc45 description {build with gfortran 4.3} {
    depends_lib-append port:gcc43
    configure.f77 ${prefix}/bin/gfortran-mp-4.3
    configure.f90 ${prefix}/bin/gfortran-mp-4.3
}

variant gcc44 conflicts g95 gcc43 gcc45 description {build with gfortran 4.4} {
    depends_lib-append port:gcc44
    configure.f77 ${prefix}/bin/gfortran-mp-4.4
    configure.f90 ${prefix}/bin/gfortran-mp-4.4
}

variant gcc45 conflicts g95 gcc43 gcc44 description {build with gfortran 4.5} {
    depends_lib-append port:gcc45
    configure.f77 ${prefix}/bin/gfortran-mp-4.5
    configure.f90 ${prefix}/bin/gfortran-mp-4.5
}

variant g95 conflicts gcc43 gcc44 gcc45 description {build with g95} {
    depends_lib-append port:g95
    configure.f77 ${prefix}/bin/g95
    configure.f90 ${prefix}/bin/g95
    configure.env-delete F77_OPENMP=-fopenmp
    configure.env-append F77_OPENMP="" F77_MP=-fstatic

}

if {![variant_isset gcc43] && ![variant_isset gcc44] && ![variant_isset g95]} {
    default_variants +gcc45
}
