rtc: fix call to ddf_log_init(NAME) to reflect changes in the mainline branch
[helenos.git] / tools / toolchain.sh
blob07fcbc438d97770fde236ec45d5f1e1d04510a1f
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.22"
56 BINUTILS_RELEASE=""
57 GCC_VERSION="4.7.1"
58 GDB_VERSION="7.4"
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 " - GNU Multiple Precision Library (GMP)"
195 echo " - GNU Make"
196 echo " - GNU tar"
197 echo " - GNU Coreutils"
198 echo " - GNU Sharutils"
199 echo " - MPFR"
200 echo " - MPC"
201 echo " - Parma Polyhedra Library (PPL)"
202 echo " - ClooG-PPL"
203 echo " - native C compiler, assembler and linker"
204 echo " - native C library with headers"
205 echo
208 download_fetch() {
209 SOURCE="$1"
210 FILE="$2"
211 CHECKSUM="$3"
213 if [ ! -f "${FILE}" ]; then
214 change_title "Downloading ${FILE}"
215 wget -c "${SOURCE}${FILE}"
216 check_error $? "Error downloading ${FILE}."
219 check_md5 "${FILE}" "${CHECKSUM}"
222 source_check() {
223 FILE="$1"
225 if [ ! -f "${FILE}" ]; then
226 echo
227 echo "File ${FILE} not found."
229 exit 4
233 cleanup_dir() {
234 DIR="$1"
236 if [ -d "${DIR}" ]; then
237 change_title "Removing ${DIR}"
238 echo " >>> Removing ${DIR}"
239 rm -fr "${DIR}"
243 create_dir() {
244 DIR="$1"
245 DESC="$2"
247 change_title "Creating ${DESC}"
248 echo ">>> Creating ${DESC}"
250 mkdir -p "${DIR}"
251 test -d "${DIR}"
252 check_error $? "Unable to create ${DIR}."
255 unpack_tarball() {
256 FILE="$1"
257 DESC="$2"
259 change_title "Unpacking ${DESC}"
260 echo " >>> Unpacking ${DESC}"
262 tar -xjf "${FILE}"
263 check_error $? "Error unpacking ${DESC}."
266 prepare() {
267 show_dependencies
268 check_dependecies
269 show_countdown 10
271 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
272 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
273 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
275 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "ee0f10756c84979622b992a4a61ea3f5"
276 download_fetch "${GCC_SOURCE}" "${GCC}" "933e6f15f51c031060af64a9e14149ff"
277 download_fetch "${GDB_SOURCE}" "${GDB}" "95a9a8305fed4d30a30a6dc28ff9d060"
280 build_target() {
281 PLATFORM="$1"
282 TARGET="$2"
284 WORKDIR="${BASEDIR}/${PLATFORM}"
285 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
286 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
287 OBJDIR="${WORKDIR}/gcc-obj"
288 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
290 if [ -z "${CROSS_PREFIX}" ] ; then
291 CROSS_PREFIX="/usr/local/cross"
294 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
296 echo ">>> Downloading tarballs"
297 source_check "${BASEDIR}/${BINUTILS}"
298 source_check "${BASEDIR}/${GCC}"
299 source_check "${BASEDIR}/${GDB}"
301 echo ">>> Removing previous content"
302 cleanup_dir "${PREFIX}"
303 cleanup_dir "${WORKDIR}"
305 create_dir "${PREFIX}" "destination directory"
306 create_dir "${OBJDIR}" "GCC object directory"
308 echo ">>> Unpacking tarballs"
309 cd "${WORKDIR}"
310 check_error $? "Change directory failed."
312 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
313 unpack_tarball "${BASEDIR}/${GCC}" "GCC"
314 unpack_tarball "${BASEDIR}/${GDB}" "GDB"
316 echo ">>> Processing binutils (${PLATFORM})"
317 cd "${BINUTILSDIR}"
318 check_error $? "Change directory failed."
320 change_title "binutils: configure (${PLATFORM})"
321 CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
322 check_error $? "Error configuring binutils."
324 change_title "binutils: make (${PLATFORM})"
325 make all install
326 check_error $? "Error compiling/installing binutils."
328 echo ">>> Processing GCC (${PLATFORM})"
329 cd "${OBJDIR}"
330 check_error $? "Change directory failed."
332 change_title "GCC: configure (${PLATFORM})"
333 "${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
334 check_error $? "Error configuring GCC."
336 change_title "GCC: make (${PLATFORM})"
337 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
338 check_error $? "Error compiling/installing GCC."
340 echo ">>> Processing GDB (${PLATFORM})"
341 cd "${GDBDIR}"
342 check_error $? "Change directory failed."
344 change_title "GDB: configure (${PLATFORM})"
345 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
346 check_error $? "Error configuring GDB."
348 change_title "GDB: make (${PLATFORM})"
349 make all install
350 check_error $? "Error compiling/installing GDB."
352 cd "${BASEDIR}"
353 check_error $? "Change directory failed."
355 echo ">>> Cleaning up"
356 cleanup_dir "${WORKDIR}"
358 echo
359 echo ">>> Cross-compiler for ${TARGET} installed."
362 if [ "$#" -lt "1" ]; then
363 show_usage
366 case "$1" in
367 "amd64")
368 prepare
369 build_target "amd64" "amd64-linux-gnu"
371 "arm32")
372 prepare
373 build_target "arm32" "arm-linux-gnueabi"
375 "ia32")
376 prepare
377 build_target "ia32" "i686-pc-linux-gnu"
379 "ia64")
380 prepare
381 build_target "ia64" "ia64-pc-linux-gnu"
383 "mips32")
384 prepare
385 build_target "mips32" "mipsel-linux-gnu"
387 "mips32eb")
388 prepare
389 build_target "mips32eb" "mips-linux-gnu"
391 "mips64")
392 prepare
393 build_target "mips64" "mips64el-linux-gnu"
395 "ppc32")
396 prepare
397 build_target "ppc32" "ppc-linux-gnu"
399 "ppc64")
400 prepare
401 build_target "ppc64" "ppc64-linux-gnu"
403 "sparc64")
404 prepare
405 build_target "sparc64" "sparc64-linux-gnu"
407 "all")
408 prepare
409 build_target "amd64" "amd64-linux-gnu"
410 build_target "arm32" "arm-linux-gnueabi"
411 build_target "ia32" "i686-pc-linux-gnu"
412 build_target "ia64" "ia64-pc-linux-gnu"
413 build_target "mips32" "mipsel-linux-gnu"
414 build_target "mips32eb" "mips-linux-gnu"
415 build_target "mips64" "mips64el-linux-gnu"
416 build_target "ppc32" "ppc-linux-gnu"
417 build_target "ppc64" "ppc64-linux-gnu"
418 build_target "sparc64" "sparc64-linux-gnu"
420 "parallel")
421 prepare
422 build_target "amd64" "amd64-linux-gnu" &
423 build_target "arm32" "arm-linux-gnueabi" &
424 build_target "ia32" "i686-pc-linux-gnu" &
425 build_target "ia64" "ia64-pc-linux-gnu" &
426 build_target "mips32" "mipsel-linux-gnu" &
427 build_target "mips32eb" "mips-linux-gnu" &
428 build_target "mips64" "mips64el-linux-gnu" &
429 build_target "ppc32" "ppc-linux-gnu" &
430 build_target "ppc64" "ppc64-linux-gnu" &
431 build_target "sparc64" "sparc64-linux-gnu" &
432 wait
434 "2-way")
435 prepare
436 build_target "amd64" "amd64-linux-gnu" &
437 build_target "arm32" "arm-linux-gnueabi" &
438 wait
440 build_target "ia32" "i686-pc-linux-gnu" &
441 build_target "ia64" "ia64-pc-linux-gnu" &
442 wait
444 build_target "mips32" "mipsel-linux-gnu" &
445 build_target "mips32eb" "mips-linux-gnu" &
446 wait
448 build_target "mips64" "mips64el-linux-gnu" &
449 build_target "ppc32" "ppc-linux-gnu" &
450 wait
452 build_target "ppc64" "ppc64-linux-gnu" &
453 build_target "sparc64" "sparc64-linux-gnu" &
454 wait
457 show_usage
459 esac