source: mainline/tools/toolchain.sh@ e503d3a9

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

not requiring /bin/bash explicitly was a stupid idea

  • Property mode set to 100755
File size: 8.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
31check_error() {
32 if [ "$1" -ne "0" ]; then
33 echo
34 echo "Script failed: $2"
35
36 exit 1
37 fi
38}
39
40check_md5() {
41 FILE="$1"
42 SUM="$2"
43
44 COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
45 if [ "${SUM}" != "${COMPUTED}" ] ; then
46 echo
47 echo "Checksum of ${FILE} does not match."
48
49 exit 2
50 fi
51}
52
53show_usage() {
54 echo "Cross-compiler toolchain build script"
55 echo
56 echo "Syntax:"
57 echo " $0 <platform>"
58 echo
59 echo "Possible target platforms are:"
60 echo " amd64 AMD64 (x86-64, x64)"
61 echo " arm32 ARM"
62 echo " ia32 IA-32 (x86, i386)"
63 echo " ia64 IA-64 (Itanium)"
64 echo " mips32 MIPS little-endian"
65 echo " mips32eb MIPS big-endian"
66 echo " ppc32 32-bit PowerPC"
67 echo " ppc64 64-bit PowerPC"
68 echo " sparc64 SPARC V9"
69 echo " all build all targets"
70 echo
71
72 exit 3
73}
74
75change_title() {
76 echo -en "\e]0;$1\a"
77}
78
79show_countdown() {
80 TM="$1"
81
82 if [ "${TM}" -eq 0 ] ; then
83 echo
84 return 0
85 fi
86
87 echo -n "${TM} "
88 change_title "${TM}"
89 sleep 1
90
91 TM="`expr "${TM}" - 1`"
92 show_countdown "${TM}"
93}
94
95show_dependencies() {
96 echo "IMPORTANT NOTICE:"
97 echo
98 echo "For a successful compilation and use of the cross-compiler"
99 echo "toolchain you need at least the following dependencies."
100 echo
101 echo "Please make sure that the dependencies are present in your"
102 echo "system. Otherwise the compilation process might fail after"
103 echo "a few seconds or minutes."
104 echo
105 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
106 echo " - gettext, zlib, Texinfo, libelf, libgomp"
107 echo " - GNU Multiple Precision Library (GMP)"
108 echo " - GNU Make"
109 echo " - GNU tar"
110 echo " - GNU Coreutils"
111 echo " - GNU Sharutils"
112 echo " - MPFR"
113 echo " - MPC"
114 echo " - Parma Polyhedra Library (PPL)"
115 echo " - ClooG-PPL"
116 echo " - native C compiler, assembler and linker"
117 echo " - native C library with headers"
118 echo
119
120 show_countdown 10
121}
122
123download_check() {
124 SOURCE="$1"
125 FILE="$2"
126 CHECKSUM="$3"
127
128 if [ ! -f "${FILE}" ]; then
129 change_title "Downloading ${FILE}"
130 wget -c "${SOURCE}${FILE}"
131 check_error $? "Error downloading ${FILE}."
132 fi
133
134 check_md5 "${FILE}" "${CHECKSUM}"
135}
136
137cleanup_dir() {
138 DIR="$1"
139
140 if [ -d "${DIR}" ]; then
141 change_title "Removing ${DIR}"
142 echo " >>> Removing ${DIR}"
143 rm -fr "${DIR}"
144 fi
145}
146
147create_dir() {
148 DIR="$1"
149 DESC="$2"
150
151 change_title "Creating ${DESC}"
152 echo ">>> Creating ${DESC}"
153
154 mkdir -p "${DIR}"
155 test -d "${DIR}"
156 check_error $? "Unable to create ${DIR}."
157}
158
159unpack_tarball() {
160 FILE="$1"
161 DESC="$2"
162
163 change_title "Unpacking ${DESC}"
164 echo " >>> Unpacking ${DESC}"
165
166 tar -xjf "${FILE}"
167 check_error $? "Error unpacking ${DESC}."
168}
169
170patch_binutils() {
171 PLATFORM="$1"
172
173 if [ "${PLATFORM}" == "arm32" ] ; then
174 patch -p1 <<EOF
175diff -Naur binutils-2.20.orig/gas/config/tc-arm.c binutils-2.20/gas/config/tc-arm.c
176--- binutils-2.20.orig/gas/config/tc-arm.c 2009-08-30 00:10:59.000000000 +0200
177+++ binutils-2.20/gas/config/tc-arm.c 2009-11-02 14:25:11.000000000 +0100
178@@ -2485,8 +2485,9 @@
179 know (frag->tc_frag_data.first_map == NULL);
180 frag->tc_frag_data.first_map = symbolP;
181 }
182- if (frag->tc_frag_data.last_map != NULL)
183+ if (frag->tc_frag_data.last_map != NULL) {
184 know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
185+ }
186 frag->tc_frag_data.last_map = symbolP;
187 }
188EOF
189 check_error $? "Error patching binutils"
190 fi
191}
192
193build_target() {
194 PLATFORM="$1"
195 TARGET="$2"
196
197 BINUTILS_VERSION="2.20"
198 GCC_VERSION="4.5.1"
199
200 BINUTILS="binutils-${BINUTILS_VERSION}.tar.bz2"
201 GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
202 GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
203 GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"
204
205 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
206 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
207
208 WORKDIR="`pwd`"
209 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
210 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
211 OBJDIR="${WORKDIR}/gcc-obj"
212
213 if [ -z "${CROSS_PREFIX}" ] ; then
214 CROSS_PREFIX="/usr/local"
215 fi
216
217 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
218
219 echo ">>> Downloading tarballs"
220 download_check "${BINUTILS_SOURCE}" "${BINUTILS}" "ee2d3e996e9a2d669808713360fa96f8"
221 download_check "${GCC_SOURCE}" "${GCC_CORE}" "dc8959e31b01a65ce10d269614815054"
222 download_check "${GCC_SOURCE}" "${GCC_OBJC}" "3c11b7037896e967eddf8178af2ddd98"
223 download_check "${GCC_SOURCE}" "${GCC_CPP}" "b294953ff0bb2f20c7acb2bf005d832a"
224
225 echo ">>> Removing previous content"
226 cleanup_dir "${PREFIX}"
227 cleanup_dir "${OBJDIR}"
228 cleanup_dir "${BINUTILSDIR}"
229 cleanup_dir "${GCCDIR}"
230
231 create_dir "${PREFIX}" "destination directory"
232 create_dir "${OBJDIR}" "GCC object directory"
233
234 echo ">>> Unpacking tarballs"
235 unpack_tarball "${BINUTILS}" "binutils"
236 unpack_tarball "${GCC_CORE}" "GCC Core"
237 unpack_tarball "${GCC_OBJC}" "Objective C"
238 unpack_tarball "${GCC_CPP}" "C++"
239
240 echo ">>> Processing binutils (${PLATFORM})"
241 cd "${BINUTILSDIR}"
242 check_error $? "Change directory failed."
243 patch_binutils "${PLATFORM}"
244
245 change_title "binutils: configure (${PLATFORM})"
246 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls
247 check_error $? "Error configuring binutils."
248
249 change_title "binutils: make (${PLATFORM})"
250 make all install
251 check_error $? "Error compiling/installing binutils."
252
253 echo ">>> Processing GCC (${PLATFORM})"
254 cd "${OBJDIR}"
255 check_error $? "Change directory failed."
256
257 change_title "GCC: configure (${PLATFORM})"
258 "${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
259 check_error $? "Error configuring GCC."
260
261 change_title "GCC: make (${PLATFORM})"
262 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
263 check_error $? "Error compiling/installing GCC."
264
265 cd "${WORKDIR}"
266 check_error $? "Change directory failed."
267
268 echo ">>> Cleaning up"
269 cleanup_dir "${OBJDIR}"
270 cleanup_dir "${BINUTILSDIR}"
271 cleanup_dir "${GCCDIR}"
272
273 echo
274 echo ">>> Cross-compiler for ${TARGET} installed."
275}
276
277if [ "$#" -lt "1" ]; then
278 show_usage
279fi
280
281show_dependencies
282
283case "$1" in
284 "amd64")
285 build_target "amd64" "amd64-linux-gnu"
286 ;;
287 "arm32")
288 build_target "arm32" "arm-linux-gnu"
289 ;;
290 "ia32")
291 build_target "ia32" "i686-pc-linux-gnu"
292 ;;
293 "ia64")
294 build_target "ia64" "ia64-pc-linux-gnu"
295 ;;
296 "ia64")
297 build_target "ia64" "ia64-pc-linux-gnu"
298 ;;
299 "mips32")
300 build_target "mips32" "mipsel-linux-gnu"
301 ;;
302 "mips32eb")
303 build_target "mips32eb" "mips-linux-gnu"
304 ;;
305 "ppc32")
306 build_target "ppc32" "ppc-linux-gnu"
307 ;;
308 "ppc64")
309 build_target "ppc64" "ppc64-linux-gnu"
310 ;;
311 "sparc64")
312 build_target "sparc64" "sparc64-linux-gnu"
313 ;;
314 "all")
315 build_target "amd64" "amd64-linux-gnu"
316 build_target "arm32" "arm-linux-gnu"
317 build_target "ia32" "i686-pc-linux-gnu"
318 build_target "ia64" "ia64-pc-linux-gnu"
319 build_target "ia64" "ia64-pc-linux-gnu"
320 build_target "mips32" "mipsel-linux-gnu"
321 build_target "mips32eb" "mips-linux-gnu"
322 build_target "ppc32" "ppc-linux-gnu"
323 build_target "ppc64" "ppc64-linux-gnu"
324 build_target "sparc64" "sparc64-linux-gnu"
325 ;;
326 *)
327 show_usage
328 ;;
329esac
Note: See TracBrowser for help on using the repository browser.