# -*- 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               legacysupport 1.1
PortGroup               makefile 1.0

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup            ERGO-Code basiclu a2828782151288efa5e2cb2e0c1ac21925ed9db9
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
version                 2.2.0
revision                1
categories              math
maintainers             {@barracuda156 gmail.com:vital.had} openmaintainer
license                 {GPL-3 MIT}
description             Sparse LU factorization and update
long_description        {*}${description}
checksums               rmd160  1186d7c129f10adbc6f7c5d275ff86326fcfd1fd \
                        sha256  25b15b96ebd739450b6a91ca86bdf939fd2096873b47557723c332d626061207 \
                        size    1328520

patchfiles-append       patch-use-right-cc.diff

post-patch {
    reinplace "s,@CC@,${configure.cc},g" ${worksrcpath}/Makefile
}

compiler.c_standard     1999

# error: ‘for’ loop initial declaration used outside C99 mode
configure.cflags-append -std=c99

# CLOCK_MONOTONIC_RAW
configure.cppflags-append \
                        -D_DARWIN_C_SOURCE

build.target            shared

destroot {
    xinstall -d ${destroot}${prefix}/include/${name}
    fs-traverse h ${worksrcpath}/include {
        if {[file isfile ${h}] && [file extension ${h}] == ".h"} {
            copy ${h} ${destroot}${prefix}/include/${name}
        }
    }
    fs-traverse l ${worksrcpath}/lib {
        if {[file isfile ${l}] && [file extension ${l}] == ".dylib"} {
            copy ${l} ${destroot}${prefix}/lib
        }
    }
}

# https://github.com/ERGO-Code/basiclu/issues/7
post-destroot {
    set dylib ${prefix}/lib/libbasiclu.${version}.dylib
    system "install_name_tool -id ${dylib} ${destroot}${dylib}"
}
