[initramfs] Enhanced output format to run `ldconfig` if etc/ld.so.conf is present
[opensde-nopast.git] / bin / sde-build-tools
blob8b709dc5aac90404a443e80dbd89f7ec34b55015
1 #!/bin/bash
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: bin/sde-build-tools
6 # Copyright (C) 2006 - 2008 The OpenSDE Project
7 # Copyright (C) 2004 - 2006 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 Clifford Wolf
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 # --- SDE-COPYRIGHT-NOTE-END ---
18 #Description: Builds tools, wrappers and caches needed for a build
20 [ -n "$SDEROOT" ] ||
21 export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
23 . "$SDEROOT/lib/libsde.in"
25 create_usage() {
26 local progname=${0##*/}
28 cat <<EOT
29 Usage: ${progname//-/ } [--config <config>] [-<stagelevel>] [--cleanup]
30 EOT
33 shortopts='0123456789c:'
34 longopts='help,config:,cfg:,cleanup'
35 options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
36 if [ $? -ne 0 ]; then
37 create_usage
38 exit -1
41 # load new arguments list
42 eval set -- "$options"
44 config=default
45 stagelevel=9
46 cleanup=0
48 while [ $# -gt 0 ]; do
49 case "$1" in
50 --help)
51 create_usage
52 exit 0
54 --cleanup)
55 cleanup=1
57 -c|--cfg|--config)
58 config="$2"
59 shift
61 -[0-9])
62 stagelevel=${1#-}
64 --)
65 shift
66 break
69 echo_abort 1 "Unknown argument '$1', aborting."
70 esac
71 shift
72 done
74 cd "$SDEROOT"
76 . lib/functions.in
77 . lib/parse-config
79 # all our work here goes to the same location, $TOOLSDIR
81 TOOLSDIR="build/$SDECFG_ID/TOOLCHAIN/$toolsdir"
82 var_remove PATH ":" $base/$TOOLSDIR/bin
83 var_remove PATH ":" $base/$TOOLSDIR/wrapper
85 mkdir -p tmp
86 mkdir -p $TOOLSDIR/bin
87 mkdir -p $TOOLSDIR/wrapper
88 mkdir -p $TOOLSDIR/lib
90 if [ $toolsdir = tools.cross ]; then
91 mkdir -p $TOOLSDIR/{var/adm,etc,share,include}
92 [ -L $TOOLSDIR/usr ] || ln -s . $TOOLSDIR/usr
93 [ -L $TOOLSDIR/sbin ] || ln -s bin $TOOLSDIR/sbin
94 [ -L $TOOLSDIR/var/adm/logs ] || ln -s ../../../../var/adm/logs \
95 $TOOLSDIR/var/adm/logs
96 mkdir -p build/$SDECFG_ID/var/adm/logs
99 x="$( bin/find config/$config/. package/. scripts/. \
100 lib/. architecture/. target/. \( ! -name '*.cache' ! \
101 -name '*.patch*' ! -name '.*' ! -name 'svn-commit.tmp' \
102 \( \! -name '*.conf' -o -name 'pkg*.conf' \) \) -a -type f \
103 -newer $TOOLSDIR/.lastupdate \
104 -printf 'Found new/updated file: %p\n' 2> /dev/null )"
106 if [ "$x" ] ; then
107 echo_header Found $( echo "$x" | wc -l ) new/updated \
108 files in source tree:
109 echo "$x" | head -n 3 | sed 's,/\./,/,g' |
110 while read y ; do echo_status $y ; done
111 [ "$( echo "$x" | tail -n +4 )" ] &&
112 echo_status "** list truncated to save space on the terminal **"
114 if [ "$SDEDEBUG_TOOLS_SKIP" = 1 ]; then
115 echo_error "Found \$SDEDEBUG_TOOLS_SKIP ..."
116 else
117 rm -f $TOOLSDIR/.lastupdate
119 if echo "$x" | grep -qv " config/$config/package" ; then
120 echo_header Re-running configuration:
121 while read -r line ; do
122 echo_status "$line"
123 done < <( ./scripts/Config -cfg $config -oldconfig )
128 if [ $cleanup = 1 ] ; then
129 echo_header "Removing old stuff in $toolsdir/ directory ..."
131 rm -f $TOOLSDIR/wrapper/*
133 rm -f $TOOLSDIR/bin/getdu
134 rm -f $TOOLSDIR/bin/getfiles
135 rm -f $TOOLSDIR/bin/fl_wrparse
136 rm -f $TOOLSDIR/bin/fl_stparse
138 rm -f $TOOLSDIR/lib/fl_wrapper.so
139 rm -f $TOOLSDIR/lib/parse-config
140 rm -f $TOOLSDIR/lib/parse-config-fixarch
141 rm -f $TOOLSDIR/.lastupdate
144 if [ ! -f $TOOLSDIR/.lastupdate ] ; then
146 echo_header "Building tools in build/.../TOOLCHAIN/$toolsdir:"
148 # CC, CXX, F77 and KCC Wrapper
150 wrappers="cmd_wrapper" ; wrappervars=
151 echo_status "Building $toolsdir/wrapper/cmd_wrapper."
152 $BUILDCC -Wall -O2 src/tools-source/cmd_wrapper.c \
153 -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
154 -o $TOOLSDIR/wrapper/tmp.$$ || exit 1
155 mv $TOOLSDIR/wrapper/tmp.$$ \
156 $TOOLSDIR/wrapper/cmd_wrapper
158 build_wrapper() {
159 local x="$( echo ${1//,/ } )" y z
160 wrappervars="$wrappervars $x"
161 while shift ; [ $# != 0 ]
163 wrappers="$wrappers $1"
164 tmp=`mktemp -p $TOOLSDIR/wrapper`
166 echo '#!/bin/bash'
168 for y in $x ; do
169 echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
170 echo "export CMD_WRAPPER_DEBUG=1"
171 done
173 for y in $x ; do
174 echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
175 echo "export CMD_WRAPPER_BYPASS=1"
176 done
178 z=; echo -n 'export CMD_WRAPPER_APPEND_PO="'
179 for y in $x; do
180 echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
181 done ; echo '"'
183 z=; echo -n 'export CMD_WRAPPER_OTHERS="'
184 for y in $x; do
185 echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
186 done ; echo '"'
188 z=; echo -n 'export CMD_WRAPPER_INSERT="'
189 for y in $x; do
190 echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
191 done ; echo '"'
193 z=; echo -n 'export CMD_WRAPPER_REMOVE="'
194 for y in $x; do
195 echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
196 done ; echo '"'
198 z=; echo -n 'export CMD_WRAPPER_APPEND="'
199 for y in $x; do
200 echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
201 done ; echo '"'
203 z=; echo -n 'export CMD_WRAPPER_FILTER="'
204 for y in $x; do
205 echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
206 done ; echo '"'
208 echo 'exec cmd_wrapper $( basename $0 ) "$@"'
209 } > $tmp
210 chmod +rx $tmp
211 mv $tmp "$TOOLSDIR/wrapper/$1"
212 done
215 while read script ; do . $script
216 done < <( bin/find package/. lib/*/. \
217 $( get_reverted `get_expanded target/%/. $targetchain` ) -name 'wrappers.in' )
219 echo_status "Building $toolsdir/wrapper/strip_wrapper."
220 cat << EOT > $TOOLSDIR/wrapper/strip_wrapper.$$
221 #!/bin/sh
222 if [ "\$STRIP_WRAPPER_NOLOOP" = 1 ] ; then
223 echo "Aaaaaeik! Strip wrapper is looping!" >&2
224 exit 1
226 if [ "\$SDECFG_DEBUG" = 0 ] ; then
227 PATH=\${PATH//\$STRIP_WRAPPER_MYPATH:/}
228 export STRIP_WRAPPER_NOLOOP=1
229 exec "\$( basename \$0 )" "\$@"
231 exit 0
233 chmod +x $TOOLSDIR/wrapper/strip_wrapper.$$
234 mv $TOOLSDIR/wrapper/strip_wrapper.$$ \
235 $TOOLSDIR/wrapper/strip_wrapper
236 wrappers="$wrappers strip_wrapper"
238 for x in strip $arch_target-strip ; do
239 [ $crossnative = cross -a $x = strip ] && continue
240 if [ -x "`type -p $x`" ] ; then
241 ln -sf strip_wrapper \
242 $TOOLSDIR/wrapper/$x
243 wrappers="$wrappers $x"
245 done
247 if [ "$toolsdir" = "tools.chroot" ]; then
248 echo_status "Building $toolsdir/wrapper/{uname,arch}."
250 sed -e "s,@@ARCH_MACHINE@@,$arch_machine,g" \
251 src/tools-source/uname_wrapper.in.sh > $TOOLSDIR/wrapper/uname
252 sed -e "s,@@ARCH@@,$( echo $arch | arch2uname ),g" \
253 src/tools-source/arch_wrapper.in.sh > $TOOLSDIR/wrapper/arch
255 chmod +x $TOOLSDIR/wrapper/{uname,arch}
256 wrappers="$wrappers uname arch"
259 echo_status "Building $toolsdir/wrapper/install_wrapper."
260 cp src/tools-source/install_wrapper.sh $TOOLSDIR/wrapper/install_wrapper
261 chmod +x $TOOLSDIR/wrapper/install_wrapper
262 ln -sf install_wrapper $TOOLSDIR/wrapper/install
263 ln -sf install_wrapper $TOOLSDIR/wrapper/cp
264 ln -sf install_wrapper $TOOLSDIR/wrapper/ln
265 ln -sf install_wrapper $TOOLSDIR/wrapper/mv
266 wrappers="$wrappers install_wrapper install cp ln mv"
268 for x in $( ls $TOOLSDIR/wrapper/ )
271 for y in $wrappers ; do
272 [ "$x" = "$y" ] && z=1
273 done
274 if [ "$z" = 0 ] ; then
275 rm -f $TOOLSDIR/wrapper/$x
277 done
279 # 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 src/tools-source/$x.c \
284 -o $TOOLSDIR/bin/$x.$$ || exit 1
285 mv $TOOLSDIR/bin/$x.$$ \
286 $TOOLSDIR/bin/$x
287 done
289 # Flist Wrapper Library
291 if [ "$SDECFG_FLIST" = "flwrapper" ] ; then
292 echo_status "Building $toolsdir/lib/fl_wrapper.so."
293 FLWRAPPER_LIBC=$( ls $xroot/{lib64,lib}/libc.* 2>/dev/null |
294 head -n1 )
295 if [ ! -f "$FLWRAPPER_LIBC" ]; then
296 abort 'Unable to detect /lib/libc.* for flwrapper'
299 if ! atstage native; then
300 FLWRAPPER_BASEDIR="-DFLWRAPPER_BASEDIR=\"$base\""
301 else
302 FLWRAPPER_BASEDIR=
305 sh src/tools-source/fl_wrapper.c.sh > tmp/fl_wrapper_$$.c
306 $BUILDCC -O2 -shared -fPIC -Wall -ldl tmp/fl_wrapper_$$.c \
307 $FLWRAPPER_BASEDIR \
308 -DFLWRAPPER_LIBC=\"${FLWRAPPER_LIBC##*/}\" \
309 -o $TOOLSDIR/lib/fl_wrapper.so.$$ || exit 1
310 rm tmp/fl_wrapper_$$.c
311 mv $TOOLSDIR/lib/fl_wrapper.so.$$ \
312 $TOOLSDIR/lib/fl_wrapper.so
314 echo_status "Testing $toolsdir/lib/fl_wrapper.so."
315 if ! sh -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$SDECFG_ID/`
316 `TOOLCHAIN/$toolsdir/lib/fl_wrapper.so\" date ; `
317 `exit \$?" >/dev/null 2>&1
318 then
319 echo_error "Detected a problem with the flist" \
320 "wrapper lib on your system."
321 echo_error "Please specify another flist-creation" \
322 "system in your build configuration."
323 rm -f $TOOLSDIR/lib/fl_wrapper.so
324 echo ; exit 1
328 # Create Parse-Config Collection
330 echo_status "Creating $toolsdir/lib/parse-config."
331 bin/find \
332 architecture/$arch/. lib/*/. package/. $( get_reverted `get_expanded target/%/. $targetchain` ) -type f \
333 '(' -name 'parse-config' -o -name 'parse-config-[0-9]' ')' \
334 -printf '%f\t%p\n' | sed \
335 -e 's,^parse-config\t,5\t,g' -e 's,^parse-config-\(.\)\t,\1\t,g' | \
336 sort -n | awk '{ $1="."; print; }' \
337 | grep -v lib/output/ \
338 > $TOOLSDIR/lib/parse-config.$$
339 mv $TOOLSDIR/lib/parse-config.$$ \
340 $TOOLSDIR/lib/parse-config
342 bin/find \
343 architecture/$arch/. lib/*/. package/. $( get_reverted `get_expanded target/%/. $targetchain` ) -type f \
344 -name 'parse-config-fixarch' \
345 -printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' \
346 > $TOOLSDIR/lib/parse-config-fixarch.$$
347 mv $TOOLSDIR/lib/parse-config-fixarch.$$ \
348 $TOOLSDIR/lib/parse-config-fixarch
350 # Create pkg_*_{pre,post}.conf files
353 echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
354 rm -f $TOOLSDIR/lib/pkg_*_{pre,post}.conf
355 for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do
356 if [ -f $y ]; then
357 echo " . $y" >> $TOOLSDIR/lib/${y##*/}
359 done
361 if atstage rebuild; then
362 for x in /var/adm/packages/*; do
363 ls -1d package/*/${x##*/}/pkg_*_{pre,post}.conf 2> /dev/null
364 done
365 else
366 for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
367 ls -1d package/$x/pkg_*_{pre,post}.conf 2> /dev/null
368 done
369 fi | while read y; do
370 echo " . $y" >> $TOOLSDIR/lib/${y##*/}
371 done
373 echo -e "${wrappervars// /\n}" | grep . | sort -u |
374 while read x ; do
375 echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
376 echo "export ${x}_WRAPPER_OTHERS= ${x}_WRAPPER_REMOVE="
377 echo "export ${x}_WRAPPER_INSERT= ${x}_WRAPPER_APPEND="
378 echo "export ${x}_WRAPPER_FILTER= ${x}_WRAPPER_APPEND_PO="
379 done > $TOOLSDIR/lib/wrapper-config.$$
380 mv $TOOLSDIR/lib/wrapper-config.$$ \
381 $TOOLSDIR/lib/wrapper-config
383 touch $TOOLSDIR/.lastupdate
386 exit 0