4 # Copyright (c) 2009 Martin Decky
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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.
32 #define GCC_GMP_VERSION_NUM(a, b, c) \
33 (((a) << 16L) | ((b) << 8) | (c))
35 #define GCC_GMP_VERSION \
36 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
38 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,2)
44 #if MPFR_VERSION < MPFR_VERSION_NUM(2, 4, 2)
50 #if MPC_VERSION < MPC_VERSION_NUM(0, 8, 1)
55 BINUTILS_VERSION
="2.23.1"
61 BINUTILS
="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2"
62 GCC
="gcc-${GCC_VERSION}.tar.bz2"
63 GDB
="gdb-${GDB_VERSION}.tar.bz2"
66 # Check if the library described in the argument
67 # exists and has acceptable version.
74 FNAME
="/tmp/conftest-$$"
76 echo "#include ${HEADER}" > "${FNAME}.c"
78 echo "int main()" >> "${FNAME}.c"
79 echo "{" >> "${FNAME}.c"
80 echo "${BODY}" >> "${FNAME}.c"
81 echo " return 0;" >> "${FNAME}.c"
82 echo "}" >> "${FNAME}.c"
84 cc
-c -o "${FNAME}.o" "${FNAME}.c" 2> "${FNAME}.log"
87 if [ "$RC" -ne "0" ] ; then
88 echo " ${DEPENDENCY} not found, too old or compiler error."
89 echo " Please recheck manually the source file \"${FNAME}.c\"."
90 echo " The compilation of the toolchain is probably going to fail,"
91 echo " you have been warned."
93 echo " ===== Compiler output ====="
95 echo " ==========================="
98 echo " ${DEPENDENCY} found"
99 rm -f "${FNAME}.log" "${FNAME}.o" "${FNAME}.c"
103 check_dependecies
() {
104 echo ">>> Basic dependency check"
105 check_dependency
"GMP" "<gmp.h>" "${GMP_MAIN}"
106 check_dependency
"MPFR" "<mpfr.h>" "${MPFR_MAIN}"
107 check_dependency
"MPC" "<mpc.h>" "${MPC_MAIN}"
112 if [ "$1" -ne "0" ]; then
114 echo "Script failed: $2"
124 COMPUTED
="`md5sum "${FILE}" | cut -d' ' -f1`"
125 if [ "${SUM}" != "${COMPUTED}" ] ; then
127 echo "Checksum of ${FILE} does not match."
134 echo "Cross-compiler toolchain build script"
137 echo " $0 <platform>"
139 echo "Possible target platforms are:"
140 echo " amd64 AMD64 (x86-64, x64)"
142 echo " ia32 IA-32 (x86, i386)"
143 echo " ia64 IA-64 (Itanium)"
144 echo " mips32 MIPS little-endian 32b"
145 echo " mips32eb MIPS big-endian 32b"
146 echo " mips64 MIPS little-endian 64b"
147 echo " ppc32 32-bit PowerPC"
148 echo " ppc64 64-bit PowerPC"
149 echo " sparc64 SPARC V9"
150 echo " all build all targets"
151 echo " parallel same as 'all', but all in parallel"
152 echo " 2-way same as 'all', but 2-way parallel"
154 echo "The toolchain will be installed to the directory specified by"
155 echo "the CROSS_PREFIX environment variable. If the variable is not"
156 echo "defined, /usr/local/cross will be used by default."
169 if [ "${TM}" -eq 0 ] ; then
178 TM
="`expr "${TM}" - 1`"
179 show_countdown
"${TM}"
182 show_dependencies
() {
183 echo "IMPORTANT NOTICE:"
185 echo "For a successful compilation and use of the cross-compiler"
186 echo "toolchain you need at least the following dependencies."
188 echo "Please make sure that the dependencies are present in your"
189 echo "system. Otherwise the compilation process might fail after"
190 echo "a few seconds or minutes."
192 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
193 echo " - gettext, zlib, Texinfo, libelf, libgomp"
195 echo " - GNU Multiple Precision Library (GMP)"
198 echo " - GNU Coreutils"
199 echo " - GNU Sharutils"
202 echo " - Parma Polyhedra Library (PPL)"
204 echo " - native C compiler, assembler and linker"
205 echo " - native C library with headers"
214 if [ ! -f "${FILE}" ]; then
215 change_title
"Downloading ${FILE}"
216 wget
-c "${SOURCE}${FILE}"
217 check_error $?
"Error downloading ${FILE}."
220 check_md5
"${FILE}" "${CHECKSUM}"
226 if [ ! -f "${FILE}" ]; then
228 echo "File ${FILE} not found."
237 if [ -d "${DIR}" ]; then
238 change_title
"Removing ${DIR}"
239 echo " >>> Removing ${DIR}"
248 change_title
"Creating ${DESC}"
249 echo ">>> Creating ${DESC}"
253 check_error $?
"Unable to create ${DIR}."
260 change_title
"Unpacking ${DESC}"
261 echo " >>> Unpacking ${DESC}"
264 check_error $?
"Error unpacking ${DESC}."
272 BINUTILS_SOURCE
="ftp://ftp.gnu.org/gnu/binutils/"
273 GCC_SOURCE
="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
274 GDB_SOURCE
="ftp://ftp.gnu.org/gnu/gdb/"
276 download_fetch
"${BINUTILS_SOURCE}" "${BINUTILS}" "33adb18c3048d057ac58d07a3f1adb38"
277 download_fetch
"${GCC_SOURCE}" "${GCC}" "e6040024eb9e761c3bea348d1fa5abb0"
278 download_fetch
"${GDB_SOURCE}" "${GDB}" "3f48f468b24447cf24820054ff6e85b1"
285 WORKDIR
="${BASEDIR}/${PLATFORM}"
286 BINUTILSDIR
="${WORKDIR}/binutils-${BINUTILS_VERSION}"
287 GCCDIR
="${WORKDIR}/gcc-${GCC_VERSION}"
288 OBJDIR
="${WORKDIR}/gcc-obj"
289 GDBDIR
="${WORKDIR}/gdb-${GDB_VERSION}"
291 if [ -z "${CROSS_PREFIX}" ] ; then
292 CROSS_PREFIX
="/usr/local/cross"
295 PREFIX
="${CROSS_PREFIX}/${PLATFORM}"
297 echo ">>> Downloading tarballs"
298 source_check
"${BASEDIR}/${BINUTILS}"
299 source_check
"${BASEDIR}/${GCC}"
300 source_check
"${BASEDIR}/${GDB}"
302 echo ">>> Removing previous content"
303 cleanup_dir
"${PREFIX}"
304 cleanup_dir
"${WORKDIR}"
306 create_dir
"${PREFIX}" "destination directory"
307 create_dir
"${OBJDIR}" "GCC object directory"
309 echo ">>> Unpacking tarballs"
311 check_error $?
"Change directory failed."
313 unpack_tarball
"${BASEDIR}/${BINUTILS}" "binutils"
314 unpack_tarball
"${BASEDIR}/${GCC}" "GCC"
315 unpack_tarball
"${BASEDIR}/${GDB}" "GDB"
317 echo ">>> Processing binutils (${PLATFORM})"
319 check_error $?
"Change directory failed."
321 change_title
"binutils: configure (${PLATFORM})"
322 CFLAGS
=-Wno-error .
/configure
"--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
323 check_error $?
"Error configuring binutils."
325 change_title
"binutils: make (${PLATFORM})"
327 check_error $?
"Error compiling/installing binutils."
329 echo ">>> Processing GCC (${PLATFORM})"
331 check_error $?
"Change directory failed."
333 change_title
"GCC: configure (${PLATFORM})"
334 "${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
335 check_error $?
"Error configuring GCC."
337 change_title
"GCC: make (${PLATFORM})"
338 PATH
="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
339 check_error $?
"Error compiling/installing GCC."
341 echo ">>> Processing GDB (${PLATFORM})"
343 check_error $?
"Change directory failed."
345 change_title
"GDB: configure (${PLATFORM})"
346 .
/configure
"--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
347 check_error $?
"Error configuring GDB."
349 change_title
"GDB: make (${PLATFORM})"
351 check_error $?
"Error compiling/installing GDB."
354 check_error $?
"Change directory failed."
356 echo ">>> Cleaning up"
357 cleanup_dir
"${WORKDIR}"
360 echo ">>> Cross-compiler for ${TARGET} installed."
363 if [ "$#" -lt "1" ]; then
370 build_target
"amd64" "amd64-linux-gnu"
374 build_target
"arm32" "arm-linux-gnueabi"
378 build_target
"ia32" "i686-pc-linux-gnu"
382 build_target
"ia64" "ia64-pc-linux-gnu"
386 build_target
"mips32" "mipsel-linux-gnu"
390 build_target
"mips32eb" "mips-linux-gnu"
394 build_target
"mips64" "mips64el-linux-gnu"
398 build_target
"ppc32" "ppc-linux-gnu"
402 build_target
"ppc64" "ppc64-linux-gnu"
406 build_target
"sparc64" "sparc64-linux-gnu"
410 build_target
"amd64" "amd64-linux-gnu"
411 build_target
"arm32" "arm-linux-gnueabi"
412 build_target
"ia32" "i686-pc-linux-gnu"
413 build_target
"ia64" "ia64-pc-linux-gnu"
414 build_target
"mips32" "mipsel-linux-gnu"
415 build_target
"mips32eb" "mips-linux-gnu"
416 build_target
"mips64" "mips64el-linux-gnu"
417 build_target
"ppc32" "ppc-linux-gnu"
418 build_target
"ppc64" "ppc64-linux-gnu"
419 build_target
"sparc64" "sparc64-linux-gnu"
423 build_target
"amd64" "amd64-linux-gnu" &
424 build_target
"arm32" "arm-linux-gnueabi" &
425 build_target
"ia32" "i686-pc-linux-gnu" &
426 build_target
"ia64" "ia64-pc-linux-gnu" &
427 build_target
"mips32" "mipsel-linux-gnu" &
428 build_target
"mips32eb" "mips-linux-gnu" &
429 build_target
"mips64" "mips64el-linux-gnu" &
430 build_target
"ppc32" "ppc-linux-gnu" &
431 build_target
"ppc64" "ppc64-linux-gnu" &
432 build_target
"sparc64" "sparc64-linux-gnu" &
437 build_target
"amd64" "amd64-linux-gnu" &
438 build_target
"arm32" "arm-linux-gnueabi" &
441 build_target
"ia32" "i686-pc-linux-gnu" &
442 build_target
"ia64" "ia64-pc-linux-gnu" &
445 build_target
"mips32" "mipsel-linux-gnu" &
446 build_target
"mips32eb" "mips-linux-gnu" &
449 build_target
"mips64" "mips64el-linux-gnu" &
450 build_target
"ppc32" "ppc-linux-gnu" &
453 build_target
"ppc64" "ppc64-linux-gnu" &
454 build_target
"sparc64" "sparc64-linux-gnu" &