--- Portfile.orig	2013-07-15 09:02:18.000000000 -0700
+++ Portfile	2015-12-13 06:51:05.000000000 -0700
@@ -1,13 +1,11 @@
 # $Id: Portfile 106046 2013-05-14 02:02:15Z ryandesign@macports.org $
 
 PortSystem      1.0
-PortGroup       archcheck 1.0
 PortGroup       muniversal 1.0
 
 name            glpk
 epoch           1
-# 4.49 removes the old API; don't update until ports using glpk have been rewritten to use the new API.
-version         4.48
+version         4.57
 license         GPL-3+
 categories      math lang
 platforms       darwin
@@ -24,24 +22,17 @@
 homepage        http://www.gnu.org/software/${name}/
 master_sites    gnu
 
-checksums       rmd160  269cb1f2b63b5a2f0a0f42b7af3ff52e8f95edfa \
-                sha256  abc2c8f895b20a91cdfcfc04367a0bc8677daf8b4ec3f3e86c5b71c79ac6adb1
+checksums       rmd160  10cbe9f5c681d5893739cde1fd9d8c16cf468c73 \
+                sha256  7323b2a7cc1f13e45fc845f0fdca74f4daea2af716f5ad2d4d55b41e8394275c
 
-depends_lib     port:gmp port:zlib
+depends_lib     port:gmp
 
-archcheck.files \
-    lib/libgmp.dylib \
-    lib/libz.dylib
+configure.args  --with-gmp
 
-configure.args  --with-gmp --with-zlib
-
-if { [variant_isset odbc] || [variant_isset mysql] } {
+if { [variant_isset odbc] || [variant_isset iodbc] || [variant_isset mysql5] || [variant_isset mysql56] } {
     depends_lib-append port:libtool
-
-    archcheck.files-append \
-        lib/libltdl.dylib
-
     configure.args-append --enable-dl
+    patchfiles-append patch-configure.diff
 }
 
 use_parallel_build  yes
@@ -49,21 +40,12 @@
 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
-}
-
 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/glpk_faq.txt \
+        doc/glpk.pdf doc/gmpl.pdf doc/cnfsat.pdf doc/gmpl_es.pdf doc/graphs.pdf \
         ${destroot}${docdir}
 
     set examplesdir ${prefix}/share/examples/${name}
@@ -78,33 +60,54 @@
         ${destroot}${examplesdir}/sql
 }
 
-variant odbc description {enable MathProg ODBC support} {
+variant odbc conflicts iodbc description {enable MathProg ODBC support using unixODBC} {
     depends_lib-append port:unixODBC
 
-    archcheck.files-append \
-        lib/libodbc.dylib
-
     configure.args-append --enable-odbc=unix
     post-patch {
         reinplace \
-            "s|libodbc.so|${prefix}/lib/libodbc.dylib|g" \
+            "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 mysql description {enable MathProg MySQL support} {
+variant mysql requires mysql5 description {legacy variant, use +mysql5 instead} {}
+
+variant mysql5 conflicts mysql56 description {enable MathProg MySQL support using MySQL 5.1} {
     depends_lib-append path:bin/mysql_config5:mysql5
 
-    archcheck.files-append \
-        lib/mysql5/mysql/libmysqlclient.dylib
+    configure.args-append --enable-mysql
+    post-patch {
+        reinplace \
+            "s|__MACPORTS__MYSQL__INCLUDE__|${prefix}/include/mysql5/mysql|g" \
+            ${worksrcpath}/configure
+	reinplace \
+            "s|__MACPORTS__MYSQL__LIB__|${prefix}/lib/mysql5/mysql|g" \
+            ${worksrcpath}/configure
+    }
+}
+
+variant mysql56 conflicts mysql5 description {enable MathProg MySQL support using MySQL 5.6} {
+    depends_lib-append port:mysql56
 
     configure.args-append --enable-mysql
     post-patch {
         reinplace \
-            "s|/usr/include/mysql|${prefix}/include/mysql5/mysql|g" \
+            "s|__MACPORTS__MYSQL__INCLUDE__|${prefix}/include/mysql56/mysql|g" \
             ${worksrcpath}/configure
         reinplace \
-            "s|libmysqlclient.so|${prefix}/lib/mysql5/mysql/libmysqlclient.dylib|g" \
+            "s|__MACPORTS__MYSQL__LIB__|${prefix}/lib/mysql56/mysql|g" \
             ${worksrcpath}/configure
     }
 }
