Last active
October 6, 2022 03:45
-
-
Save doubleotoo/4121648 to your computer and use it in GitHub Desktop.
Quick and dirty script to automate the installation of the Boost C++ libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# | |
# Usage: ./install-boost <version: x.xx.x> | |
: ${PATH:=} | |
: ${LD_LIBRARY_PATH:=} | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <version: 1.39.0>" | |
exit 1 | |
fi | |
VERSION="$1" | |
VERSION_UNDERSCORES="$(echo "$VERSION" | sed 's/\./_/g')" | |
TARBALL="boost_${VERSION_UNDERSCORES}.tar.gz" | |
DOWNLOAD_URL="http://sourceforge.net/projects/boost/files/boost/${VERSION}/${TARBALL}/download" | |
if [ -z "${GCC_HOME}" ]; then | |
echo "[FATAL] \$GCC_HOME is not set" | |
exit 1 | |
fi | |
GCC_VERSION="$(gcc -dumpversion)" | |
echo "[INFO] Boost '$VERSION'" | |
echo "[INFO] GCC '$GCC_VERSION'" | |
# Installation location | |
: ${PREFIX:=${VERSION_UNDERSCORES}/gcc/${GCC_VERSION}} | |
mkdir -p "$PREFIX" | |
cd "$PREFIX" | |
PREFIX="$(pwd)" | |
echo "[INFO] Installing to '$PREFIX'" | |
echo "[INFO] Creating workspace in '$(pwd)'" | |
mkdir -p workspace | |
cd workspace | |
SOURCE="$(pwd)/boost_${VERSION_UNDERSCORES}" | |
#------------------------------------------------------------------------------- | |
# Download and unpack | |
#------------------------------------------------------------------------------- | |
if [ ! -f "$TARBALL" ]; then | |
echo "[INFO] Downloading '$DOWNLOAD_URL'" | |
wget --no-check-certificate "$DOWNLOAD_URL" | |
else | |
echo "[INFO] '$TARBALL' already exists. Skipping..." | |
fi | |
if [ ! -d "$SOURCE" ]; then | |
echo "[INFO] Unpacking $TARBALL" | |
tar xzf "$TARBALL" | |
else | |
echo "[INFO] '$SOURCE' already exists. Skipping..." | |
fi | |
#------------------------------------------------------------------------------- | |
# Setup build environment and toolchain | |
#------------------------------------------------------------------------------- | |
echo "[INFO] Build environment:" | |
echo "[INFO] - BOOST ${GCC_VERSION}" | |
#------------------------------------------------------------------------------- | |
# Build and install | |
#------------------------------------------------------------------------------- | |
cd "$SOURCE" | |
if [ ! -e "${PREFIX}/bin" ]; then | |
echo "[INFO] Configuring BOOST" | |
time "./bootstrap.sh" --prefix="${PREFIX}" | |
echo "[INFO] Building BOOST" | |
BOOST_BUILD_CMD= | |
if [ -e "${SOURCE}/bjam" ]; then | |
BOOST_BUILD_CMD="bjam" | |
elif [ -e "${SOURCE}/b2" ]; then | |
BOOST_BUILD_CMD="b2" | |
else | |
echo "[ERROR] boost build script not found (bjam/b2)" | |
fi | |
PROCESSORS="$(cat /proc/cpuinfo | grep processor | wc -l)" | |
PARALLELISM="$((($PROCESSORS * 2)))" | |
echo "[INFO] Using '$PARALLELISM' levels of parallelism" | |
time "./${BOOST_BUILD_CMD}" install --prefix="${PREFIX}" -j "${PARALLELISM}" | |
if [ "$(uname --machine)" = "x86_64" ]; then | |
export LIBDIR="lib64" | |
else | |
export LIBDIR="lib" | |
fi | |
echo "[INFO] Creating BOOST environment setup file" | |
cat > "${PREFIX}/setup.sh" <<-EOF | |
#!/bin/bash | |
# | |
# Automatically generated by $0 on $(date) | |
export BOOST_HOME="${PREFIX}" | |
export LD_LIBRARY_PATH="\${BOOST_HOME}/lib:\${LD_LIBRARY_PATH}" | |
source "${GCC_HOME}/setup.sh" | |
EOF | |
echo "[INFO] Setting file permissions for group" | |
chmod -R g+r "${PREFIX}" | |
find "${PREFIX}" -type d -exec chmod g+x {} \; | |
else | |
echo "[INFO] Installation already exists in '$PREFIX'. Skipping..." | |
fi | |
echo "[INFO] Success!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment