* lhw changed Url http -> https
[t2sde.git] / scripts / Build-Tools
blobdebd2f0b290fe0edbb9b90c1a5f1e8a6b14e8b1d
1 #!/usr/bin/env bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Build-Tools
5 # Copyright (C) 2004 - 2024 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # This Copyright note is generated by scripts/Create-CopyPatch,
9 # more information can be found in the files COPYING and README.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License version 2.
13 # --- T2-COPYRIGHT-NOTE-END ---
15 config=default
16 stagelevel=9
17 cleanup=0
19 while [ "$1" ]; do
20 case "$1" in
21 -cleanup) cleanup=1; shift ;;
22 -cfg) config=$2; shift; shift ;;
23 -[0-9]) options="$options $1" stagelevel=${1#-}; shift ;;
24 *) echo "Usage: $0 [ -cfg config ] [ -0 | -9 ] \\"
25 echo " ${0//?/ } [ -cleanup ]"; exit 1 ;;
26 esac
27 done
29 . scripts/parse-config
30 . scripts/functions.in
32 var_remove PATH ":" $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin
33 var_remove PATH ":" $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper
35 mkdir -p src
36 mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin
37 mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper
38 mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib
40 if [ $toolsdir = cross ]; then
41 mkdir -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/{var/adm,etc,share,include}
42 [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/usr ] ||
43 ln -s . build/$SDECFG_ID/TOOLCHAIN/$toolsdir/usr
44 [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/sbin ] ||
45 ln -s bin build/$SDECFG_ID/TOOLCHAIN/$toolsdir/sbin
46 [ -L build/$SDECFG_ID/TOOLCHAIN/$toolsdir/var/adm/logs ] ||
47 ln -s ../../../../var/adm/logs \
48 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/var/adm/logs
49 mkdir -p build/$SDECFG_ID/var/adm/logs
52 x="$(bash scripts/xfind.sh config/$config/. package/. scripts/. \
53 misc/. architecture/. target/. \( ! -name '*.cache' ! \
54 -name '*.patch*' ! -name '.*' ! -name 'svn-commit.tmp' \
55 \( ! -name '*.conf' -o -name 'pkg*.conf' \) \) -a -type f \
56 -newer build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate \
57 -printf 'Found new/updated file: %p\n' 2> /dev/null)"
59 if [ "$x" ]; then
60 echo_header Found $(echo "$x" | wc -l) new/updated \
61 files in source tree:
62 echo "$x" | head -n 3 | sed 's,/\./,/,g' |
63 while read y; do echo_status $y; done
64 [ "$(echo "$x" | tail -n +4)" ] &&
65 echo_status "** list truncated to save space on the terminal **"
67 if [ "$SDEDEBUG_TOOLS_SKIP" = 1 ]; then
68 echo_error "Found \$SDEDEBUG_TOOLS_SKIP"
69 else
70 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
71 if echo "$x" | grep -qv " config/$config/"; then
72 echo_header Re-running configuration:
73 while read -r line; do
74 echo_status "$line"
75 done < <(scripts/Config -cfg $config -oldconfig)
80 if [ $cleanup = 1 ]; then
81 echo_header "Removing old stuff in $toolsdir/"
83 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/*
85 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/getdu
86 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/getfiles
87 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/fl_wrparse
88 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/fl_stparse
90 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
91 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
92 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch
93 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate
96 if [ ! -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/.lastupdate ]; then
98 echo_header "Building tools in build/.../TOOLCHAIN/$toolsdir:"
100 # CC, CXX, F77 and KCC Wrapper
101 wrappers="cmd_wrapper" wrappervars=
102 echo_status "Building $toolsdir/wrapper/cmd_wrapper"
103 $BUILDCC -Wall -O2 misc/tools-source/cmd_wrapper.c \
104 -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
105 -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$ || exit 1
106 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/{tmp.$$,cmd_wrapper}
108 build_wrapper() {
109 local x="$(echo ${1//,/ })" y z
110 wrappervars="$wrappervars $x"
111 while shift; [ $# != 0 ]
113 wrappers="$wrappers $1"
114 tmp=`mktemp -p build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper`
116 echo '#!/usr/bin/env bash'
118 for y in $x; do
119 echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
120 echo "export CMD_WRAPPER_DEBUG=1"
121 done
123 for y in $x; do
124 echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
125 echo "export CMD_WRAPPER_BYPASS=1"
126 done
128 z=""; echo -n 'export CMD_WRAPPER_APPEND_PO="'
129 for y in $x; do
130 echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
131 done; echo '"'
133 z=""; echo -n 'export CMD_WRAPPER_OTHERS="'
134 for y in $x; do
135 echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
136 done; echo '"'
138 z=""; echo -n 'export CMD_WRAPPER_INSERT="'
139 for y in $x; do
140 echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
141 done; echo '"'
143 z=""; echo -n 'export CMD_WRAPPER_REMOVE="'
144 for y in $x; do
145 echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
146 done; echo '"'
148 z=""; echo -n 'export CMD_WRAPPER_APPEND="'
149 for y in $x; do
150 echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
151 done; echo '"'
153 z=""; echo -n 'export CMD_WRAPPER_FILTER="'
154 for y in $x; do
155 echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
156 done; echo '"'
158 echo 'exec cmd_wrapper $(basename $0) "$@"'
159 } > $tmp
160 chmod +rx $tmp
161 mv $tmp "build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$1"
162 done
165 while read script; do . $script
166 done < <(bash scripts/xfind.sh package/. \
167 $(get_reverted `get_expanded target/%/. $targetchain`) misc/. -name 'wrappers.in')
169 echo_status "Building $toolsdir/wrapper/strip_wrapper"
170 cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$
171 #!/usr/bin/env bash
172 if [ "\$STRIP_WRAPPER_NOLOOP" = 1 ]; then
173 echo "Error: Strip wrapper is looping!" >&2
174 exit 1
176 if [ "\$SDECFG_DEBUG" = 0 -o "\$STRIP_WRAPPER_BYPASS" = 1 ]; then
177 PATH=\${PATH//\$STRIP_WRAPPER_MYPATH:/}
178 export STRIP_WRAPPER_NOLOOP=1
179 exec "\$(basename \$0)" "\$@"
181 exit 0
183 chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper.$$
184 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/strip_wrapper{.$$,}
185 wrappers="$wrappers strip_wrapper"
187 for x in strip $arch_target-strip; do
188 [ $crossnative = cross -a $x = strip ] && continue
189 ln -sf strip_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$x
190 wrappers="$wrappers $x"
191 done
193 case $arch_target in
194 *mingw32*) uname_machine=MINGW32 ;;
195 *darwin*) uname_machine=Darwin ;;
196 *) uname_machine=Linux ;;
197 esac
198 echo_status "Building $toolsdir/wrapper/{arch,uname}"
199 cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname.$$
200 #!/usr/bin/env bash
202 arch=\$(echo \${arch_machine} | sed 's/armv.*/arm/; s/sparcv.*/sparc/; s/powerpc/ppc/')
204 echo "You should not run uname during the build: \$*" >&2
205 [ -z "\$1" ] && set -- '-s'
207 # shorten long options
208 opts="\$(echo " \$*" | sed 's/--all/-a/; s/--kernel-name/-s/; s/--nodename/-n/;
209 s/--kernel-release/-r/; s/--release/-r/;
210 s/--machine/-m/; s/--processor/-p/;
211 s/--operating-system/-o/; s/--kernel-version/-v/;')"
212 str=
213 # expand combined options
214 opts="\$(echo "\$opts" | sed 's/[^-]/ -&/g; s/- //g; s/-a/-m -n -r -s -v/')"
215 newopts="\${opts// -s/}"
216 [ "\$newopts" != "\$opts" ] && str="\$str $uname_machine"
217 opts="\$newopts" newopts="\${opts// -n/}"
218 [ "\$newopts" != "\$opts" ] && str="\$str \$(hostname)"
219 opts="\$newopts" newopts="\${opts// -r/}"
220 if [ "\$newopts" != "\$opts" ]; then
221 # TODO: not hardcode system version
222 [ $SDECFG_KERNEL = "darwin" ] && str="\$str 21.5.0" ||
223 str="\$str $(sed -n 's/\[V\] \([^ ]*\).*/\1/p' \
224 $base/package/*/linux-header/linux-header.desc)-inside-t2-sandbox"
226 opts="\$newopts" newopts="\${opts// -v/}"
227 [ "\$newopts" != "\$opts" ] && str="\$str #1 SMP $(date)"
228 opts="\$newopts" newopts="\${opts// -m/}"
229 [ "\$newopts" != "\$opts" ] && str="\$str \$arch"
230 opts="\$newopts" newopts="\${opts// -p/}"
231 [ "\$newopts" != "\$opts" ] && str="\$str unknown"
232 opts="\$newopts" newopts="\${opts// -o/}"
233 [ "\$newopts" != "\$opts" ] && str="\$str GNU/$uname_machine"
235 if [ "\$newopts" ]; then
236 echo "uname wrapper: Unknown option: '\$newopts'" >&2
237 exit 1
239 echo \${str:1} # skip the leading blank
241 unset uname_machine
243 cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch.$$
244 #!/bin/sh
245 echo "You should not run arch during the build!" >&2
246 echo "$(echo $arch | arch2uname)"
248 chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/{arch,uname}.$$
249 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/arch{.$$,}
250 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/uname{.$$,}
251 wrappers="$wrappers arch uname"
253 if [ $crossnative = cross ]; then
254 echo_status "Building $toolsdir/wrapper/ldconfig"
255 cat << EOT > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ldconfig.$$
256 #!/bin/sh
257 echo "You should not run ldconfig during the build!" >&2
259 chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ldconfig.$$
260 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ldconfig{.$$,}
261 wrappers="$wrappers ldconfig"
264 echo_status "Building $toolsdir/wrapper/install_wrapper"
265 cp misc/tools-source/install_wrapper.sh build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install_wrapper
266 chmod +x build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install_wrapper
267 ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/install
268 ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/cp
269 ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/ln
270 ln -sf install_wrapper build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/mv
271 wrappers="$wrappers install_wrapper install cp ln mv"
273 # Remove unknown, spurious wrappers from potential prev. run
274 wrappers=" $wrappers " # add whitespace for quick match below
275 for w in $(ls build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/); do
276 [ "${wrappers// $w /}" = "$wrappers" ] &&
277 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/$w
278 done
280 # Various small tools
281 for x in getdu getfiles fl_wrparse fl_stparse; do
282 echo_status "Building $toolsdir/bin/$x"
283 $BUILDCC -Wall -O2 misc/tools-source/$x.c \
284 -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x.$$ || exit 1
285 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x.$$ \
286 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/bin/$x
287 done
289 # Flist Wrapper Library
290 if [ "$SDECFG_FLIST" = "flwrapper" ]; then
291 echo_status "Building $toolsdir/lib/fl_wrapper.so"
293 tmp=build/$SDECFG_ID/TOOLCHAIN/$toolsdir/wrapper/tmp.$$
294 $BUILDCC -Wall -Os misc/archive/hello.c -o $tmp
296 FLWRAPPER_LIBC=$(readelf --dynamic $tmp |
297 sed -n 's/.*\[\(lib[cC].*\)]/\1/p')
298 [ ! "$FLWRAPPER_LIBC" ] &&
299 FLWRAPPER_LIBC=$(ldd $tmp |
300 sed -n '/lib[cC]\./ { s/.* => //; s/[\t ]*\([^\t ]*\).*/\1/p }')
301 rm -f $tmp
303 if [ ! "$FLWRAPPER_LIBC" ]; then
304 abort 'Unable to detect default libc for flwrapper'
307 if [ $stagelevel -lt 2 ]; then
308 FLWRAPPER_BASEDIR=-DFLWRAPPER_BASEDIR=\"$base\"
309 else
310 FLWRAPPER_BASEDIR=
313 bash misc/tools-source/fl_wrapper.c.sh > src/fl_wrapper_$$.c
314 $BUILDCC -O2 -shared -fPIC -Wall -Wno-format-truncation \
315 src/fl_wrapper_$$.c $FLWRAPPER_BASEDIR \
316 -DFLWRAPPER_LIBC=\"${FLWRAPPER_LIBC##*/}\" \
317 -o build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so.$$ -ldl || exit 1
318 rm src/fl_wrapper_$$.c
319 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so.$$ \
320 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
322 echo_status "Testing $toolsdir/lib/fl_wrapper.so"
323 if ! bash -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$SDECFG_ID/`
324 `TOOLCHAIN/$toolsdir/lib/fl_wrapper.so\" date; `
325 `exit \$?" >/dev/null 2>&1
326 then
327 echo_error "Detected a problem with the flist" \
328 "wrapper lib on your system."
329 echo_error "Please specify another flist-creation" \
330 "system in your build configuration."
331 rm -f build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so
332 echo; exit 1
336 # Create Parse-Config Collection
337 echo_status "Creating $toolsdir/lib/parse-config"
338 bash scripts/xfind.sh \
339 architecture/$arch/. kernel/$kernel/. package/. $(get_reverted `get_expanded target/%/. $targetchain`) misc/ -type f \
340 '(' -name 'parse-config' -o -name 'parse-config-[0-9]' ')' \
341 -printf '%f\t%p\n' | sed \
342 -e 's,^parse-config\t,5\t,g' -e 's,^parse-config-\(.\)\t,\1\t,g' | \
343 sort -n | gawk '{ $1="."; print; }' \
344 > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config.$$
345 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config.$$ \
346 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
348 bash scripts/xfind.sh \
349 architecture/$arch/. kernel/$kernel/. package/. $(get_reverted `get_expanded target/%/. $targetchain`) misc/ -type f \
350 -name 'parse-config-fixarch' \
351 -printf '%f\t%p\n' | sort | gawk '{ $1="."; print; }' \
352 > build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch.$$
353 mv build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch.$$ \
354 build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config-fixarch
356 # 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