source: mainline/contrib/toolchain.sh@ 2a70672

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2a70672 was f2f89315, checked in by Jiri Svoboda <jiri@…>, 16 years ago

Fix typo. Use proper architecture names.

  • Property mode set to 100755
File size: 5.0 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
94build_target() {
95 PLATFORM="$1"
96 TARGET="$2"
97
98 BINUTILS_VERSION="2.19.1"
99 GCC_VERSION="4.4.1"
100
101 BINUTILS="binutils-${BINUTILS_VERSION}.tar.bz2"
102 GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2"
103 GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2"
104 GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2"
105
106 BINUTILS_SOURCE="ftp://ftp.gnu.org/gnu/binutils/"
107 GCC_SOURCE="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
108
109 WORKDIR="`pwd`"
110 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
111 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
112 OBJDIR="${WORKDIR}/gcc-obj"
113
114 if [ -z "${CROSS_PREFIX}" ] ; then
115 CROSS_PREFIX="/usr/local"
116 fi
117
118 PREFIX="${CROSS_PREFIX}/${PLATFORM}"
119
120 echo ">>> Downloading tarballs"
121 download_check "${BINUTILS_SOURCE}" "${BINUTILS}" "09a8c5821a2dfdbb20665bc0bd680791"
122 download_check "${GCC_SOURCE}" "${GCC_CORE}" "d19693308aa6b2052e14c071111df59f"
123 download_check "${GCC_SOURCE}" "${GCC_OBJC}" "f7b2a606394036e81433b2f4c3251cba"
124 download_check "${GCC_SOURCE}" "${GCC_CPP}" "d449047b5761348ceec23739f5553e0b"
125
126 echo ">>> Removing previous content"
127 cleanup_dir "${PREFIX}"
128 cleanup_dir "${OBJDIR}"
129 cleanup_dir "${BINUTILSDIR}"
130 cleanup_dir "${GCCDIR}"
131
132 create_dir "${PREFIX}" "destination directory"
133 create_dir "${OBJDIR}" "GCC object directory"
134
135 echo ">>> Unpacking tarballs"
136 unpack_tarball "${BINUTILS}" "binutils"
137 unpack_tarball "${GCC_CORE}" "GCC Core"
138 unpack_tarball "${GCC_OBJC}" "Objective C"
139 unpack_tarball "${GCC_CPP}" "C++"
140
141 echo ">>> Compiling and installing binutils"
142 cd "${BINUTILSDIR}"
143 check_error $? "Change directory failed."
144 ./configure "--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" "--disable-nls"
145 check_error $? "Error configuring binutils."
146 make all install
147 check_error $? "Error compiling/installing binutils."
148
149 echo ">>> Compiling and installing GCC"
150 cd "${OBJDIR}"
151 check_error $? "Change directory failed."
152 "${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
153 check_error $? "Error configuring GCC."
154 PATH="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
155 check_error $? "Error compiling/installing GCC."
156
157 cd "${WORKDIR}"
158 check_error $? "Change directory failed."
159
160 echo ">>> Cleaning up"
161 cleanup_dir "${OBJDIR}"
162 cleanup_dir "${BINUTILSDIR}"
163 cleanup_dir "${GCCDIR}"
164
165 echo
166 echo ">>> Cross-compiler for ${TARGET} installed."
167}
168
169if [ "$#" -lt "1" ]; then
170 show_usage
171fi
172
173case "$1" in
174 "amd64")
175 build_target "amd64" "amd64-linux-gnu"
176 ;;
177 "arm32")
178 build_target "arm32" "arm-linux-gnu"
179 ;;
180 "ia32")
181 build_target "ia32" "i686-pc-linux-gnu"
182 ;;
183 "ia64")
184 build_target "ia64" "ia64-pc-linux-gnu"
185 ;;
186 "ia64")
187 build_target "ia64" "ia64-pc-linux-gnu"
188 ;;
189 "mips32")
190 build_target "mips32" "mipsel-linux-gnu"
191 ;;
192 "mips32eb")
193 build_target "mips32eb" "mips-linux-gnu"
194 ;;
195 "ppc32")
196 build_target "ppc32" "ppc-linux-gnu"
197 ;;
198 "ppc64")
199 build_target "ppc64" "ppc64-linux-gnu"
200 ;;
201 "sparc64")
202 build_target "sparc64" "sparc64-linux-gnu"
203 ;;
204 "all")
205 build_target "amd64" "amd64-linux-gnu"
206 build_target "arm32" "arm-linux-gnu"
207 build_target "ia32" "i686-pc-linux-gnu"
208 build_target "ia64" "ia64-pc-linux-gnu"
209 build_target "ia64" "ia64-pc-linux-gnu"
210 build_target "mips32" "mipsel-linux-gnu"
211 build_target "mips32eb" "mips-linux-gnu"
212 build_target "ppc32" "ppc-linux-gnu"
213 build_target "ppc64" "ppc64-linux-gnu"
214 build_target "sparc64" "sparc64-linux-gnu"
215 ;;
216 *)
217 show_usage
218 ;;
219esac
Note: See TracBrowser for help on using the repository browser.