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

github.setup            sivantoledo taucs 2.2.1 v
revision                0
categories              math
license                 LGPL
maintainers             {gmail.com:mark.brethen @mbrethen} {mcalhoun @MarcusCalhoun-Lopez} openmaintainer

description             C library of sparse linear solvers

long_description        TAUCS is a ${description}.

homepage                https://www.tau.ac.il/~stoledo/taucs

checksums               rmd160  c9e8a9377fe69b60e58db4f474eb631d9923f263 \
                        sha256  7b682b602bc173110bc68e586a7d36129cff6bf59c6766b518e60adff16a31e5 \
                        size    1594127
github.tarball_from     archive

depends_lib-append      port:metis \
                        port:libf2c

# requires C99
compiler.blacklist-append \
                        {clang < 211.10.1}
compilers.choose        cc
compilers.setup         -gcc44
linalg.setup            noveclibfort blas_only

post-extract {
    fs-traverse item ${worksrcpath} {
        if {[file isdirectory ${item}]} {
            file attributes ${item} -permissions a+rx
        } else {
            file attributes ${item} -permissions a+r
        }
    }
}

patchfiles              patch-dylib.diff \
                        patch-ldflags.diff \
                        patch-taucs-build.diff

configure.pre_args
configure.universal_args

configure.post_args-append \
                        " && printenv >> config/${os.platform}.mk"

configure.env-append    PREFIX=${prefix} \
                        LIBMETIS=-lmetis \
                        LIBF77=-lf2c \
                        LIBC= \
                        OSTYPE=${os.platform}

pre-configure {
    configure.env-append \
                        LIBBLAS=${linalglib} \
                        LIBLAPACK=
}

if {${build_arch} eq "ppc" || ${build_arch} eq "ppc64"} {
    configure.cflags-append \
                        -faltivec
}

destroot {
    foreach dir {bin lib} {
        delete ${worksrcpath}/${dir}/${os.platform}/exists.log
    }
    xinstall -m 0755 {*}[glob ${worksrcpath}/bin/${os.platform}/*]       ${destroot}${prefix}/bin/
    #xinstall -m 0644 {*}[glob ${worksrcpath}/lib/${os.platform}/*.a]     ${destroot}${prefix}/lib/
    xinstall -m 0755 {*}[glob ${worksrcpath}/lib/${os.platform}/*.dylib] ${destroot}${prefix}/lib/
    xinstall -m 0644 {*}[glob ${worksrcpath}/build/${os.platform}/*.h]   ${destroot}${prefix}/include/
    xinstall -m 0644 {*}[glob ${worksrcpath}/src/*.h]                    ${destroot}${prefix}/include/
    ln -s libtaucs.1.dylib ${destroot}${prefix}/lib/libtaucs.dylib
    xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
    xinstall -m 0644 {*}[glob ${worksrcpath}/doc/*.pdf]                  ${destroot}${prefix}/share/doc/${name}/
}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "(\[0-9.\]+)/${distfiles}"
