# -*- 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           compilers 1.0
PortGroup           gnu_info 1.0

name                gsl
version             2.8
revision            0

checksums           rmd160  689cece61600b028d38db8a362191541ef00e3b6 \
                    sha256  6a99eeed15632c6354895b1dd542ed5a855c0f15d9ad1326c6fe2b2c9e423190 \
                    size    8997136

categories          math science
maintainers         {dtakahashi @daitakahashi} \
                    {@Dave-Allured noaa.gov:dave.allured} \
                    openmaintainer
license             GPL-3+
homepage            https://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.

# Normal releases.
master_sites        gnu

# Alpha releases only.
#master_sites        ftp://alpha.gnu.org/gnu/gsl
#distname            gsl-${version}

configure.args      --infodir=${prefix}/share/info \
                    --mandir=${prefix}/share/man

configure.checks.implicit_function_declaration.whitelist-append \
                    finite \
                    strchr

# Version 2.8 added -Wl,-no_fixup_chains flag,
# which is not universally supported. Drop it.
# Related: https://github.com/haskell/zlib/issues/53
patchfiles-append   patch-fix-linking.diff

test.run            yes
test.target         check

gnu_info.name       gsl-ref

compilers.choose    cc
compilers.setup

set python_version  3.12
set python_ver_no_dot [string map {. {}} ${python_version}]

variant doc description {Build documentation} {
    depends_build   port:ghostscript \
                    bin:latexmk:latexmk \
                    bin:latex:texlive \
                    port:texlive-latex-extra \
                    port:py${python_ver_no_dot}-sphinx \
                    port:py${python_ver_no_dot}-sphinx_rtd_theme \
                    port:py${python_ver_no_dot}-sphinxcontrib-websupport

    patchfiles-append \
                    patch-python_version.diff

    post-patch {
        reinplace "s|__MACPORTS_SPHINX_BUILD__|sphinx-build-${python_version}|g" ${worksrcpath}/doc/Makefile.in
    }

    post-build {
        system -W ${worksrcpath}/doc "make latexpdf"
        system -W ${worksrcpath}/doc "make html"
    }

    post-destroot {
        xinstall -d ${destroot}${prefix}/share/doc/${name}
        xinstall -c -m 0644 ${worksrcpath}/doc/_build/latex/gsl-ref.pdf ${destroot}${prefix}/share/doc/${name}
        copy ${worksrcpath}/doc/_build/html ${destroot}${prefix}/share/doc/${name}/
    }
}

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

platform darwin i386 {
    if { [variant_isset optimize] } {
        if { [clang_variant_isset] } {
            configure.optflags  -march=native
        } elseif { [gcc_variant_isset] } {
            configure.optflags  -ftree-vectorize -march=native -mno-avx
            if { ! ([variant_isset gcc44] ||
                    [variant_isset gcc45] ||
                    [variant_isset gcc46]) } {
                ## Haswell's new instruction sets need to be disabled,
                ## because these instructions are not recognized by
                ## cctools' assembler
                configure.optflags-append -mno-avx2 -mno-bmi -mno-bmi2
            }
        } else {
            #Default compiler. Check if the compiler supports "native" architecture
            if { [string match "clang" ${configure.cc}] } {
                configure.optflags  -march=native
            }
        }
    }
}

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