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

linalg.setup        noveclibfort

name                py-cvxopt
python.rootname     cvxopt
version             1.3.2
revision            3
categories-append   math
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            https://cvxopt.org/


checksums           rmd160  e181f9ef9224136835a34f6142c9974335d95ebf \
                    sha256  3461fa42c1b2240ba4da1d985ca73503914157fc4c77417327ed6d7d85acdbe6 \
                    size    4108454

python.versions     39 310 311 312 313

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
    }

    depends_build-append    port:py${python.version}-setuptools_scm

    # 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
}
