# $Id: Portfile 50604 2009-05-04 23:40:02Z mcalhoun@macports.org $

PortSystem      1.0
PortGroup       muniversal 1.0

name            glpk
version         4.37
categories      math lang
platforms       darwin
maintainers     fastmail.fm:lutz.horn
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        http://www.gnu.org/software/${name}/
master_sites    gnu

checksums       md5 e88e0d36681566eeb333dde0be57224e \
                sha1 51d0db56764671912914c0c2b068a49d7cb723f2 \
                rmd160 d636ac3f0f2c70b7786d1179a9566b9b244c2891

depends_lib     port:gmp port:zlib

configure.args  --with-gmp --with-zlib

if { [variant_isset odbc] || [variant_isset mysql] } {
    depends_lib-append port:libtool
    configure.args-append --enable-dl
}

use_parallel_build  yes

test.run        yes
test.target     check

post-patch {
    # glpk uses nmedit to make certain symbols local.
    # octave 3.0.3 relies on the obsolete __glp_lib_print_hook and __glp_lib_fault_hook symbols, so they must be kept global.
    # See http://www.nabble.com/octave-3.0.3-build-problem-due-to-glpk-td19945239.html for a discussion.
    reinplace \
        "s|export-symbols-regex '^(glp_\\|_glp_lpx_).*'|export-symbols-regex '^(glp_\\|_glp_lpx_\\|_glp_lib_fault_hook\\|_glp_lib_print_hook).*'|g" \
        ${worksrcpath}/src/Makefile.in
}

variant examples description {install examples} {
    post-destroot {
        set examplesdir ${destroot}${prefix}/share/doc/${name}/examples
        xinstall -m 755 -d ${examplesdir}
        foreach fl [glob -tails -directory ${worksrcpath}/examples *.{c,mod,lp,mps,dat}] {
            xinstall -m 644 -W ${worksrcpath}/examples $fl ${examplesdir}
        }
        xinstall -m 755 -d ${examplesdir}/sql
        foreach fl [glob -tails -directory ${worksrcpath}/examples/sql *.{mod,sql}] {
            xinstall -m 644 -W ${worksrcpath}/examples/sql $fl ${examplesdir}/sql
        }
    }
}

variant doc description {build and install documentation} {
    depends_build-append path:${prefix}/bin/pdflatex:texlive \
        path:${prefix}/bin/texi2pdf:texinfo
    post-destroot {
        set docdir ${destroot}${prefix}/share/doc/${name}
        xinstall -m 755 -d ${docdir}
        system "cd ${worksrcpath}/doc && ${prefix}/bin/pdflatex glpk.tex && ${prefix}/bin/pdflatex glpk.tex"
        system "cd ${worksrcpath}/doc && ${prefix}/bin/texi2pdf gmpl.texi"
        xinstall -m 644 -W ${worksrcpath}/doc glpk.pdf gmpl.pdf glpk_faq.txt ${docdir}
        xinstall -m 644 -W ${worksrcpath} AUTHORS COPYING ChangeLog INSTALL NEWS README ${docdir}
    }
}

variant odbc description {enable MathProg ODBC support} {
    depends_lib-append port:unixODBC
    configure.args-append --enable-odbc=unix
    post-patch {
        reinplace \
            "s|libodbc.so|${prefix}/lib/libodbc.dylib|g" \
            ${worksrcpath}/configure
    }
}

variant mysql description {enable MathProg MySQL support} {
    depends_lib-append port:mysql5
    configure.args-append --enable-mysql
    post-patch {
        reinplace \
            "s|/usr/include/mysql|${prefix}/include/mysql5/mysql|g" \
            ${worksrcpath}/configure
        reinplace \
            "s|libmysqlclient.so|${prefix}/lib/mysql5/mysql/libmysqlclient.dylib|g" \
            ${worksrcpath}/configure
    }
}

livecheck.check regex
livecheck.url   http://ftp.gnu.org/gnu/${name}/?C=M&O=D
livecheck.regex ${name}-(\\d+\\.\\d+)
