# -*- 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 114186 2013-12-01 13:58:44Z nicos@macports.org $

PortSystem          1.0

name                gsl
conflicts           gsl-devel
version             1.16
revision            2
categories          math science
maintainers         openmaintainer gmail.com:dtakahashi42
license             GPL-3+
homepage            http://www.gnu.org/software/gsl
description         A numerical library for C and C++ programmers
long_description    The GNU Scientific Library (GSL) is a numerical library  \
                    for C and C++ programmers.  It is free software under the \
                    GNU General Public License.  \
                    \
                    The library provides a wide range of mathematical routines \
                    such as random number generators, special functions and \
                    least-squares fitting. There are over 1000 functions in total.

master_sites        gnu
checksums           rmd160  45e707ad8b5abd77f760827ee49ece9277a36a80 \
                    sha256  73bc2f51b90d2a780e6d266d43e487b3dbd78945dd0b04b14ca5980fe28d2f53

platforms           darwin

depends_build       port:texinfo
use_parallel_build  yes

configure.args      --mandir=${prefix}/share/man --infodir=${prefix}/share/info
test.run            yes
test.target         check

post-activate    {
    system "install-info ${prefix}/share/info/gsl-ref.info ${prefix}/share/info/dir"
}

variant doc description "Install PDF and HTML documentation" {
    depends_build   port:ghostscript bin:latex:texlive
    post-destroot   {
        system "cd ${worksrcpath} && make dvi"
        system "cd ${worksrcpath}/doc && dvipdf gsl-ref.dvi gsl-ref.pdf"
        xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
        xinstall -c -m 644 ${worksrcpath}/doc/gsl-ref.pdf ${destroot}${prefix}/share/doc/${name}
        system "cd ${worksrcpath}/doc && latex fftalgorithms"
        system "cd ${worksrcpath}/doc && bibtex fftalgorithms"
        system "cd ${worksrcpath}/doc && latex fftalgorithms"
        system "cd ${worksrcpath}/doc && latex fftalgorithms"
        system "cd ${worksrcpath}/doc && dvipdf fftalgorithms.dvi fftalgorithms.pdf"
        xinstall -c -m 644 ${worksrcpath}/doc/fftalgorithms.pdf ${destroot}${prefix}/share/doc/${name}
        system "cd ${worksrcpath} && make html"
        xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}/html
        eval xinstall -c -m 644 [glob ${worksrcpath}/doc/gsl-ref.html/*] ${destroot}${prefix}/share/doc/${name}/html
    }
}

variant gcc43 conflicts gcc44 gcc45 gcc46 gcc47 gcc48 mpclang33 description "Use GCC 4.3 for compilation of GSL" {
    configure.compiler          macports-gcc-4.3
}

variant gcc44 conflicts gcc43 gcc45 gcc46 gcc47 gcc48 mpclang33 description "Use GCC 4.4 for compilation of GSL" {
    configure.compiler          macports-gcc-4.4
}

variant gcc45 conflicts gcc43 gcc44 gcc46 gcc47 gcc48 mpclang33 description "Use GCC 4.5 for compilation of GSL" {
    configure.compiler          macports-gcc-4.5
}

variant gcc46 conflicts gcc43 gcc44 gcc45 gcc47 gcc48 mpclang33 description "Use GCC 4.6 for compilation of GSL" {
    configure.compiler          macports-gcc-4.6
}

variant gcc47 conflicts gcc43 gcc44 gcc45 gcc46 gcc48 mpclang33 description "Use GCC 4.7 for compilation of GSL" {
    configure.compiler          macports-gcc-4.7
}

variant gcc48 conflicts gcc43 gcc44 gcc45 gcc46 gcc47 mpclang33 description "Use GCC 4.8 for compilation of GSL" {
    configure.compiler          macports-gcc-4.8
}

variant mpclang33 conflicts gcc43 gcc44 gcc45 gcc46 gcc47 description "Use clang 3.3 for compilation of GSL" {
    configure.compiler          macports-clang-3.3
}

variant optimize description "Provide further optimization options (depending on compiler used)" {
    configure.optflags-append   -O3
}

platform darwin i386 {
    if { [variant_isset optimize] } {
        if { [variant_isset mpclang33] } {
            configure.optflags  -march=native
        } elseif { [variant_isset gcc43] } {
            configure.optflags  -ftree-vectorize -march=native
        } elseif { [variant_isset gcc44] || [variant_isset gcc45] ||
                   [variant_isset gcc46] || [variant_isset gcc47] || 
                   [variant_isset gcc48] } {
            # Currently, gcc cannot compile AVX instructions on OSX
            configure.optflags  -ftree-vectorize -march=native -mno-avx
        } else {
            #Default compiler. Check if the compiler supports "native" architecture
            if { [string match "clang" ${configure.compiler}] } {
                configure.optflags  -march=native
            }
        }
    }
}

livecheck.type  regex
livecheck.url   http://ftp.gnu.org/gnu/gsl/
livecheck.regex ${name}-(\[\\d.\]+)${extract.suffix}
