Added multilib support to SAT. Now floatingpoint support should work and we should...
[fw/cortex-toolchain] / summon-arm-toolchain
1 #!/bin/bash
2 # Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
3 # Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
4
5 #
6 # Requirements (example is for Debian, replace package names as needed):
7 #
8 # apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev \
9 # libmpc-dev autoconf texinfo build-essential
10 #
11 # Or on Ubuntu Maverick give `apt-get build-dep gcc-4.5` a try.
12 #
13
14 # Stop if any command fails
15 set -e
16
17 ##############################################################################
18 # Settings section
19 # You probably want to customize those
20 ##############################################################################
21 TARGET=arm-none-eabi            # Or: TARGET=arm-elf
22 PREFIX=${HOME}/sat      # Install location of your final toolchain
23 DARWIN_OPT_PATH=/opt/local      # Path in which MacPorts or Fink is installed
24 # Set to 'sudo' if you need superuser privileges while installing
25 SUDO=
26 # Set to 1 to be quieter while running
27 QUIET=0
28 # Set to 1 to use linaro gcc instead of the FSF gcc
29 USE_LINARO=1
30 # Set to 1 to enable building of OpenOCD
31 OOCD_EN=1
32 # Set to 1 to build libstm32 provided by ST
33 LIBSTM32_EN=0
34 # Set to 1 to build libopenstm32 an open source library for stm32
35 LIBOPENSTM32_EN=1
36 # Make the gcc default to Cortex-M3
37 DEFAULT_TO_CORTEX_M3=0
38
39 ##############################################################################
40 # Version and download url settings section
41 ##############################################################################
42 if [ ${USE_LINARO} == 0 ] ; then
43         # For FSF GCC:
44         GCCVERSION=4.5.2
45         GCC=gcc-${GCCVERSION}
46         GCCURL=http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.gz
47 else
48         # For the Linaro GCC:
49         GCCRELEASE=4.5-2011.02-0
50         GCCVERSION=4.5-2011.02-0
51         GCC=gcc-linaro-${GCCVERSION}
52         GCCURL=http://launchpad.net/gcc-linaro/4.5/${GCCRELEASE}/+download/${GCC}.tar.bz2
53 fi
54
55 BINUTILS=binutils-2.21
56 NEWLIB=newlib-1.19.0
57 GDB=gdb-7.2
58 OOCD=master
59 LIBCMSIS=v1.10-2
60 LIBSTM32=v3.0.0-1
61 LIBSTM32USB=v3.0.1-1
62 LIBOPENSTM32=master
63
64 ##############################################################################
65 # Flags section
66 ##############################################################################
67
68 if which getconf > /dev/null; then
69         CPUS=$(getconf _NPROCESSORS_ONLN)
70 else
71         CPUS=1
72 fi
73 PARALLEL=-j$((CPUS + 1))
74 echo "${CPUS} cpu's detected running make with '${PARALLEL}' flag"
75
76 GDBFLAGS=
77 BINUTILFLAGS=
78
79 if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
80         GCCFLAGS=
81 else
82         # To default to the Cortex-M3:
83         GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
84 fi
85
86 # Pull in the local configuration, if any
87 if [ -f local.sh ]; then
88     . ./local.sh
89 fi
90
91 MAKEFLAGS=${PARALLEL}
92 TARFLAGS=v
93
94 if [ ${QUIET} != 0 ]; then
95     TARFLAGS=
96     MAKEFLAGS="${MAKEFLAGS} -s"
97 fi
98
99 export PATH="${PREFIX}/bin:${PATH}"
100
101 SUMMON_DIR=$(pwd)
102 SOURCES=${SUMMON_DIR}/sources
103 STAMPS=${SUMMON_DIR}/stamps
104
105
106 ##############################################################################
107 # Tool section
108 ##############################################################################
109 TAR=tar
110
111 ##############################################################################
112 # OS and Tooldetection section
113 # Detects which tools and flags to use
114 ##############################################################################
115
116 case "$(uname)" in
117         Linux)
118         echo "Found Linux OS."
119         ;;
120         Darwin)
121         echo "Found Darwin OS."
122         GCCFLAGS="${GCCFLAGS} \
123                   --with-gmp=${DARWIN_OPT_PATH} \
124                   --with-mpfr=${DARWIN_OPT_PATH} \
125                   --with-mpc=${DARWIN_OPT_PATH} \
126                   --with-libiconv-prefix=${DARWIN_OPT_PATH}"
127         OOCD_CFLAGS="-I/opt/mine/include -I/opt/local/include"
128         OOCD_LDFLAGS="-L/opt/mine/lib -L/opt/local/lib"
129         ;;
130         CYGWIN*)
131         echo "Found CygWin that means Windows most likely."
132         ;;
133         *)
134         echo "Found unknown OS. Aborting!"
135         exit 1
136         ;;
137 esac
138
139 ##############################################################################
140 # Building section
141 # You probably don't have to touch anything after this
142 ##############################################################################
143
144 # Fetch a versioned file from a URL
145 function fetch {
146     if [ ! -e ${STAMPS}/$1.fetch ]; then
147         log "Downloading $1 sources..."
148         wget -c --no-passive-ftp $2
149         touch ${STAMPS}/$1.fetch
150     fi
151 }
152
153 # Log a message out to the console
154 function log {
155     echo "******************************************************************"
156     echo "* $*"
157     echo "******************************************************************"
158 }
159
160 # Unpack an archive
161 function unpack {
162     log Unpacking $*
163     # Use 'auto' mode decompression.  Replace with a switch if tar doesn't support -a
164     ARCHIVE=$(ls ${SOURCES}/$1.tar.*)
165     case ${ARCHIVE} in
166         *.bz2)
167             echo "archive type bz2"
168             TYPE=j
169             ;;
170         *.gz)
171             echo "archive type gz"
172             TYPE=z
173             ;;
174         *)
175             echo "Unknown archive type of $1"
176             echo ${ARCHIVE}
177             exit 1
178             ;;
179     esac
180     ${TAR} xf${TYPE}${TARFLAGS} ${SOURCES}/$1.tar.*
181 }
182
183 # Install a build
184 function install {
185     log $1
186     ${SUDO} make ${MAKEFLAGS} $2 $3 $4 $5 $6 $7 $8
187 }
188
189
190 mkdir -p ${STAMPS} ${SOURCES}
191
192 cd ${SOURCES}
193
194 fetch ${BINUTILS} http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
195 fetch ${GCC} ${GCCURL}
196 fetch ${NEWLIB} ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
197 fetch ${GDB} http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
198
199 if [ ${OOCD_EN} != 0 ]; then
200 if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
201         log "Cloning OpenOCD sources..."
202         git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
203         cd openocd-${OOCD}
204         ./bootstrap
205         cd ..
206         tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
207         #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
208         #    bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
209         rm -rf openocd-${OOCD}
210 fi
211 fi
212
213 if [ ${LIBSTM32_EN} != 0 ]; then
214 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
215         log "Cloning libcmsis sources..."
216         git clone git://git.open-bldc.org/libcmsis.git
217         cd libcmsis
218         git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
219             bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
220         cd ..
221         rm -rf libcmsis
222 fi
223
224 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
225         log "Cloning libstm32 sources..."
226         git clone git://git.open-bldc.org/libstm32.git
227         cd libstm32
228         git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
229             bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
230         cd ..
231         rm -rf libstm32
232 fi
233
234 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
235         log "Cloning libstm32usb sources..."
236         git clone git://git.open-bldc.org/libstm32usb.git
237         cd libstm32usb
238         git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
239             bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
240         cd ..
241         rm -rf libstm32usb
242 fi
243 fi
244
245 if [ ${LIBOPENSTM32_EN} != 0 ]; then
246 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
247         log "Cloning libopenstm32 sources..."
248         git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
249         cd libopenstm32
250         git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
251             bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
252         cd ..
253         rm -rf libopenstm32
254 fi
255 fi
256
257 cd ${SUMMON_DIR}
258
259 if [ ! -e build ]; then
260     mkdir build
261 fi
262
263 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
264     unpack ${BINUTILS}
265     cd build
266     log "Configuring ${BINUTILS}"
267     ../${BINUTILS}/configure --target=${TARGET} \
268                            --prefix=${PREFIX} \
269                            --enable-interwork \
270                            --enable-multilib \
271                            --with-gnu-as \
272                            --with-gnu-ld \
273                            --disable-nls \
274                            --disable-werror \
275                            ${BINUTILFLAGS}
276     log "Building ${BINUTILS}"
277     make ${MAKEFLAGS}
278     install ${BINUTILS} install
279     cd ..
280     log "Cleaning up ${BINUTILS}"
281     touch ${STAMPS}/${BINUTILS}.build
282     rm -rf build/* ${BINUTILS}
283 fi
284
285 if [ ! -e ${STAMPS}/${GCC}-${NEWLIB}.build ]; then
286     unpack ${GCC}
287     unpack ${NEWLIB}
288
289     log "Adding newlib symlink to gcc"
290     ln -f -s `pwd`/${NEWLIB}/newlib ${GCC}
291     log "Adding libgloss symlink to gcc"
292     ln -f -s `pwd`/${NEWLIB}/libgloss ${GCC}
293
294     if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
295         log "Patching gcc to add multilib support"
296         cd ${GCC}
297         patch -p0 -i ../patches/patch-gcc-config-arm-t-arm-elf.diff
298         cd ..
299     fi
300
301     cd build
302     log "Configuring ${GCC} and ${NEWLIB}"
303     ../${GCC}/configure --target=${TARGET} \
304                       --prefix=${PREFIX} \
305                       --enable-interwork \
306                       --enable-multilib \
307                       --enable-languages="c,c++" \
308                       --with-newlib \
309                       --with-gnu-as \
310                       --with-gnu-ld \
311                       --disable-nls \
312                       --disable-shared \
313                       --disable-threads \
314                       --with-headers=newlib/libc/include \
315                       --disable-libssp \
316                       --disable-libstdcxx-pch \
317                       --disable-libmudflap \
318                       --disable-libgomp \
319                       --disable-werror \
320                       --with-system-zlib \
321                       --disable-newlib-supplied-syscalls \
322                       ${GCCFLAGS}
323     log "Building ${GCC} and ${NEWLIB}"
324     make ${MAKEFLAGS}
325     install ${GCC} install
326     cd ..
327     log "Cleaning up ${GCC} and ${NEWLIB}"
328     touch ${STAMPS}/${GCC}-${NEWLIB}.build
329     rm -rf build/* ${GCC} ${NEWLIB}
330 fi
331
332 if [ ! -e ${STAMPS}/${GDB}.build ]; then
333     unpack ${GDB}
334     cd build
335     log "Configuring ${GDB}"
336     ../${GDB}/configure --target=${TARGET} \
337                       --prefix=${PREFIX} \
338                       --enable-interwork \
339                       --enable-multilib \
340                       --disable-werror \
341                       ${GDBFLAGS}
342     log "Building ${GDB}"
343     make ${MAKEFLAGS}
344     install ${GDB} install
345     cd ..
346     log "Cleaning up ${GDB}"
347     touch ${STAMPS}/${GDB}.build
348     rm -rf build/* ${GDB}
349 fi
350
351 if [ ${OOCD_EN} != 0 ]; then
352 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
353     unpack openocd-${OOCD}
354     cd build
355     log "Configuring openocd-${OOCD}"
356     CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
357     LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
358     ../openocd-${OOCD}/configure --enable-maintainer-mode \
359                                  --prefix=${PREFIX} \
360                                  --enable-dummy \
361                                  --enable-ft2232_libftdi \
362                                  --enable-usb_blaster_libftdi \
363                                  --enable-ep93xx \
364                                  --enable-at91rm9200 \
365                                  --enable-presto_libftdi \
366                                  --enable-usbprog \
367                                  --enable-jlink \
368                                  --enable-vsllink \
369                                  --enable-rlink \
370                                  --enable-arm-jtag-ew
371     log "Building openocd-${OOCD}"
372     make ${MAKEFLAGS}
373     install openocd-${OOCD} install
374     cd ..
375     log "Cleaning up openocd-${OOCD}"
376     touch ${STAMPS}/openocd-${OOCD}.build
377     rm -rf build/* ${OOCD}
378 fi
379 fi
380
381 if [ ${LIBSTM32_EN} != 0 ]; then
382 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
383     unpack libcmsis-${LIBCMSIS}
384     cd libcmsis-${LIBCMSIS}
385     log "Building libcmsis-${LIBCMSIS}"
386     make arch_prefix=${TARGET} prefix=${PREFIX}
387     install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
388     cd ..
389     log "Cleaning up libcmsis-${LIBCMSIS}"
390     touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
391     rm -rf libcmsis-${LIBCMSIS}
392 fi
393
394 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
395     unpack libstm32-${LIBSTM32}
396     cd libstm32-${LIBSTM32}
397     log "Building libstm32-${LIBSTM32}"
398     make arch_prefix=${TARGET} prefix=${PREFIX}
399     install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
400     cd ..
401     log "Cleaning up libstm32-${LIBSTM32}"
402     touch ${STAMPS}/libstm32-${LIBSTM32}.build
403     rm -rf libstm32-${LIBSTM32}
404 fi
405
406 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
407     unpack libstm32usb-${LIBSTM32USB}
408     cd libstm32usb-${LIBSTM32USB}
409     log "Building libstm32usb-${LIBSTM32USB}"
410     make arch_prefix=${TARGET} prefix=${PREFIX}
411     install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
412     cd ..
413     log "Cleaning up libstm32usb-${LIBSTM32USB}"
414     touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
415     rm -rf libstm32usb-${LIBSTM32USB}
416 fi
417 fi
418
419 if [ $LIBOPENSTM32_EN != 0 ]; then
420 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
421     unpack libopenstm32-${LIBOPENSTM32}
422     cd libopenstm32-${LIBOPENSTM32}
423     log "Building libopenstm32-${LIBOPENSTM32}"
424     make PREFIX=${TARGET} DESTDIR=${PREFIX}
425     install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
426     cd ..
427     log "Cleaning up libopenstm32-${LIBOPENSTM32}"
428     touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
429     rm -rf libopenstm32-${LIBOPENSTM32}
430 fi
431 fi