# -*- 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                glpk
epoch               1
version             5.0
revision            0
license             GPL-3+
categories          math lang
maintainers         nomaintainer
description         GNU Linear Programming Kit

long_description    The GLPK (GNU Linear Programming Kit) package is intended for \
                    solving large-scale linear programming (LP), mixed integer \
                    programming (MIP), and other related problems. It is a set of \
                    routines written in ANSI C and organized in the form of a \
                    callable library.

homepage            https://www.gnu.org/software/${name}/
master_sites        gnu

checksums           rmd160  bbf7d77de79d486bb6292f095f22713518399060 \
                    sha256  4a1013eebb50f728fc601bdd833b0b2870333c3b3e5a816eeba921d95bec6f15 \
                    size    4132649

depends_lib         port:gmp
configure.args      --with-gmp

if {[variant_isset odbc] || [variant_isset iodbc] || [variant_isset mysql56] || [variant_isset mysql8]} {
    depends_lib-append      port:libtool
    configure.args-append   --enable-dl
    patchfiles-append       patch-configure.diff
}

if { ${os.major} <= 10 } {
    configure.args-append   --disable-reentrant
}

use_parallel_build  yes

test.run            yes
test.target         check

set docdir          ${prefix}/share/doc/${name}

post-destroot {
    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} AUTHORS COPYING ChangeLog NEWS README \
        doc/glpk.pdf doc/gmpl.pdf doc/cnfsat.pdf doc/gmpl_es.pdf doc/graphs.pdf \
        ${destroot}${docdir}

    set examplesdir ${prefix}/share/examples/${name}
    xinstall -d ${destroot}${examplesdir}
    xinstall -m 644 \
        {*}[glob -directory ${worksrcpath}/examples *.{c,mod,lp,mps,dat}] \
        ${destroot}${examplesdir}

    xinstall -d ${destroot}${examplesdir}/sql
    xinstall -m 644 \
        {*}[glob -directory ${worksrcpath}/examples/sql *.{mod,sql}] \
        ${destroot}${examplesdir}/sql
}

variant odbc conflicts iodbc description {enable MathProg ODBC support using unixODBC} {
    depends_lib-append      port:unixODBC
    configure.args-append   --enable-odbc=unix

    post-patch {
        reinplace \
            "s|__MACPORTS__ODBC__LIB__|${prefix}/lib|g" \
            ${worksrcpath}/configure
    }
}

variant iodbc description {enable MathProg ODBC support using iODBC} {
    depends_lib-append      port:libiodbc
    configure.args-append   --enable-odbc

    post-patch {
        reinplace \
            "s|__MACPORTS__IODBC__LIB__|${prefix}/lib|g" \
            ${worksrcpath}/configure
    }
}

variant mysql56 conflicts mysql8 description {enable MathProg MySQL support using MySQL 5.6} {
    depends_lib-append      port:mysql56
    configure.args-append   --enable-mysql

    post-patch {
        reinplace \
            "s|__MACPORTS__MYSQL__INCLUDE__|${prefix}/include/mysql56/mysql|g" \
            ${worksrcpath}/configure
        reinplace \
            "s|__MACPORTS__MYSQL__LIB__|${prefix}/lib/mysql56/mysql|g" \
            ${worksrcpath}/configure
    }
}

variant mysql8 conflicts mysql56 description {enable MathProg MySQL support using MySQL 8} {
    depends_lib-append      port:mysql8
    configure.args-append   --enable-mysql

    post-patch {
        reinplace \
            "s|__MACPORTS__MYSQL__INCLUDE__|${prefix}/include/mysql8/mysql|g" \
            ${worksrcpath}/configure
        reinplace \
            "s|__MACPORTS__MYSQL__LIB__|${prefix}/lib/mysql8/mysql|g" \
            ${worksrcpath}/configure
    }
}
