-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuild-Tools
executable file
·397 lines (350 loc) · 13.6 KB
/
Build-Tools
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
#!/bin/bash
#
# --- T2-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# T2 SDE: scripts/Build-Tools
# Copyright (C) 2004 - 2011 The T2 SDE Project
# Copyright (C) 1998 - 2003 ROCK Linux Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- T2-COPYRIGHT-NOTE-END ---
config=default
stagelevel=9
cleanup=0
while [ "$1" ] ; do
case "$1" in
-cleanup) cleanup=1 ; shift ;;
-cfg) config=$2 ; shift ; shift ;;
-[0-9]) options="$options $1" ; stagelevel=${1#-} ; shift ;;
*) echo "Usage: $0 [ -cfg config ] [ -0 | -9 ] \\"
echo " ${0//?/ } [ -cleanup ]" ; exit 1 ;;
esac
done
. scripts/parse-config
. scripts/functions.in
var_remove PATH ":" $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin
var_remove PATH ":" $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper
mkdir -p src
mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin
mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper
mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib
if [ $toolsdir = tools.cross ]; then
mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/{var/adm,etc,share,include}
[ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/usr ] ||
ln -s . build/$SDECFG_ID/TOOLCHAIN/$toolsdir/usr
[ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/sbin ] ||
ln -s bin build/$SDECFG_ID/TOOLCHAIN/$toolsdir/sbin
[ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/var/adm/logs ] ||
ln -s ../../../../var/adm/logs \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/var/adm/logs
mkdir -p build/$SDECFG_ID/var/adm/logs
fi
x="$( bash scripts/xfind.sh config/$config/. package/. scripts/. \
misc/. architecture/. target/. \( ! -name '*.cache' ! \
-name '*.patch*' ! -name '.*' ! -name 'svn-commit.tmp' \
\( \! -name '*.conf' -o -name 'pkg*.conf' \) \) -a -type f \
-newer build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate \
-printf 'Found new/updated file: %p\n' 2> /dev/null )"
if [ "$x" ] ; then
echo_header Found $( echo "$x" | wc -l ) new/updated \
files in source tree:
echo "$x" | head -n 3 | sed 's,/\./,/,g' |
while read y ; do echo_status $y ; done
[ "$( echo "$x" | tail -n +4 )" ] &&
echo_status "** list truncated to save space on the terminal **"
if [ "$SDEDEBUG_TOOLS_SKIP" = 1 ]; then
echo_error "Found \$SDEDEBUG_TOOLS_SKIP ..."
else
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
if echo "$x" | grep -qv " config/$config/" ; then
echo_header Re-running configuration:
while read -r line ; do
echo_status "$line"
done < <( ./scripts/Config -cfg $config -oldconfig )
fi
fi
fi
if [ $cleanup = 1 ] ; then
echo_header "Removing old stuff in $toolsdir/ directory ..."
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/*
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/getdu
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/getfiles
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/fl_wrparse
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/fl_stparse
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
fi
if [ ! -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate ] ; then
echo_header "Building tools in build/.../TOOLCHAIN/$toolsdir:"
# CC, CXX, F77 and KCC Wrapper
#
wrappers="cmd_wrapper" ; wrappervars=""
echo_status "Building $toolsdir/wrapper/cmd_wrapper."
$BUILDCC -Wall -O2 misc/tools-source/cmd_wrapper.c \
-DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
-o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$ || exit 1
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/cmd_wrapper
#
build_wrapper() {
local x="$( echo ${1//,/ } )" y z
wrappervars="$wrappervars $x"
while shift ; [ $# != 0 ]
do
wrappers="$wrappers $1"
tmp=`mktemp -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper`
{
echo '#!/bin/bash'
for y in $x ; do
echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
echo "export CMD_WRAPPER_DEBUG=1"
done
for y in $x ; do
echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
echo "export CMD_WRAPPER_BYPASS=1"
done
z=""; echo -n 'export CMD_WRAPPER_APPEND_PO="'
for y in $x; do
echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
done ; echo '"'
z=""; echo -n 'export CMD_WRAPPER_OTHERS="'
for y in $x; do
echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
done ; echo '"'
z=""; echo -n 'export CMD_WRAPPER_INSERT="'
for y in $x; do
echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
done ; echo '"'
z=""; echo -n 'export CMD_WRAPPER_REMOVE="'
for y in $x; do
echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
done ; echo '"'
z=""; echo -n 'export CMD_WRAPPER_APPEND="'
for y in $x; do
echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
done ; echo '"'
z=""; echo -n 'export CMD_WRAPPER_FILTER="'
for y in $x; do
echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
done ; echo '"'
echo 'exec cmd_wrapper $( basename $0 ) "$@"'
} > $tmp
chmod +rx $tmp
mv $tmp "build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$1"
done
}
#
while read script ; do . $script
done < <( bash scripts/xfind.sh package/. \
$( get_reverted `get_expanded target/%/. $targetchain` ) misc/. -name 'wrappers.in' )
#
echo_status "Building $toolsdir/wrapper/strip_wrapper."
cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$
#!/bin/bash
if [ "\$STRIP_WRAPPER_NOLOOP" = 1 ] ; then
echo "Aaaaaeik! Strip wrapper is looping!" >&2
exit 1
fi
if [ "\$SDECFG_DEBUG" = 0 ] ; then
PATH=\${PATH//\$STRIP_WRAPPER_MYPATH:/}
export STRIP_WRAPPER_NOLOOP=1
exec "\$( basename \$0 )" "\$@"
fi
exit 0
EOT
chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper
wrappers="$wrappers strip_wrapper"
#
for x in strip $arch_target-strip ; do
[ $crossnative = cross -a $x = strip ] && continue
if [ -x "`type -p $x`" ] ; then
ln -sf strip_wrapper \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$x
wrappers="$wrappers $x"
fi
done
#
case $arch_target in
*mingw32*) uname_machine=MINGW32 ;;
*) uname_machine=Linux ;;
esac
echo_status "Building $toolsdir/wrapper/{uname,arch}."
cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname.$$
#!/bin/bash
arch=\$(echo \${arch_machine} | sed -e 's/sparcv.*/sparc/' -e 's/powerpc/ppc/')
echo "You should not call uname during the build!" >&2
[ -z "\$1" ] && set -- '-s'
# shorten long options
opts=" \$(echo \$* | sed 's/--all/-a/;s/--kernel-name/-s/;s/--nodename/-n/;
s/--kernel-release/-r/;s/--kernel-version/-v/;
s/--machine/-m/;s/--processor/-p/;')"
# expand combined options
opts=" \$(echo \$opts | sed 's/[^-]/ -&/g ; s/- //g ; s/-a/-m -n -r -s -v/')"
str=
newopts="\${opts// -s/}"
[ "\$newopts" != "\$opts" ] && str="\$str $uname_machine"
opts="\$newopts"; newopts="\${opts// -n/}"
[ "\$newopts" != "\$opts" ] && str="\$str \$(hostname)"
opts="\$newopts"; newopts="\${opts// -r/}"
[ "\$newopts" != "\$opts" ] &&
str="\$str $(sed -n 's/\[V\] \([^ ]*\).*/\1/p' \
$base/package/*/linux-header/linux-header.desc)-inside-t2-sandbox"
opts="\$newopts"; newopts="\${opts// -v/}"
[ "\$newopts" != "\$opts" ] && str="\$str #1: SMP $(date)"
opts="\$newopts"; newopts="\${opts// -m/}"
[ "\$newopts" != "\$opts" ] && str="\$str \$arch"
opts="\$newopts"; newopts="\${opts// -p/}"
[ "\$newopts" != "\$opts" ] && str="\$str unknown"
if [ "\$newopts" ]; then
echo "uname wrapper: Unknown option:\$newopts" >&2
exit 1
fi
echo \${str:1} # skip the leading blank ,-)
EOT
unset uname_machine
cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch.$$
#!/bin/sh
echo "You should not call arch during the build!" >&2
echo "$(echo $arch | arch2uname)"
EOT
chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/{uname,arch}.$$
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch
wrappers="$wrappers uname arch"
#
echo_status "Building $toolsdir/wrapper/install_wrapper."
cp misc/tools-source/install_wrapper.sh build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install_wrapper
chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install_wrapper
ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install
ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/cp
ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ln
ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/mv
wrappers="$wrappers install_wrapper install cp ln mv"
#
for x in $( ls build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ )
do
z=0
for y in $wrappers ; do
[ "$x" = "$y" ] && z=1
done
if [ "$z" = 0 ] ; then
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$x
fi
done
# Various small tools
#
for x in getdu getfiles fl_wrparse fl_stparse ; do
echo_status "Building $toolsdir/bin/$x."
$BUILDCC -Wall -O2 misc/tools-source/$x.c \
-o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x.$$ || exit 1
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x
done
# Flist Wrapper Library
#
if [ "$SDECFG_FLIST" = "flwrapper" ] ; then
echo_status "Building $toolsdir/lib/fl_wrapper.so."
tmp=`mktemp`
$BUILDCC -Wall -Os misc/archive/hello.c -o $tmp
FLWRAPPER_LIBC=$( ldd $tmp |
sed -n -e 's/.* => //' -e 's/[\t ]*\([^\t ]*\).*/\1/' \
-e '/\/lib[cC]\./p' )
rm -f $tmp
if [ ! -f "$FLWRAPPER_LIBC" ]; then
abort 'Unable to detect default libc for flwrapper'
fi
if [ $stagelevel -lt 2 ]; then
FLWRAPPER_BASEDIR=-DFLWRAPPER_BASEDIR=\"$base\"
else
FLWRAPPER_BASEDIR=
fi
sh misc/tools-source/fl_wrapper.c.sh > src/fl_wrapper_$$.c
$BUILDCC -O2 -shared -fPIC -Wall src/fl_wrapper_$$.c \
$FLWRAPPER_BASEDIR \
-DFLWRAPPER_LIBC=\"${FLWRAPPER_LIBC##*/}\" \
-o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so.$$ -ldl || exit 1
rm src/fl_wrapper_$$.c
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
echo_status "Testing $toolsdir/lib/fl_wrapper.so."
if ! sh -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$SDECFG_ID/`
`TOOLCHAIN/$toolsdir/lib/fl_wrapper.so\" date ; `
`exit \$?" >/dev/null 2>&1
then
echo_error "Detected a problem with the flist" \
"wrapper lib on your system."
echo_error "Please specify another flist-creation" \
"system in your build configuration."
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
echo ; exit 1
fi
fi
# Create Parse-Config Collection
#
echo_status "Creating $toolsdir/lib/parse-config."
bash scripts/xfind.sh \
architecture/$arch/. kernel/$kernel/. package/. $( get_reverted `get_expanded target/%/. $targetchain` ) misc/ -type f \
'(' -name 'parse-config' -o -name 'parse-config-[0-9]' ')' \
-printf '%f\t%p\n' | sed \
-e 's,^parse-config\t,5\t,g' -e 's,^parse-config-\(.\)\t,\1\t,g' | \
sort -n | awk '{ $1="."; print; }' \
> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config.$$
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
bash scripts/xfind.sh \
architecture/$arch/. kernel/$kernel/. package/. $( get_reverted `get_expanded target/%/. $targetchain` ) misc/ -type f \
-name 'parse-config-fixarch' \
-printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' \
> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch.$$
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch
# Create pkg_*_{pre,post}.conf files
#
echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_*_{pre,post}.conf
for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
for y in `echo package/$x/pkg_*_{pre,post}.conf`; do
if [ -f $y ]; then
echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/}
fi
done
done
for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do
if [ -f $y ]; then
echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/}
fi
done
for y in `echo kernel/$kernel/pkg_*_{pre,post}.conf`; do
if [ -f $y ]; then
echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/}
fi
done
for y in `echo target/$target/pkg_*_{pre,post}.conf`; do
if [ -f $y ]; then
echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/}
fi
done
echo -e "${wrappervars// /\n}" | grep . | sort -u |
while read x ; do
echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
echo "export ${x}_WRAPPER_OTHERS='' ${x}_WRAPPER_REMOVE=''"
echo "export ${x}_WRAPPER_INSERT='' ${x}_WRAPPER_APPEND=''"
echo "export ${x}_WRAPPER_FILTER='' ${x}_WRAPPER_APPEND_PO=''"
done > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config.$$
mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config.$$ \
build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config
touch build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
fi
exit 0