Skip to content

Instantly share code, notes, and snippets.

@notwa
Last active September 20, 2021 08:03
Show Gist options
  • Save notwa/08a0aa2674347a11c75f8811b986b80e to your computer and use it in GitHub Desktop.
Save notwa/08a0aa2674347a11c75f8811b986b80e to your computer and use it in GitHub Desktop.
coin-or stuff
#!/usr/bin/env bash
set -e
prefix="/opt/coin-or"
# get json2 for helping with github APIs later:
if [ ! -s "json2" ]; then
curl -LsS https://github.com/vi/json2/raw/master/json2 -o json2
fi
chmod +x json2
# ensure we can actually run it:
./json2 <<< '{}' >/dev/null
# prepare paths:
mkdir -p $prefix/lib/pkgconfig
export PATH="$prefix/bin:$PATH"
export PKG_CONFIG_PATH="$prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
# prepare a mapping of coin-or project names to their tar.gz's:
declare -A tgzs
note() {
echo -e "\e[1m$@\e[0m" >&2
}
stfu() {
"$@" > .stdout 2> .stderr || fail=$?
if [[ "$fail" -ne 0 ]]; then
echo "command failed with exit status $fail:" >&2
echo -E "$@" >&2
echo >&2
note '$ tail .stdout'
tail .stdout >&2
echo >&2
note '$ tail .stderr'
tail .stderr >&2
return "$fail"
fi
}
get_autotool() {
if [ -s "$1.tar.gz" ]; then
note "skipping downloading $1"
return 0
fi
note "downloading $1"
curl -LsS "http://ftp.gnu.org/gnu/${1%-*}/$1.tar.gz" -o "$1.tar.gz"
}
make_autotool() {
if [[ $(command -v "${1%-*}") == "$prefix/bin"* ]]; then
note "skipping building $1"
return 0
fi
note "building $1"
# always extract in case configs/caches got messed up (as they do):
tar -xzf "$1.tar.gz"
pushd "$1" >/dev/null
stfu ./configure --prefix=$prefix
stfu make
stfu make install
popd >/dev/null
}
get_coin() {
organ="coin-or"
if [ "$1" == "BuildTools" ] || [[ "$1" == "ThirdParty-"* ]]; then
organ="coin-or-tools"
fi
if [ -n "$2" ]; then
note "downloading $1 from branch $2"
tgz="$organ-$1-$2.tar.gz"
tgzs["$1"]="$tgz"
curl -LsS "https://github.com/$organ/$1/tarball/$2" -o "$tgz"
return 0
fi
curl -LsS "https://api.github.com/repos/$organ/$1/tags" | ./json2 > temp
for i in {0..9}; do # check first few tags for a release
grep -Eq "^/$i/name=releases" temp || continue
url="$(grep -E "^/$i/tarball_url=" temp)"
url="${url#*=}"
sha="$(grep -E "^/$i/commit/sha=" temp)"
sha="${sha#*=}"
tgz="$organ-$1-${sha::7}.tar.gz"
tgzs["$1"]="$tgz"
if [ -s "$tgz" ]; then
note "skipping downloading $1 (${sha::7})"
else
note "downloading $1 (${sha::7})"
curl -LsS "$url" -o "$tgz"
fi
return 0
done
echo "failed to find the latest release of $1" >&2
return 1
}
make_coin() {
note "building $1"
tgz="${tgzs[$1]}"
# always extract in case configs/caches got messed up (as they do):
tar -xzf "$tgz"
dir="$(tar -tzf "$tgz" | head -1 | cut -f1 -d/)"
pushd "$dir" >/dev/null
if [[ "$1" == "ThirdParty-"* ]]; then
stfu "./get.${1##*-}"
fi
if [ "$1" = Bonmin ]; then
sed -i 's/.*DECLARE_STD_EXCEPTION.*/#undef IPOPTLIB_EXPORT\n#define IPOPTLIB_EXPORT\n\0\n#undef IPOPTLIB_EXPORT\n#define IPOPTLIB_EXPORT __declspec(dllimport)/' Bonmin/src/Interfaces/BonTMINLP.hpp
fi
shift
stfu ./configure --prefix=$prefix "$@"
stfu make
stfu make install
popd >/dev/null
}
for autotool in autoconf-2.59 automake-1.9.6 libtool-1.5.22; do
get_autotool "$autotool"
make_autotool "$autotool"
done
get_coin ThirdParty-ASL
get_coin CoinUtils
get_coin Osi
get_coin Clp
get_coin Cgl
get_coin Cbc
get_coin Ipopt
get_coin Bonmin
make_coin ThirdParty-ASL
make_coin CoinUtils
make_coin Osi
make_coin Clp
make_coin Cgl
make_coin Cbc
make_coin Ipopt --with-lapack="/mingw64/lib/libopenblas.dll.a"
make_coin Bonmin
# known working versions:
# ThirdParty-ASL (bf5d14b)
# CoinUtils (f709081)
# Osi (dfa6449)
# Clp (756ddd3)
# Cgl (31797b2)
# Cbc (7b5ccc0)
# Ipopt (2971727)
# Bonmin (65c56ce)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment