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

name                DSDP
version             5.8
revision            6
categories          math science
platforms           darwin
maintainers         nomaintainer
license             Permissive

description         DSDP is a open source implementation of an interior-point method for semidefinite programming

long_description    DSDP provides primal and dual solutions, exploits low-rank structure \
                    and sparsity in the data, and has relatively low memory requirements for an \
                    interior-point method. The dual-scaling algorithm implemented in this package has \
                    a convergence proof and worst-case polynomial complexity under mild assumptions on the data

homepage            https://www.mcs.anl.gov/hs/software/DSDP/
master_sites        ${homepage}

distname            ${name}${version}
use_zip             yes

checksums           rmd160  75cf8629445522a4f9bbfffdcec25e832c8ffc4e \
                    sha256  8915e55456f1a7cc5c970ad157d094a5fb399737cf192dfe79b89c2d94d97a8a \
                    size    2769752

patchfiles          patch-make.include.diff \
                    patch-src-sys-dsdploginfo.c.diff

use_configure       no

build.target        dsdpapi
if {!${universal_possible} || ![variant_isset universal]} {
    build.env-append                              \
        DSDPROOT=${worksrcpath}                   \
        MP_ARCHFLAGS=${configure.cc_archflags}
} else {
    foreach arch ${configure.universal_archs} {
        lappend merger_build_env(${arch})    \
            DSDPROOT=${worksrcpath}-${arch}  \
            "MP_ARCHFLAGS=-arch ${arch}"
    }
}

variant atlas description {Use ATLAS as BLAS, LAPACK library} {
    depends_lib-append      port:atlas
}

variant octave description {Build DSDP with octave interface} {
    build.target            all
    depends_lib-append      path:bin/octave:octave
}

post-patch {
    reinplace "s|@@MP_CC@@|${configure.cc}|g" \
        ${worksrcpath}/make.include
    if {[variant_isset atlas]} {
        reinplace "s|@@MP_LAPACKBLAS@@|-ltatlas -lm|g" \
            ${worksrcpath}/make.include
    } else {
        reinplace "s|@@MP_LAPACKBLAS@@|-Wl,-framework -Wl,Accelerate|g" \
            ${worksrcpath}/make.include
    }
}

# muniversal build requires Makefile
post-extract {
    set makefile [open ${worksrcpath}/Makefile-Install "w"]
    puts ${makefile} "MSITE:=\$(shell ${prefix}/bin/octave-config --m-site-dir)/dsdp"
    puts ${makefile} {install:}
    puts ${makefile} "\t/usr/bin/install -m 0644 include/* \$(DESTDIR)${prefix}/include/"
    puts ${makefile} "\t/usr/bin/install -m 0644 lib/* \$(DESTDIR)${prefix}/lib/"
    foreach bin "dsdp5 maxcut theta" {
        puts ${makefile} "\t/usr/bin/install -m 0755 bin/${bin} \$(DESTDIR)${prefix}/bin/"
    }
    if {[variant_isset octave]} {
        puts ${makefile} "\t/usr/bin/install -d -m 0755 \$(DESTDIR)\$(MSITE)"
        puts ${makefile} "\t/usr/bin/install -m 0644 matlab/Contents \$(DESTDIR)\$(MSITE)"
        puts ${makefile} "\t/usr/bin/install -m 0644 matlab/*.m \$(DESTDIR)\$(MSITE)"
        puts ${makefile} "\t/usr/bin/install -m 0644 matlab/*.dat-s \$(DESTDIR)\$(MSITE)"
        puts ${makefile} "\t/usr/bin/install -m 0644 matlab/*.out \$(DESTDIR)\$(MSITE)"
        puts ${makefile} "\t/usr/bin/install -m 0755 matlab/*.mex \$(DESTDIR)\$(MSITE)"
    }
    close ${makefile}
}
destroot.args-append -f Makefile-Install

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     <a href=\"${name}(.*).tar.gz\">.tar.gz</a>
