ns8250: fix misspellings
[helenos.git] / tools / toolchain.sh
blob6e78330e9c206e107d2e56f0d10bf2d7c7c52b75
1 #! /bin/bash
4 # Copyright (c) 2009 Martin Decky
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
11 # - Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # - The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 GMP_MAIN=<<EOF
32 #define GCC_GMP_VERSION_NUM(a, b, c) \
33 (((a) << 16L) | ((b) << 8) | (c))
35 #define GCC_GMP_VERSION \
36 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
38 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,2)
39 choke me
40 #endif
41 EOF
43 MPFR_MAIN=<<EOF
44 #if MPFR_VERSION < MPFR_VERSION_NUM(2, 4, 2)
45 choke me
46 #endif
47 EOF
49 MPC_MAIN=<<EOF
50 #if MPC_VERSION < MPC_VERSION_NUM(0, 8, 1)
51 choke me
52 #endif
53 EOF
55 BINUTILS_VERSION="2.23.1"
56 BINUTILS_RELEASE=""
57 GCC_VERSION="4.8.0"
58 GDB_VERSION="7.5.1"
60 BASEDIR="`pwd`"
61 BINUTILS="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2"
62 GCC="gcc-${GCC_VERSION}.tar.bz2"
63 GDB="gdb-${GDB_VERSION}.tar.bz2"
66 # Check if the library described in the argument
67 # exists and has acceptable version.
69 check_dependency() {
70 DEPENDENCY="$1"
71 HEADER="$2"
72 BODY="$3"
74 FNAME="/tmp/conftest-$$"
76 echo "#include ${HEADER}" > "${FNAME}.c"
77 echo >> "${FNAME}.c"
78 echo "int main()" >> "${FNAME}.c"
79 echo "{" >> "${FNAME}.c"
80 echo "${BODY}" >> "${FNAME}.c"
81 echo " return 0;" >> "${FNAME}.c"
82 echo "}" >> "${FNAME}.c"
84 cc -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
85 RC="$?"
87 if [ "$RC" -ne "0" ] ; then
88 echo " ${DEPENDENCY} not found, too old or compiler error."
89 echo " Please recheck manually the source file \"${FNAME}.c\"."
90 echo " The compilation of the toolchain is probably going to fail,"
91 echo " you have been warned."
92 echo
93 echo " ===== Compiler output ====="
94 cat "${FNAME}.log"
95 echo " ==========================="
96 echo
97 else
98 echo " ${DEPENDENCY} found"
99 rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
103 check_dependecies() {
104 echo ">>> Basic dependency check"
105 check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}"
106 check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}"
107 check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}"
108 echo
111 check_error() {
112 if [ "$1" -ne "0" ]; then
113 echo
114 echo "Script failed: $2"
116 exit 1
120 check_md5() {
121 FILE="$1"
122 SUM="$2"
124 COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
125 if [ "${SUM}" != "${COMPUTED}" ] ; then
126 echo
127 echo "Checksum of ${FILE} does not match."
129 exit 2
133 show_usage() {
134 echo "Cross-compiler toolchain build script"
135 echo
136 echo "Syntax:"
137 echo " $0 <platform>"
138 echo
139 echo "Possible target platforms are:"
140 echo " amd64 AMD64 (x86-64, x64)"
141 echo " arm32 ARM"
142 echo " ia32 IA-32 (x86, i386)"
143 echo " ia64 IA-64 (Itanium)"
144 echo " mips32 MIPS little-endian 32b"
145 echo " mips32eb MIPS big-endian 32b"
146 echo " mips64 MIPS little-endian 64b"
147 echo " ppc32 32-bit PowerPC"
148 echo " ppc64 64-bit PowerPC"
149 echo " sparc64 SPARC V9"
150 echo " all build all targets"
151 echo " parallel same as 'all', but all in parallel"
152 echo " 2-way same as 'all', but 2-way parallel"
153 echo
154 echo "The toolchain will be installed to the directory specified by"
155 echo "the CROSS_PREFIX environment variable. If the variable is not"
156 echo "defined, /usr/local/cross will be used by default."
157 echo
159 exit 3
162 change_title() {
163 echo -en "\e]0;$1\a"
166 show_countdown() {
167 TM="$1"
169 if [ "${TM}" -eq 0 ] ; then
170 echo
171 return 0
174 echo -n "${TM} "
175 change_title "${TM}"
176 sleep 1
178 TM="`expr "${TM}" - 1`"
179 show_countdown "${TM}"
182 show_dependencies() {
183 echo "IMPORTANT NOTICE:"
184 echo
185 echo "For a successful compilation and use of the cross-compiler"
186 echo "toolchain you need at least the following dependencies."
187 echo
188 echo "Please make sure that the dependencies are present in your"
189 echo "system. Otherwise the compilation process might fail after"
190 echo "a few seconds or minutes."
191 echo
192 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
193 echo " - gettext, zlib, Texinfo, libelf, libgomp"
194 echo " - terminfo"
195 echo " - GNU Multiple Precision Library (GMP)"
196 echo " - GNU Make"
197 echo " - GNU tar"
198 echo " - GNU Coreutils"
199 echo " - GNU Sharutils"
200 echo " - MPFR"
201 echo " - MPC"
202 echo " - Parma Polyhedra Library (PPL)"
203 echo " - ClooG-PPL"
204 echo " - native C compiler, assembler and linker"
205 echo " - native C library with headers"
206 echo
209 download_fetch() {
210 SOURCE="$1"
211 FILE="$2"
212 CHECKSUM="$3"
214 if [ ! -f "${FILE}" ]; then
215 change_title "Downloading ${FILE}"
216 wget -c "${SOURCE}${FILE}"
217 check_error $? "Error downloading ${FILE}."
220 check_md5 "${FILE}" "${CHECKSUM}"
223 source_check() {
224 FILE="$1"
226 if [ ! -f "${FILE}" ]; then
227 echo
228 echo "File ${FILE} not found."
230 exit 4
234 cleanup_dir() {
235 DIR="$1"
237 if [ -d "${DIR}" ]; then
238 change_title "Removing ${DIR}"
239 echo " >>> Removing ${DIR}"
240 rm -fr "${DIR}"
244 create_dir() {
245 DIR="$1"
246 DESC="$2"
248 change_title "Creating ${DESC}"
249 echo ">>> Creating ${DESC}"
251 mkdir -p "${DIR}"
252 test -d "${DIR}"
253 check_error $? "Unable to create ${DIR}."
256 unpack_tarball() {
257 FILE="$1"
258 DESC="$2"
260 change_title "Unpacking ${DESC}"
261 echo " >>> Unpacking ${DESC}"
263 tar -xjf "${FILE}"
264 check_error $? "Error unpacking ${DESC}."
267 prepare() {
268 show_dependencies
269 check_dependecies
270 show_countdown 10
272 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
273 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
274 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
276 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "33adb18c3048d057ac58d07a3f1adb38"
277 download_fetch "${GCC_SOURCE}" "${GCC}" "e6040024eb9e761c3bea348d1fa5abb0"
278 download_fetch "${GDB_SOURCE}" "${GDB}" "3f48f468b24447cf24820054ff6e85b1"
281 build_target() {
282 PLATFORM="$1"
283 TARGET="$2"
285 WORKDIR="${BASEDIR}/${PLATFORM}"
286 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
287 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
288 OBJDIR="${WORKDIR}/gcc-obj"
289 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
291 if [ -z "${CROSS_PREFIX}" ] ; then
292 CROSS_PREFIX="/usr/local/cross"
295 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
297 echo ">>> Downloading tarballs"
298 source_check "${BASEDIR}/${BINUTILS}"
299 source_check "${BASEDIR}/${GCC}"
300 source_check "${BASEDIR}/${GDB}"
302 echo ">>> Removing previous content"
303 cleanup_dir "${PREFIX}"
304 cleanup_dir "${WORKDIR}"
306 create_dir "${PREFIX}" "destination directory"
307 create_dir "${OBJDIR}" "GCC object directory"
309 echo ">>> Unpacking tarballs"
310 cd "${WORKDIR}"
311 check_error $? "Change directory failed."
313 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
314 unpack_tarball "${BASEDIR}/${GCC}" "GCC"
315 unpack_tarball "${BASEDIR}/${GDB}" "GDB"
317 echo ">>> Processing binutils (${PLATFORM})"
318 cd "${BINUTILSDIR}"
319 check_error $? "Change directory failed."
321 change_title "binutils: configure (${PLATFORM})"
322 CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
323 check_error $? "Error configuring binutils."
325 change_title "binutils: make (${PLATFORM})"
326 make all install
327 check_error $? "Error compiling/installing binutils."
329 echo ">>> Processing GCC (${PLATFORM})"
330 cd "${OBJDIR}"
331 check_error $? "Change directory failed."
333 change_title "GCC: configure (${PLATFORM})"
334 "${GCCDIR}/configure" "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --with-gnu-as --with-gnu-ld --disable-nls --disable-threads --enable-languages=c,objc,c++,obj-c++ --disable-multilib --disable-libgcj --without-headers --disable-shared --enable-lto --disable-werror
335 check_error $? "Error configuring GCC."
337 change_title "GCC: make (${PLATFORM})"
338 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
339 check_error $? "Error compiling/installing GCC."
341 echo ">>> Processing GDB (${PLATFORM})"
342 cd "${GDBDIR}"
343 check_error $? "Change directory failed."
345 change_title "GDB: configure (${PLATFORM})"
346 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
347 check_error $? "Error configuring GDB."
349 change_title "GDB: make (${PLATFORM})"
350 make all install
351 check_error $? "Error compiling/installing GDB."
353 cd "${BASEDIR}"
354 check_error $? "Change directory failed."
356 echo ">>> Cleaning up"
357 cleanup_dir "${WORKDIR}"
359 echo
360 echo ">>> Cross-compiler for ${TARGET} installed."
363 if [ "$#" -lt "1" ]; then
364 show_usage
367 case "$1" in
368 "amd64")
369 prepare
370 build_target "amd64" "amd64-linux-gnu"
372 "arm32")
373 prepare
374 build_target "arm32" "arm-linux-gnueabi"
376 "ia32")
377 prepare
378 build_target "ia32" "i686-pc-linux-gnu"
380 "ia64")
381 prepare
382 build_target "ia64" "ia64-pc-linux-gnu"
384 "mips32")
385 prepare
386 build_target "mips32" "mipsel-linux-gnu"
388 "mips32eb")
389 prepare
390 build_target "mips32eb" "mips-linux-gnu"
392 "mips64")
393 prepare
394 build_target "mips64" "mips64el-linux-gnu"
396 "ppc32")
397 prepare
398 build_target "ppc32" "ppc-linux-gnu"
400 "ppc64")
401 prepare
402 build_target "ppc64" "ppc64-linux-gnu"
404 "sparc64")
405 prepare
406 build_target "sparc64" "sparc64-linux-gnu"
408 "all")
409 prepare
410 build_target "amd64" "amd64-linux-gnu"
411 build_target "arm32" "arm-linux-gnueabi"
412 build_target "ia32" "i686-pc-linux-gnu"
413 build_target "ia64" "ia64-pc-linux-gnu"
414 build_target "mips32" "mipsel-linux-gnu"
415 build_target "mips32eb" "mips-linux-gnu"
416 build_target "mips64" "mips64el-linux-gnu"
417 build_target "ppc32" "ppc-linux-gnu"
418 build_target "ppc64" "ppc64-linux-gnu"
419 build_target "sparc64" "sparc64-linux-gnu"
421 "parallel")
422 prepare
423 build_target "amd64" "amd64-linux-gnu" &
424 build_target "arm32" "arm-linux-gnueabi" &
425 build_target "ia32" "i686-pc-linux-gnu" &
426 build_target "ia64" "ia64-pc-linux-gnu" &
427 build_target "mips32" "mipsel-linux-gnu" &
428 build_target "mips32eb" "mips-linux-gnu" &
429 build_target "mips64" "mips64el-linux-gnu" &
430 build_target "ppc32" "ppc-linux-gnu" &
431 build_target "ppc64" "ppc64-linux-gnu" &
432 build_target "sparc64" "sparc64-linux-gnu" &
433 wait
435 "2-way")
436 prepare
437 build_target "amd64" "amd64-linux-gnu" &
438 build_target "arm32" "arm-linux-gnueabi" &
439 wait
441 build_target "ia32" "i686-pc-linux-gnu" &
442 build_target "ia64" "ia64-pc-linux-gnu" &
443 wait
445 build_target "mips32" "mipsel-linux-gnu" &
446 build_target "mips32eb" "mips-linux-gnu" &
447 wait
449 build_target "mips64" "mips64el-linux-gnu" &
450 build_target "ppc32" "ppc-linux-gnu" &
451 wait
453 build_target "ppc64" "ppc64-linux-gnu" &
454 build_target "sparc64" "sparc64-linux-gnu" &
455 wait
458 show_usage
460 esac