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.
18 #-------------------------------------------------------------------------------
20 # Modify these versions to match the corresponding patch.
21 BINUTILS=binutils-2.22+mpss3.2
26 # Path of your Barrelfish source and build tree.
27 BARRELFISH_SOURCE=/home/acreto/barrelfish.xeon-phi
28 BARRELFISH_BUILD=${BARRELFISH_SOURCE}/build
30 # Where the toolchain will be built and installed.
31 # Note: the toolchain is specific to the Barrelfish tree mentioned above.
32 TOOLCHAIN_PREFIX=${BARRELFISH_SOURCE}/toolchain
34 # Cross compiler target.
35 #TARGET=x86_64-pc-barrelfish
36 export TARGET=k1om-pc-barrelfish
37 #TARGET=i586-pc-barrelfish
38 #TARGET=i586-scc-barrelfish
40 # Directory this shell script is stored in.
41 # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
42 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
45 BINUTILS_PATCH="${SCRIPT_DIR}/${BINUTILS}-barrelfish.patch"
46 GCC_PATCH="${SCRIPT_DIR}/${GCC}-barrelfish.patch"
50 if [[ -z "${MAKE_JOBS}" ]]; then
51 # Guess a sensible value - default: #cores + 2.
52 MAKE_JOBS=$(($(grep "^core id" /proc/cpuinfo | sort -u | wc -l) + 2))
55 #-------------------------------------------------------------------------------
58 exit_with_error() { echo "error: $1" && exit 1; }
59 [[ ! -d "${BARRELFISH_SOURCE}" ]] && \
60 exit_with_error "Barrelfish source not found (${BARRELFISH_SOURCE})."
61 [[ ! -d "${BARRELFISH_BUILD}" ]] && \
62 exit_with_error "Barrelfish tree not found (${BARRELFISH_BUILD})."
63 [[ -d "${TOOLCHAIN_PREFIX}" ]] && \
64 exit_with_error "toolchain already built in ${TOOLCHAIN_PREFIX}."
65 [[ ! -f "${BINUTILS_PATCH}" ]] && \
66 exit_with_error "binutils patch not found (${BINUTILS_PATCH})."
67 [[ ! -f "${GCC_PATCH}" ]] && \
68 exit_with_error "GCC patch not found (${GCC_PATCH})."
70 TOOLCHAIN_BUILD="$(mktemp -d --tmpdir barrelfish-toolchain-build.XXXXXXXXXX)"
74 # Build the toolchain.
75 export PATH=${PATH}:${TOOLCHAIN_PREFIX}/bin
76 export PREFIX=${TOOLCHAIN_PREFIX}
78 pushd "${TOOLCHAIN_BUILD}"
80 # 1. binutils - GNU Binary Utilities
81 cp "${SCRIPT_DIR}/${BINUTILS}.tar.bz2" "${TOOLCHAIN_BUILD}/${BINUTILS}.tar.bz2"
82 tar xjvf "${TOOLCHAIN_BUILD}/${BINUTILS}.tar.bz2"
84 patch -p1 < "${BINUTILS_PATCH}"
87 mkdir -p ${BINUTILS}-build/
88 pushd ${BINUTILS}-build/
89 ../${BINUTILS}/configure \
90 --prefix="${TOOLCHAIN_PREFIX}" \
91 --target="${TARGET}" \
104 make MAKEINFO=true ARCH=k1om -j${MAKE_JOBS}
105 make MAKEINFO=true install-strip
106 popd # ${BINUTILS}-build/
108 # 2. GCC - GNU Compiler Collection
109 cp "${SCRIPT_DIR}/${GCC}.tar.bz2" "${TOOLCHAIN_BUILD}/${GCC}.tar.bz2"
110 tar xjvf "${TOOLCHAIN_BUILD}/${GCC}.tar.bz2"
112 source ./contrib/download_prerequisites
113 # http://stackoverflow.com/questions/407523/escape-a-string-for-sed-search-pattern
114 BF_SOURCE_ESCAPED=$(echo "${BARRELFISH_SOURCE}" | sed -e 's/[\/&]/\\&/g')
115 BF_BUILD_ESCAPED=$(echo "${BARRELFISH_BUILD}" | sed -e 's/[\/&]/\\&/g')
116 sed -r -e "s/\{\{BF_SRC\}\}/${BF_SOURCE_ESCAPED}/g" \
117 -e "s/\{\{BF_BUILD\}\}/${BF_BUILD_ESCAPED}/g" \
118 "${GCC_PATCH}" | patch -p1
121 mkdir -p ${GCC}-build/
123 ../${GCC}/configure \
124 --prefix="${TOOLCHAIN_PREFIX}" \
125 --target="${TARGET}" \
126 --enable-languages=c \
127 --enable-initfini-array \
129 --with-multilib-list=m64 \
135 --with-arch-64=k1om \
136 --with-tune-64=k1om \
142 # --disable-multilib \
144 make MAKEINFO=true ARCH=k1om all-gcc -j$MAKE_JOBS
145 make MAKEINFO=true ARCH=k1om install-gcc -j$MAKE_JOBS
148 ../${GCC}/configure \
149 --prefix="${TOOLCHAIN_PREFIX}" \
150 --target="${TARGET}" \
151 --enable-languages=c \
152 --enable-initfini-array \
154 --with-multilib-list=m64 \
161 --with-arch-64=k1om \
162 --with-tune-64=k1om \
168 # --disable-multilib \
170 make MAKEINFO=true all -j$MAKE_JOBS
171 make MAKEINFO=true install-strip -j$MAKE_JOBS
174 popd # ${TOOLCHAIN_BUILD}
176 rm -rf "${TOOLCHAIN_BUILD}"
177 rm -rf "${TOOLCHAIN_BUILD}"