3 # C/C++ toolchain build script for Barrelfish.
4 # http://redmine.aluzina.org/projects/barrelfish/wiki/Toolchain_from_sources
5 # http://wiki.barrelfish.org/CrossCompiler
7 # In order to build a toolchain you will need to install the following packages:
8 # $ sudo apt-get install gcc g++ make patch bison flex texinfo
10 # These are also required but will be downloaded automatically during the build:
11 # libgmp-dev, libmpc-dev, libmpfr-dev
13 # Optional (for Graphite optimizations): libcloog-ppl-dev.
15 set -e # Die if any command fails.
16 set -x # Trace each command before execution.
22 export TARGET=x86_64-k1om-barrelfish
24 # Path of your Barrelfish source and build tree.
25 BARRELFISH_SOURCE=$BASEDIR/barrelfish.xeon-phi
26 BARRELFISH_BUILD=$BASEDIR/barrelfish.xeon-phi/build
28 # Modify these versions to match the corresponding patch.
29 BINUTILS=binutils-2.24
33 # Directory this shell script is stored in.
34 # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
35 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
38 BINUTILS_PATCH="${SCRIPT_DIR}/${BINUTILS}-barrelfish.patch"
39 GCC_PATCH="${SCRIPT_DIR}/${GCC}-barrelfish.patch"
41 #-------------------------------------------------------------------------------
43 # Where the toolchain will be built and installed.
44 # Note: the toolchain is specific to the Barrelfish tree mentioned above.
45 TOOLCHAIN_PREFIX=${BARRELFISH_SOURCE}/toolchain
49 #-------------------------------------------------------------------------------
52 exit_with_error() { echo "error: $1" && exit 1; }
53 [[ ! -d "${BARRELFISH_SOURCE}" ]] && \
54 exit_with_error "Barrelfish source not found (${BARRELFISH_SOURCE})."
55 [[ ! -d "${BARRELFISH_BUILD}" ]] && \
56 exit_with_error "Barrelfish tree not found (${BARRELFISH_BUILD})."
57 [[ -d "${TOOLCHAIN_PREFIX}" ]] && \
58 exit_with_error "toolchain already built in ${TOOLCHAIN_PREFIX}."
59 [[ ! -f "${BINUTILS_PATCH}" ]] && \
60 exit_with_error "binutils patch not found (${BINUTILS_PATCH})."
61 [[ ! -f "${GCC_PATCH}" ]] && \
62 exit_with_error "GCC patch not found (${GCC_PATCH})."
65 # Build the toolchain.
66 export PATH=${PATH}:${TOOLCHAIN_PREFIX}/bin
67 export PREFIX=${TOOLCHAIN_PREFIX}
70 TOOLCHAIN_BUILD="$(mktemp -d --tmpdir barrelfish-toolchain-build.XXXXXXXXXX)"
75 if [[ -z "${MAKE_JOBS}" ]]; then
76 # Guess a sensible value - default: #cores + 2.
77 MAKE_JOBS=$(($(grep "^core id" /proc/cpuinfo | sort -u | wc -l) + 2))
81 pushd "${TOOLCHAIN_BUILD}"
83 # 1. binutils - GNU Binary Utilities
84 wget "http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.gz"
85 tar xzvf ${BINUTILS}.tar.gz
87 patch -p1 < "${BINUTILS_PATCH}"
89 mkdir -p ${BINUTILS}-build/
90 pushd ${BINUTILS}-build/
91 ../${BINUTILS}/configure \
92 --prefix="${TOOLCHAIN_PREFIX}" \
93 --target="${TARGET}" \
100 popd # ${BINUTILS}-build/
102 # 2. GCC - GNU Compiler Collection
103 wget "ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/${GCC}/${GCC}.tar.bz2"
104 tar xjvf ${GCC}.tar.bz2
106 source ./contrib/download_prerequisites
107 # http://stackoverflow.com/questions/407523/escape-a-string-for-sed-search-pattern
108 BF_SOURCE_ESCAPED=$(echo "${BARRELFISH_SOURCE}" | sed -e 's/[\/&]/\\&/g')
109 BF_BUILD_ESCAPED=$(echo "${BARRELFISH_BUILD}" | sed -e 's/[\/&]/\\&/g')
110 sed -r -e "s/\{\{BF_SRC\}\}/${BF_SOURCE_ESCAPED}/g" \
111 -e "s/\{\{BF_BUILD\}\}/${BF_BUILD_ESCAPED}/g" \
112 "${GCC_PATCH}" | patch -p1
115 mkdir -p ${GCC}-build/
117 ../${GCC}/configure \
118 --prefix="${TOOLCHAIN_PREFIX}" \
119 --target="${TARGET}" \
120 --enable-languages=c,c++ \
121 --enable-initfini-array \
125 --disable-multilib # from xeon phi inside cluster
131 popd # ${TOOLCHAIN_BUILD}
133 rm -rf "${TOOLCHAIN_BUILD}"