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