# -*- 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           python 1.0
PortGroup           github 1.0
PortGroup           linear_algebra  1.0
linalg.setup        noveclibfort

github.setup        cvxopt cvxopt 1.1.9
revision            1
name                py-cvxopt
categories-append   math
platforms           darwin
license             GPL-3+
maintainers         {gmail.com:jjstickel @jjstickel} openmaintainer

description         Python module for convex optimization
long_description    CVXOPT is a free software package for convex \
                    optimization based on the Python programming \
                    language. It can be used with the interactive \
                    Python interpreter, on the command line by \
                    executing Python scripts, or integrated in other \
                    software via Python extension modules. Its main \
                    purpose is to make the development of software for \
                    convex optimization applications straightforward \
                    by building on Python's extensive standard library \
                    and on the strengths of Python as a high-level \
                    programming language.
homepage            http://cvxopt.org/

checksums           rmd160  bff5c419f73203fe35dc23a1be74f7d4c3aa7322 \
                    sha256  5cbc2f3ab1573bace9fca6d39cddab86370828f0a50c84fdbd056269c6ec10ac

python.versions     27 34 35 36 37

if {${subport} ne ${name}} {
    # ignore empty BLAS and LAPACK inputs
    patchfiles      patch-setup.py.diff

    build.env-append \
        CVXOPT_BLAS_LIB_DIR=${prefix}/lib \
        CVXOPT_LAPACK_LIB=

    pre-build {
        set blas_lib {}
        set blas_extra_link_args {}
        foreach lib [split ${linalglib} " "] {
            if { [lrange ${lib} 0 1] eq "-l" } {
                lappend blas_lib [lrange ${lib} end]
            } else {
                lappend blas_extra_link_args ${lib}
            }
        }

        build.env-append \
            CVXOPT_BLAS_LIB=[join ${blas_lib} ";"] \
            CVXOPT_BLAS_EXTRA_LINK_ARGS=[join ${blas_extra_link_args} ";"]
    }

    variant gsl description {Build GSL module} {
        depends_lib-append  port:gsl

        build.env-append \
            CVXOPT_BUILD_GSL=1 \
            CVXOPT_GSL_LIB_DIR=${prefix}/lib \
            CVXOPT_GSL_INC_DIR=${prefix}/include
    }

    variant fftw description {Build FFTW module} {
        depends_lib-append  port:fftw-3

        build.env-append \
            CVXOPT_BUILD_FFTW=1 \
            CVXOPT_FFTW_LIB_DIR=${prefix}/lib \
            CVXOPT_FFTW_INC_DIR=${prefix}/include
    }

    variant glpk description {Build GLPK module} {
        depends_lib-append  port:glpk

        build.env-append \
            CVXOPT_BUILD_GLPK=1 \
            CVXOPT_GLPK_LIB_DIR=${prefix}/lib \
            CVXOPT_GLPK_INC_DIR=${prefix}/include
    }

    variant dsdp description {Build DSDP module} {
        depends_lib-append  port:DSDP

        build.env-append \
            CVXOPT_BUILD_DSDP=1 \
            CVXOPT_DSDP_LIB_DIR=${prefix}/lib \
            CVXOPT_DSDP_INC_DIR=${prefix}/include
    }

    # link against MacPorts SuiteSparse
    depends_lib-append  port:SuiteSparse_config \
                        port:SuiteSparse_AMD \
                        port:SuiteSparse_COLAMD \
                        port:SuiteSparse_CHOLMOD \
                        port:SuiteSparse_UMFPACK
    build.env-append \
        CVXOPT_SUITESPARSE_SRC_DIR="" \
        CVXOPT_SUITESPARSE_LIB_DIR=${prefix}/lib \
        CVXOPT_SUITESPARSE_INC_DIR=${prefix}/include

    default_variants +gsl +glpk +fftw +dsdp

    livecheck.type 	none
}