root/scripts/build_arm_toolchain.sh

Revision 562:b8f202cf1188, 4.4 kB (checked in by David Anderson <dave@…>, 7 months ago)

Move the ARM toolchain builder script to the top-level scripts directory.

  • Property exe set to *
Line 
1#!/bin/sh
2#
3# Copyright (c) 2008 the NxOS developers
4#
5# See AUTHORS for a full list of the developers.
6#
7# Redistribution of this file is permitted under
8# the terms of the GNU Public License (GPL) version 2.
9#
10# Build an ARM cross-compiler toolchain (including binutils, gcc and
11# newlib) on autopilot.
12
13ROOT=`pwd`
14SRCDIR=$ROOT/src
15BUILDDIR=$ROOT/build
16PREFIX=$ROOT/install
17
18GCC_URL=ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/releases/gcc-4.2.2/gcc-core-4.2.2.tar.bz2
19GCC_VERSION=4.2.2
20GCC_DIR=gcc-$GCC_VERSION
21
22BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2
23BINUTILS_VERSION=2.18
24BINUTILS_DIR=binutils-$BINUTILS_VERSION
25
26NEWLIB_URL=ftp://sources.redhat.com/pub/newlib/newlib-1.15.0.tar.gz
27NEWLIB_VERSION=1.15.0
28NEWLIB_DIR=newlib-$NEWLIB_VERSION
29
30echo "I will build an arm-elf cross-compiler:
31
32  Prefix: $PREFIX
33  Sources: $SRCDIR
34  Build files: $BUILDDIR
35
36Press ^C now if you do NOT want to do this."
37read IGNORE
38
39#
40# Helper functions.
41#
42ensure_source()
43{
44    URL=$1
45    FILE=$(basename $1)
46
47    if [ ! -e $FILE ]; then
48        wget -O$FILE $URL
49    fi
50}
51
52unpack_source()
53{
54(
55    cd $SRCDIR
56    ARCHIVE_SUFFIX=${1##*.}
57    if [ "$ARCHIVE_SUFFIX" = "gz" ]; then
58      tar zxvf $1
59    elif [ "$ARCHIVE_SUFFIX" = "bz2" ]; then
60      tar jxvf $1
61    else
62      echo "Unknown archive format for $1"
63      exit 1
64    fi
65)
66}
67
68# Create all the directories we need.
69mkdir -p $SRCDIR $BUILDDIR $PREFIX
70
71(
72cd $SRCDIR
73
74# First grab all the source files...
75ensure_source $GCC_URL
76ensure_source $BINUTILS_URL
77ensure_source $NEWLIB_URL
78
79# ... And unpack the sources.
80unpack_source $(basename $GCC_URL)
81unpack_source $(basename $BINUTILS_URL)
82unpack_source $(basename $NEWLIB_URL)
83)
84
85# Set the PATH to include the binaries we're going to build.
86OLD_PATH=$PATH
87export PATH=$PREFIX/bin:$PATH
88
89#
90# Stage 1: Build binutils
91#
92(
93(
94# First we need to patch binutils, because makeinfo 4.11 fails the
95# autoconf check.
96cd $SRCDIR/$BINUTILS_DIR
97patch -p0 <<"EOF"
98--- configure~ 2007-10-10 22:14:56.000000000 +1300
99+++ configure 2007-10-10 22:14:56.000000000 +1300
100@@ -3680,7 +3680,7 @@
101     # For an installed makeinfo, we require it to be from texinfo 4.4 or
102     # higher, else we use the "missing" dummy.
103     if ${MAKEINFO} --version \
104-       | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[4-9]|[5-9])' >/dev/null 2>&1; then
105+       | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.([4-9]|[1-9][0-9])|[5-9])' >/dev/null 2>&1; then
106       :
107     else
108       MAKEINFO="$MISSING makeinfo"
109EOF
110) || exit 1
111
112# Now, build it.
113mkdir -p $BUILDDIR/$BINUTILS_DIR
114cd $BUILDDIR/$BINUTILS_DIR
115
116$SRCDIR/$BINUTILS_DIR/configure --target=arm-elf --prefix=$PREFIX \
117    --enable-interwork --enable-multilib --with-float=soft \
118    && make all install
119) || exit 1
120
121#
122# Stage 2: Patch the GCC multilib rules, then build the gcc compiler only
123#
124(
125MULTILIB_CONFIG=$SRCDIR/$GCC_DIR/gcc/config/arm/t-arm-elf
126
127echo "
128
129MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork
130MULTILIB_DIRNAMES += normal interwork
131
132" >> $MULTILIB_CONFIG
133
134mkdir -p $BUILDDIR/$GCC_DIR
135cd $BUILDDIR/$GCC_DIR
136
137$SRCDIR/$GCC_DIR/configure --target=arm-elf --prefix=$PREFIX \
138    --enable-interwork --enable-multilib --with-float=soft \
139    --enable-languages="c" --with-newlib \
140    --with-headers=$SRCDIR/$NEWLIB_DIR/newlib/libc/include \
141    && make all-gcc install-gcc
142) || exit 1
143
144#
145# Stage 3: Build and install newlib
146#
147(
148(
149# Same issue, we have to patch to support makeinfo >= 4.11.
150cd $SRCDIR/$NEWLIB_DIR
151patch -p0 <<"EOF"
152--- configure~ 2007-10-10 22:14:56.000000000 +1300
153+++ configure 2007-10-10 22:14:56.000000000 +1300
154@@ -3680,7 +3680,7 @@
155     # For an installed makeinfo, we require it to be from texinfo 4.4 or
156     # higher, else we use the "missing" dummy.
157     if ${MAKEINFO} --version \
158-       | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[4-9]|[5-9])' >/dev/null 2>&1; then
159+       | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.([4-9]|[1-9][0-9])|[5-9])' >/dev/null 2>&1; then
160       :
161     else
162       MAKEINFO="$MISSING makeinfo"
163EOF
164) || exit 1
165
166# And now we can build it.
167mkdir -p $BUILDDIR/$NEWLIB_DIR
168cd $BUILDDIR/$NEWLIB_DIR
169
170$SRCDIR/$NEWLIB_DIR/configure --target=arm-elf --prefix=$PREFIX \
171    --enable-interwork --enable-multilib --with-float=soft \
172    && make all install
173) || exit 1
174
175#
176# Stage 4: Build and install the rest of GCC.
177#
178(
179cd $BUILDDIR/$GCC_DIR
180
181make all install
182) || exit 1
183
184export PATH=$OLD_PATH
185
186echo "
187Build complete! Add $PREFIX/bin to your PATH to make arm-elf-gcc and friends
188accessible directly.
189"
Note: See TracBrowser for help on using the browser.