stm32 libraries now create their stamps in stamp directory. libopenstm32 is checking...
[fw/cortex-toolchain] / contrib / arm-toolchain-build.sh
1 #!/bin/bash
2 #
3 # Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
4 # Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
5 # Modified by Christophe Duparquet <e39@free.fr>, released as public domain.
6
7 # NOTE by esden:
8 #
9 # This script was contributed by Cristophe it contains several implementation
10 # improvements. I did not test it myself and I know that it lacks support for
11 # linaro GCC. I currenty have no time to integrate the improvements into the
12 # original summon-arm-toolchain. It is a nice reference where SAR should go
13 # implementationwise, IMHO. Maybe someone with some more time on their hands
14 # would help out here and incorporate the improvements into the original SAR
15 # that more up to date and has additional features. It would be very
16 # appreciated.
17 #
18 # Also take a look into the HOW-TO-SUBMIT section of the main README what is
19 # the prefered way to submit patches to SAR.
20
21 # This script will build a GNU ARM toolchain in the directory arm-toolchain.
22 # Process can be suspended and restarted at will.
23 # Packages are downloaded to arm-toolchain/archives/.
24 # Packages are extracted to arm-toolchain/sources/.
25 # Packages are built in arm-toolchain/build/.
26 # arm-toolchain/install contains the result of make install for each tool.
27 # arm-toolchain/status contains the status of each part of the process (logs, errors...)
28
29
30 # PACKAGE_DESCRIPTION = BASE_URL ARCHIVE_BASENAME PACKAGE_VERSION ARCHIVE_TYPE URL_OPTIONS
31 #
32 BINUTILS="http://ftp.gnu.org/gnu/binutils binutils 2.19.1 tar.bz2"
33 GCC="ftp://ftp.lip6.fr/pub/gcc/releases/gcc-4.4.4 gcc 4.4.4 tar.bz2"
34 GDB="http://ftp.gnu.org/gnu/gdb gdb 7.1 tar.bz2"
35 NEWLIB="ftp://sources.redhat.com/pub/newlib newlib 1.18.0 tar.gz --no-passive-ftp"
36 INSIGHT="ftp://sourceware.org/pub/insight/releases insight 6.8-1 tar.bz2"
37
38 LIBCMSIS="git://git.open-bldc.org libcmsis git dir"
39 LIBSTM32="git://git.open-bldc.org libstm32 git dir"
40 LIBSTM32USB="git://git.open-bldc.org libstm32usb git dir"
41 LIBOPENSTM32="git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32 libopenstm32 git dir"
42
43
44 TARGET=arm-none-eabi                    # Or: TARGET=arm-elf
45
46 BASEDIR=$(pwd)/arm-toolchain            # Base directory
47 ARCHIVES=${BASEDIR}/archives            # Where to store downloaded packages
48 SOURCES=${BASEDIR}/sources              # Where to extract packages
49 BUILD=${BASEDIR}/build                  # Where to build packages
50 STATUS=${BASEDIR}/status                # Where to store building process status
51 PREFIX=${BASEDIR}/install               # Install location of your final toolchain
52
53 PARALLEL=-j$(getconf _NPROCESSORS_ONLN)
54
55 export PATH="${PREFIX}/bin:${PATH}"
56 mkdir -p ${ARCHIVES} ${SOURCES} ${BUILD} ${STATUS}
57
58
59 die() {
60     echo -e "\n\n**FAIL**"
61     tail ${CMD}
62     # echo -e "\nIn ${ERR} :"
63     tail ${ERR}
64     echo
65     exit
66 }
67
68
69 context() {
70     URL=$1
71     ANAME=$2
72     AVERSION=$3
73     ATYPE=$4
74     URL_OPTIONS=$5
75
76     SOURCE=$ANAME-$AVERSION
77     ARCHIVE=$SOURCE.$ATYPE
78 }
79
80
81 fetch() {
82     CMD=${STATUS}/${SOURCE}.fetch.cmd
83     LOG=${STATUS}/${SOURCE}.fetch.log
84     ERR=${STATUS}/${SOURCE}.fetch.errors
85     DONE=${STATUS}/${SOURCE}.fetch.done
86
87     if [ -e ${DONE} ]; then
88         echo "${SOURCE} already fetched"
89         return
90     fi
91
92     case ${URL} in
93         http://*)
94             COMMAND=wget
95             ;;
96         ftp://*)
97             COMMAND=wget
98             ;;
99         git://*)
100             COMMAND=git
101             ;;
102         *)
103             echo "${URL}: unknown protocol." >${ERR}
104             die
105     esac
106
107     case $COMMAND in
108         wget)
109             cd "$ARCHIVES"
110             echo -n "Downloading $ARCHIVE ... "
111             echo wget -c $URL_OPTIONS "$URL/$ARCHIVE" >${CMD}
112             wget -c $URL_OPTIONS "$URL/$ARCHIVE" >${LOG} 2>${ERR} || die
113             ;;
114         git)
115             cd "$SOURCES"
116             rm -rf "$ANAME-git"
117             echo -n "Downloading $SOURCE ... "
118             echo git clone "$URL/$ANAME.git" >${CMD}
119             ((git clone "$URL/$ANAME.git" || git clone "$URL/$ANAME") \
120                 && mv ${ANAME} ${ANAME}-git) >${LOG} 2>${ERR} || die
121             ;;
122     esac
123     echo "OK."
124     touch ${DONE}
125 }
126
127
128 extract() {
129     CMD=${STATUS}/${SOURCE}.extract.cmd
130     LOG=${STATUS}/${SOURCE}.extract.log
131     ERR=${STATUS}/${SOURCE}.extract.errors
132     DONE=${STATUS}/${SOURCE}.extract.done
133
134     cd ${BASEDIR}
135     if [ -e ${DONE} ] ; then
136         echo "${SOURCE} already extracted"
137     else
138         echo -n "Extracting ${SOURCE} ... "
139         cd ${SOURCES}
140         case ${ATYPE} in
141             tar.gz)
142                 COMMAND=xvzf
143                 ;;
144             tar.bz2)
145                 COMMAND=xvjf
146                 ;;
147             dir)
148                 COMMAND=""
149                 cp -a "$SOURCES/$SOURCE" "$BUILD/$SOURCE"
150                 ;;
151             *)
152                 if [ -d ${ARCHIVES}/${ARCHIVE} ] ; then
153                     ln -s ${ARCHIVES}/${ARCHIVE} .
154                     ln -s ${ARCHIVES}/${ARCHIVE} ${BUILD}
155                     touch ${DONE}
156                     return
157                 else
158                     echo "${ARCHIVE}: unknown archive format." >${ERR}
159                     die
160                 fi
161         esac
162         if [ -n "$COMMAND" ] ; then
163             echo "tar $COMMAND ${ARCHIVES}/${ARCHIVE}" >${CMD}
164             tar $COMMAND ${ARCHIVES}/${ARCHIVE} >${LOG} 2>${ERR} || die
165         fi
166         echo "OK."
167         touch ${DONE}
168     fi
169 }
170
171
172 configure() {
173     OPTIONS=$*
174
175     unset ZPASS
176     [ -z "$PASS" ] || ZPASS=".$PASS"
177     CMD=${STATUS}/${SOURCE}.configure${ZPASS}.cmd
178     LOG=${STATUS}/${SOURCE}.configure${ZPASS}.log
179     ERR=${STATUS}/${SOURCE}.configure${ZPASS}.errors
180     DONE=${STATUS}/${SOURCE}.configure${ZPASS}.done
181
182     cd ${BASEDIR}
183     if [ -e ${DONE} ]; then
184         echo "${SOURCE} already configured"
185     else
186         echo -n "Configuring ${SOURCE} ... "
187         mkdir -p ${BUILD}/${SOURCE}
188         cd ${BUILD}/${SOURCE}
189         echo "${SOURCES}/${SOURCE}/configure $OPTIONS" >${CMD}
190         ${SOURCES}/${SOURCE}/configure $OPTIONS >${LOG} 2>${ERR} || die
191         echo "OK."
192         touch ${DONE}
193     fi
194     unset PASS ZPASS
195 }
196
197
198 domake() {
199     WHAT=$1 ; shift
200     OPTIONS=$*
201
202     [ -z "$WHAT" ] || ZWHAT=".$WHAT"
203     [ -z "$PASS" ] || ZPASS=".$PASS"
204     CMD=${STATUS}/${SOURCE}.make${ZWHAT}${ZPASS}.cmd
205     LOG=${STATUS}/${SOURCE}.make${ZWHAT}${ZPASS}.log
206     ERR=${STATUS}/${SOURCE}.make${ZWHAT}${ZPASS}.errors
207     DONE=${STATUS}/${SOURCE}.make${ZWHAT}${ZPASS}.done
208
209     cd ${BASEDIR}
210     if [ -e ${DONE} ]; then
211         echo "Make ${SOURCE} \"${WHAT}\" already done"
212     else
213         echo -n "Make ${SOURCE} \"${WHAT}\" ... "
214         cd ${BUILD}/${SOURCE}
215         echo "make ${WHAT} $OPTIONS" >${CMD}
216         make ${PARALLEL} ${WHAT} $OPTIONS >${LOG} 2>${ERR} || die
217         echo "OK."
218         touch ${DONE}
219     fi
220     unset PASS ZPASS ZWHAT
221 }
222
223
224 # Binutils
225 #
226 context $BINUTILS
227 fetch
228 extract
229 configure \
230     --target=${TARGET} \
231     --prefix=${PREFIX} \
232     --enable-interwork \
233     --enable-multilib \
234     --with-gnu-as \
235     --with-gnu-ld \
236     --disable-nls \
237     --disable-werror
238 domake
239 domake install
240
241
242 # GCC pass 1
243 #
244 context $GCC
245 fetch
246 extract
247 PASS=1 configure \
248     --target=${TARGET} \
249     --prefix=${PREFIX} \
250     --enable-interwork \
251     --enable-multilib \
252     --enable-languages="c" \
253     --with-newlib \
254     --without-headers \
255     --disable-shared \
256     --with-gnu-as \
257     --with-gnu-ld \
258     --disable-nls \
259     --disable-werror
260 PASS=1 domake all-gcc
261 PASS=1 domake install-gcc
262
263
264 # Newlib
265 #
266 context $NEWLIB
267 fetch
268 extract
269 configure \
270     --target=${TARGET} \
271     --prefix=${PREFIX} \
272     --enable-interwork \
273     --enable-multilib \
274     --with-gnu-as \
275     --with-gnu-ld \
276     --disable-nls \
277     --disable-werror \
278     --disable-newlib-supplied-syscalls
279 domake
280 domake install
281
282
283 # GCC pass 2
284 #
285 context $GCC
286 # rm -rf ${BUILD}/${SOURCE}
287 # rm ${STATUS}/${SOURCE}.configure.done
288 PASS=2 configure \
289     --target=${TARGET} \
290     --prefix=${PREFIX} \
291     --enable-interwork \
292     --enable-multilib \
293     --enable-languages="c,c++" \
294     --with-newlib \
295     --disable-shared \
296     --with-gnu-as \
297     --with-gnu-ld \
298     --disable-nls \
299     --disable-werror
300 PASS=2 domake
301 PASS=2 domake install
302
303
304 # GDB
305 #
306 context $GDB
307 fetch
308 extract
309 configure \
310     --target=${TARGET} \
311     --prefix=${PREFIX} \
312     --enable-interwork \
313     --enable-multilib \
314     --disable-werror
315 domake
316 domake install
317
318
319 # Insight
320 #
321 context $INSIGHT
322 fetch
323 extract
324 configure \
325     --target=${TARGET} \
326     --prefix=${PREFIX} \
327     --enable-languages=c,c++ \
328     --enable-thumb \
329     --enable-interwork \
330     --enable-multilib \
331     --enable-tui \
332     --with-newlib \
333     --disable-werror \
334     --disable-libada \
335     --disable-libssp \
336     --with-expat
337 domake
338 domake install
339
340
341 # libcmsis
342 #
343 context $LIBCMSIS
344 fetch
345 extract
346 domake "" arch_prefix=${TARGET} prefix=${PREFIX}
347 domake install arch_prefix=${TARGET} prefix=${PREFIX}
348
349
350 # libstm32
351 #
352 context $LIBSTM32
353 fetch
354 extract
355 domake "" arch_prefix=${TARGET} prefix=${PREFIX}
356 domake install arch_prefix=${TARGET} prefix=${PREFIX}
357
358
359 # libstm32usb
360 #
361 context $LIBSTM32USB
362 fetch
363 extract
364 domake "" arch_prefix=${TARGET} prefix=${PREFIX}
365 domake install arch_prefix=${TARGET} prefix=${PREFIX}
366
367
368 # libopenstm32
369 #
370 context $LIBOPENSTM32
371 fetch
372 extract
373 domake "" DESTDIR=${PREFIX} PREFIX=${TARGET}
374 domake install DESTDIR=${PREFIX} PREFIX=${TARGET}