cd src/

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

if [ -n "$MSYSTEM" ]; then
    for a in ../patches/mingw/*.patch; do
        patch -p1 < $a
    done
    sed -i "s|-version-info|-no-undefined -version-info|g" src/Makefile.am
    autoreconf -vfi
fi

# 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 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)
#          `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

sdh_make_install

sdh_generate_windows_lib_files glpk
