| 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 | |
|---|
| 13 | ROOT=`pwd` |
|---|
| 14 | SRCDIR=$ROOT/src |
|---|
| 15 | BUILDDIR=$ROOT/build |
|---|
| 16 | PREFIX=$ROOT/install |
|---|
| 17 | |
|---|
| 18 | GCC_URL=ftp://ftp.irisa.fr/pub/mirrors/gcc.gnu.org/gcc/releases/gcc-4.2.2/gcc-core-4.2.2.tar.bz2 |
|---|
| 19 | GCC_VERSION=4.2.2 |
|---|
| 20 | GCC_DIR=gcc-$GCC_VERSION |
|---|
| 21 | |
|---|
| 22 | BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2 |
|---|
| 23 | BINUTILS_VERSION=2.18 |
|---|
| 24 | BINUTILS_DIR=binutils-$BINUTILS_VERSION |
|---|
| 25 | |
|---|
| 26 | NEWLIB_URL=ftp://sources.redhat.com/pub/newlib/newlib-1.15.0.tar.gz |
|---|
| 27 | NEWLIB_VERSION=1.15.0 |
|---|
| 28 | NEWLIB_DIR=newlib-$NEWLIB_VERSION |
|---|
| 29 | |
|---|
| 30 | echo "I will build an arm-elf cross-compiler: |
|---|
| 31 | |
|---|
| 32 | Prefix: $PREFIX |
|---|
| 33 | Sources: $SRCDIR |
|---|
| 34 | Build files: $BUILDDIR |
|---|
| 35 | |
|---|
| 36 | Press ^C now if you do NOT want to do this." |
|---|
| 37 | read IGNORE |
|---|
| 38 | |
|---|
| 39 | # |
|---|
| 40 | # Helper functions. |
|---|
| 41 | # |
|---|
| 42 | ensure_source() |
|---|
| 43 | { |
|---|
| 44 | URL=$1 |
|---|
| 45 | FILE=$(basename $1) |
|---|
| 46 | |
|---|
| 47 | if [ ! -e $FILE ]; then |
|---|
| 48 | wget -O$FILE $URL |
|---|
| 49 | fi |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | unpack_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. |
|---|
| 69 | mkdir -p $SRCDIR $BUILDDIR $PREFIX |
|---|
| 70 | |
|---|
| 71 | ( |
|---|
| 72 | cd $SRCDIR |
|---|
| 73 | |
|---|
| 74 | # First grab all the source files... |
|---|
| 75 | ensure_source $GCC_URL |
|---|
| 76 | ensure_source $BINUTILS_URL |
|---|
| 77 | ensure_source $NEWLIB_URL |
|---|
| 78 | |
|---|
| 79 | # ... And unpack the sources. |
|---|
| 80 | unpack_source $(basename $GCC_URL) |
|---|
| 81 | unpack_source $(basename $BINUTILS_URL) |
|---|
| 82 | unpack_source $(basename $NEWLIB_URL) |
|---|
| 83 | ) |
|---|
| 84 | |
|---|
| 85 | # Set the PATH to include the binaries we're going to build. |
|---|
| 86 | OLD_PATH=$PATH |
|---|
| 87 | export 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. |
|---|
| 96 | cd $SRCDIR/$BINUTILS_DIR |
|---|
| 97 | patch -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" |
|---|
| 109 | EOF |
|---|
| 110 | ) || exit 1 |
|---|
| 111 | |
|---|
| 112 | # Now, build it. |
|---|
| 113 | mkdir -p $BUILDDIR/$BINUTILS_DIR |
|---|
| 114 | cd $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 | ( |
|---|
| 125 | MULTILIB_CONFIG=$SRCDIR/$GCC_DIR/gcc/config/arm/t-arm-elf |
|---|
| 126 | |
|---|
| 127 | echo " |
|---|
| 128 | |
|---|
| 129 | MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork |
|---|
| 130 | MULTILIB_DIRNAMES += normal interwork |
|---|
| 131 | |
|---|
| 132 | " >> $MULTILIB_CONFIG |
|---|
| 133 | |
|---|
| 134 | mkdir -p $BUILDDIR/$GCC_DIR |
|---|
| 135 | cd $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. |
|---|
| 150 | cd $SRCDIR/$NEWLIB_DIR |
|---|
| 151 | patch -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" |
|---|
| 163 | EOF |
|---|
| 164 | ) || exit 1 |
|---|
| 165 | |
|---|
| 166 | # And now we can build it. |
|---|
| 167 | mkdir -p $BUILDDIR/$NEWLIB_DIR |
|---|
| 168 | cd $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 | ( |
|---|
| 179 | cd $BUILDDIR/$GCC_DIR |
|---|
| 180 | |
|---|
| 181 | make all install |
|---|
| 182 | ) || exit 1 |
|---|
| 183 | |
|---|
| 184 | export PATH=$OLD_PATH |
|---|
| 185 | |
|---|
| 186 | echo " |
|---|
| 187 | Build complete! Add $PREFIX/bin to your PATH to make arm-elf-gcc and friends |
|---|
| 188 | accessible directly. |
|---|
| 189 | " |
|---|