# -*- 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           github 1.0

github.setup        flame libflame f38dd83e30136b4e25eb2343813ee4fbd7c16681
version             2024.05.20
revision            0
categories          math
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             BSD
description         LAPACK-like library for dense matrix computations
long_description    ${name} is a portable library for dense matrix computations, \
                    providing much of the functionality present in LAPACK. \
                    This is a counterpart for blis implementation of BLAS.
github.tarball_from archive
checksums           rmd160  94fff489ee73e642eb543234d88f6099e56a86bd \
                    sha256  72c31f89e2cb6f76d286a5c0b0650357a70c4bfc6afeac0453fcf314d14c2ade \
                    size    23854087

patchfiles          patch-Makefile.diff \
                    patch-flame.pc.diff \
                    mac-update-makefile.patch

post-patch {
    reinplace "s|/usr/bin/env python|${configure.python}|" ${worksrcpath}/build/flatten-headers.py

    # populate pkg-config flame.pc file
    reinplace "s|@prefix@|${prefix}|g" ${worksrcpath}/flame.pc
    reinplace "s|@exec_prefix@|${prefix}|g" ${worksrcpath}/flame.pc
    reinplace "s|@libdir@|${prefix}/lib|g" ${worksrcpath}/flame.pc
    reinplace "s|@includedir@|${prefix}/include|g" ${worksrcpath}/flame.pc
    reinplace "s|@PACKAGE_VERSION@|${version}|g" ${worksrcpath}/flame.pc
    reinplace "s|@LDFLAGS@|${configure.ldflags}|g" ${worksrcpath}/flame.pc
}

compiler.c_standard 1999
compilers.setup     require_fortran

compiler.blacklist-append \
                    *gcc-4.* {clang < 500}

configure.args-append \
                    --enable-blis-use-of-fla-malloc \
                    --enable-lapack2flame \
                    --enable-multithreading=pthreads \
                    --with-cc=${configure.cc} \
                    --enable-dynamic-build \
                    --disable-static-build

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    depends_build-append    port:python311
    license_noconflict      python311
    configure.python        ${prefix}/bin/python3.11
} elseif {${os.platform} eq "darwin" && ${os.major} >= 19} {
    configure.python        /usr/bin/python3
} else {
    configure.python        /usr/bin/python
}

configure.args-append \
                    --with-python=${configure.python}

post-destroot {
    set pkgconfigdir ${prefix}/share/pkgconfig
    xinstall -d ${destroot}${pkgconfigdir}
    xinstall -m 0644 -W ${worksrcpath} flame.pc ${destroot}/${pkgconfigdir}/
}
