# -*- 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
# $Id: Portfile 115521 2014-01-04 00:24:09Z ryandesign@macports.org $

PortSystem          1.0

name                DSDP
version             5.8
revision            2
categories          math science
platforms           darwin
maintainers         nomaintainer

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            http://www.mcs.anl.gov/hs/software/DSDP/
master_sites        ${homepage}

distname            ${name}${version}
use_zip             yes

checksums           md5     f61d3759cc8c6de688ab5c30877ca83c \
                    sha1    8327a6fe2de902d97c3b4cf63668f2731c84b80d \
                    rmd160  75cf8629445522a4f9bbfffdcec25e832c8ffc4e

depends_lib         port:atlas

patchfiles          patch-make.include.diff

use_configure       no

build.target        dsdpapi
build.env-append    DSDPROOT=${worksrcpath}

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
    reinplace "s|@@MP_ARCHFLAGS@@|${configure.cc_archflags}|g" \
        ${worksrcpath}/make.include
}

destroot {
    xinstall ${worksrcpath}/lib/libdsdp.a ${destroot}${prefix}/lib
    eval xinstall [glob ${worksrcpath}/include/*] ${destroot}${prefix}/include
    xinstall ${worksrcpath}/bin/dsdp5 ${destroot}${prefix}/bin
    xinstall ${worksrcpath}/bin/maxcut ${destroot}${prefix}/bin
    xinstall ${worksrcpath}/bin/theta ${destroot}${prefix}/bin
    
    if {[variant_isset octave]} {
        if {[catch {set msite [exec ${prefix}/bin/octave-config --m-site-dir]}]} {
            set msite ${prefix}/share/dsdp/matlab
        }
        set msite ${msite}/dsdp
        xinstall -d ${destroot}${msite}
        eval file copy [glob ${worksrcpath}/matlab/*] ${destroot}${msite}
    }
}

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