source: mainline/contrib/toolchain.sh@ 1647323

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

move to GCC 4.4.2 and binutils 2.20
(there is a small patch which is needed to build binutils for arm32 on recent versions of host GCC)

  • Property mode set to 100755
File size: 5.7 KB
Line 
1#!/bin/bash
2
3# Cross-compiler toolchain build script
4# by Martin Decky <martin@decky.cz>
5#
6# GPL'ed, copyleft
7#
8
9check_error() {
10 if [ "$1" -ne "0" ]; then
11 echo
12 echo "Script failed: $2"
13 exit 1
14 fi
15}
16
17check_md5() {
18 FILE="$1"
19 SUM="$2"
20
21 COMPUTED="`md5sum "${FILE}" | cut -d' ' -f1`"
22 if [ "${SUM}" != "${COMPUTED}" ] ; then
23 echo
24 echo "Checksum of ${FILE} does not match."
25 exit 2
26 fi
27}
28
29show_usage() {
30 echo "Cross-compiler toolchain build script"
31 echo
32 echo "Syntax:"
33 echo " $0 <platform>"
34 echo
35 echo "Possible target platforms are:"
36 echo " amd64 AMD64 (x86-64, x64)"
37 echo " arm32 ARM"
38 echo " ia32 IA-32 (x86, i386)"
39 echo " ia64 IA-64 (Itanium)"
40 echo " mips32 MIPS little-endian"
41 echo " mips32eb MIPS big-endian"
42 echo " ppc32 32-bit PowerPC"
43 echo " ppc64 64-bit PowerPC"
44 echo " sparc64 SPARC V9"
45 echo " all build all targets"
46 echo
47
48 exit 3
49}
50
51download_check() {
52 SOURCE="$1"
53 FILE="$2"
54 CHECKSUM="$3"
55
56 if [ ! -f "${FILE}" ]; then
57 wget -c "${SOURCE}${FILE}"
58 check_error $? "Error downloading ${FILE}."
59 fi
60
61 check_md5 "${FILE}" "${CHECKSUM}"
62}
63
64cleanup_dir() {
65 DIR="$1"
66
67 if [ -d "${DIR}" ]; then
68 echo " >>> Removing ${DIR}"
69 rm -fr "${DIR}"
70 fi
71}
72
73create_dir() {
74 DIR="$1"
75 DESC="$2"
76
77 echo ">>> Creating ${DESC}"
78
79 mkdir -p "${DIR}"
80 test -d "${DIR}"
81 check_error $? "Unable to create ${DIR}."
82}
83
84unpack_tarball() {
85 FILE="$1"
86 DESC="$2"
87
88 echo " >>> ${DESC}"
89
90 tar -xjf "${FILE}"
91 check_error $? "Error unpacking ${DESC}."
92}
93
94patch_binutils() {
95 PLATFORM="$1"
96
97 if [ "${PLATFORM}" == "arm32" ] ; then
98 patch -p1 <<EOF
99diff -Naur binutils-2.20.orig/gas/config/tc-arm.c binutils-2.20/gas/config/tc-arm.c
100--- binutils-2.20.orig/gas/config/tc-arm.c 2009-08-30 00:10:59.000000000 +0200
101+++ binutils-2.20/gas/config/tc-arm.c 2009-11-02 14:25:11.000000000 +0100
102@@ -2485,8 +2485,9 @@
103 know (frag->tc_frag_data.first_map == NULL);
104 frag->tc_frag_data.first_map = symbolP;
105 }
106- if (frag->tc_frag_data.last_map != NULL)
107+ if (frag->tc_frag_data.last_map != NULL) {
108 know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
109+ }
110 frag->tc_frag_data.last_map = symbolP;
111 }
112EOF
113 check_error $? "Error patching binutils"
114 fi
115}
116
117build_target() {
118 PLATFORM="$1"
119 TARGET="$2"
120
121 BINUTILS_VERSION="2.20"
122 GCC_VERSION="4.4.2"
123
124 BINUTILS="binutils-${BINUTILS_VERSION}.tar.bz2"
125 GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
126 GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
127 GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"
128
129 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
130 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
131
132 WORKDIR="`pwd`"
133 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
134 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
135 OBJDIR="${WORKDIR}/gcc-obj"
136
137 if [ -z "${CROSS_PREFIX}" ] ; then
138 CROSS_PREFIX="/usr/local"
139 fi
140
141 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
142
143 echo ">>> Downloading tarballs"
144 download_check "${BINUTILS_SOURCE}" "${BINUTILS}" "ee2d3e996e9a2d669808713360fa96f8"
145 download_check "${GCC_SOURCE}" "${GCC_CORE}" "d50ec5af20508974411d0c83c5f4e396"
146 download_check "${GCC_SOURCE}" "${GCC_OBJC}" "d8d26187d386a0591222a580b5a5b3d3"
147 download_check "${GCC_SOURCE}" "${GCC_CPP}" "43b1e4879eb282dc4b05e4c016d356d7"
148
149 echo ">>> Removing previous content"
150 cleanup_dir "${PREFIX}"
151 cleanup_dir "${OBJDIR}"
152 cleanup_dir "${BINUTILSDIR}"
153 cleanup_dir "${GCCDIR}"
154
155 create_dir "${PREFIX}" "destination directory"
156 create_dir "${OBJDIR}" "GCC object directory"
157
158 echo ">>> Unpacking tarballs"
159 unpack_tarball "${BINUTILS}" "binutils"
160 unpack_tarball "${GCC_CORE}" "GCC Core"
161 unpack_tarball "${GCC_OBJC}" "Objective C"
162 unpack_tarball "${GCC_CPP}" "C++"
163
164 echo ">>> Compiling and installing binutils"
165 cd "${BINUTILSDIR}"
166 check_error $? "Change directory failed."
167 patch_binutils "${PLATFORM}"
168 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" "--disable-nls"
169 check_error $? "Error configuring binutils."
170 make all install
171 check_error $? "Error compiling/installing binutils."
172
173 echo ">>> Compiling and installing GCC"
174 cd "${OBJDIR}"
175 check_error $? "Change directory failed."
176 "${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
177 check_error $? "Error configuring GCC."
178 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
179 check_error $? "Error compiling/installing GCC."
180
181 cd "${WORKDIR}"
182 check_error $? "Change directory failed."
183
184 echo ">>> Cleaning up"
185 cleanup_dir "${OBJDIR}"
186 cleanup_dir "${BINUTILSDIR}"
187 cleanup_dir "${GCCDIR}"
188
189 echo
190 echo ">>> Cross-compiler for ${TARGET} installed."
191}
192
193if [ "$#" -lt "1" ]; then
194 show_usage
195fi
196
197case "$1" in
198 "amd64")
199 build_target "amd64" "amd64-linux-gnu"
200 ;;
201 "arm32")
202 build_target "arm32" "arm-linux-gnu"
203 ;;
204 "ia32")
205 build_target "ia32" "i686-pc-linux-gnu"
206 ;;
207 "ia64")
208 build_target "ia64" "ia64-pc-linux-gnu"
209 ;;
210 "ia64")
211 build_target "ia64" "ia64-pc-linux-gnu"
212 ;;
213 "mips32")
214 build_target "mips32" "mipsel-linux-gnu"
215 ;;
216 "mips32eb")
217 build_target "mips32eb" "mips-linux-gnu"
218 ;;
219 "ppc32")
220 build_target "ppc32" "ppc-linux-gnu"
221 ;;
222 "ppc64")
223 build_target "ppc64" "ppc64-linux-gnu"
224 ;;
225 "sparc64")
226 build_target "sparc64" "sparc64-linux-gnu"
227 ;;
228 "all")
229 build_target "amd64" "amd64-linux-gnu"
230 build_target "arm32" "arm-linux-gnu"
231 build_target "ia32" "i686-pc-linux-gnu"
232 build_target "ia64" "ia64-pc-linux-gnu"
233 build_target "ia64" "ia64-pc-linux-gnu"
234 build_target "mips32" "mipsel-linux-gnu"
235 build_target "mips32eb" "mips-linux-gnu"
236 build_target "ppc32" "ppc-linux-gnu"
237 build_target "ppc64" "ppc64-linux-gnu"
238 build_target "sparc64" "sparc64-linux-gnu"
239 ;;
240 *)
241 show_usage
242 ;;
243esac
Note: See TracBrowser for help on using the repository browser.