forked from MaxKellermann/cegcc-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·504 lines (413 loc) · 11.6 KB
/
build.sh
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
#! /usr/bin/env bash
set -e
BASE_DIRECTORY=`dirname $0`
BASE_DIRECTORY=`(cd ${BASE_DIRECTORY}; pwd)`
ME=`basename $0`
# FIXME: some components need this (mingwdll), but they shouldn't.
export BASE_DIRECTORY
#
# Initializations.
#
export BUILD_DIR=`pwd`
ac_default_prefix="/opt/cegcc"
# The list of components, in build order. There's a build_FOO
# function for each of these components
COMPONENTS=( binutils bootstrap_gcc mingw w32api gcc )
#profile docs
COMPONENTS_NUM=${#COMPONENTS[*]}
# Build comma separated list of components, for user display.
for ((i=0;i<$COMPONENTS_NUM;i++)); do
if [ $i = 0 ]; then
COMPONENTS_COMMA_LIST=${COMPONENTS[${i}]}
else
COMPONENTS_COMMA_LIST="${COMPONENTS_COMMA_LIST}, ${COMPONENTS[${i}]}"
fi
done
usage()
{
cat << _ACEOF
$ME builds the mingw32ce toolchain.
Usage: $0 [OPTIONS] ...
-h, --help print this help, then exit
--prefix=PREFIX install toolchain in PREFIX
[$ac_default_prefix]
--host=HOST host on which the toolchain will run [BUILD]
--target=TARGET configure for building compilers for TARGET [arm-mingw32ce]
-j, --parallelism PARALLELISM Pass PARALLELISM as -jPARALLELISM
to make invocations.
--components=LIST specify which components to build
valid components are: ${COMPONENTS_COMMA_LIST}
[all]
--incremental do an incremental build
Report bugs to <[email protected]>.
_ACEOF
}
ac_prev=
for ac_option
do
# If the previous option needs an argument, assign it.
if test -n "$ac_prev"; then
eval "$ac_prev=\$ac_option"
ac_prev=
continue
fi
ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)' ||true`
case $ac_option in
-help | --help | --hel | --he | -h)
usage; exit 0 ;;
-j | --parallelism | --parallelis | --paralleli | --parallel \
| --paralle | --parall | --paral | --para | --par \
| --pa)
ac_prev=parallelism ;;
-j=* | --parallelism=* | --parallelis=* | --paralleli=* | --parallel=* \
| --paralle=* | --parall=* | --paral=* | --para=* | --par=* \
| --pa=*)
parallelism=$ac_optarg ;;
-j*)
parallelism=`echo $ac_option | sed 's/-j//'` ;;
-prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
ac_prev=prefix ;;
-prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
prefix=$ac_optarg ;;
-components | --components | --component | --componen | \
--compone | --compon | --compo | --comp | --com \
| --co | --c)
ac_prev=components ;;
-components=* | --components=* | --component=* | --componen=* \
| --compone=* | --compon=* | --compo=* | --comp=* | --com=* \
| --co=* | --c=*)
components=$ac_optarg ;;
--host)
ac_prev=host ;;
--host=*)
host=$ac_optarg ;;
--target)
ac_prev=target ;;
--target=*)
target=$ac_optarg ;;
--incremental)
incremental=yes ;;
-*) { echo "$as_me: error: unrecognized option: $ac_option
Try \`$0 --help' for more information." >&2
{ (exit 1); exit 1; }; }
;;
*=*)
ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
# Reject names that are not valid shell variable names.
expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
{ echo "$as_me: error: invalid variable name: $ac_envvar" >&2
{ (exit 1); exit 1; }; }
ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
eval "$ac_envvar='$ac_optarg'"
export $ac_envvar ;;
*)
;;
esac
done
# We don't want no errors from here on.
set -e
if test -n "$ac_prev"; then
ac_option=--`echo $ac_prev | sed 's/_/-/g'`
{ echo "$as_me: error: missing argument to $ac_option" >&2
{ (exit 1); exit 1; }; }
fi
# Be sure to have absolute paths.
for ac_var in prefix
do
eval ac_val=$`echo $ac_var`
case $ac_val in
[\\/$]* | ?:[\\/]* | NONE | '' ) ;;
*) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
{ (exit 1); exit 1; }; };;
esac
done
if [ "x${prefix}" != "x" ]; then
export PREFIX="${prefix}"
else
export PREFIX=${ac_default_prefix}
fi
# Figure out what components where requested to be built.
if test x"${components+set}" != xset; then
components=all
else
if test x"${components}" = x ||
test x"${components}" = xyes;
then
echo --components needs at least one argument 1>&2
exit 1
fi
fi
if [ "x${parallelism}" != "x" ]; then
PARALLELISM="-j${parallelism}"
else
PARALLELISM=
fi
# embedded tabs in the sed below -- do not untabify
components=`echo "${components}" | sed -e 's/[ ,][ ,]*/,/g' -e 's/,$//'`
# Don't build in source directory, it will clobber things and cleanup is hard.
if [ -d ${BUILD_DIR}/.git ]; then
echo "Don't build in a source directory, please create an empty directory and build there."
echo "Example :"
echo " mkdir /tmp/cegcc-output"
echo " cd /tmp/cegcc-output"
echo " \$OLDPWD/build.sh $@"
exit 1
fi
# configure_module MODULE SUBDIR [configure-arguments ...]
function configure_module()
{
local module="$1"
local subdir="$2"
shift 2
src="${BASE_DIRECTORY}/${module}"
mkdir -p $subdir
cd $subdir
if [ "$incremental" = "yes" \
-a Makefile -nt $src/configure \
-a Makefile -nt $src/Makefile.in ]; then
# Makefile is fresh, don't need to reconfigure
return
fi
$src/configure \
--prefix=${PREFIX} \
--build=${BUILD} \
"$@"
}
function configure_host_module()
{
configure_module "$@" \
--build=$(gcc -dumpmachine) \
--host=${HOST} \
--target=${TARGET}
}
function configure_target_module()
{
configure_module "$@" \
--host=${TARGET} \
--target=${TARGET}
}
build_binutils()
{
echo ""
echo "BUILDING BINUTILS --------------------------"
echo ""
echo ""
configure_host_module binutils binutils \
--disable-unit-tests \
--disable-nls \
--disable-werror
make ${PARALLELISM}
make install
cd ${BUILD_DIR}
}
build_bootstrap_gcc()
{
configure_host_module gcc gcc-bootstrap \
--with-gcc \
--with-gnu-ld \
--with-gnu-as \
--disable-threads \
--disable-nls \
--enable-languages=c \
--disable-win32-registry \
--disable-multilib \
--disable-shared \
--disable-interwork \
--without-newlib \
--enable-checking
make ${PARALLELISM} all-gcc
make configure-target-libgcc
make install-gcc
gcc_version=`${PREFIX}/bin/${TARGET}-gcc -dumpversion`
cd ${TARGET}/libgcc
make ${PARALLELISM} libgcc.a
/usr/bin/install -c -m 644 libgcc.a ${PREFIX}/lib/gcc/${TARGET}/${gcc_version}
cd ${BUILD_DIR}
}
build_w32api()
{
configure_target_module w32api w32api
make ${PARALLELISM}
make install
#
# Create a cegcc.h file with some sensible input
# Code is copied from the scripts/make_release.sh script.
# This will probably always have "old" numbers
#
# CEGCC_VERSION_MAJOR=`echo $VERSION | awk -F. '{print $1}'`
# CEGCC_VERSION_MINOR=`echo $VERSION | awk -F. '{print $2}'`
# CEGCC_VERSION_PATCHLEVEL=`echo $VERSION | awk -F. '{print $3}'`
#
# Version patchlevel 999 refers to SVN from now on :-)
#
CEGCC_VERSION_MAJOR=0
CEGCC_VERSION_MINOR=55
CEGCC_VERSION_PATCHLEVEL=999
#
INCFILE=${BASE_DIRECTORY}/w32api/include/cegcc.h.in
DESTFILE=${PREFIX}/${TARGET}/include/cegcc.h
#
L1=`grep -s -n "Automatic changes below" ${INCFILE} | awk -F: '{print $1}'`
L2=`grep -s -n "Automatic changes above" ${INCFILE} | awk -F: '{print $1}'`
head -$L1 ${INCFILE} >${DESTFILE}
echo "#define __CEGCC_VERSION_MAJOR__ " $CEGCC_VERSION_MAJOR >> ${DESTFILE}
echo "#define __CEGCC_VERSION_MINOR__ " $CEGCC_VERSION_MINOR >> ${DESTFILE}
echo "#define __CEGCC_VERSION_PATCHLEVEL__ " $CEGCC_VERSION_PATCHLEVEL >> ${DESTFILE}
echo "#define __CEGCC_BUILD_DATE__" `date +%Y%m%d` >> ${DESTFILE}
tail -n +$L2 ${INCFILE} >>${DESTFILE}
cd ${BUILD_DIR}
}
build_mingw()
{
configure_target_module mingw mingw
make ${PARALLELISM}
make install
cd ${BUILD_DIR}
}
build_gcc()
{
configure_host_module gcc gcc \
--with-gcc \
--with-gnu-ld \
--with-gnu-as \
--enable-threads=win32 \
--disable-nls \
--enable-languages=c,c++ \
--disable-win32-registry \
--disable-multilib \
--disable-interwork \
--without-newlib \
--enable-checking \
--with-headers \
--disable-__cxa_atexit
# we build libstdc++ as dll, so we don't need this.
# --enable-fully-dynamic-string \
# --enable-sjlj-exceptions \
# --disable-clocale \
make ${PARALLELISM}
make install
#
# Clean up one file
#
cd ${BUILD_DIR}
}
build_gdb()
{
echo ""
echo "BUILDING GDB --------------------------"
echo ""
echo ""
configure_host_module gdb gdb \
--with-gcc \
--with-gnu-ld \
--with-gnu-as \
--disable-nls \
--disable-win32-registry \
--disable-multilib \
--disable-interwork \
--enable-checking
export CFLAGS=${PREV_CFLAGS}
make ${PARALLELISM}
make install
cd ${BUILD_DIR}
}
build_gdbserver()
{
echo ""
echo "BUILDING gdbserver --------------------------"
echo ""
echo ""
configure_target_module gdb/gdbserver gdbserver
make ${PARALLELISM}
make install
cd ${BUILD_DIR}
}
build_docs()
{
echo ""
echo "INSTALLING documentation --------------------------"
echo ""
echo ""
mkdir -p ${PREFIX}/share/docs
mkdir -p ${PREFIX}/share/images
cd ${BASE_DIRECTORY}/../docs
tar cf - . | (cd ${PREFIX}/share/docs; tar xf -)
cd ${BASE_DIRECTORY}/../website
tar cf - images | (cd ${PREFIX}/share; tar xf -)
cd ${BASE_DIRECTORY}/..
cp NEWS README ${PREFIX}
cp src/binutils/COPYING ${PREFIX}
cp src/binutils/COPYING.LIB ${PREFIX}
cp src/newlib/COPYING.NEWLIB ${PREFIX}
cd ${BUILD_DIR}
}
build_profile()
{
echo ""
echo "BUILDING profiling libraries --------------------------"
echo ""
echo ""
mkdir -p profile
cd profile
configure_target_module profile profile
make ${PARALLELISM}
make install
cd ${BUILD_DIR}
}
build_all()
{
for ((i=0;i<$COMPONENTS_NUM;i++)); do
comp=${COMPONENTS[${i}]}
build_$comp
done
}
split_components=`echo "${components}" | sed -e 's/,/ /g'`
# check for valid options before trying to build them all.
eval "set -- $split_components"
while [ -n "$1" ]; do
if [ "$1" != "all" ]; then
found=false
for ((i=0;i<$COMPONENTS_NUM;i++)); do
if [ "${COMPONENTS[${i}]}" = "$1" ]; then
found=true
fi
done
if [ $found = false ] ; then
echo "Please enter a valid build option."
exit 1
fi
fi
shift
done
if [ "x${target}" != "x" ]; then
export TARGET="${target}"
else
export TARGET="arm-mingw32ce"
fi
export BUILD=`sh ${BASE_DIRECTORY}/gcc/config.guess`
if [ "x${host}" != "x" ]; then
export HOST="${host}"
else
export HOST=${BUILD}
fi
export PATH=${PREFIX}/bin:${PATH}
echo "Building mingw32ce:"
echo "source: ${BASE_DIRECTORY}"
echo "building in: ${BUILD_DIR}"
echo "prefix: ${PREFIX}"
echo "components: ${components}"
echo "Build: ${BUILD}"
echo "Host: ${HOST}"
echo "Target: ${TARGET}"
mkdir -p ${BUILD_DIR}
mkdir -p ${PREFIX}
# Now actually build them.
eval "set -- $split_components"
while [ -n "$1" ]; do
build_${1}
shift
done
echo ""
echo "DONE --------------------------"
echo ""
echo ""