Added: new boot.S, serial out for Xeon Phi
[barrelfish] / tools / k1om / gnu-gcc / build-toolchain.sh
1 #!/usr/bin/env bash
2
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
6 #
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
9 #
10 # These are also required but will be downloaded automatically during the build:
11 #   libgmp-dev, libmpc-dev, libmpfr-dev
12 #
13 # Optional (for Graphite optimizations): libcloog-ppl-dev.
14
15 set -e  # Die if any command fails.
16 set -x  # Trace each command before execution.
17
18 BASEDIR=$(pwd)
19 BASEDIR=/home/acreto
20
21
22 export TARGET=x86_64-k1om-barrelfish
23
24 # Path of your Barrelfish source and build tree.
25 BARRELFISH_SOURCE=$BASEDIR/barrelfish.xeon-phi
26 BARRELFISH_BUILD=$BASEDIR/barrelfish.xeon-phi/build
27
28 # Modify these versions to match the corresponding patch.
29 BINUTILS=binutils-2.24
30 GCC=gcc-4.8.2
31
32
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 )"
36
37 # Paths to patches.
38 BINUTILS_PATCH="${SCRIPT_DIR}/${BINUTILS}-barrelfish.patch"
39 GCC_PATCH="${SCRIPT_DIR}/${GCC}-barrelfish.patch"
40
41 #-------------------------------------------------------------------------------
42
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
46
47
48
49 #-------------------------------------------------------------------------------
50
51 # Sanity checks.
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})."
63
64
65 # Build the toolchain.
66 export PATH=${PATH}:${TOOLCHAIN_PREFIX}/bin
67 export PREFIX=${TOOLCHAIN_PREFIX}
68
69
70 TOOLCHAIN_BUILD="$(mktemp -d --tmpdir barrelfish-toolchain-build.XXXXXXXXXX)"
71
72
73 # Build parallelism
74 MAKE_JOBS=
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))
78 fi
79
80
81 pushd "${TOOLCHAIN_BUILD}"
82
83 # 1. binutils - GNU Binary Utilities
84 wget "http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.gz"
85 tar xzvf ${BINUTILS}.tar.gz
86 pushd ${BINUTILS}/
87 patch -p1 < "${BINUTILS_PATCH}"
88 popd  # ${BINUTILS}/
89 mkdir -p ${BINUTILS}-build/
90 pushd ${BINUTILS}-build/
91 ../${BINUTILS}/configure \
92     --prefix="${TOOLCHAIN_PREFIX}" \
93     --target="${TARGET}" \
94     --enable-threads \
95     --enable-lto \
96     --with-cpu=k1om \
97     --with-arch=k1om \
98     --with-tune=k1om \
99     --enable-plugins \
100     --disable-nls \
101     --enable-plugins \
102     --disable-nls
103 make -j${MAKE_JOBS}
104 make install-strip
105 popd  # ${BINUTILS}-build/
106
107 # 2. GCC - GNU Compiler Collection
108 wget "ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/${GCC}/${GCC}.tar.bz2"
109 tar xjvf ${GCC}.tar.bz2
110 pushd ${GCC}/
111 source ./contrib/download_prerequisites
112 # http://stackoverflow.com/questions/407523/escape-a-string-for-sed-search-pattern
113 BF_SOURCE_ESCAPED=$(echo "${BARRELFISH_SOURCE}" | sed -e 's/[\/&]/\\&/g')
114 BF_BUILD_ESCAPED=$(echo "${BARRELFISH_BUILD}" | sed -e 's/[\/&]/\\&/g')
115 sed -r -e "s/\{\{BF_SRC\}\}/${BF_SOURCE_ESCAPED}/g" \
116        -e "s/\{\{BF_BUILD\}\}/${BF_BUILD_ESCAPED}/g" \
117        "${GCC_PATCH}" | patch -p1
118 popd  # ${GCC}/
119
120 mkdir -p ${GCC}-build/
121 pushd ${GCC}-build/
122 ../${GCC}/configure \
123     --prefix="${TOOLCHAIN_PREFIX}" \
124     --target="${TARGET}" \
125     --enable-languages=c \
126     --enable-initfini-array \
127     --disable-nls \
128     --disable-libssp \
129     --with-newlib \
130     --nobootstrap \
131     --with-gnu-as \
132     --with-gnu-ld \
133     --disable-multilib # from xeon phi inside cluster
134
135 #    --with-cpu=k1om \
136 #    --with-arch=k1om \
137 #    --with-tune=k1om \
138
139 make -j$MAKE_JOBS
140 make install-strip
141
142 popd  # ${GCC}-build/
143
144 popd  # ${TOOLCHAIN_BUILD}
145
146 rm -rf "${TOOLCHAIN_BUILD}"