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.22"
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"
194 echo " - GNU Multiple Precision Library (GMP)"
197 echo " - GNU Coreutils"
198 echo " - GNU Sharutils"
201 echo " - Parma Polyhedra Library (PPL)"
203 echo " - native C compiler, assembler and linker"
204 echo " - native C library with headers"
213 if [ ! -f "${FILE}" ]; then
214 change_title
"Downloading ${FILE}"
215 wget
-c "${SOURCE}${FILE}"
216 check_error $?
"Error downloading ${FILE}."
219 check_md5
"${FILE}" "${CHECKSUM}"
225 if [ ! -f "${FILE}" ]; then
227 echo "File ${FILE} not found."
236 if [ -d "${DIR}" ]; then
237 change_title
"Removing ${DIR}"
238 echo " >>> Removing ${DIR}"
247 change_title
"Creating ${DESC}"
248 echo ">>> Creating ${DESC}"
252 check_error $?
"Unable to create ${DIR}."
259 change_title
"Unpacking ${DESC}"
260 echo " >>> Unpacking ${DESC}"
263 check_error $?
"Error unpacking ${DESC}."
271 BINUTILS_SOURCE
="ftp://ftp.gnu.org/gnu/binutils/"
272 GCC_SOURCE
="ftp://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/"
273 GDB_SOURCE
="ftp://ftp.gnu.org/gnu/gdb/"
275 download_fetch
"${BINUTILS_SOURCE}" "${BINUTILS}" "ee0f10756c84979622b992a4a61ea3f5"
276 download_fetch
"${GCC_SOURCE}" "${GCC}" "933e6f15f51c031060af64a9e14149ff"
277 download_fetch
"${GDB_SOURCE}" "${GDB}" "95a9a8305fed4d30a30a6dc28ff9d060"
284 WORKDIR
="${BASEDIR}/${PLATFORM}"
285 BINUTILSDIR
="${WORKDIR}/binutils-${BINUTILS_VERSION}"
286 GCCDIR
="${WORKDIR}/gcc-${GCC_VERSION}"
287 OBJDIR
="${WORKDIR}/gcc-obj"
288 GDBDIR
="${WORKDIR}/gdb-${GDB_VERSION}"
290 if [ -z "${CROSS_PREFIX}" ] ; then
291 CROSS_PREFIX
="/usr/local/cross"
294 PREFIX
="${CROSS_PREFIX}/${PLATFORM}"
296 echo ">>> Downloading tarballs"
297 source_check
"${BASEDIR}/${BINUTILS}"
298 source_check
"${BASEDIR}/${GCC}"
299 source_check
"${BASEDIR}/${GDB}"
301 echo ">>> Removing previous content"
302 cleanup_dir
"${PREFIX}"
303 cleanup_dir
"${WORKDIR}"
305 create_dir
"${PREFIX}" "destination directory"
306 create_dir
"${OBJDIR}" "GCC object directory"
308 echo ">>> Unpacking tarballs"
310 check_error $?
"Change directory failed."
312 unpack_tarball
"${BASEDIR}/${BINUTILS}" "binutils"
313 unpack_tarball
"${BASEDIR}/${GCC}" "GCC"
314 unpack_tarball
"${BASEDIR}/${GDB}" "GDB"
316 echo ">>> Processing binutils (${PLATFORM})"
318 check_error $?
"Change directory failed."
320 change_title
"binutils: configure (${PLATFORM})"
321 CFLAGS
=-Wno-error .
/configure
"--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-" --disable-nls --disable-werror
322 check_error $?
"Error configuring binutils."
324 change_title
"binutils: make (${PLATFORM})"
326 check_error $?
"Error compiling/installing binutils."
328 echo ">>> Processing GCC (${PLATFORM})"
330 check_error $?
"Change directory failed."
332 change_title
"GCC: configure (${PLATFORM})"
333 "${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
334 check_error $?
"Error configuring GCC."
336 change_title
"GCC: make (${PLATFORM})"
337 PATH
="${PATH}:${PREFIX}/bin" make all-gcc install-gcc
338 check_error $?
"Error compiling/installing GCC."
340 echo ">>> Processing GDB (${PLATFORM})"
342 check_error $?
"Change directory failed."
344 change_title
"GDB: configure (${PLATFORM})"
345 .
/configure
"--target=${TARGET}" "--prefix=${PREFIX}" "--program-prefix=${TARGET}-"
346 check_error $?
"Error configuring GDB."
348 change_title
"GDB: make (${PLATFORM})"
350 check_error $?
"Error compiling/installing GDB."
353 check_error $?
"Change directory failed."
355 echo ">>> Cleaning up"
356 cleanup_dir
"${WORKDIR}"
359 echo ">>> Cross-compiler for ${TARGET} installed."
362 if [ "$#" -lt "1" ]; then
369 build_target
"amd64" "amd64-linux-gnu"
373 build_target
"arm32" "arm-linux-gnueabi"
377 build_target
"ia32" "i686-pc-linux-gnu"
381 build_target
"ia64" "ia64-pc-linux-gnu"
385 build_target
"mips32" "mipsel-linux-gnu"
389 build_target
"mips32eb" "mips-linux-gnu"
393 build_target
"mips64" "mips64el-linux-gnu"
397 build_target
"ppc32" "ppc-linux-gnu"
401 build_target
"ppc64" "ppc64-linux-gnu"
405 build_target
"sparc64" "sparc64-linux-gnu"
409 build_target
"amd64" "amd64-linux-gnu"
410 build_target
"arm32" "arm-linux-gnueabi"
411 build_target
"ia32" "i686-pc-linux-gnu"
412 build_target
"ia64" "ia64-pc-linux-gnu"
413 build_target
"mips32" "mipsel-linux-gnu"
414 build_target
"mips32eb" "mips-linux-gnu"
415 build_target
"mips64" "mips64el-linux-gnu"
416 build_target
"ppc32" "ppc-linux-gnu"
417 build_target
"ppc64" "ppc64-linux-gnu"
418 build_target
"sparc64" "sparc64-linux-gnu"
422 build_target
"amd64" "amd64-linux-gnu" &
423 build_target
"arm32" "arm-linux-gnueabi" &
424 build_target
"ia32" "i686-pc-linux-gnu" &
425 build_target
"ia64" "ia64-pc-linux-gnu" &
426 build_target
"mips32" "mipsel-linux-gnu" &
427 build_target
"mips32eb" "mips-linux-gnu" &
428 build_target
"mips64" "mips64el-linux-gnu" &
429 build_target
"ppc32" "ppc-linux-gnu" &
430 build_target
"ppc64" "ppc64-linux-gnu" &
431 build_target
"sparc64" "sparc64-linux-gnu" &
436 build_target
"amd64" "amd64-linux-gnu" &
437 build_target
"arm32" "arm-linux-gnueabi" &
440 build_target
"ia32" "i686-pc-linux-gnu" &
441 build_target
"ia64" "ia64-pc-linux-gnu" &
444 build_target
"mips32" "mipsel-linux-gnu" &
445 build_target
"mips32eb" "mips-linux-gnu" &
448 build_target
"mips64" "mips64el-linux-gnu" &
449 build_target
"ppc32" "ppc-linux-gnu" &
452 build_target
"ppc64" "ppc64-linux-gnu" &
453 build_target
"sparc64" "sparc64-linux-gnu" &