-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-common.sh
executable file
·367 lines (331 loc) · 10.3 KB
/
build-common.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
# Copyright (c) 2011-2013, ARM Limited
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of ARM nor the names of its contributors may be used
# to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
error () {
set +u
echo "$0: error: $@" >&2
exit 1
set -u
}
warning () {
set +u
echo "$0: warning: $@" >&2
set -u
}
copy_dir() {
set +u
mkdir -p "$2"
(cd "$1" && tar cf - .) | (cd "$2" && tar xf -)
set -u
}
copy_dir_clean() {
set +u
mkdir -p "$2"
(cd "$1" && tar cf - \
--exclude=CVS --exclude=.svn --exclude=.git --exclude=.pc \
--exclude="*~" --exclude=".#*" \
--exclude="*.orig" --exclude="*.rej" \
.) | (cd "$2" && tar xf -)
set -u
}
# Create source package excluding source control information
# parameter 1: base dir of the source tree
# parameter 2: dirname of the source tree
# parameter 3: target package name
# parameter 4-10: additional excluding
# This function will create bz2 package for files under param1/param2,
# excluding unnecessary parts, and create package named param2.
pack_dir_clean() {
set +u
tar cjfh $3 \
--exclude=CVS --exclude=.svn --exclude=.git --exclude=.pc \
--exclude="*~" --exclude=".#*" \
--exclude="*.orig" --exclude="*.rej" $4 $5 $6 $7 $8 $9 ${10} \
-C $1 $2
set -u
}
# Clean all global shell variables except for those needed by build scripts
clean_env () {
set +u
local var_list
local var
var_list=`export|grep "^declare -x"|sed -e "s/declare -x //"|cut -d"=" -f1`
for var in $var_list ; do
case $var in
DEJAGNU|\
DISPLAY|\
HOME|\
LD_LIBRARY_PATH|\
LOGNAME|\
PATH|\
PWD|\
SHELL|\
SHLVL|\
TERM|\
USER|\
USERNAME|\
com.apple.*|\
XAUTHORITY)
;;
*)
unset $var
;;
esac
done
export LANG=C
set -u
}
stack_level=0
# Start a new stack level to save variables
# Must call this before saving any variables
saveenv () {
set +u
# Force expr return 0 to avoid script fail
stack_level=`expr $stack_level \+ 1 || true`
eval stack_list_$stack_level=
set -u
}
# Save a variable to current stack level, and set new value to this var.
# If a variable has been saved, won't save it. Just set new value
# Must be called when stack_level > 0
# $1: variable name
# $2: new variable value
saveenvvar () {
set +u
if [ $stack_level -le 0 ]; then
error Must call saveenv before calling saveenvvar
fi
local varname="$1"
local newval="$2"
eval local oldval=\"\${$varname}\"
eval local saved=\"\${level_saved_${stack_level}_${varname}}\"
if [ "x$saved" = "x" ]; then
# The variable wasn't saved in the level before. Save it
eval local temp=\"\${stack_list_$stack_level}\"
eval stack_list_$stack_level=\"$varname $temp\"
eval save_level_${stack_level}_$varname=\"$oldval\"
eval level_saved_${stack_level}_$varname="yes"
eval level_preset_${stack_level}_${varname}=\"\${$varname+set}\"
#echo Save $varname: \"$oldval\"
fi
eval export $varname=\"$newval\"
#echo $varname set to \"$newval\"
set -u
}
# Restore all variables that have been saved in current stack level
restoreenv () {
set +u
if [ $stack_level -le 0 ]; then
error "Trying to restore from an empty stack"
fi
eval local list=\"\${stack_list_$stack_level}\"
local varname
for varname in $list; do
eval local varname_preset=\"\${level_preset_${stack_level}_${varname}}\"
if [ "x$varname_preset" = "xset" ] ; then
eval $varname=\"\${save_level_${stack_level}_$varname}\"
else
unset $varname
fi
eval level_saved_${stack_level}_$varname=
# eval echo $varname restore to \\\"\"\${$varname}\"\\\"
done
# Force expr return 0 to avoid script fail
stack_level=`expr $stack_level \- 1 || true`
set -u
}
prependenvvar() {
set +u
eval local oldval=\"\$$1\"
saveenvvar "$1" "$2$oldval"
set -u
}
prepend_path() {
set +u
eval local old_path="\"\$$1\""
if [ x"$old_path" == "x" ]; then
prependenvvar "$1" "$2"
else
prependenvvar "$1" "$2:"
fi
set -u
}
# Strip binary files as in "strip binary" form, for both native(linux/mac) and mingw.
strip_binary() {
set +e
if [ $# -ne 2 ] ; then
warning "strip_binary: Missing arguments"
return 0
fi
local strip="$1"
local bin="$2"
file $bin | grep -q -P "(\bELF\b)|(\bPE\b)|(\bPE32\b)"
if [ $? -eq 0 ]; then
$strip $bin 2>/dev/null || true
fi
set -e
}
# Copy target libraries from each multilib directories.
# Usage copy_multi_libs dst_prefix=... src_prefix=... target_gcc=...
copy_multi_libs() {
local -a multilibs
local multilib
local multi_dir
local src_prefix
local dst_prefix
local src_dir
local dst_dir
local target_gcc
for arg in "$@" ; do
eval "${arg// /\\ }"
done
multilibs=( $("${target_gcc}" -print-multi-lib 2>/dev/null) )
for multilib in "${multilibs[@]}" ; do
multi_dir="${multilib%%;*}"
src_dir=${src_prefix}/${multi_dir}
dst_dir=${dst_prefix}/${multi_dir}
cp -f "${src_dir}/libstdc++.a" "${dst_dir}/libstdc++_s.a"
cp -f "${src_dir}/libsupc++.a" "${dst_dir}/libsupc++_s.a"
cp -f "${src_dir}/libc.a" "${dst_dir}/libc_s.a"
cp -f "${src_dir}/libg.a" "${dst_dir}/libg_s.a"
cp -f "${src_dir}/librdimon.a" "${dst_dir}/librdimon_s.a"
cp -f "${src_dir}/nano.specs" "${dst_dir}/"
cp -f "${src_dir}/rdimon.specs" "${dst_dir}/"
cp -f "${src_dir}/nosys.specs" "${dst_dir}/"
cp -f "${src_dir}/"*crt0.o "${dst_dir}/"
done
}
# Clean up unnecessary global shell variables
clean_env
ROOT=`pwd`
SRCDIR=$ROOT/src
BUILDDIR_NATIVE=$ROOT/build-native
BUILDDIR_MINGW=$ROOT/build-mingw
INSTALLDIR_NATIVE=$ROOT/install-native
INSTALLDIR_NATIVE_DOC=$ROOT/install-native/share/doc/gcc-arm-none-eabi
INSTALLDIR_MINGW=$ROOT/install-mingw
INSTALLDIR_MINGW_DOC=$ROOT/install-mingw/share/doc/gcc-arm-none-eabi
PACKAGEDIR=$ROOT/pkg
BINUTILS=binutils
CLOOG=cloog-0.18.0
EXPAT=expat-2.0.1
GCC=gcc
GCC_PLUGINS=gcc-plugins
GDB=gdb
GMP=gmp-4.3.2
NEWLIB_NANO=newlib-nano-2.1
SAMPLES=samples
LIBELF=libelf-0.8.13
LIBICONV=libiconv-1.14
MPC=mpc-0.8.1
MPFR=mpfr-2.4.2
NEWLIB=newlib
ISL=isl-0.11.1
ZLIB=zlib-1.2.5
INSTALLATION=installation
SAMPLES=samples
BUILD_MANUAL=build-manual
CLOOG_PACK=$CLOOG.tar.gz
EXPAT_PACK=$EXPAT.tar.gz
GMP_PACK=$GMP.tar.bz2
LIBELF_PACK=$LIBELF.tar.gz
LIBICONV_PACK=$LIBICONV.tar.gz
MPC_PACK=$MPC.tar.gz
MPFR_PACK=$MPFR.tar.bz2
ISL_PACK=$ISL.tar.bz2
ZLIB_PACK=$ZLIB.tar.bz2
ZLIB_PATCH=$ZLIB.patch
RELEASEDATE=`date +%Y%m%d`
release_year=${RELEASEDATE:0:4}
release_month=${RELEASEDATE:4:2}
case $release_month in
01|02|03)
RELEASEVER=${release_year}q1
;;
04|05|06)
RELEASEVER=${release_year}q2
;;
07|08|09)
RELEASEVER=${release_year}q3
;;
10|11|12)
RELEASEVER=${release_year}q4
;;
esac
RELEASE_FILE=release.txt
README_FILE=readme.txt
LICENSE_FILE=license.txt
SAMPLES_DOS_FILES=$SAMPLES/readme.txt
BUILD_MANUAL_FILE=How-to-build-toolchain.pdf
GCC_VER=`cat $SRCDIR/$GCC/gcc/BASE-VER`
GCC_VER_NAME=`echo $GCC_VER | cut -d'.' -f1,2 | sed -e 's/\./_/g'`
HOST_MINGW=i686-w64-mingw32
HOST_MINGW_TOOL=i686-w64-mingw32
TARGET=arm-none-eabi
ENV_CFLAGS=
ENV_CPPFLAGS=
ENV_LDFLAGS=
BINUTILS_CONFIG_OPTS=
GCC_CONFIG_OPTS=
GDB_CONFIG_OPTS=
NEWLIB_CONFIG_OPTS=
PKGVERSION="GNU Tools for ARM Embedded Processors"
BUGURL=""
# Set variables according to real environment to make this script can run
# on Ubuntu and Mac OS X.
build_gcc_plugin=no
uname_string=`uname | sed 'y/LINUXDARWIN/linuxdarwin/'`
host_arch=`uname -m | sed 'y/XI/xi/'`
if [ "x$uname_string" == "xlinux" ] ; then
BUILD="$host_arch"-linux-gnu
HOST_NATIVE="$host_arch"-linux-gnu
READLINK=readlink
JOBS=`grep ^processor /proc/cpuinfo|wc -l`
GCC_CONFIG_OPTS_LCPP="--with-host-libstdcxx=-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm"
TAR=tar
MD5="md5sum -b"
PACKAGE_NAME_SUFFIX=linux
build_gcc_plugin=yes
elif [ "x$uname_string" == "xdarwin" ] ; then
BUILD=x86_64-apple-darwin10
HOST_NATIVE=x86_64-apple-darwin10
READLINK=greadlink
# Disable parallel build for mac as we will randomly run into "Permission denied" issue.
# JOBS=`sysctl -n hw.ncpu`
JOBS=1
GCC_CONFIG_OPTS_LCPP="--with-host-libstdcxx=-static-libgcc -Wl,-lstdc++ -lm"
TAR=gnutar
MD5="md5 -r"
PACKAGE_NAME_SUFFIX=mac
else
error "Unsupported build system : $uname_string"
fi
OBJ_SUFFIX_MINGW=$TARGET-$RELEASEDATE-$HOST_MINGW
OBJ_SUFFIX_NATIVE=$TARGET-$RELEASEDATE-$HOST_NATIVE
PACKAGE_NAME=gcc-$TARGET-$GCC_VER_NAME-$RELEASEVER-$RELEASEDATE
PACKAGE_NAME_NATIVE=$PACKAGE_NAME-$PACKAGE_NAME_SUFFIX
PACKAGE_NAME_MINGW=$PACKAGE_NAME-win32
INSTALL_PACKAGE_NAME=gcc-$TARGET-$GCC_VER_NAME-$RELEASEVER