# $Id: Portfile 92780 2012-05-06 16:48:56Z ram@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0

name            fftw-3
version         3.3.2
categories      math
license         GPL-2+
platforms       darwin
maintainers     ram openmaintainer
homepage        http://www.fftw.org/
distname        fftw-${version}

master_sites \
    ${homepage} \
    ftp://ftp.fftw.org/pub/fftw/ \
    ftp://ftp.kusastro.kyoto-u.ac.jp/pub/src/GNU/fftw/

description \
    Fast C routines to compute the Discrete Fourier Transform

long_description \
    FFTW is a C subroutine library for computing the \
    Discrete Fourier Transform (DFT) in one or more \
    dimensions, of both real and complex data, and of \
    arbitrary input size. We believe that FFTW, which is \
    free software, should become the FFT library of choice \
    for most applications. Our benchmarks, performed on a \
    variety of platforms, show that FFTW's performance is \
    typically superior to that of other publicly available \
    FFT software. Moreover, FFTW's performance is portable: \
    the program will perform well on most architectures \
    without modification. \
    This port is of fftw version 3.x. It has many \
    improvements relative to 2.x, but is not backwardly \
    compatible.

checksums \
    rmd160 dbf87fcb7812024b80744335d433ade53bad8a4f \
    sha256 b1236a780ca6e66fc5f8eda6ef0665d680e8253d9f01d7bf211b714a50032d01

configure.args \
    --enable-threads \
    --disable-fortran \
    --enable-shared

configure.cflags-append \
    -fno-common \
    -O3 \
    -fomit-frame-pointer \
    -fstrict-aliasing

array set merger_configure_args {
    ppc    "--enable-fma"
    ppc64  "--enable-fma"
    i386   "--enable-sse2"
    x86_64 "--enable-sse2"
}

test.run     yes
test.target  check

use_parallel_build yes

platform i386 {
  if {![variant_isset universal]} {
    configure.args-append --enable-sse2
  }
}

platform powerpc {
  if {![variant_isset universal]} {
    configure.args-append --enable-fma
  }
}

subport fftw-3-single {
    configure.args-append --enable-float

    array set merger_configure_args {
        ppc    "--enable-fma --enable-altivec"
        ppc64  "--enable-fma --enable-altivec"
        i386   "--enable-sse"
        x86_64 "--enable-sse"
    }

    depends_lib port:fftw-3

    platform i386 {
        if {![variant_isset universal]} {
            configure.args-delete --enable-sse2
            configure.args-append --enable-sse
        }
    }

    platform powerpc {
        if {![variant_isset universal]} {
            configure.args-append --enable-altivec
        }
    }

    post-destroot {
        file delete ${destroot}${prefix}/include/fftw3.f
        file delete ${destroot}${prefix}/include/fftw3.f03
        file delete ${destroot}${prefix}/include/fftw3l.f03
        file delete ${destroot}${prefix}/include/fftw3q.f03
        file delete ${destroot}${prefix}/include/fftw3.h
        file delete ${destroot}${prefix}/bin/fftw-wisdom-to-conf
        file delete ${destroot}${prefix}/share/man/man1/fftw-wisdom-to-conf.1
        file delete ${destroot}${prefix}/share/info/fftw3.info
        file delete ${destroot}${prefix}/share/info/fftw3.info-1
        file delete ${destroot}${prefix}/share/info/fftw3.info-2
        file delete ${destroot}${prefix}/share/info/fftw3.info-3
        file delete ${destroot}${prefix}/share/info/fftw3.info-4
        file delete ${destroot}${prefix}/share/info/fftw3.info-5
    }
}

subport fftw-3-long {
    configure.args-append --enable-long-double

     array set merger_configure_args {
        ppc    ""
        ppc64  ""
        i386   ""
        x86_64 ""
    }

    depends_lib port:fftw-3

    platform i386 {
        if {![variant_isset universal]} {
            configure.args-delete --enable-sse2
        }
    }

    platform powerpc {
        if {![variant_isset universal]} {
            configure.args-delete --enable-fma
        }
    }

    post-destroot {
        file delete ${destroot}${prefix}/include/fftw3.f
        file delete ${destroot}${prefix}/include/fftw3.f03
        file delete ${destroot}${prefix}/include/fftw3l.f03
        file delete ${destroot}${prefix}/include/fftw3q.f03
        file delete ${destroot}${prefix}/include/fftw3.h
        file delete ${destroot}${prefix}/bin/fftw-wisdom-to-conf
        file delete ${destroot}${prefix}/share/man/man1/fftw-wisdom-to-conf.1
        file delete ${destroot}${prefix}/share/info/fftw3.info
        file delete ${destroot}${prefix}/share/info/fftw3.info-1
        file delete ${destroot}${prefix}/share/info/fftw3.info-2
        file delete ${destroot}${prefix}/share/info/fftw3.info-3
        file delete ${destroot}${prefix}/share/info/fftw3.info-4
        file delete ${destroot}${prefix}/share/info/fftw3.info-5
    }
}

variant gcc42 description {create Fortran wrappers using gcc42} conflicts gcc43 gcc44 gcc45 gcc46 gcc47 g95 {
    depends_lib-append    port:gcc42
    depends_skip_archcheck gcc42
    configure.f77         gfortran-mp-4.2
    configure.args-delete --disable-fortran
    if { ${os.arch} == "i386" } {
        lappend merger_configure_args(ppc)     "--disable-fortran"
        lappend merger_configure_args(ppc64)   "--disable-fortran"
    } else {
        lappend merger_configure_args(i386)    "--disable-fortran"
        lappend merger_configure_args(x86_64)  "--disable-fortran"
    }
}

variant gcc43 description {create Fortran wrappers using gcc43} conflicts gcc42 gcc44 gcc45 gcc46 gcc47 g95 {
    depends_lib-append    port:gcc43
    configure.f77         gfortran-mp-4.3
    configure.args-delete --disable-fortran
    if { ${os.arch} == "i386" } {
        lappend merger_configure_args(ppc)     "--disable-fortran"
        lappend merger_configure_args(ppc64)   "--disable-fortran"
    } else {
        lappend merger_configure_args(i386)    "--disable-fortran"
        lappend merger_configure_args(x86_64)  "--disable-fortran"
    }
}

variant gcc44 description {create Fortran wrappers using gcc44} conflicts gcc42 gcc43 gcc45 gcc46 gcc47 g95 {
    depends_lib-append    port:gcc44
    configure.f77         gfortran-mp-4.4
    configure.args-delete --disable-fortran
    if { ${os.arch} == "i386" } {
        lappend merger_configure_args(ppc)     "--disable-fortran"
        lappend merger_configure_args(ppc64)   "--disable-fortran"
    } else {
        lappend merger_configure_args(i386)    "--disable-fortran"
        lappend merger_configure_args(x86_64)  "--disable-fortran"
    }
}

variant gcc45 description {create Fortran wrappers using gcc45} conflicts gcc42 gcc43 gcc44 gcc46 gcc47 g95 {
    depends_lib-append    port:gcc45
    configure.f77         gfortran-mp-4.5
    configure.args-delete --disable-fortran
    if { ${os.arch} == "i386" } {
        lappend merger_configure_args(ppc)     "--disable-fortran"
        lappend merger_configure_args(ppc64)   "--disable-fortran"
    } else {
        lappend merger_configure_args(i386)    "--disable-fortran"
        lappend merger_configure_args(x86_64)  "--disable-fortran"
    }
}

variant gcc46 description {create Fortran wrappers using gcc46} conflicts gcc42 gcc43 gcc44 gcc45 gcc47 g95 {
    depends_lib-append    port:gcc46
    configure.f77         gfortran-mp-4.6
    configure.args-delete --disable-fortran
    if { ${os.arch} == "i386" } {
        lappend merger_configure_args(ppc)     "--disable-fortran"
        lappend merger_configure_args(ppc64)   "--disable-fortran"
    } else {
        lappend merger_configure_args(i386)    "--disable-fortran"
        lappend merger_configure_args(x86_64)  "--disable-fortran"
    }
}

variant gcc47 description {create Fortran wrappers using gcc47} conflicts gcc42 gcc43 gcc44 gcc45 gcc46 g95 {
    depends_lib-append    port:gcc47
    configure.f77         gfortran-mp-4.7
    configure.args-delete --disable-fortran
    if { ${os.arch} == "i386" } {
        lappend merger_configure_args(ppc)     "--disable-fortran"
        lappend merger_configure_args(ppc64)   "--disable-fortran"
    } else {
        lappend merger_configure_args(i386)    "--disable-fortran"
        lappend merger_configure_args(x86_64)  "--disable-fortran"
    }
}

variant g95 description {create Fortran wrappers using f95} conflicts gcc42 gcc43 gcc44 gcc45 gcc46 {
    depends_lib-append    port:g95
    depends_skip_archcheck g95
    configure.f77         g95
    configure.args-delete --disable-fortran
    if { ${os.arch} == "i386" } {
        lappend merger_configure_args(ppc)     "--disable-fortran"
        lappend merger_configure_args(ppc64)   "--disable-fortran"
        lappend merger_configure_args(x86_64)  "--disable-fortran"
    } else {
        lappend merger_configure_args(i386)    "--disable-fortran"
        lappend merger_configure_args(ppc64)   "--disable-fortran"
        lappend merger_configure_args(x86_64)  "--disable-fortran"
    }
}

variant openmpi description {compile FFTW MPI library with OpenMPI} conflicts mpich2 {
    depends_lib-append      port:openmpi
    configure.env           MPICC=${prefix}/lib/openmpi/bin/mpicc
    configure.args-append   --enable-mpi
}

variant mpich2 description {compile FFTW MPI library with MPICH2} conflicts openmpi {
    depends_lib-append      port:mpich2
    configure.env           MPICC=${prefix}/bin/mpicc
    configure.args-append   --enable-mpi
}

if {${name} == ${subport}} {
    livecheck.type  regex
    livecheck.url   ${homepage}
    livecheck.regex {FFTW (\d+(?:\.\d+)*) is the latest}
} else {
    livecheck.type  none
}
