Modified the build process to one step build of gcc and newlib. Updated gcc linaro...
[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     log "Adding newlib symlink to gcc"
289     ln -s `pwd`/${NEWLIB}/newlib ${GCC}
290     log "Adding libgloss symlink to gcc"
291     ln -s `pwd`/${NEWLIB}/libgloss ${GCC}
292     cd build
293     log "Configuring ${GCC} and ${NEWLIB}"
294     ../${GCC}/configure --target=${TARGET} \
295                       --prefix=${PREFIX} \
296                       --enable-interwork \
297                       --enable-multilib \
298                       --enable-languages="c,c++" \
299                       --with-newlib \
300                       --with-gnu-as \
301                       --with-gnu-ld \
302                       --disable-nls \
303                       --disable-shared \
304                       --disable-threads \
305                       --with-headers=newlib/libc/include \
306                       --disable-libssp \
307                       --disable-libstdcxx-pch \
308                       --disable-libmudflap \
309                       --disable-libgomp \
310                       --disable-werror \
311                       --with-system-zlib \
312                       --disable-newlib-supplied-syscalls \
313                       ${GCCFLAGS}
314     log "Building ${GCC} and ${NEWLIB}"
315     make ${MAKEFLAGS}
316     install ${GCC} install
317     cd ..
318     log "Cleaning up ${GCC} and ${NEWLIB}"
319     touch ${STAMPS}/${GCC}-${NEWLIB}.build
320     rm -rf build/* ${GCC} ${NEWLIB}
321 fi
322
323 if [ ! -e ${STAMPS}/${GDB}.build ]; then
324     unpack ${GDB}
325     cd build
326     log "Configuring ${GDB}"
327     ../${GDB}/configure --target=${TARGET} \
328                       --prefix=${PREFIX} \
329                       --enable-interwork \
330                       --enable-multilib \
331                       --disable-werror \
332                       ${GDBFLAGS}
333     log "Building ${GDB}"
334     make ${MAKEFLAGS}
335     install ${GDB} install
336     cd ..
337     log "Cleaning up ${GDB}"
338     touch ${STAMPS}/${GDB}.build
339     rm -rf build/* ${GDB}
340 fi
341
342 if [ ${OOCD_EN} != 0 ]; then
343 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
344     unpack openocd-${OOCD}
345     cd build
346     log "Configuring openocd-${OOCD}"
347     CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
348     LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
349     ../openocd-${OOCD}/configure --enable-maintainer-mode \
350                                  --prefix=${PREFIX} \
351                                  --enable-dummy \
352                                  --enable-ft2232_libftdi \
353                                  --enable-usb_blaster_libftdi \
354                                  --enable-ep93xx \
355                                  --enable-at91rm9200 \
356                                  --enable-presto_libftdi \
357                                  --enable-usbprog \
358                                  --enable-jlink \
359                                  --enable-vsllink \
360                                  --enable-rlink \
361                                  --enable-arm-jtag-ew
362     log "Building openocd-${OOCD}"
363     make ${MAKEFLAGS}
364     install openocd-${OOCD} install
365     cd ..
366     log "Cleaning up openocd-${OOCD}"
367     touch ${STAMPS}/openocd-${OOCD}.build
368     rm -rf build/* ${OOCD}
369 fi
370 fi
371
372 if [ ${LIBSTM32_EN} != 0 ]; then
373 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
374     unpack libcmsis-${LIBCMSIS}
375     cd libcmsis-${LIBCMSIS}
376     log "Building libcmsis-${LIBCMSIS}"
377     make arch_prefix=${TARGET} prefix=${PREFIX}
378     install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
379     cd ..
380     log "Cleaning up libcmsis-${LIBCMSIS}"
381     touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
382     rm -rf libcmsis-${LIBCMSIS}
383 fi
384
385 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
386     unpack libstm32-${LIBSTM32}
387     cd libstm32-${LIBSTM32}
388     log "Building libstm32-${LIBSTM32}"
389     make arch_prefix=${TARGET} prefix=${PREFIX}
390     install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
391     cd ..
392     log "Cleaning up libstm32-${LIBSTM32}"
393     touch ${STAMPS}/libstm32-${LIBSTM32}.build
394     rm -rf libstm32-${LIBSTM32}
395 fi
396
397 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
398     unpack libstm32usb-${LIBSTM32USB}
399     cd libstm32usb-${LIBSTM32USB}
400     log "Building libstm32usb-${LIBSTM32USB}"
401     make arch_prefix=${TARGET} prefix=${PREFIX}
402     install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
403     cd ..
404     log "Cleaning up libstm32usb-${LIBSTM32USB}"
405     touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
406     rm -rf libstm32usb-${LIBSTM32USB}
407 fi
408 fi
409
410 if [ $LIBOPENSTM32_EN != 0 ]; then
411 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
412     unpack libopenstm32-${LIBOPENSTM32}
413     cd libopenstm32-${LIBOPENSTM32}
414     log "Building libopenstm32-${LIBOPENSTM32}"
415     make PREFIX=${TARGET} DESTDIR=${PREFIX}
416     install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
417     cd ..
418     log "Cleaning up libopenstm32-${LIBOPENSTM32}"
419     touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
420     rm -rf libopenstm32-${LIBOPENSTM32}
421 fi
422 fi