# -*- 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           cmake 1.1
PortGroup           compilers 1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1

# getline, strndup, strnlen
legacysupport.newest_darwin_requires_legacy 10

github.setup        mpimd-csc flexiblas 3.4.2 v
revision            0
categories          math science
license             GPL-3+
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         A BLAS and LAPACK wrapper library with runtime exchangeable backends
long_description    {*}${description}
homepage            https://www.mpi-magdeburg.mpg.de/projects/flexiblas
checksums           rmd160  bd953eecd649b7418b83ff76f928b55c5c1f571f \
                    sha256  e5311cdfbe6d1c8a102289150b5fa8e82c48f8eabe4a5e182964afe81036c323 \
                    size    71565455
github.tarball_from archive

# https://github.com/mpimd-csc/flexiblas/issues/40
depends_lib-append  port:blis \
                    path:lib/libopenblas.dylib:OpenBLAS

# https://github.com/mpimd-csc/flexiblas/issues/37
patchfiles-append   patch-remove-faulty-flags.diff

set py_ver          3.11
set py_ver_nodot    [string map {. {}} ${py_ver}]
configure.python    ${prefix}/bin/python${py_ver}

post-patch {
    reinplace "s,/usr/bin/env python,${configure.python}," \
                    ${worksrcpath}/test/usage/python-numpy-scipy/numpy-scipy-benchmark.py
    reinplace "s,/usr/bin/env python3,${configure.python}," \
                    ${worksrcpath}/tools/code_generators/generate_hook_profile_lapack.py \
                    ${worksrcpath}/tools/code_generators/generate_lapack.py \
                    ${worksrcpath}/tools/code_generators/generate_lapack_dummy.py
}

compilers.setup     require_fortran
compiler.thread_local_storage yes
compiler.openmp_version 2.5
compiler.c_standard 1999

configure.args-append \
                    -DABI=GNU \
                    -DBLAS_AUTO_DETECT=ON \
                    -DBUILD_SHARED_LIBS=ON \
                    -DDEV=OFF \
                    -DEXAMPLES=OFF \
                    -DLAPACK=ON \
                    -DLINK_OPENMP=ON \
                    -DMKL_BUILDER=OFF \
                    -DPythonInterp=${prefix}/bin/python${py_ver} \
                    -DTESTS=ON

if {[string match *clang* ${configure.compiler}]} {
    configure.ldflags-append \
                    -L${prefix}/lib/libomp \
                    -lomp
}

# Do not depend on atlas by default, since it presently does not build on Catalina and newer,
# while on older systems it requires building multiple extra gcc/libgcc versions.
variant atlas description "Build with Atlas support" {
    depends_lib-append \
                    port:atlas
}

depends_test-append port:python${py_ver_nodot}

test.run            yes
test.target         test
test.cmd-prepend    DYLD_LIBRARY_PATH=${cmake.build_dir}/lib