source: mainline/tools/toolchain.sh@ 8f6c7785

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8f6c7785 was 8f6c7785, checked in by Dominik Taborsky (AT DOT) <brembyseznamcz>, 13 years ago

logical write functional

  • Property mode set to 100755
File size: 11.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)
45 choke 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
55BINUTILS_VERSION="2.22"
56BINUTILS_RELEASE=""
57#GCC_VERSION="4.7.2"
58GCC_VERSION="4.7.3"
59#GCC_VERSION="4.8.0"
60GDB_VERSION="7.5"
61
62BASEDIR="`pwd`"
63BINUTILS="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2"
64GCC="gcc-${GCC_VERSION}.tar.bz2"
65GDB="gdb-${GDB_VERSION}.tar.bz2"
66
67#
68# Check if the library described in the argument
69# exists and has acceptable version.
70#
71check_dependency() {
72 DEPENDENCY="$1"
73 HEADER="$2"
74 BODY="$3"
75
76 FNAME="/tmp/conftest-$$"
77
78 echo "#include ${HEADER}" > "${FNAME}.c"
79 echo >> "${FNAME}.c"
80 echo "int main()" >> "${FNAME}.c"
81 echo "{" >> "${FNAME}.c"
82 echo "${BODY}" >> "${FNAME}.c"
83 echo " return 0;" >> "${FNAME}.c"
84 echo "}" >> "${FNAME}.c"
85
86 cc -c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
87 RC="$?"
88
89 if [ "$RC" -ne "0" ] ; then
90 echo " ${DEPENDENCY} not found, too old or compiler error."
91 echo " Please recheck manually the source file \"${FNAME}.c\"."
92 echo " The compilation of the toolchain is probably going to fail,"
93 echo " you have been warned."
94 echo
95 echo " ===== Compiler output ====="
96 cat "${FNAME}.log"
97 echo " ==========================="
98 echo
99 else
100 echo " ${DEPENDENCY} found"
101 rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
102 fi
103}
104
105check_dependecies() {
106 echo ">>> Basic dependency check"
107 check_dependency "GMP" "<gmp.h>" "${GMP_MAIN}"
108 check_dependency "MPFR" "<mpfr.h>" "${MPFR_MAIN}"
109 check_dependency "MPC" "<mpc.h>" "${MPC_MAIN}"
110 echo
111}
112
113check_error() {
114 if [ "$1" -ne "0" ]; then
115 echo
116 echo "Script failed: $2"
117
118 exit 1
119 fi
120}
121
122check_md5() {
123 FILE="$1"
124 SUM="$2"
125
126 COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
127 if [ "${SUM}" != "${COMPUTED}" ] ; then
128 echo
129 echo "Checksum of ${FILE} does not match."
130
131 exit 2
132 fi
133}
134
135show_usage() {
136 echo "Cross-compiler toolchain build script"
137 echo
138 echo "Syntax:"
139 echo " $0 <platform>"
140 echo
141 echo "Possible target platforms are:"
142 echo " amd64 AMD64 (x86-64, x64)"
143 echo " arm32 ARM"
144 echo " ia32 IA-32 (x86, i386)"
145 echo " ia64 IA-64 (Itanium)"
146 echo " mips32 MIPS little-endian 32b"
147 echo " mips32eb MIPS big-endian 32b"
148 echo " mips64 MIPS little-endian 64b"
149 echo " ppc32 32-bit PowerPC"
150 echo " ppc64 64-bit PowerPC"
151 echo " sparc64 SPARC V9"
152 echo " all build all targets"
153 echo " parallel same as 'all', but all in parallel"
154 echo " 2-way same as 'all', but 2-way parallel"
155 echo
156 echo "The toolchain will be installed to the directory specified by"
157 echo "the CROSS_PREFIX environment variable. If the variable is not"
158 echo "defined, /usr/local/cross will be used by default."
159 echo
160
161 exit 3
162}
163
164change_title() {
165 echo -en "\e]0;$1\a"
166}
167
168show_countdown() {
169 TM="$1"
170
171 if [ "${TM}" -eq 0 ] ; then
172 echo
173 return 0
174 fi
175
176 echo -n "${TM} "
177 change_title "${TM}"
178 sleep 1
179
180 TM="`expr "${TM}" - 1`"
181 show_countdown "${TM}"
182}
183
184show_dependencies() {
185 echo "IMPORTANT NOTICE:"
186 echo
187 echo "For a successful compilation and use of the cross-compiler"
188 echo "toolchain you need at least the following dependencies."
189 echo
190 echo "Please make sure that the dependencies are present in your"
191 echo "system. Otherwise the compilation process might fail after"
192 echo "a few seconds or minutes."
193 echo
194 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
195 echo " - gettext, zlib, Texinfo, libelf, libgomp"
196 echo " - terminfo"
197 echo " - GNU Multiple Precision Library (GMP)"
198 echo " - GNU Make"
199 echo " - GNU tar"
200 echo " - GNU Coreutils"
201 echo " - GNU Sharutils"
202 echo " - MPFR"
203 echo " - MPC"
204 echo " - Parma Polyhedra Library (PPL)"
205 echo " - ClooG-PPL"
206 echo " - native C compiler, assembler and linker"
207 echo " - native C library with headers"
208 echo
209}
210
211download_fetch() {
212 SOURCE="$1"
213 FILE="$2"
214 CHECKSUM="$3"
215
216 if [ ! -f "${FILE}" ]; then
217 change_title "Downloading ${FILE}"
218 wget -c "${SOURCE}${FILE}"
219 check_error $? "Error downloading ${FILE}."
220 fi
221
222 check_md5 "${FILE}" "${CHECKSUM}"
223}
224
225source_check() {
226 FILE="$1"
227
228 if [ ! -f "${FILE}" ]; then
229 echo
230 echo "File ${FILE} not found."
231
232 exit 4
233 fi
234}
235
236cleanup_dir() {
237 DIR="$1"
238
239 if [ -d "${DIR}" ]; then
240 change_title "Removing ${DIR}"
241 echo " >>> Removing ${DIR}"
242 rm -fr "${DIR}"
243 fi
244}
245
246create_dir() {
247 DIR="$1"
248 DESC="$2"
249
250 change_title "Creating ${DESC}"
251 echo ">>> Creating ${DESC}"
252
253 mkdir -p "${DIR}"
254 test -d "${DIR}"
255 check_error $? "Unable to create ${DIR}."
256}
257
258unpack_tarball() {
259 FILE="$1"
260 DESC="$2"
261
262 change_title "Unpacking ${DESC}"
263 echo " >>> Unpacking ${DESC}"
264
265 tar -xjf "${FILE}"
266 check_error $? "Error unpacking ${DESC}."
267}
268
269prepare() {
270 show_dependencies
271 check_dependecies
272 show_countdown 10
273
274 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
275 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
276 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/"
277
278 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "ee0f10756c84979622b992a4a61ea3f5"
279 download_fetch "${GCC_SOURCE}" "${GCC}" "cc308a0891e778cfda7a151ab8a6e762"
280 download_fetch "${GDB_SOURCE}" "${GDB}" "24a6779a9fe0260667710de1b082ef61"
281}
282
283build_target() {
284 PLATFORM="$1"
285 TARGET="$2"
286
287 WORKDIR="${BASEDIR}/${PLATFORM}"
288 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
289 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
290 OBJDIR="${WORKDIR}/gcc-obj"
291 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
292
293 if [ -z "${CROSS_PREFIX}" ] ; then
294 CROSS_PREFIX="/usr/local/cross"
295 fi
296
297 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
298
299 echo ">>> Downloading tarballs"
300 #source_check "${BASEDIR}/${BINUTILS}"
301 source_check "${BASEDIR}/${GCC}"
302 #source_check "${BASEDIR}/${GDB}"
303
304 echo ">>> Removing previous content"
305 #cleanup_dir "${PREFIX}"
306 #cleanup_dir "${WORKDIR}"
307
308 create_dir "${PREFIX}" "destination directory"
309 create_dir "${OBJDIR}" "GCC object directory"
310
311 echo ">>> Unpacking tarballs"
312 cd "${WORKDIR}"
313 check_error $? "Change directory failed."
314
315 #unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils"
316 unpack_tarball "${BASEDIR}/${GCC}" "GCC"
317 #unpack_tarball "${BASEDIR}/${GDB}" "GDB"
318
319 #echo ">>> Processing binutils (${PLATFORM})"
320 #cd "${BINUTILSDIR}"
321 #check_error $? "Change directory failed."
322
323 #change_title "binutils: configure (${PLATFORM})"
324 #CFLAGS=-Wno-error ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
325 #check_error $? "Error configuring binutils."
326
327 #change_title "binutils: make (${PLATFORM})"
328 #make all install
329 #check_error $? "Error compiling/installing binutils."
330
331 echo ">>> Processing GCC (${PLATFORM})"
332 cd "${OBJDIR}"
333 check_error $? "Change directory failed."
334
335 change_title "GCC: configure (${PLATFORM})"
336 "${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
337 check_error $? "Error configuring GCC."
338
339 change_title "GCC: make (${PLATFORM})"
340 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
341 check_error $? "Error compiling/installing GCC."
342
343 #echo ">>> Processing GDB (${PLATFORM})"
344 #cd "${GDBDIR}"
345 #check_error $? "Change directory failed."
346
347 #change_title "GDB: configure (${PLATFORM})"
348 #./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
349 #check_error $? "Error configuring GDB."
350
351 #change_title "GDB: make (${PLATFORM})"
352 #make all install
353 #check_error $? "Error compiling/installing GDB."
354
355 cd "${BASEDIR}"
356 check_error $? "Change directory failed."
357
358 echo ">>> Cleaning up"
359 cleanup_dir "${WORKDIR}"
360
361 echo
362 echo ">>> Cross-compiler for ${TARGET} installed."
363}
364
365if [ "$#" -lt "1" ]; then
366 show_usage
367fi
368
369case "$1" in
370 "amd64")
371 #prepare
372 build_target "amd64" "amd64-linux-gnu"
373 ;;
374 "arm32")
375 prepare
376 build_target "arm32" "arm-linux-gnueabi"
377 ;;
378 "ia32")
379 #prepare
380 build_target "ia32" "i686-pc-linux-gnu"
381 ;;
382 "ia64")
383 prepare
384 build_target "ia64" "ia64-pc-linux-gnu"
385 ;;
386 "mips32")
387 prepare
388 build_target "mips32" "mipsel-linux-gnu"
389 ;;
390 "mips32eb")
391 prepare
392 build_target "mips32eb" "mips-linux-gnu"
393 ;;
394 "mips64")
395 prepare
396 build_target "mips64" "mips64el-linux-gnu"
397 ;;
398 "ppc32")
399 prepare
400 build_target "ppc32" "ppc-linux-gnu"
401 ;;
402 "ppc64")
403 prepare
404 build_target "ppc64" "ppc64-linux-gnu"
405 ;;
406 "sparc64")
407 prepare
408 build_target "sparc64" "sparc64-linux-gnu"
409 ;;
410 "all")
411 prepare
412 build_target "amd64" "amd64-linux-gnu"
413 build_target "arm32" "arm-linux-gnueabi"
414 build_target "ia32" "i686-pc-linux-gnu"
415 build_target "ia64" "ia64-pc-linux-gnu"
416 build_target "mips32" "mipsel-linux-gnu"
417 build_target "mips32eb" "mips-linux-gnu"
418 build_target "mips64" "mips64el-linux-gnu"
419 build_target "ppc32" "ppc-linux-gnu"
420 build_target "ppc64" "ppc64-linux-gnu"
421 build_target "sparc64" "sparc64-linux-gnu"
422 ;;
423 "parallel")
424 prepare
425 build_target "amd64" "amd64-linux-gnu" &
426 build_target "arm32" "arm-linux-gnueabi" &
427 build_target "ia32" "i686-pc-linux-gnu" &
428 build_target "ia64" "ia64-pc-linux-gnu" &
429 build_target "mips32" "mipsel-linux-gnu" &
430 build_target "mips32eb" "mips-linux-gnu" &
431 build_target "mips64" "mips64el-linux-gnu" &
432 build_target "ppc32" "ppc-linux-gnu" &
433 build_target "ppc64" "ppc64-linux-gnu" &
434 build_target "sparc64" "sparc64-linux-gnu" &
435 wait
436 ;;
437 "2-way")
438 prepare
439 build_target "amd64" "amd64-linux-gnu" &
440 build_target "arm32" "arm-linux-gnueabi" &
441 wait
442
443 build_target "ia32" "i686-pc-linux-gnu" &
444 build_target "ia64" "ia64-pc-linux-gnu" &
445 wait
446
447 build_target "mips32" "mipsel-linux-gnu" &
448 build_target "mips32eb" "mips-linux-gnu" &
449 wait
450
451 build_target "mips64" "mips64el-linux-gnu" &
452 build_target "ppc32" "ppc-linux-gnu" &
453 wait
454
455 build_target "ppc64" "ppc64-linux-gnu" &
456 build_target "sparc64" "sparc64-linux-gnu" &
457 wait
458 ;;
459 *)
460 show_usage
461 ;;
462esac
Note: See TracBrowser for help on using the repository browser.