# -*- 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 108109 2013-07-13 06:46:00Z takeshi@macports.org $

PortSystem        1.0

name              fgsl
version           0.9.4
revision          1
categories        math science
maintainers       takeshi
license           GPL-2
description       Fortran interface to the GNU scientific library
long_description  \
    A portable, object-based Fortran interface to the GNU scientific library, \
    a collection of numerical routines for scientific computing.
homepage          http://www.lrz.de/services/software/mathematik/gsl/fortran/
platforms         darwin
master_sites      ${homepage}
checksums         md5     cee6760809bc1ddbb6172fc8818a76b2 \
                  sha1    82f3047a3b1b1970fae741946fd8479f15595362 \
                  rmd160  7c12162b4fb64746d91715756c01e52dbb4e0e09
depends_lib       port:gsl
patch {
    reinplace "s| \$bits | \"\$bits\" |" ${worksrcpath}/configure
    reinplace "s|uname -i|uname -m|" ${worksrcpath}/configure
    reinplace "s|fgsl_doc|share/doc/fgsl|" ${worksrcpath}/Makefile
    reinplace "s|\$(PREFIX)|\$(DESTDIR)\$(PREFIX)|" ${worksrcpath}/Makefile
    reinplace "s|error_3\.exe||" ${worksrcpath}/doc/examples/Makefile
}

if {![variant_isset g95] && ![variant_isset gcc45] && ![variant_isset gcc46] && ![variant_isset gcc48]} {
    default_variants +gcc47
}

if {[variant_isset g95]} {
    set f90 g95
} elseif {[variant_isset gcc45]} {
    set f90 gfortran-mp-4.5
} elseif {[variant_isset gcc46]} {
    set f90 gfortran-mp-4.6
} elseif {[variant_isset gcc47]} {
    set f90 gfortran-mp-4.7
} elseif {[variant_isset gcc48]} {
    set f90 gfortran-mp-4.8
}
if {![variant_isset g95]} {
    post-patch {
        reinplace "s|gfortran|${f90}|" ${worksrcpath}/configure
    }
}

configure.pre_args-delete --prefix=${prefix}
configure.args    "--prefix ${prefix} --f90 ${f90} --cc ${configure.cc} --gsl ${prefix}"

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/${name}/examples
    eval xinstall -m 644 [glob ${worksrcpath}/doc/examples/*] ${destroot}${prefix}/share/${name}/examples
    xinstall -m 644 ${worksrcpath}/make.inc ${destroot}${prefix}/share/${name}
    reinplace "s|../make.inc|make.inc|" ${destroot}${prefix}/share/${name}/examples/Makefile
    reinplace "s|-I../..|-I${prefix}/include/\$(F90)|" ${destroot}${prefix}/share/${name}/examples/Makefile
}

universal_variant no

variant g95 conflicts gcc45 gcc46 gcc47 gcc48 description {build with g95} {
    depends_build-append port:g95
}
variant gcc45 conflicts g95 gcc46 gcc47 gcc48 description {build with gcc45} {
    depends_build-append port:gcc45
}
variant gcc46 conflicts g95 gcc45 gcc47 gcc48 description {build with gcc46} {
    depends_build-append port:gcc46
}
variant gcc47 conflicts g95 gcc45 gcc46 gcc48 description {build with gcc47} {
    depends_build-append port:gcc47
}
variant gcc48 conflicts g95 gcc45 gcc46 gcc47 description {build with gcc48} {
    depends_build-append port:gcc48
}

livecheck.type  regex
livecheck.url   ${homepage}
livecheck.regex {Download .*version ([0-9]+\.[0-9]+\.*[0-9]*)}
