892c687563be7fa940c1dc193a836e79495cb1ae
[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 TARGET=arm-none-eabi            # Or: TARGET=arm-elf
6 PREFIX=${HOME}/arm-none-eabi    # Install location of your final toolchain
7 PARALLEL=""                     # Or: PARALLEL="-j 5" for 4 CPUs
8 DARWIN_OPT_PATH=/opt/local      # Path in which MacPorts or Fink is installed
9
10 BINUTILS=binutils-2.19.1
11 GCC=gcc-4.4.2
12 NEWLIB=newlib-1.17.0
13 GDB=gdb-7.1
14 LIBCMSIS=v1.10-2
15 LIBSTM32=v3.0.0-1
16 LIBSTM32USB=v3.0.1-1
17 LIBOPENSTM32=master
18 LIBSTM32_EN=0
19 LIBOPENSTM32_EN=0
20
21 SUMMON_DIR=$(pwd)
22 SOURCES=${SUMMON_DIR}/sources
23
24 export PATH="${PREFIX}/bin:${PATH}"
25
26 GCCFLAGS=
27 GDBFLAGS=
28 BINUTILFLAGS=
29
30 case "$(uname)" in
31         Linux)
32         echo "Found Linux OS."
33         ;;
34         Darwin)
35         echo "Found Darwin OS."
36         GCCFLAGS="--with-gmp=${DARWIN_OPT_PATH} \
37                   --with-mpfr=${DARWIN_OPT_PATH} \
38                   -with-libiconv-prefix=${DARWIN_OPT_PATH}"
39         ;;
40         *)
41         echo "Found unknown OS. Aborting!"
42         exit 1
43         ;;
44 esac
45
46 if [ ! -e ${SOURCES} ]; then
47     mkdir ${SOURCES}
48 fi
49
50 cd ${SOURCES}
51
52 echo "Downloading binutils sources..."
53 wget -c http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
54
55 echo "Downloading gcc sources..."
56 wget -c http://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.bz2
57
58 echo "Downloading newlib sources..."
59 wget -c --no-passive-ftp ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
60
61 echo "Downloading gdb sources..."
62 wget -c http://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
63
64 if [ ${LIBSTM32_EN} != 0 ]; then
65 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
66         echo "Cloning libcmsis sources..."
67         git clone git://git.open-bldc.org/libcmsis.git
68         cd libcmsis
69         git archive --format=tar --prefix=libcmsis-${LIBCMSIS}/ ${LIBCMSIS} | \
70             bzip2 --stdout > ../libcmsis-${LIBCMSIS}.tar.bz2
71         cd ..
72         rm -rf libcmsis
73 fi
74
75 if [ ! -e libstm32-${LIBSTM32}.tar.bz2 ]; then
76         echo "Cloning libstm32 sources..."
77         git clone git://git.open-bldc.org/libstm32.git
78         cd libstm32
79         git archive --format=tar --prefix=libstm32-${LIBSTM32}/ ${LIBSTM32} | \
80             bzip2 --stdout > ../libstm32-${LIBSTM32}.tar.bz2
81         cd ..
82         rm -rf libstm32
83 fi
84
85 if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
86         echo "Cloning libstm32usb sources..."
87         git clone git://git.open-bldc.org/libstm32usb.git
88         cd libstm32usb
89         git archive --format=tar --prefix=libstm32usb-${LIBSTM32USB}/ ${LIBSTM32USB} | \
90             bzip2 --stdout > ../libstm32usb-${LIBSTM32USB}.tar.bz2
91         cd ..
92         rm -rf libstm32usb
93 fi
94 fi
95
96 if [ ${LIBOPENSTM32_EN} != 0 ]; then
97 if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
98         echo "Cloning libopenstm32 sources..."
99         git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
100         cd libopenstm32
101         git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
102             bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
103         cd ..
104         rm -rf libopenstm32
105 fi
106 fi
107
108 cd ${SUMMON_DIR}
109
110 if [ ! -e build ]; then
111     mkdir build
112 fi
113
114 if [ ! -e .${BINUTILS}.build ]; then
115     echo "******************************************************************"
116     echo "* Unpacking ${BINUTILS}"
117     echo "******************************************************************"
118     tar xfvj ${SOURCES}/${BINUTILS}.tar.bz2
119     cd build
120     echo "******************************************************************"
121     echo "* Configuring ${BINUTILS}"
122     echo "******************************************************************"
123     ../${BINUTILS}/configure --target=${TARGET} \
124                            --prefix=${PREFIX} \
125                            --enable-interwork \
126                            --enable-multilib \
127                            --with-gnu-as \
128                            --with-gnu-ld \
129                            --disable-nls \
130                            --disable-werror \
131                            ${BINUTILFLAGS} || exit
132     echo "******************************************************************"
133     echo "* Building ${BINUTILS}"
134     echo "******************************************************************"
135     make ${PARALLEL} || exit
136     echo "******************************************************************"
137     echo "* Installing ${BINUTILS}"
138     echo "******************************************************************"
139     make install || exit
140     cd ..
141     echo "******************************************************************"
142     echo "* Cleaning up ${BINUTILS}"
143     echo "******************************************************************"
144     touch .${BINUTILS}.build
145     rm -rf build/* ${BINUTILS}
146 fi
147
148 if [ ! -e .${GCC}-boot.build ]; then
149     echo "******************************************************************"
150     echo "* Unpacking ${GCC}-boot"
151     echo "******************************************************************"
152     tar xfvj ${SOURCES}/${GCC}.tar.bz2
153     cd build
154     echo "******************************************************************"
155     echo "* Configuring ${GCC}-boot"
156     echo "******************************************************************"
157     ../${GCC}/configure --target=${TARGET} \
158                       --prefix=${PREFIX} \
159                       --enable-interwork \
160                       --enable-multilib \
161                       --enable-languages="c" \
162                       --with-newlib \
163                       --without-headers \
164                       --disable-shared \
165                       --with-gnu-as \
166                       --with-gnu-ld \
167                       --disable-nls \
168                       --disable-werror \
169                       ${GCCFLAGS} || exit
170     echo "******************************************************************"
171     echo "* Building ${GCC}-boot"
172     echo "******************************************************************"
173     make ${PARALLEL} all-gcc || exit
174     echo "******************************************************************"
175     echo "* Installing ${GCC}-boot"
176     echo "******************************************************************"
177     make install-gcc || exit
178     cd ..
179     echo "******************************************************************"
180     echo "* Cleaning up ${GCC}-boot"
181     echo "******************************************************************"
182     touch .${GCC}-boot.build
183     rm -rf build/* ${GCC}
184 fi
185
186 if [ ! -e .${NEWLIB}.build ]; then
187     echo "******************************************************************"
188     echo "* Unpacking ${NEWLIB}"
189     echo "******************************************************************"
190     tar xfvz ${SOURCES}/${NEWLIB}.tar.gz
191     cd build
192     echo "******************************************************************"
193     echo "* Configuring ${NEWLIB}"
194     echo "******************************************************************"
195     ../${NEWLIB}/configure --target=${TARGET} \
196                          --prefix=${PREFIX} \
197                          --enable-interwork \
198                          --enable-multilib \
199                          --with-gnu-as \
200                          --with-gnu-ld \
201                          --disable-nls \
202                          --disable-werror \
203                          --disable-newlib-supplied-syscalls || exit
204     echo "******************************************************************"
205     echo "* Building ${NEWLIB}"
206     echo "******************************************************************"
207     make ${PARALLEL} || exit
208     echo "******************************************************************"
209     echo "* Installing ${NEWLIB}"
210     echo "******************************************************************"
211     make install || exit
212     cd ..
213     echo "******************************************************************"
214     echo "* Cleaning up ${NEWLIB}"
215     echo "******************************************************************"
216     touch .${NEWLIB}.build
217     rm -rf build/* ${NEWLIB}
218 fi
219
220 # Yes, you need to build gcc again!
221 if [ ! -e .${GCC}.build ]; then
222     echo "******************************************************************"
223     echo "* Unpacking ${GCC}"
224     echo "******************************************************************"
225     tar xfvj ${SOURCES}/${GCC}.tar.bz2
226     cd build
227     echo "******************************************************************"
228     echo "* Configuring ${GCC}"
229     echo "******************************************************************"
230     ../${GCC}/configure --target=${TARGET} \
231                       --prefix=${PREFIX} \
232                       --enable-interwork \
233                       --enable-multilib \
234                       --enable-languages="c,c++" \
235                       --with-newlib \
236                       --disable-shared \
237                       --with-gnu-as \
238                       --with-gnu-ld \
239                       --disable-nls \
240                       --disable-werror \
241                      ${GCCFLAGS} || exit
242     echo "******************************************************************"
243     echo "* Building ${GCC}"
244     echo "******************************************************************"
245     make ${PARALLEL} || exit
246     echo "******************************************************************"
247     echo "* Installing ${GCC}"
248     echo "******************************************************************"
249     make install || exit
250     cd ..
251     echo "******************************************************************"
252     echo "* Cleaning up ${GCC}"
253     echo "******************************************************************"
254     touch .${GCC}.build
255     rm -rf build/* ${GCC}
256 fi
257
258 if [ ! -e .${GDB}.build ]; then
259     echo "******************************************************************"
260     echo "* Unpacking ${GDB}"
261     echo "******************************************************************"
262     tar xfvj ${SOURCES}/${GDB}.tar.bz2
263     cd build
264     echo "******************************************************************"
265     echo "* Configuring ${GDB}"
266     echo "******************************************************************"
267     ../${GDB}/configure --target=${TARGET} \
268                       --prefix=${PREFIX} \
269                       --enable-interwork \
270                       --enable-multilib \
271                       --disable-werror \
272                       ${GDBFLAGS} || exit
273     echo "******************************************************************"
274     echo "* Building ${GDB}"
275     echo "******************************************************************"
276     make ${PARALLEL} || exit
277     echo "******************************************************************"
278     echo "* Installing ${GDB}"
279     echo "******************************************************************"
280     make install || exit
281     cd ..
282     echo "******************************************************************"
283     echo "* Cleaning up ${GDB}"
284     echo "******************************************************************"
285     touch .${GDB}.build
286     rm -rf build/* ${GDB}
287 fi
288
289 if [ ${LIBSTM32_EN} != 0 ]; then
290 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
291     echo "******************************************************************"
292     echo "* Unpacking libcmsis-${LIBCMSIS}"
293     echo "******************************************************************"
294     tar xfvj ${SOURCES}/libcmsis-${LIBCMSIS}.tar.bz2
295     cd libcmsis-${LIBCMSIS}
296     echo "******************************************************************"
297     echo "* Building libcmsis-${LIBCMSIS}"
298     echo "******************************************************************"
299     make arch_prefix=${TARGET} prefix=${PREFIX} || exit
300     echo "******************************************************************"
301     echo "* Installing libcmsis-${LIBCMSIS}"
302     echo "******************************************************************"
303     make arch_prefix=${TARGET} prefix=${PREFIX} install || exit
304     cd ..
305     echo "******************************************************************"
306     echo "* Cleaning up libcmsis-${LIBCMSIS}"
307     echo "******************************************************************"
308     touch .libcmsis-${LIBCMSIS}.build
309     rm -rf libcmsis-${LIBCMSIS}
310 fi
311
312 if [ ! -e .libstm32-${LIBSTM32}.build ]; then
313     echo "******************************************************************"
314     echo "* Unpacking libstm32-${LIBSTM32}"
315     echo "******************************************************************"
316     tar xfvj ${SOURCES}/libstm32-${LIBSTM32}.tar.bz2
317     cd libstm32-${LIBSTM32}
318     echo "******************************************************************"
319     echo "* Building libstm32-${LIBSTM32}"
320     echo "******************************************************************"
321     make arch_prefix=${TARGET} prefix=${PREFIX} || exit
322     echo "******************************************************************"
323     echo "* Installing libstm32-${LIBSTM32}"
324     echo "******************************************************************"
325     make arch_prefix=${TARGET} prefix=${PREFIX} install || exit
326     cd ..
327     echo "******************************************************************"
328     echo "* Cleaning up libstm32-${LIBSTM32}"
329     echo "******************************************************************"
330     touch .libstm32-${LIBSTM32}.build
331     rm -rf libstm32-${LIBSTM32}
332 fi
333
334 if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
335     echo "******************************************************************"
336     echo "* Unpacking libstm32usb-${LIBSTM32USB}"
337     echo "******************************************************************"
338     tar xfvj ${SOURCES}/libstm32usb-${LIBSTM32USB}.tar.bz2
339     cd libstm32usb-${LIBSTM32USB}
340     echo "******************************************************************"
341     echo "* Building libstm32usb-${LIBSTM32USB}"
342     echo "******************************************************************"
343     make arch_prefix=${TARGET} prefix=${PREFIX} || exit
344     echo "******************************************************************"
345     echo "* Installing libstm32usb-${LIBSTM32USB}"
346     echo "******************************************************************"
347     make arch_prefix=${TARGET} prefix=${PREFIX} install || exit
348     cd ..
349     echo "******************************************************************"
350     echo "* Cleaning up libstm32usb-${LIBSTM32USB}"
351     echo "******************************************************************"
352     touch .libstm32usb-${LIBSTM32USB}.build
353     rm -rf libstm32usb-${LIBSTM32USB}
354 fi
355 fi
356
357 if [ $LIBOPENSTM32_EN != 0 ]; then
358     echo "******************************************************************"
359     echo "* Unpacking libopenstm32-${LIBOPENSTM32}"
360     echo "******************************************************************"
361     tar xfvj ${SOURCES}/libopenstm32-${LIBOPENSTM32}.tar.bz2
362     cd libopenstm32-${LIBOPENSTM32}
363     echo "******************************************************************"
364     echo "* Building libopenstm32-${LIBOPENSTM32}"
365     echo "******************************************************************"
366     make PREFIX=${TARGET} DESTDIR=${PREFIX} || exit
367     echo "******************************************************************"
368     echo "* Installing libopenstm32-${LIBOPENSTM32}"
369     echo "******************************************************************"
370     make PREFIX=${TARGET} DESTDIR=${PREFIX} install || exit
371     cd ..
372     echo "******************************************************************"
373     echo "* Cleaning up libopenstm32-${LIBOPENSTM32}"
374     echo "******************************************************************"
375     touch .libopenstm32-${LIBOPENSTM32}.build
376     rm -rf libopenstm32-${LIBOPENSTM32}
377 fi