source: mainline/tools/toolchain.sh@ b0beee82

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b0beee82 was 3f7efa79, checked in by Martin Decky <martin@…>, 14 years ago

add basic dependency check to the toolchain build script
(based on a contribution to Kalisto by Tomas Martinec)

  • Property mode set to 100755
File size: 10.4 KB
Line 
1#! /bin/bash
2
3#
4# Copyright (c) 2009 Martin Decky
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10#
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.
18#
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.
29#
30
31GMP_MAIN=<<EOF
32#define GCC_GMP_VERSION_NUM(a, b, c) \
33 (((a) << 16L) | ((b) << 8) | (c))
34
35#define GCC_GMP_VERSION \
36 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
37
38#if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,2)
39 choke me
40#endif
41EOF
42
43MPFR_MAIN=<<EOF
44#if MPFR_VERSION < MPFR_VERSION_NUM(2, 4, 2)
45choke me
46 #endif
47EOF
48
49MPC_MAIN=<<EOF
50#if MPC_VERSION < MPC_VERSION_NUM(0, 8, 1)
51 choke me
52#endif
53EOF
54
55#
56# Check if the library described in the argument
57# exists and has acceptable version.
58#
59check_dependency() {
60 DEPENDENCY="$1"
61 HEADER="$2"
62 BODY="$3"
63
64 FNAME="/tmp/conftest-$$"
65
66 echo "#include ${HEADER}" > "${FNAME}.c"
67 echo >> "${FNAME}.c"
68 echo "int main()" >> "${FNAME}.c"
69 echo "{" >> "${FNAME}.c"
70 echo "${BODY}" >> "${FNAME}.c"
71 echo " return 0;" >> "${FNAME}.c"
72 echo "}" >> "${FNAME}.c"
73
74 cc -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
75 RC="$?"
76
77 if [ "$RC" -ne "0" ] ; then
78 echo " ${DEPENDENCY} not found, too old or compiler error."
79 echo " Please recheck manually the source file \"${FNAME}.c\"."
80 echo " The compilation of the toolchain is probably going to fail,"
81 echo " you have been warned."
82 echo
83 echo " ===== Compiler output ====="
84 cat "${FNAME}.log"
85 echo " ==========================="
86 echo
87 else
88 echo " ${DEPENDENCY} found"
89 rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
90 fi
91}
92
93check_dependecies() {
94 echo ">>> Basic dependency check"
95 check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}"
96 check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}"
97 check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}"
98 echo
99}
100
101check_error() {
102 if [ "$1" -ne "0" ]; then
103 echo
104 echo "Script failed: $2"
105
106 exit 1
107 fi
108}
109
110check_md5() {
111 FILE="$1"
112 SUM="$2"
113
114 COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
115 if [ "${SUM}" != "${COMPUTED}" ] ; then
116 echo
117 echo "Checksum of ${FILE} does not match."
118
119 exit 2
120 fi
121}
122
123show_usage() {
124 echo "Cross-compiler toolchain build script"
125 echo
126 echo "Syntax:"
127 echo " $0 <platform>"
128 echo
129 echo "Possible target platforms are:"
130 echo " amd64 AMD64 (x86-64, x64)"
131 echo " arm32 ARM"
132 echo " ia32 IA-32 (x86, i386)"
133 echo " ia64 IA-64 (Itanium)"
134 echo " mips32 MIPS little-endian 32b"
135 echo " mips32eb MIPS big-endian 32b"
136 echo " mips64 MIPS little-endian 64b"
137 echo " ppc32 32-bit PowerPC"
138 echo " ppc64 64-bit PowerPC"
139 echo " sparc64 SPARC V9"
140 echo " all build all targets"
141 echo
142 echo "The toolchain will be installed to the directory specified by"
143 echo "the CROSS_PREFIX environment variable. If the variable is not"
144 echo "defined, /usr/local will be used by default."
145 echo
146
147 exit 3
148}
149
150change_title() {
151 echo -en "\e]0;$1\a"
152}
153
154show_countdown() {
155 TM="$1"
156
157 if [ "${TM}" -eq 0 ] ; then
158 echo
159 return 0
160 fi
161
162 echo -n "${TM} "
163 change_title "${TM}"
164 sleep 1
165
166 TM="`expr "${TM}" - 1`"
167 show_countdown "${TM}"
168}
169
170show_dependencies() {
171 echo "IMPORTANT NOTICE:"
172 echo
173 echo "For a successful compilation and use of the cross-compiler"
174 echo "toolchain you need at least the following dependencies."
175 echo
176 echo "Please make sure that the dependencies are present in your"
177 echo "system. Otherwise the compilation process might fail after"
178 echo "a few seconds or minutes."
179 echo
180 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
181 echo " - gettext, zlib, Texinfo, libelf, libgomp"
182 echo " - GNU Multiple Precision Library (GMP)"
183 echo " - GNU Make"
184 echo " - GNU tar"
185 echo " - GNU Coreutils"
186 echo " - GNU Sharutils"
187 echo " - MPFR"
188 echo " - MPC"
189 echo " - Parma Polyhedra Library (PPL)"
190 echo " - ClooG-PPL"
191 echo " - native C compiler, assembler and linker"
192 echo " - native C library with headers"
193 echo
194}
195
196download_check() {
197 SOURCE="$1"
198 FILE="$2"
199 CHECKSUM="$3"
200
201 if [ ! -f "${FILE}" ]; then
202 change_title "Downloading ${FILE}"
203 wget -c "${SOURCE}${FILE}"
204 check_error $? "Error downloading ${FILE}."
205 fi
206
207 check_md5 "${FILE}" "${CHECKSUM}"
208}
209
210cleanup_dir() {
211 DIR="$1"
212
213 if [ -d "${DIR}" ]; then
214 change_title "Removing ${DIR}"
215 echo " >>> Removing ${DIR}"
216 rm -fr "${DIR}"
217 fi
218}
219
220create_dir() {
221 DIR="$1"
222 DESC="$2"
223
224 change_title "Creating ${DESC}"
225 echo ">>> Creating ${DESC}"
226
227 mkdir -p "${DIR}"
228 test -d "${DIR}"
229 check_error $? "Unable to create ${DIR}."
230}
231
232unpack_tarball() {
233 FILE="$1"
234 DESC="$2"
235
236 change_title "Unpacking ${DESC}"
237 echo " >>> Unpacking ${DESC}"
238
239 tar -xjf "${FILE}"
240 check_error $? "Error unpacking ${DESC}."
241}
242
243patch_binutils() {
244 PLATFORM="$1"
245
246 if [ "${PLATFORM}" == "arm32" ] ; then
247 patch -p1 <<EOF
248diff -Naur binutils-2.20.orig/gas/config/tc-arm.c binutils-2.20/gas/config/tc-arm.c
249--- binutils-2.20.orig/gas/config/tc-arm.c 2009-08-30 00:10:59.000000000 +0200
250+++ binutils-2.20/gas/config/tc-arm.c 2009-11-02 14:25:11.000000000 +0100
251@@ -2485,8 +2485,9 @@
252 know (frag->tc_frag_data.first_map == NULL);
253 frag->tc_frag_data.first_map = symbolP;
254 }
255- if (frag->tc_frag_data.last_map != NULL)
256+ if (frag->tc_frag_data.last_map != NULL) {
257 know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
258+ }
259 frag->tc_frag_data.last_map = symbolP;
260 }
261EOF
262 check_error $? "Error patching binutils"
263 fi
264}
265
266build_target() {
267 PLATFORM="$1"
268 TARGET="$2"
269
270 BINUTILS_VERSION="2.20"
271 GCC_VERSION="4.5.1"
272
273 BINUTILS="binutils-${BINUTILS_VERSION}.tar.bz2"
274 GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
275 GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
276 GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"
277
278 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
279 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
280
281 WORKDIR="`pwd`"
282 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
283 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
284 OBJDIR="${WORKDIR}/gcc-obj"
285
286 if [ -z "${CROSS_PREFIX}" ] ; then
287 CROSS_PREFIX="/usr/local"
288 fi
289
290 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
291
292 echo ">>> Downloading tarballs"
293 download_check "${BINUTILS_SOURCE}" "${BINUTILS}" "ee2d3e996e9a2d669808713360fa96f8"
294 download_check "${GCC_SOURCE}" "${GCC_CORE}" "dc8959e31b01a65ce10d269614815054"
295 download_check "${GCC_SOURCE}" "${GCC_OBJC}" "3c11b7037896e967eddf8178af2ddd98"
296 download_check "${GCC_SOURCE}" "${GCC_CPP}" "b294953ff0bb2f20c7acb2bf005d832a"
297
298 echo ">>> Removing previous content"
299 cleanup_dir "${PREFIX}"
300 cleanup_dir "${OBJDIR}"
301 cleanup_dir "${BINUTILSDIR}"
302 cleanup_dir "${GCCDIR}"
303
304 create_dir "${PREFIX}" "destination directory"
305 create_dir "${OBJDIR}" "GCC object directory"
306
307 echo ">>> Unpacking tarballs"
308 unpack_tarball "${BINUTILS}" "binutils"
309 unpack_tarball "${GCC_CORE}" "GCC Core"
310 unpack_tarball "${GCC_OBJC}" "Objective C"
311 unpack_tarball "${GCC_CPP}" "C++"
312
313 echo ">>> Processing binutils (${PLATFORM})"
314 cd "${BINUTILSDIR}"
315 check_error $? "Change directory failed."
316 patch_binutils "${PLATFORM}"
317
318 change_title "binutils: configure (${PLATFORM})"
319 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls
320 check_error $? "Error configuring binutils."
321
322 change_title "binutils: make (${PLATFORM})"
323 make all install
324 check_error $? "Error compiling/installing binutils."
325
326 echo ">>> Processing GCC (${PLATFORM})"
327 cd "${OBJDIR}"
328 check_error $? "Change directory failed."
329
330 change_title "GCC: configure (${PLATFORM})"
331 "${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
332 check_error $? "Error configuring GCC."
333
334 change_title "GCC: make (${PLATFORM})"
335 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
336 check_error $? "Error compiling/installing GCC."
337
338 cd "${WORKDIR}"
339 check_error $? "Change directory failed."
340
341 echo ">>> Cleaning up"
342 cleanup_dir "${OBJDIR}"
343 cleanup_dir "${BINUTILSDIR}"
344 cleanup_dir "${GCCDIR}"
345
346 echo
347 echo ">>> Cross-compiler for ${TARGET} installed."
348}
349
350if [ "$#" -lt "1" ]; then
351 show_usage
352fi
353
354show_dependencies
355check_dependecies
356show_countdown 10
357
358case "$1" in
359 "amd64")
360 build_target "amd64" "amd64-linux-gnu"
361 ;;
362 "arm32")
363 build_target "arm32" "arm-linux-gnu"
364 ;;
365 "ia32")
366 build_target "ia32" "i686-pc-linux-gnu"
367 ;;
368 "ia64")
369 build_target "ia64" "ia64-pc-linux-gnu"
370 ;;
371 "ia64")
372 build_target "ia64" "ia64-pc-linux-gnu"
373 ;;
374 "mips32")
375 build_target "mips32" "mipsel-linux-gnu"
376 ;;
377 "mips32eb")
378 build_target "mips32eb" "mips-linux-gnu"
379 ;;
380 "mips64")
381 build_target "mips64" "mips64el-linux-gnu"
382 ;;
383 "ppc32")
384 build_target "ppc32" "ppc-linux-gnu"
385 ;;
386 "ppc64")
387 build_target "ppc64" "ppc64-linux-gnu"
388 ;;
389 "sparc64")
390 build_target "sparc64" "sparc64-linux-gnu"
391 ;;
392 "all")
393 build_target "amd64" "amd64-linux-gnu"
394 build_target "arm32" "arm-linux-gnu"
395 build_target "ia32" "i686-pc-linux-gnu"
396 build_target "ia64" "ia64-pc-linux-gnu"
397 build_target "ia64" "ia64-pc-linux-gnu"
398 build_target "mips32" "mipsel-linux-gnu"
399 build_target "mips32eb" "mips-linux-gnu"
400 build_target "mips64" "mips64el-linux-gnu"
401 build_target "ppc32" "ppc-linux-gnu"
402 build_target "ppc64" "ppc64-linux-gnu"
403 build_target "sparc64" "sparc64-linux-gnu"
404 ;;
405 *)
406 show_usage
407 ;;
408esac
Note: See TracBrowser for help on using the repository browser.