* updated kmime (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / scripts / Build-Tools
blobbdf6dbfaf73efe9d751b0a03c1c22c9235fbd960
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # This copyright note is auto-generated by scripts/Create-CopyPatch.
5 #
6 # T2 SDE: scripts/Build-Tools
7 # Copyright (C) 2004 - 2021 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 ROCK Linux Project
9 #
10 # More information can be found in the files COPYING and README.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; version 2 of the License. A copy of the
15 # GNU General Public License can be found in the file COPYING.
16 # --- T2-COPYRIGHT-NOTE-END ---
18 config=default
19 stagelevel=9
20 cleanup=0
22 while [ "$1" ]; do
23 case "$1" in
24 -cleanup) cleanup=1; shift ;;
25 -cfg) config=$2; shift; shift ;;
26 -[0-9]) options="$options $1"; stagelevel=${1#-}; shift ;;
27 *) echo "Usage: $0 [ -cfg config ] [ -0 | -9 ] \\"
28 echo " ${0//?/ } [ -cleanup ]"; exit 1 ;;
29 esac
30 done
32 . scripts/parse-config
33 . scripts/functions.in
35 var_remove PATH ":" $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin
36 var_remove PATH ":" $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper
38 mkdir -p src
39 mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin
40 mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper
41 mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib
43 if [ $toolsdir = tools.cross ]; then
44 mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/{var/adm,etc,share,include}
45 [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/usr ] ||
46 ln -s . build/$SDECFG_ID/TOOLCHAIN/$toolsdir/usr
47 [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/sbin ] ||
48 ln -s bin build/$SDECFG_ID/TOOLCHAIN/$toolsdir/sbin
49 [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/var/adm/logs ] ||
50 ln -s ../../../../var/adm/logs \
51 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/var/adm/logs
52 mkdir -p build/$SDECFG_ID/var/adm/logs
55 x="$( bash scripts/xfind.sh config/$config/. package/. scripts/. \
56 misc/. architecture/. target/. \( ! -name '*.cache' ! \
57 -name '*.patch*' ! -name '.*' ! -name 'svn-commit.tmp' \
58 \( \! -name '*.conf' -o -name 'pkg*.conf' \) \) -a -type f \
59 -newer build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate \
60 -printf 'Found new/updated file: %p\n' 2> /dev/null )"
62 if [ "$x" ]; then
63 echo_header Found $( echo "$x" | wc -l ) new/updated \
64 files in source tree:
65 echo "$x" | head -n 3 | sed 's,/\./,/,g' |
66 while read y; do echo_status $y; done
67 [ "$( echo "$x" | tail -n +4 )" ] &&
68 echo_status "** list truncated to save space on the terminal **"
70 if [ "$SDEDEBUG_TOOLS_SKIP" = 1 ]; then
71 echo_error "Found \$SDEDEBUG_TOOLS_SKIP"
72 else
73 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
74 if echo "$x" | grep -qv " config/$config/"; then
75 echo_header Re-running configuration:
76 while read -r line; do
77 echo_status "$line"
78 done < <( scripts/Config -cfg $config -oldconfig )
83 if [ $cleanup = 1 ]; then
84 echo_header "Removing old stuff in $toolsdir/"
86 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/*
88 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/getdu
89 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/getfiles
90 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/fl_wrparse
91 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/fl_stparse
93 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
94 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
95 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch
96 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
99 if [ ! -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate ]; then
101 echo_header "Building tools in build/.../TOOLCHAIN/$toolsdir:"
103 # CC, CXX, F77 and KCC Wrapper
105 wrappers="cmd_wrapper"; wrappervars=""
106 echo_status "Building $toolsdir/wrapper/cmd_wrapper"
107 $BUILDCC -Wall -O2 misc/tools-source/cmd_wrapper.c \
108 -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
109 -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$ || exit 1
110 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$ \
111 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/cmd_wrapper
113 build_wrapper() {
114 local x="$( echo ${1//,/ } )" y z
115 wrappervars="$wrappervars $x"
116 while shift; [ $# != 0 ]
118 wrappers="$wrappers $1"
119 tmp=`mktemp -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper`
121 echo '#!/bin/bash'
123 for y in $x; do
124 echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
125 echo "export CMD_WRAPPER_DEBUG=1"
126 done
128 for y in $x; do
129 echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
130 echo "export CMD_WRAPPER_BYPASS=1"
131 done
133 z=""; echo -n 'export CMD_WRAPPER_APPEND_PO="'
134 for y in $x; do
135 echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
136 done; echo '"'
138 z=""; echo -n 'export CMD_WRAPPER_OTHERS="'
139 for y in $x; do
140 echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
141 done; echo '"'
143 z=""; echo -n 'export CMD_WRAPPER_INSERT="'
144 for y in $x; do
145 echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
146 done; echo '"'
148 z=""; echo -n 'export CMD_WRAPPER_REMOVE="'
149 for y in $x; do
150 echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
151 done; echo '"'
153 z=""; echo -n 'export CMD_WRAPPER_APPEND="'
154 for y in $x; do
155 echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
156 done; echo '"'
158 z=""; echo -n 'export CMD_WRAPPER_FILTER="'
159 for y in $x; do
160 echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
161 done; echo '"'
163 echo 'exec cmd_wrapper $( basename $0 ) "$@"'
164 } > $tmp
165 chmod +rx $tmp
166 mv $tmp "build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$1"
167 done
170 while read script; do . $script
171 done < <( bash scripts/xfind.sh package/. \
172 $( get_reverted `get_expanded target/%/. $targetchain` ) misc/. -name 'wrappers.in' )
174 echo_status "Building $toolsdir/wrapper/strip_wrapper"
175 cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$
176 #!/bin/bash
177 if [ "\$STRIP_WRAPPER_NOLOOP" = 1 ]; then
178 echo "Aaaaaeik! Strip wrapper is looping!" >&2
179 exit 1
181 if [ "\$SDECFG_DEBUG" = 0 ]; then
182 PATH=\${PATH//\$STRIP_WRAPPER_MYPATH:/}
183 export STRIP_WRAPPER_NOLOOP=1
184 exec "\$( basename \$0 )" "\$@"
186 exit 0
188 chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$
189 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$ \
190 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper
191 wrappers="$wrappers strip_wrapper"
193 for x in strip $arch_target-strip; do
194 [ $crossnative = cross -a $x = strip ] && continue
195 if [ -x "`type -p $x`" ]; then
196 ln -sf strip_wrapper \
197 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$x
198 wrappers="$wrappers $x"
200 done
202 case $arch_target in
203 *mingw32*) uname_machine=MINGW32 ;;
204 *) uname_machine=Linux ;;
205 esac
206 echo_status "Building $toolsdir/wrapper/{uname,arch}"
207 cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname.$$
208 #!/bin/bash
210 arch=\$(echo \${arch_machine} | sed 's/armv.*/arm/; s/sparcv.*/sparc/; s/powerpc/ppc/')
212 echo "You should not run uname during the build: \$*" >&2
213 [ -z "\$1" ] && set -- '-s'
215 # shorten long options
216 opts="\$(echo " \$*" | sed 's/--all/-a/; s/--kernel-name/-s/; s/--nodename/-n/;
217 s/--kernel-release/-r/; s/--release/-r/;
218 s/--machine/-m/; s/--processor/-p/;
219 s/--operating-system/-o/; s/--kernel-version/-v/;')"
220 str=
221 # expand combined options
222 opts="\$(echo "\$opts" | sed 's/[^-]/ -&/g; s/- //g; s/-a/-m -n -r -s -v/')"
223 newopts="\${opts// -s/}"
224 [ "\$newopts" != "\$opts" ] && str="\$str $uname_machine"
225 opts="\$newopts"; newopts="\${opts// -n/}"
226 [ "\$newopts" != "\$opts" ] && str="\$str \$(hostname)"
227 opts="\$newopts"; newopts="\${opts// -r/}"
228 [ "\$newopts" != "\$opts" ] &&
229 str="\$str $(sed -n 's/\[V\] \([^ ]*\).*/\1/p' \
230 $base/package/*/linux-header/linux-header.desc)-inside-t2-sandbox"
231 opts="\$newopts"; newopts="\${opts// -v/}"
232 [ "\$newopts" != "\$opts" ] && str="\$str #1 SMP $(date)"
233 opts="\$newopts"; newopts="\${opts// -m/}"
234 [ "\$newopts" != "\$opts" ] && str="\$str \$arch"
235 opts="\$newopts"; newopts="\${opts// -p/}"
236 [ "\$newopts" != "\$opts" ] && str="\$str unknown"
237 opts="\$newopts"; newopts="\${opts// -o/}"
238 [ "\$newopts" != "\$opts" ] && str="\$str GNU/$uname_machine"
240 if [ "\$newopts" ]; then
241 echo "uname wrapper: Unknown option: '\$newopts'" >&2
242 exit 1
244 echo \${str:1} # skip the leading blank
246 unset uname_machine
248 cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch.$$
249 #!/bin/bash
250 echo "You should not run arch during the build!" >&2
251 echo "$(echo $arch | arch2uname)"
253 chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/{uname,arch}.$$
254 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname.$$ \
255 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname
256 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch.$$ \
257 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch
258 wrappers="$wrappers uname arch"
260 echo_status "Building $toolsdir/wrapper/install_wrapper"
261 cp misc/tools-source/install_wrapper.sh build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install_wrapper
262 chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install_wrapper
263 ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install
264 ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/cp
265 ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ln
266 ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/mv
267 wrappers="$wrappers install_wrapper install cp ln mv"
269 for x in $( ls build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ )
272 for y in $wrappers; do
273 [ "$x" = "$y" ] && z=1
274 done
275 if [ "$z" = 0 ]; then
276 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$x
278 done
280 # Various small tools
282 for x in getdu getfiles fl_wrparse fl_stparse; do
283 echo_status "Building $toolsdir/bin/$x"
284 $BUILDCC -Wall -O2 misc/tools-source/$x.c \
285 -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x.$$ || exit 1
286 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x.$$ \
287 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x
288 done
290 # Flist Wrapper Library
292 if [ "$SDECFG_FLIST" = "flwrapper" ]; then
293 echo_status "Building $toolsdir/lib/fl_wrapper.so"
295 tmp=build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$
296 $BUILDCC -Wall -Os misc/archive/hello.c -o $tmp
297 FLWRAPPER_LIBC=$(ldd $tmp |
298 sed -n '/lib[cC]\./ { s/.* => //; s/[\t ]*\([^\t ]*\).*/\1/p }')
299 rm -f $tmp
301 if [ ! -f "$FLWRAPPER_LIBC" ]; then
302 abort 'Unable to detect default libc for flwrapper'
305 if [ $stagelevel -lt 2 ]; then
306 FLWRAPPER_BASEDIR=-DFLWRAPPER_BASEDIR=\"$base\"
307 else
308 FLWRAPPER_BASEDIR=
311 bash misc/tools-source/fl_wrapper.c.sh > src/fl_wrapper_$$.c
312 $BUILDCC -O2 -shared -fPIC -Wall -Wno-format-truncation \
313 src/fl_wrapper_$$.c $FLWRAPPER_BASEDIR \
314 -DFLWRAPPER_LIBC=\"${FLWRAPPER_LIBC##*/}\" \
315 -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so.$$ -ldl || exit 1
316 rm src/fl_wrapper_$$.c
317 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so.$$ \
318 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
320 echo_status "Testing $toolsdir/lib/fl_wrapper.so"
321 if ! bash -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$SDECFG_ID/`
322 `TOOLCHAIN/$toolsdir/lib/fl_wrapper.so\" date; `
323 `exit \$?" >/dev/null 2>&1
324 then
325 echo_error "Detected a problem with the flist" \
326 "wrapper lib on your system."
327 echo_error "Please specify another flist-creation" \
328 "system in your build configuration."
329 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
330 echo; exit 1
334 # Create Parse-Config Collection
336 echo_status "Creating $toolsdir/lib/parse-config"
337 bash scripts/xfind.sh \
338 architecture/$arch/. kernel/$kernel/. package/. $( get_reverted `get_expanded target/%/. $targetchain` ) misc/ -type f \
339 '(' -name 'parse-config' -o -name 'parse-config-[0-9]' ')' \
340 -printf '%f\t%p\n' | sed \
341 -e 's,^parse-config\t,5\t,g' -e 's,^parse-config-\(.\)\t,\1\t,g' | \
342 sort -n | awk '{ $1="."; print; }' \
343 > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config.$$
344 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config.$$ \
345 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
347 bash scripts/xfind.sh \
348 architecture/$arch/. kernel/$kernel/. package/. $( get_reverted `get_expanded target/%/. $targetchain` ) misc/ -type f \
349 -name 'parse-config-fixarch' \
350 -printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' \
351 > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch.$$
352 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch.$$ \
353 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch
355 # Create pkg_*_{pre,post}.conf files
358 echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
359 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_*_{pre,post}.conf
360 for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
361 for y in `echo package/$x/pkg_*_{pre,post}.conf`; do
362 if [ -f $y ]; then
363 echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/}
365 done
366 done
368 for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do
369 if [ -f $y ]; then
370 echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/}
372 done
374 for y in `echo kernel/$kernel/pkg_*_{pre,post}.conf`; do
375 if [ -f $y ]; then
376 echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/}
378 done
380 for y in `echo target/$target/pkg_*_{pre,post}.conf`; do
381 if [ -f $y ]; then
382 echo " . $y" >> build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/${y##*/}
384 done
386 echo -e "${wrappervars// /
387 }" | grep . | sort -u |
388 while read x; do
389 echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
390 echo "export ${x}_WRAPPER_OTHERS='' ${x}_WRAPPER_REMOVE=''"
391 echo "export ${x}_WRAPPER_INSERT='' ${x}_WRAPPER_APPEND=''"
392 echo "export ${x}_WRAPPER_FILTER='' ${x}_WRAPPER_APPEND_PO=''"
393 done > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config.$$
394 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config.$$ \
395 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/wrapper-config
397 touch build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
400 exit 0