cd src/

# Use newer version of config.guess and config.sub (see Trac #19713)
cp "$SAGE_ROOT"/config/config.* .

# Note: The following doesn't work with spaces in `$SAGE_LOCAL`, but we don't
#       support that anyway, since many upstream packages don't.
#       On the other hand, the only packages GLPK uses that Sage provides are
#       GMP/MPIR and zlib, so we should just use `$SAGE_CONFIGURE_GMP` and
#       `--with-zlib="$SAGE_LOCAL"` below (which is safe), and omit the fol-
#       lowing two lines. (TODO)
#
#       Turns out that (as of version 4.55)
#       1) GLPK unconditionally uses its own copy of zlib (cf. `SPKG.txt`),
#          and the `configure` option `--with-zlib` is no longer valid;
#       2) `configure` doesn't support specifying the location of the GMP
#          library to use; only `--with-gmp[=yes]` or `--with-gmp=no`
#          are valid options.  So we *have to* add Sage's include and
#          library directories to `CPPFLAGS` (done here) and `LDFLAGS`
#          (already the default):
CPPFLAGS="-I$SAGE_LOCAL/include $CPPFLAGS"

export CFLAGS LDFLAGS CPPFLAGS

sdh_configure --with-gmp --disable-static
sdh_make

# Remove old libraries to make sure we can downgrade it if needed.
# See https://trac.sagemath.org/ticket/23596#comment:4 and later.
rm -f "$SAGE_LOCAL"/lib/libglpk.*

sdh_make_install
