3 # Copyright (C) 2008-2009 by coresystems GmbH
4 # written by Patrick Georgi <patrick.georgi@coresystems.de> and
5 # Stefan Reinauer <stefan.reinauer@coresystems.de>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 CROSSGCC_DATE="August 18th, 2009"
22 CROSSGCC_VERSION="0.9"
33 BINUTILS_VERSION=2.19.1
37 GMP_ARCHIVE="ftp://ftp.gmplib.org/pub/gmp-${GMP_VERSION}/gmp-${GMP_VERSION}.tar.bz2"
38 MPFR_ARCHIVE="http://www.mpfr.org/mpfr-${MPFR_VERSION}/mpfr-${MPFR_VERSION}.tar.bz2"
39 GCC_ARCHIVE="ftp://ftp.gwdg.de/pub/gnu/ftp/gnu/gcc/gcc-${GCC_VERSION}/gcc-core-${GCC_VERSION}.tar.bz2"
40 BINUTILS_ARCHIVE="http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.bz2"
41 GDB_ARCHIVE="http://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.bz2"
43 GMP_DIR="gmp-${GMP_VERSION}"
44 MPFR_DIR="mpfr-${MPFR_VERSION}"
45 GCC_DIR="gcc-${GCC_VERSION}"
46 BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
47 GDB_DIR="gdb-${GDB_VERSION}"
64 # result: GNU version of that tool on stdout
65 # or no output if no GNU version was found
66 for i in "$1" "g$1" "gnu$1"; do
67 if test -x "`which $i 2>/dev/null`"; then
68 if test `$i --version 2>/dev/null |grep -c GNU` -gt 0; then
74 printf "${RED}ERROR:${red} Missing toolchain: $1${NC}\n" >&2
79 PATCH=`searchgnu patch`
84 printf "Cleaning up temporary files... "
85 rm -rf build-* combined gcc-* gmp-* mpfr-* binutils-* gdb-*
86 printf "${green}ok${NC}\n"
91 printf "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>]\n"
92 printf " $0 [-V|--version]\n"
93 printf " $0 [-h|--help]\n\n"
96 printf " [-V|--version] print version number and exit\n"
97 printf " [-h|--help] print this help and exit\n"
98 printf " [-c|--clean] remove temporary files before build\n"
99 printf " [-t|--savetemps] don't remove temporary files after build\n"
100 printf " [-p|--platform <platform>] target platform to build cross compiler for\n"
101 printf " (defaults to $TARGETARCH)\n"
102 printf " [-d|--directory <target dir>] target directory to install cross compiler to\n"
103 printf " (defaults to $TARGETDIR)\n\n"
104 printf " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
105 printf " (for RPM builds, default unset)\n\n"
110 # version tag is always printed, so just print the license here
113 Copyright (C) 2008-2009 by coresystems GmbH
115 This program is free software; you can redistribute it and/or modify
116 it under the terms of the GNU General Public License as published by
117 the Free Software Foundation; version 2 of the License.
119 This program is distributed in the hope that it will be useful,
120 but WITHOUT ANY WARRANTY; without even the implied warranty of
121 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
122 GNU General Public License for more details.
127 printf "${blue}Welcome to the ${red}coresystems${blue} cross toolchain builder v$CROSSGCC_VERSION ($CROSSGCC_DATE)${NC}\n\n"
129 # parse parameters.. try to find out whether we're running GNU getopt
130 getoptbrand="`getopt -V`"
131 if [ "${getoptbrand:0:6}" == "getopt" ]; then
132 # Detected GNU getopt that supports long options.
133 args=`getopt -l version,help,clean,directory:,platform:,destdir:,savetemps Vhcd:p:D:t -- "$@"`
136 # Detected non-GNU getopt
137 args=`getopt Vhcd:p:D:t $*`
148 -V|--version) shift; myversion; exit 0;;
149 -h|--help) shift; myhelp; exit 0;;
150 -c|--clean) shift; cleanup;;
151 -t|--savetemps) shift; SAVETEMPS=1;;
152 -d|--directory) shift; TARGETDIR="$1"; shift;;
153 -p|--platform) shift; TARGETARCH="$1"; shift;;
154 -D|--destdir) shift; DESTDIR="$1"; shift;;
156 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
161 printf "Downloading tar balls ... \n"
163 for ARCHIVE in $GMP_ARCHIVE $MPFR_ARCHIVE $GCC_ARCHIVE $BINUTILS_ARCHIVE $GDB_ARCHIVE; do
164 FILE=`basename $ARCHIVE`
166 test -f tarballs/$FILE && printf "(cached)" || (
167 printf "(downloading)"
171 test -f tarballs/$FILE || printf "Failed to download $FILE.\n"
172 test -f tarballs/$FILE || exit 1
175 printf "Downloaded tar balls ... "
176 printf "${green}ok${NC}\n"
178 printf "Unpacking and patching ... \n"
179 for PACKAGE in GMP MPFR GCC BINUTILS GDB; do
180 archive=$PACKAGE"_ARCHIVE"
184 printf " * `basename $archive`\n"
186 test ${archive:${#archive}-2:2} = "gz" && FLAGS=zxf
187 test ${archive:${#archive}-3:3} = "bz2" && FLAGS=jxf
188 $TAR $FLAGS tarballs/`basename $archive`
189 for patch in patches/${!dir}"_*.patch"; do
190 test -r $patch || continue
191 printf " o `basename $patch`\n"
192 patch -s -N -p0 < `echo $patch`
196 printf "Unpacked and patched ... "
197 printf "${green}ok${NC}\n"
199 mkdir -p build-gmp build-mpfr build-binutils build-gcc build-gdb
200 if [ -f build-gmp/.success ]; then
201 printf "Skipping GMP as it is already built\n"
203 printf "Building GMP ${GMP_VERSION} ... "
207 if [ `uname` = "Darwin" ]; then
208 # generally the OS X compiler can create x64 binaries.
209 # Per default it generated i386 binaries in 10.5 and x64
210 # binaries in 10.6 (even if the kernel is 32bit)
211 # For some weird reason, 10.5 autodetects an ABI=64 though
212 # so we're setting the ABI explicitly here.
214 touch .architecture_check.c
215 gcc .architecture_check.c -c -o .architecture_check.o
216 ARCH=`file .architecture_check.o |cut -f5 -d\ `
217 test "$ARCH" = "x86_64" && OPTIONS="ABI=64"
218 rm .architecture_check.c .architecture_check.o
221 ../${GMP_DIR}/configure --disable-shared --prefix=$TARGETDIR $OPTIONS \
223 $MAKE || touch .failed
224 $MAKE install DESTDIR=$DESTDIR || touch .failed
225 if [ ! -f .failed ]; then touch .success; fi
226 ) &> build-gmp/crossgcc-build.log
227 test -r build-gmp/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
228 test -r build-gmp/.failed && exit 1
231 #if [ "$DESTDIR" != "" -a ! -x $TARGETDIR ]; then
232 # # create compat link
233 # ln -s $DESTDIR$TARGETDIR $TARGETDIR
236 # Now set CFLAGS to match GMP CFLAGS.
237 HOSTCFLAGS=`grep __GMP_CFLAGS $DESTDIR$TARGETDIR/include/gmp.h |cut -d\" -f2`
239 if [ -f build-mpfr/.success ]; then
240 printf "Skipping MPFR as it is already built\n"
242 printf "Building MPFR ${MPFR_VERSION} ... "
244 test `uname` = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
247 ../${MPFR_DIR}/configure --disable-shared --prefix=$TARGETDIR \
248 --infodir=$TARGETDIR/info \
249 --with-gmp=$DESTDIR$TARGETDIR CFLAGS="$HOSTCFLAGS" || touch .failed
250 $MAKE || touch .failed
251 $MAKE install DESTDIR=$DESTDIR || touch .failed
253 # work around build problem of libgmp.la
254 if [ "$DESTDIR" != "" ]; then
255 perl -pi -e "s,$DESTDIR,," $DESTDIR$TARGETDIR/libgmp.la
258 if [ ! -f .failed ]; then touch .success; fi
259 ) &> build-mpfr/crossgcc-build.log
260 test -r build-mpfr/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
261 test -r build-mpfr/.failed && exit 1
264 if [ -f build-binutils/.success ]; then
265 printf "Skipping binutils as it is already built\n"
267 printf "Building binutils ${BINUTILS_VERSION} ... "
271 ../binutils-${BINUTILS_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \
272 --disable-werror --disable-nls \
273 CFLAGS="$HOSTCFLAGS" || touch .failed
274 $MAKE || touch .failed
275 $MAKE install DESTDIR=$DESTDIR || touch .failed
276 if [ ! -f .failed ]; then touch .success; fi
277 ) &> build-binutils/crossgcc-build.log
278 test -r build-binutils/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
279 test -r build-binutils/.failed && exit 1
282 if [ -f build-gcc/.success ]; then
283 printf "Skipping GCC as it is already built\n"
285 printf "Building GCC ${GCC_VERSION} ... "
289 # GCC does not honour HOSTCFLAGS at all. CFLAGS are used for
290 # both target and host object files. This is pretty misdesigned.
291 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
292 # but it does not seem to work properly. At least the host library
293 # libiberty is not compiled with CFLAGS_FOR_BUILD.
294 CFLAGS_FOR_BUILD="$HOSTCFLAGS" ../gcc-${GCC_VERSION}/configure \
295 --prefix=$TARGETDIR --libexecdir=$TARGETDIR/lib \
296 --target=${TARGETARCH} --disable-werror \
297 --disable-libssp --disable-bootstrap --disable-nls \
298 --with-gmp=$DESTDIR$TARGETDIR --with-mpfr=$DESTDIR$TARGETDIR \
300 $MAKE CFLAGS_FOR_BUILD="$HOSTCFLAGS" || touch .failed
301 $MAKE install DESTDIR=$DESTDIR || touch .failed
302 if [ ! -f .failed ]; then touch .success; fi
303 ) &> build-gcc/crossgcc-build.log
304 test -r build-gcc/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
305 test -r build-gcc/.failed && exit 1
308 if [ -f build-gdb/.success ]; then
309 printf "Skipping GDB as it is already built\n"
311 printf "Building GDB ${GDB_VERSION} ... "
314 export PATH=$PATH:$PREFIX/bin
316 ../gdb-${GDB_VERSION}/configure --prefix=$TARGETDIR --target=${TARGETARCH} \
317 --disable-werror --disable-nls
318 $MAKE || touch .failed
319 $MAKE install DESTDIR=$DESTDIR || touch .failed
320 if [ ! -f .failed ]; then touch .success; fi
321 ) &> build-gdb/crossgcc-build.log
322 test -r build-gdb/.failed && printf "${RED}failed${NC}\n" || printf "${green}ok${NC}\n"
323 test -r build-gdb/.failed && exit 1
326 if [ $SAVETEMPS -eq 0 ]; then
327 printf "Cleaning up... "
328 rm -rf ${GMP_DIR} build-gmp
329 rm -rf ${MPFR_DIR} build-mpfr
330 rm -rf ${BINUTILS_DIR} build-binutils
331 rm -rf ${GCC_DIR} build-gcc
332 rm -rf ${GDB_DIR} build-gdb
333 printf "${green}ok${NC}\n"
335 printf "Leaving temporary files around... ${green}ok${NC}\n"
338 printf "\n${green}You can now run your $TARGETARCH cross toolchain from $TARGETDIR.${NC}\n"