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