# -*- 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 117253 2014-02-20 18:50:55Z macsforever2000@macports.org $

PortSystem          1.0
PortGroup           python 1.0

set _name           obspy
set _n              [string index ${_name} 0]

name                py-obspy
version             0.9.0
categories-append   science
platforms           darwin
license             LGPL-3

maintainers         bo.ingv.it:Peter.Danecek openmaintainer

description         Python framework for processing seismological data

long_description    \
    This port provides a development snapshot of the ObsPy package. \
    ObsPy is an open-source project dedicated to provide a Python framework \
    for processing seismological data. It provides support for file formats \
    and signal processing routines which allow the manipulation, analysis \
    and visualization of seismological time series. The goal of the ObsPy \
    project is to facilitate rapid application development for seismology.

homepage            http://www.obspy.org/

use_zip             yes
distname            ${_name}-${version}
master_sites        https://pypi.python.org/packages/source/${_n}/${_name}/

checksums           md5     f720f675e66e8b2b6518e41b9ab9ada4 \
                    rmd160  b58932bc76e1bd21a2280d78aa868c767e3491b1 \
                    sha256  91367c7d1b63a4289b4a0ee84d49978d7523776da10629aa40a3aab197fad5e7

python.versions     26 27

if {${name} ne ${subport}} {
    depends_build-append    port:py${python.version}-numpy
    # Note: setuptools required only for developers

    depends_lib-append      port:py${python.version}-numpy \
                            port:py${python.version}-scipy \
                            port:py${python.version}-lxml \
                            port:py${python.version}-suds \
                            port:py${python.version}-sqlalchemy \
                            port:py${python.version}-matplotlib

    # Note: Required for post-installation testing only
    depends_run-append      port:py${python.version}-flake8 \
                            port:py${python.version}-nose \
                            port:py${python.version}-mock

    # py-scipy is not universal
    universal_variant       no

    # Note: temporary workaround for numpy.distutils behaviour
    patchfiles              patch-setup.py.diff

    # Check if and how to use compiler portgroup ...
    #
    set gcc_versions {4.3 4.4 4.5 4.6 4.7 4.8 4.9}
    set default_fortran_variant +gcc48

    foreach ver ${gcc_versions} {
        set ver_no_dot [join [split ${ver} "."] ""]

        set variant_line {variant gcc${ver_no_dot} description "build with gfortran from gcc${ver_no_dot}"}

        foreach over ${gcc_versions} {
            if {${ver} == ${over}} {
                continue
            }

            set over_no_dot [join [split ${over} "."] ""]
            append variant_line " conflicts gcc${over_no_dot}"
        }
        append variant_line { {}}

        eval $variant_line

        if {[variant_isset gcc${ver_no_dot}]} {
            if {${default_fortran_variant} != "+gcc${ver_no_dot}"} {
                set default_fortran_variant ""
            }
        }
    }

    if {${default_fortran_variant} != ""} {
        default_variants-append "${default_fortran_variant}"
    }

    foreach ver ${gcc_versions} {
        set ver_no_dot [join [split ${ver} "."] ""]

        if {[variant_isset gcc${ver_no_dot}]} {
            depends_lib-append path:lib/libgcc/libgcc_s.1.dylib:libgcc
            depends_build-append port:gcc${ver_no_dot}

            configure.fc  ${prefix}/bin/gfortran-mp-${ver}
            configure.f77 ${prefix}/bin/gfortran-mp-${ver}
            configure.f90 ${prefix}/bin/gfortran-mp-${ver}

            # `setup.py install` tests for Fortran compiler
            destroot.env-append FC=${configure.fc}
            destroot.env-append F77=${configure.f77}
            destroot.env-append F90=${configure.f90}
        }
    }

    livecheck.type  none
} else {
    livecheck.type  regex
    livecheck.url   [lindex ${master_sites} 0]
    livecheck.regex ">${_name}-(\\d+(\\.\\d+)+)\\${extract.suffix}<"
}
