3 ############################################################################
5 # Script for generating a PowerPC cross compiler using crosstool.
7 # Copyright (C) 2009 Bart Van Assche <bvanassche@acm.org>.
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation, version 2
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 ############################################################################
21 #########################
22 # Function definitions #
23 #########################
25 # Print an error message and exit.
27 echo "build failed: $@"
31 # Print command-line help.
34 Usage: $0 [-h] [-t crosstools-directory] [gcc-version glibc-version]
38 # Extract and run crosstool for the specified gcc and glibc versions.
39 generate_cross_compiler() {
41 export GLIBC_DIR=glibc-$2
43 export GLIBCTHREADS_FILENAME=glibc-linuxthreads-$2
44 # glibc-crypt is only needed for glibc 2.1.x and earlier glibc versions.
45 unset GLIBCCRYPT_FILENAME
46 if [ "${2#2.1.}" != "${2}" ]; then
47 GLIBCCRYPT_FILENAME=glibc-crypt-2.1
49 export GLIBCCRYPT_FILENAME
51 if [ "${1#4.}" != "${1}" -a "${2#2.[12].}" != "$2" ]; then
52 # Use gcc 2.95.3 for compiling glibc 2.1.* and glibc 2.2.*.
53 GCC_CORE_DIR=gcc-2.95.3
55 GCC_CORE_DIR=gcc-3.3.6
59 export GCC_EXTRA_CONFIG="--disable-linux-futex --disable-mudflap --disable-nls"
62 # gcc 4.x aborts with a syntax error on glibc's inline functions if you do
63 # not specify -fgnu89-inline.
64 #if [ "${1#4.}" != "${1}" ]; then
65 # export TARGET_FLAGS="$TARGET_FLAGS -fgnu89-inline"
68 if ! /bin/rm -rf $RESULT_TOP/${GCC_DIR}-${GLIBC_DIR}; then
69 abort "Need write permission in $RESULT_TOP/${GCC_DIR}-${GLIBC_DIR}"
71 if ! /bin/mkdir -p $RESULT_TOP/$GCC_DIR-$GLIBC_DIR/$TARGET; then
72 abort "Need write permission in $RESULT_TOP/${GCC_DIR}-${GLIBC_DIR}/$TARGET"
75 /bin/rm -rf $CROSSTOOL_FOLDER
76 if [ ! -e $TARBALLS_DIR/crosstool-${CROSSTOOL_VERSION}.tar.gz ]; then
78 if cd $TARBALLS_DIR; then
79 wget -q -nc "http://kegel.com/crosstool/crosstool-${CROSSTOOL_VERSION}.tar.gz"
83 /bin/tar -zxf $TARBALLS_DIR/crosstool-${CROSSTOOL_VERSION}.tar.gz
84 /bin/tar -C patches -cf - . | /bin/tar -C $CROSSTOOL_FOLDER/patches -xf -
87 for f in ../crosstool-patches/*
89 patch -p1 -f < "$f" || exit $?
93 # /bin/rm -rf $CROSSTOOL_FOLDER
97 #########################
98 # Argument processing #
99 #########################
101 if [ "$SHELL" = "/bin/tcsh" ]; then
102 abort "tcsh is not supported."
105 set -- $(/usr/bin/getopt ht: "$@")
106 while [ "${1#-}" != "${1}" ]; do
109 -t) result_top="$2"; shift; shift;;
114 #########################
116 #########################
118 set -e # Exit immediately if a simple command fails.
119 set -x # Enable echo mode.
121 # Variables that are ignored by crosstool.
123 CROSSTOOL_VERSION=0.43
124 CROSSTOOL_FOLDER=$PWD/crosstool-$CROSSTOOL_VERSION
125 KERNEL_VERSION=2.6.22
129 # Variables that are used by the crosstool script as input.
131 # Directory where cross-compilation tools will be installed.
132 export RESULT_TOP=${result_top:-$HOME/x86_64-ppc}
133 # Directory where the tool tar files can be found.
134 export TARBALLS_DIR=$HOME/software/downloads
135 # Target architecture: Pentium CPU, Linux OS.
136 export TARGET=powerpc-linux
137 # Compilation flags for target tools such as glibc.
138 export TARGET_CFLAGS="-O"
140 export BINUTILS_DIR=binutils-2.16.1
141 # Languages that must be supported by the gcc cross-compiler.
142 export GCC_LANGUAGES="c,c++"
144 export GDB_DIR=gdb-6.8
145 # Linux kernel version.
146 export LINUX_DIR=linux-$KERNEL_VERSION
147 # Linux kernel config.
148 export KERNELCONFIG=$PWD/kernel-config/$KERNEL_VERSION/.config
150 export PARALLELMFLAGS="-s -j3"
152 ##############################
153 # Cross-compiler generation. #
154 ##############################
156 if ! /bin/mkdir -p $RESULT_TOP; then
157 abort "You need write permission in $RESULT_TOP"
160 if [ "$#" = 0 ]; then
161 generate_cross_compiler 4.1.1 2.3.6
162 elif [ "$#" = 2 ]; then
163 generate_cross_compiler "$1" "$2"
166 abort "Wrong number of arguments."