buildboost
#!/bin/bash
# Script arguments:
# $1: <version> representing the boost version number to install (e.g. '60' for version 1.60)
# $2: 'force' if installation should proceed even if /usr/local/include/boost already exists, it removes /usr/local/include/boost and /usr/local/lib/lobboost_*!
if [ "$2" != "force" ] && [ -d /usr/local/include/boost ]; then
echo boost already installed in /usr/local
else
SAVE=`pwd`
BOOSTVER=$1
BOOSTDOWNLOAD="http://sourceforge.net/projects/boost/files/boost/1.${BOOSTVER}.0/boost_1_${BOOSTVER}_0.tar.bz2/download"
mkdir -p ~/boost
cd ~/boost
if [ "$2" = "force" ]; then
# Force boost to be downloaded and unpacked again
rm -f boost_1_${BOOSTVER}_0.tar.bz2
sudo rm -rf boost_1_${BOOSTVER}_0
# b2 install should copy the includes to /usr/local/include/boost, but this sometimes
# doesn't seem to happen - possibly if the files are already there.
sudo rm -rf /usr/local/include/boost
sudo rm -f /usr/local/lib/libboost_*
fi
if [ -e boost_1_${BOOSTVER}_0.tar.bz2 ]; then
echo boost_1_${BOOSTVER}_0.tar.bz2 already exists
else
echo Downloading boost_1_${BOOSTVER}_0.tar.bz2
#sudo apt-get update
wget -c "$BOOSTDOWNLOAD" -O boost_1_${BOOSTVER}_0.tar.bz2
fi
if [ -d boost_1_${BOOSTVER}_0 ]; then
echo folder boost_1_${BOOSTVER}_0 already exists
else
echo uncompressing tarball
tar --bzip2 -xf boost_1_${BOOSTVER}_0.tar.bz2
fi
cd boost_1_${BOOSTVER}_0
./bootstrap.sh
echo "Building both static and shared boost libraries"
echo "Headers will be installed under /usr/local/include/boost"
echo "Libraries will be installed under /usr/local/lib"
echo "Writing stdout to boost_1_${BOOSTVER}_0/out.txt and stderr to boost_1_${BOOSTVER}_0/err.txt"
echo "Have patience this takes a long time..."
sudo ./b2 cxxflags="-std=c++11 -fPIC" link=static,shared install 1>out.txt 2>err.txt
# Seems to be needed to allow the boost shared libraries in /usr/local/lib to be found
# when applications using these shared libraries are run.
# It was found that /etc/ld.so.conf.d/libc.conf already contains /usr/local/lib
sudo ldconfig
cd $SAVE
fi