summaryrefslogtreecommitdiff
path: root/contrib/arm-toolchain-build.sh
blob: fd75a65e48fd2e8fe2ca0fdb6c5b2bfeb8572eb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/bin/bash
#
# Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
# Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
# Modified by Christophe Duparquet <e39@free.fr>, released as public domain.

# NOTE by esden:
#
# This script was contributed by Cristophe it contains several implementation
# improvements. I did not test it myself and I know that it lacks support for
# linaro GCC. I currenty have no time to integrate the improvements into the
# original summon-arm-toolchain. It is a nice reference where SAR should go
# implementationwise, IMHO. Maybe someone with some more time on their hands
# would help out here and incorporate the improvements into the original SAR
# that more up to date and has additional features. It would be very
# appreciated.
#
# Also take a look into the HOW-TO-SUBMIT section of the main README what is
# the prefered way to submit patches to SAR.

# This script will build a GNU ARM toolchain in the directory arm-toolchain.
# Process can be suspended and restarted at will.
# Packages are downloaded to arm-toolchain/archives/.
# Packages are extracted to arm-toolchain/sources/.
# Packages are built in arm-toolchain/build/.
# arm-toolchain/install contains the result of make install for each tool.
# arm-toolchain/status contains the status of each part of the process (logs, errors...)


# PACKAGE_DESCRIPTION = BASE_URL ARCHIVE_BASENAME PACKAGE_VERSION ARCHIVE_TYPE URL_OPTIONS
#
BINUTILS="http://ftp.gnu.org/gnu/binutils binutils 2.19.1 tar.bz2"
GCC="ftp://ftp.lip6.fr/pub/gcc/releases/gcc-4.4.4 gcc 4.4.4 tar.bz2"
GDB="http://ftp.gnu.org/gnu/gdb gdb 7.1 tar.bz2"
NEWLIB="ftp://sources.redhat.com/pub/newlib newlib 1.18.0 tar.gz --no-passive-ftp"
INSIGHT="ftp://sourceware.org/pub/insight/releases insight 6.8-1 tar.bz2"

LIBCMSIS="git://git.open-bldc.org libcmsis git dir"
LIBSTM32="git://git.open-bldc.org libstm32 git dir"
LIBSTM32USB="git://git.open-bldc.org libstm32usb git dir"
LIBOPENSTM32="git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32 libopenstm32 git dir"


TARGET=arm-none-eabi			# Or: TARGET=arm-elf

BASEDIR=$(pwd)/arm-toolchain		# Base directory
ARCHIVES=${BASEDIR}/archives		# Where to store downloaded packages
SOURCES=${BASEDIR}/sources		# Where to extract packages
BUILD=${BASEDIR}/build			# Where to build packages
STATUS=${BASEDIR}/status		# Where to store building process status
PREFIX=${BASEDIR}/install		# Install location of your final toolchain

PARALLEL=-j$(getconf _NPROCESSORS_ONLN)

export PATH="${PREFIX}/bin:${PATH}"
mkdir -p ${ARCHIVES} ${SOURCES} ${BUILD} ${STATUS}


die() {
    echo -e "\n\n**FAIL**"
    tail ${CMD}
    # echo -e "\nIn ${ERR} :"
    tail ${ERR}
    echo
    exit
}


context() {
    URL=$1
    ANAME=$2
    AVERSION=$3
    ATYPE=$4
    URL_OPTIONS=$5

    SOURCE=$ANAME-$AVERSION
    ARCHIVE=$SOURCE.$ATYPE
}


fetch() {
    CMD=${STATUS}/${SOURCE}.fetch.cmd
    LOG=${STATUS}/${SOURCE}.fetch.log
    ERR=${STATUS}/${SOURCE}.fetch.errors
    DONE=${STATUS}/${SOURCE}.fetch.done

    if [ -e ${DONE} ]; then
     	echo "${SOURCE} already fetched"
     	return
    fi

    case ${URL} in
	http://*)
	    COMMAND=wget
	    ;;
	ftp://*)
	    COMMAND=wget
	    ;;
	git://*)
	    COMMAND=git
	    ;;
	*)
	    echo "${URL}: unknown protocol." >${ERR}
	    die
    esac

    case $COMMAND in
	wget)
	    cd "$ARCHIVES"
	    echo -n "Downloading $ARCHIVE ... "
	    echo wget -c $URL_OPTIONS "$URL/$ARCHIVE" >${CMD}
	    wget -c $URL_OPTIONS "$URL/$ARCHIVE" >${LOG} 2>${ERR} || die
	    ;;
	git)
	    cd "$SOURCES"
	    rm -rf "$ANAME-git"
	    echo -n "Downloading $SOURCE ... "
	    echo git clone "$URL/$ANAME.git" >${CMD}
	    ((git clone "$URL/$ANAME.git" || git clone "$URL/$ANAME") \
		&& mv ${ANAME} ${ANAME}-git) >${LOG} 2>${ERR} || die
	    ;;
    esac
    echo "OK."
    touch ${DONE}
}


extract() {
    CMD=${STATUS}/${SOURCE}.extract.cmd
    LOG=${STATUS}/${SOURCE}.extract.log
    ERR=${STATUS}/${SOURCE}.extract.errors
    DONE=${STATUS}/${SOURCE}.extract.done

    cd ${BASEDIR}
    if [ -e ${DONE} ] ; then
	echo "${SOURCE} already extracted"
    else
	echo -n "Extracting ${SOURCE} ... "
	cd ${SOURCES}
	case ${ATYPE} in
	    tar.gz)
		COMMAND=xvzf
		;;
	    tar.bz2)
		COMMAND=xvjf
		;;
	    dir)
		COMMAND=""
		cp -a "$SOURCES/$SOURCE" "$BUILD/$SOURCE"
		;;
	    *)
		if [ -d ${ARCHIVES}/${ARCHIVE} ] ; then
		    ln -s ${ARCHIVES}/${ARCHIVE} .
		    ln -s ${ARCHIVES}/${ARCHIVE} ${BUILD}
		    touch ${DONE}
		    return
		else
		    echo "${ARCHIVE}: unknown archive format." >${ERR}
		    die
		fi
	esac
	if [ -n "$COMMAND" ] ; then
	    echo "tar $COMMAND ${ARCHIVES}/${ARCHIVE}" >${CMD}
	    tar $COMMAND ${ARCHIVES}/${ARCHIVE} >${LOG} 2>${ERR} || die
	fi
	echo "OK."
	touch ${DONE}
    fi
}


configure() {
    OPTIONS=$*

    unset ZPASS
    [ -z "$PASS" ] || ZPASS=".$PASS"
    CMD=${STATUS}/${SOURCE}.configure${ZPASS}.cmd
    LOG=${STATUS}/${SOURCE}.configure${ZPASS}.log
    ERR=${STATUS}/${SOURCE}.configure${ZPASS}.errors
    DONE=${STATUS}/${SOURCE}.configure${ZPASS}.done

    cd ${BASEDIR}
    if [ -e ${DONE} ]; then
	echo "${SOURCE} already configured"
    else
	echo -n "Configuring ${SOURCE} ... "
	mkdir -p ${BUILD}/${SOURCE}
	cd ${BUILD}/${SOURCE}
	echo "${SOURCES}/${SOURCE}/configure $OPTIONS" >${CMD}
	${SOURCES}/${SOURCE}/configure $OPTIONS >${LOG} 2>${ERR} || die
	echo "OK."
	touch ${DONE}
    fi
    unset PASS ZPASS
}


domake() {
    WHAT=$1 ; shift
    OPTIONS=$*

    [ -z "$WHAT" ] || ZWHAT=".$WHAT"
    [ -z "$PASS" ] || ZPASS=".$PASS"
    CMD=${STATUS}/${SOURCE}.make${ZWHAT}${ZPASS}.cmd
    LOG=${STATUS}/${SOURCE}.make${ZWHAT}${ZPASS}.log
    ERR=${STATUS}/${SOURCE}.make${ZWHAT}${ZPASS}.errors
    DONE=${STATUS}/${SOURCE}.make${ZWHAT}${ZPASS}.done

    cd ${BASEDIR}
    if [ -e ${DONE} ]; then
	echo "Make ${SOURCE} \"${WHAT}\" already done"
    else
	echo -n "Make ${SOURCE} \"${WHAT}\" ... "
	cd ${BUILD}/${SOURCE}
	echo "make ${WHAT} $OPTIONS" >${CMD}
	make ${PARALLEL} ${WHAT} $OPTIONS >${LOG} 2>${ERR} || die
	echo "OK."
	touch ${DONE}
    fi
    unset PASS ZPASS ZWHAT
}


# Binutils
#
context $BINUTILS
fetch
extract
configure \
    --target=${TARGET} \
    --prefix=${PREFIX} \
    --enable-interwork \
    --enable-multilib \
    --with-gnu-as \
    --with-gnu-ld \
    --disable-nls \
    --disable-werror
domake
domake install


# GCC pass 1
#
context $GCC
fetch
extract
PASS=1 configure \
    --target=${TARGET} \
    --prefix=${PREFIX} \
    --enable-interwork \
    --enable-multilib \
    --enable-languages="c" \
    --with-newlib \
    --without-headers \
    --disable-shared \
    --with-gnu-as \
    --with-gnu-ld \
    --disable-nls \
    --disable-werror
PASS=1 domake all-gcc
PASS=1 domake install-gcc


# Newlib
#
context $NEWLIB
fetch
extract
configure \
    --target=${TARGET} \
    --prefix=${PREFIX} \
    --enable-interwork \
    --enable-multilib \
    --with-gnu-as \
    --with-gnu-ld \
    --disable-nls \
    --disable-werror \
    --disable-newlib-supplied-syscalls
domake
domake install


# GCC pass 2
#
context $GCC
# rm -rf ${BUILD}/${SOURCE}
# rm ${STATUS}/${SOURCE}.configure.done
PASS=2 configure \
    --target=${TARGET} \
    --prefix=${PREFIX} \
    --enable-interwork \
    --enable-multilib \
    --enable-languages="c,c++" \
    --with-newlib \
    --disable-shared \
    --with-gnu-as \
    --with-gnu-ld \
    --disable-nls \
    --disable-werror
PASS=2 domake
PASS=2 domake install


# GDB
#
context $GDB
fetch
extract
configure \
    --target=${TARGET} \
    --prefix=${PREFIX} \
    --enable-interwork \
    --enable-multilib \
    --disable-werror
domake
domake install


# Insight
#
context $INSIGHT
fetch
extract
configure \
    --target=${TARGET} \
    --prefix=${PREFIX} \
    --enable-languages=c,c++ \
    --enable-thumb \
    --enable-interwork \
    --enable-multilib \
    --enable-tui \
    --with-newlib \
    --disable-werror \
    --disable-libada \
    --disable-libssp \
    --with-expat
domake
domake install


# libcmsis
#
context $LIBCMSIS
fetch
extract
domake "" arch_prefix=${TARGET} prefix=${PREFIX}
domake install arch_prefix=${TARGET} prefix=${PREFIX}


# libstm32
#
context $LIBSTM32
fetch
extract
domake "" arch_prefix=${TARGET} prefix=${PREFIX}
domake install arch_prefix=${TARGET} prefix=${PREFIX}


# libstm32usb
#
context $LIBSTM32USB
fetch
extract
domake "" arch_prefix=${TARGET} prefix=${PREFIX}
domake install arch_prefix=${TARGET} prefix=${PREFIX}


# libopenstm32
#
context $LIBOPENSTM32
fetch
extract
domake "" DESTDIR=${PREFIX} PREFIX=${TARGET}
domake install DESTDIR=${PREFIX} PREFIX=${TARGET}