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