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

github.setup        Reference-LAPACK lapack 3.12.1 v
revision            0
github.tarball_from archive

if {${subport} eq ${name}} {
    compilers.choose    cc fc f77 f90
    compilers.setup     require_fortran -clang
    compilers.add_gcc_rpath_support no
}

categories          math devel science
license             BSD
maintainers         {takeshi @tenomoto} \
                    {@Dave-Allured noaa.gov:dave.allured} \
                    openmaintainer

checksums           rmd160  f9d12f41e67e36110243dc5856168aeb65ec42c8 \
                    sha256  2ca6407a001a474d4d4d35f3a61550156050c48016d949f0da0529c0aa052422 \
                    size    8067087

description         Linear Algebra PACKage
long_description \
    LAPACK is written in Fortran 90 and provides routines \
    for solving systems of simultaneous linear equations, \
    least-squares solutions of linear systems of equations, \
    eigenvalue problems, and singular value problems.
homepage            http://www.netlib.org/${name}/

# Version numbering mistake.  Remove after 3.12.1.
patchfiles-append   patch-version-nums.3.12.1-ONLY.diff

# Fix 10.7 build for "invalid instruction mnemonic 'cvtsi2ssl'"
# Copied from https://github.com/macports/macports-ports/pull/17193
# https://github.com/william-dawson/NTPoly/issues/192
compiler.blacklist-append \
                    {clang < 500}

configure.cppflags-append \
                    -DADD_
# remove MACOSX_DEPLOYMENT_TARGET #53565
macosx_deployment_target
configure.args-delete \
                    -DCMAKE_INSTALL_RPATH=${prefix}/lib \
                    -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib

configure.args-append \
                    -DBUILD_SHARED_LIBS=ON \
                    -DCBLAS=ON \
                    -DLAPACKE=ON \
                    -DCMAKE_INSTALL_INCLUDEDIR=${prefix}/include/${name} \
                    -DCMAKE_INSTALL_LIBDIR=${prefix}/lib/${name} \
                    -DCMAKE_INSTALL_RPATH=${prefix}/lib/${name} \
                    -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib/${name}

if {${subport} eq ${name}} {
    if {[variant_isset gfortran]} {
        set gccPort [fortran_depends_port_name ${compilers.gcc_default}]
        configure.ldflags-append    -L${prefix}/lib/${gccPort} -lgfortran
    }
    variant accelerate conflicts openblas description {use BLAS in Accelerate.framework} {
        depends_lib-append          port:vecLibFort
        configure.ldflags-append    -lvecLibFort
    }
    variant openblas conflicts accelerate description {use BLAS in openblas} {
        depends_lib-append          path:lib/libopenblas.dylib:OpenBLAS
        configure.ldflags-append    -lopenblas
    }
    if {[variant_isset accelerate] || [variant_isset openblas]} {
       configure.args-append       -DUSE_OPTIMIZED_BLAS=ON
    }
    post-destroot {
        # move CMake scripts to the directory cmake expects to find them in
        xinstall -m 755 -d ${destroot}${cmake_share_module_dir}
        file delete -force ${destroot}${cmake_share_module_dir}
        move ${destroot}${prefix}/lib/${name}/cmake \
            ${destroot}${cmake_share_module_dir}
    }
}

# Disable extended Index-64 API with _64 suffix.
# Was introduced in LAPACK 3.12.0.
# To be re-enabled when corresponding extended API becomes available
#   for +openblas or +accelerate.
# Ref. CMakeLists.txt
# Fixes https://trac.macports.org/ticket/69295

if {${subport} eq ${name}} {
    if {[variant_isset accelerate] || [variant_isset openblas]} {
       configure.args-append       -DBUILD_INDEX64_EXT_API=OFF
    }
}

notes        "C headers are installed in ${prefix}/include/${name}."
notes-append "LAPACK man pages are currently broken."
notes-append "See on-line docs at https://www.netlib.org/lapack/ ."

# Build system for man pages was changed upstream.
# To recover man page subport code for previous version,
# please see portfile history for 2024 January 20.
