#-*- 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

PortSystem            1.0
PortGroup             mpi 1.0

name                  gerris
set snapshot          131206
version               0.9.2-20${snapshot}
revision              6
categories            science
license               GPL-2+
maintainers           {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
description           a program for solving fluid flow equations
long_description      Gerris is a Free Software program for the solution of the partial differential equations describing fluid flow.
homepage              http://gfs.sourceforge.net/
distname              ${name}-snapshot-${snapshot}
master_sites          http://gerris.dalembert.upmc.fr/gerris/tarballs/

checksums             rmd160  5575376c8d9ce252215dd361443dfeb1c8e82144 \
                      sha256  d5346a362b104ccc858c4b79938727d56c4654b103c268e54cf3aa56d0b55b39 \
                      size    2841686

# C99 required
mpi.setup             require_fortran \
                      -gcc44

# most of the patches are from Gentoo
#    https://gitweb.gentoo.org/repo/gentoo.git/tree/sci-libs/gerris/gerris-20131206-r1.ebuild
patchfiles-append     patch-fortran_lib.diff \
                      patch-hypre_no_mpi.diff \
                      patch-lis_names.diff \
                      patch-configure.diff

depends_build         port:pkgconfig

# N.B. wavewatch and agmg are non-free
depends_lib           path:lib/pkgconfig/glib-2.0.pc:glib2  \
                      port:gts \
                      port:proj5 \
                      port:netcdf \
                      port:hypre \
                      port:gsl \
                      port:fftw-3 \
                      port:ode \
                      port:lis

pre-configure {
    if {[mpi_variant_isset]} {
        configure.args-append --enable-mpi \
                              --with-mpicc=${configure.cc}
    } else {
        configure.args-append --disable-mpi
    }
}

mpi.enforce_variant   netcdf
mpi.enforce_variant   hypre
mpi.enforce_variant   lis
mpi.enforce_variant   fftw-3
mpi.enforce_variant   lis

if {${os.platform} eq "darwin" && ${os.major} > 22} {
    if {[string match *clang* ${configure.compiler}]} {
        configure.cflags-append \
                    -Wno-error=incompatible-function-pointer-types
    }
}

# proj port is installed in a non-standard location
configure.cppflags-append -I${prefix}/lib/proj5/include
configure.ldflags-append  -L${prefix}/lib/proj5/lib

test.run              yes
test.target           check
post-extract {
    # test files do not have the correct permissions
    foreach file [glob ${worksrcpath}/test/**/*.sh] {
        file attributes ${file} -permissions +x
    }
}

livecheck.regex       {gerris-snapshot-(\d+(?:\.\d+)*)}
livecheck.version     ${snapshot}
