Skip to content

Instantly share code, notes, and snippets.

@lukele
Created March 7, 2013 22:37
Show Gist options
  • Save lukele/5112485 to your computer and use it in GitHub Desktop.
Save lukele/5112485 to your computer and use it in GitHub Desktop.
Script that makes building zibpot python bindings easier.
#!/bin/bash
if [ -z "$1" ]; then
echo "usage: ./zibopt-install.sh <build-dir>"
exit 1
fi
function bailout {
echo "$1"
exit 1
}
function popd_and_exit {
popd
exit 1
}
# Check if virtualenv is installed
python -c "import virtualenv" || bailout "please install virtualenv with \`sudo pip install virtualenv\`"
# Check for the virtualenv binary
virtualenv_bin=$(which virtualenv)
test -z "$virtualenv_bin" && bailout "please install virtualenv with \`sudo pip install virtualenv\`"
# Test if the build dir exists, if so, exit.
test -d "$1" && bailout "<build-dir> must not exist, I'll create it for you."
"$virtualenv_bin" --no-site-packages "$1"
pushd "$1";
BUILDDIR=$(pwd -P)
popd
ZIBOPT_NAME="ziboptsuite-2.1.1"
ZIBOPT_URL="http://scip.zib.de/download/release/${ZIBOPT_NAME}.tgz"
SHARED_LIBRARY="libzibopt-2.1.1.darwin.x86_64.gnu.opt.so"
pushd "$BUILDDIR"
# Check if we're in a virtualenv environment and activate it.
test -r "$BUILDDIR/bin/activate" || bailout "Failed to create the virtual environment. Abort."
test -r "$BUILDDIR/bin/activate" && source "$BUILDDIR/bin/activate"
# Create the sources dir where the zibopt C library sources are stored.
mkdir -p "$BUILDDIR/sources"
# Create a directory where the zibopt C library will be stored.
mkdir -p "$BUILDDIR/clib"
# Download the zibopt library and extract it.
pushd "$BUILDDIR/sources"
curl -O $ZIBOPT_URL || popd_and_exit
tar xzvf ${ZIBOPT_NAME}.tgz || popd_and_exit
# Now on to building the zibopt library.
pushd ${ZIBOPT_NAME}
make ziboptlib SHARED=true ZIMPL=false ZLIB=false READLINE=false || popd_and_exit
cp lib/${SHARED_LIBRARY} "$BUILDDIR/clib" || popd_and_exit
echo "CLIB: $BUILDDIR/clib"
pushd "$BUILDDIR/clib"
ln -s ${SHARED_LIBRARY} libzibopt.so || popd_and_exit
popd
popd
# Now on to building the zibopt python bindings.
export LD_LIBRARY_PATH="$BUILDDIR/clib"
export LIBRARY_PATH=${LD_LIBRARY_PATH}
export C_INCLUDE_PATH="$BUILDDIR/sources/${ZIBOPT_NAME}/scip-2.1.1/src/"
pip install python-zibopt
# Last but not least, change the linker path of any .so files
pushd "$BUILDDIR/lib/python2.7/site-packages/zibopt"
for so in *.so; do
install_name_tool -change "lib/${SHARED_LIBRARY}" "$BUILDDIR/clib/${SHARED_LIBRARY}" $so
done
popd
popd
# Check if the zibopt is working now
python -c "import zibopt" || bailout "Fuck! Doesn't work"
popd
echo "Enjoy your working zibopt."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment