Last active
March 5, 2018 15:39
-
-
Save jdtournier/cf06ab4136efbca6b4ccca32b50b2891 to your computer and use it in GitHub Desktop.
a script to download and compile all dependencies for MRtrix3 for installation on older distributions
This file contains hidden or 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 | |
# to be used for installation on older systems when all else fails... | |
# | |
# Notes: | |
# | |
# - to prevent unnecessary downloads, dependencies are only fetched if the | |
# 'source_install_files' folder does not already exist. Delete it if you want to | |
# fetch them again. | |
# | |
# - to prevent re-building the dependencies, they are only built if the 'lib64' | |
# symbolic link is not present. Delete it if you need to build them again. | |
# | |
# - to prevent unnecessarily recompiling all of MRtrix3, the configure script | |
# is only run if the 'config' file is absent. Delete it to force a reconfigure. | |
# set this to 1 to build Qt and mrview / shview: | |
BUILD_GUI=0 | |
# any additional option to MRtrix3's configure script: | |
CONFIG_OPTIONS="" | |
if [ ! -f build -o ! -f build ]; then | |
echo "Run this script from the MRtrix3 toplevel folder" | |
exit 1 | |
fi | |
if [ $BUILD_GUI -eq 0 ]; then | |
CONFIG_OPTIONS="-nogui "$CONFIG_OPTIONS | |
fi | |
export NUMBER_OF_THREADS=$(getconf _NPROCESSORS_ONLN) | |
ROOT="$(pwd)" | |
LOG="${ROOT}/build_from_source.log" | |
set -e | |
function fetch { | |
if [ -d "$1" ]; then | |
echo $1 already fetched - skipping | |
return | |
fi | |
echo fetching $1 ... | |
dir="$(mktemp -d)" | |
( | |
cd $dir | |
wget -nv --show-progress "$2" | |
tarball="$(ls)" | |
echo unpacking $1 ... | |
tar xf $tarball | |
rm -f $tarball | |
) | |
mv "$dir/"* "$1" | |
rmdir "$dir" | |
} | |
function compile { | |
name="$1" | |
if [ -f "${name}_installed" ]; then | |
echo $1 already compiled and installed - skipping | |
return | |
fi | |
shift | |
echo building $name ... | |
( | |
cd "$name" | |
eval "$@" &> "${LOG}" | |
make -j ${NUMBER_OF_THREADS} &> "${LOG}" | |
make install &> "${LOG}" | |
) | |
touch "${name}_installed" | |
} | |
mkdir -p source_install_files | |
if [ ! -L lib64 ]; then | |
ln -s lib lib64 | |
fi | |
export PATH="${ROOT}/bin:$PATH" | |
( | |
cd source_install_files | |
fetch gcc ftp://ftp.gnu.org/gnu/gcc/gcc-5.5.0/gcc-5.5.0.tar.gz | |
fetch zlib https://zlib.net/zlib-1.2.11.tar.gz | |
fetch fftw ftp://ftp.fftw.org/pub/fftw/fftw-3.3.7.tar.gz | |
fetch xz http://download.openpkg.org/components/cache/xz/xz-5.2.3.tar.gz | |
fetch jpeg http://www.ijg.org/files/jpegsrc.v9c.tar.gz | |
fetch tiff ftp://download.osgeo.org/libtiff/tiff-4.0.9.tar.gz | |
fetch python3 https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz | |
fetch eigen3 http://bitbucket.org/eigen/eigen/get/3.3.4.tar.bz2 | |
# get GCC dependencies: | |
if [ ! -L gcc/mpfr ] || [ ! -L gcc/gmp ] || [ ! -L gcc/mpc ]; then ( | |
cd gcc | |
echo "fetching GCC prerequisites..." | |
./contrib/download_prerequisites | |
) | |
fi | |
if [ $BUILD_GUI -gt 0 ]; then | |
fetch qt5-base http://download.qt.io/official_releases/qt/5.9/5.9.4/submodules/qtbase-opensource-src-5.9.4.tar.xz | |
fetch qt5-svg http://download.qt.io/official_releases/qt/5.9/5.9.4/submodules/qtsvg-opensource-src-5.9.4.tar.xz | |
fi | |
mkdir -p g++ | |
compile g++ ../gcc/configure --prefix="${ROOT}" -disable-multilib --enable-languages=c,c++ | |
# common environmemnt variables: | |
export prefix="${ROOT}" CFLAGS="-isystem ${ROOT}/include" LDFLAGS="-L${ROOT}/lib" | |
compile zlib ./configure | |
compile fftw ./configure --prefix=${ROOT} --enable-shared | |
compile xz ./configure --prefix=${ROOT} --enable-shared | |
compile jpeg ./configure --prefix=${ROOT} --enable-shared | |
compile tiff ./configure --prefix=${ROOT} --enable-shared | |
compile python3 ./configure --prefix="${ROOT}" | |
if [ $BUILD_GUI -gt 0 ]; then | |
compile qt5-base ./configure -opensource -confirm-license --prefix=${ROOT} -no-openssl -qt-libpng -qt-xcb | |
compile qt5-svg qmake | |
fi | |
) | |
# build MRtrix3 | |
export CXX=bin/g++ CFLAGS='-isystem /include' EIGEN_CFLAGS="-isystem source_install_files/eigen3/" | |
if [ ! -f config ]; then | |
bin/python3 configure $CONFIG_OPTIONS | |
fi | |
bin/python3 build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment