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