* initial build progress indicator for target and emerge
[t2sde.git] / scripts / Build-Pkg
blob70cd854f6dd2d6669f6126e35c5910df2560420a
1 #!/usr/bin/env bash
3 # --- T2-COPYRIGHT-BEGIN ---
4 # t2/scripts/Build-Pkg
5 # Copyright (C) 2004 - 2025 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 # SPDX-License-Identifier: GPL-2.0
8 # --- T2-COPYRIGHT-END ---
10 exec 2>&1
12 buildstart="`date '+%s'`"
14 options=''
15 config=default
17 clear_src=1
18 norebuild=0
19 update=0
21 make_tar=''
22 prefix="usr"
23 prefix_auto=1
24 verbose=0
25 xtrace=0
26 debug=0
27 chroot=0
28 root=""
29 id=''
30 progress=
32 stagelevel=9
33 this_is_the_2nd_run=0
36 # ---- Functions
40 help_msg() {
41 spacer=" "
42 echo
43 echo "Usage: scripts/Build-Pkg" \
44 "[ -0 | -1 | -2 ... | -8 | -9 ] \\"
45 echo "$spacer [ -v ] [ -xtrace ] [ -chroot ] \\"
46 echo "$spacer [ -root { <rootdir> | auto } ] \\"
47 echo "$spacer [ -cfg <config> ] [ -update ] \\"
48 echo "$spacer [ -prefix <prefix-dir> ] [ -norebuild ] \\"
49 echo "$spacer [ -noclearsrc ] \\"
50 echo "$spacer [ -id <id> ] [ -debug ] pkg-name(s)"
51 echo
56 # ---- Parse options + config and make Build-Pkg sub-calls
59 while [ "$1" ]; do
60 case "$1" in
61 -this_is_the_2nd_run) this_is_the_2nd_run=1 ;;
62 -[0-9]) options="$options $1" stagelevel=${1#-} ;;
63 -v) options="$options $1" verbose=1 ;;
64 -xtrace) options="$options $1" xtrace=1 ;;
65 -debug) options="$options $1" debug=1 clear_src=0 ;;
66 -update) options="$options $1" update=1 ;;
67 -chroot) options="$options $1" chroot=1 ;;
68 -chr-sub) options="$options $1" chroot=0 ;;
69 -cfg) options="$options $1 $2" config="$2" ; shift ;;
70 -progress) options="$options $1 $2" progress="$2" ; shift ;;
71 -root) options="$options $1 $2" root="$2" ; shift ;;
72 -prefix) options="$options $1 $2" prefix="$2" prefix_auto=0 ; shift ;;
73 -id) options="$options $1 $2" id="$2" ; shift ;;
74 -noclearsrc) options="$options $1" clear_src=0 ;;
75 -norebuild) options="$options $1" norebuild=1 ;;
76 -*) help_msg; exit 1 ;;
77 *) break ;;
78 esac
79 shift
80 done
82 # check if arguments are left as package names
83 if [ $# = 0 ]; then
84 help_msg; exit 1
87 . scripts/functions.in
88 . scripts/parse-config
90 if [ -z "$root" -a $stagelevel -le 2 ] ||
91 [ -z "$root" -a $chroot -eq 1 ] ||
92 [ "$root" = auto ]; then
93 # stage 0 cross compiler build
94 if [ $stagelevel -eq 0 ]; then root="build/$SDECFG_ID/TOOLCHAIN/$toolsdir"
95 # the new systems root
96 else root="build/$SDECFG_ID"; fi
99 [ "$root" -a "${root#/}" = "$root" ] && root="$base/$root"
101 # remove leading and trailing / on prefix and root
102 prefix=${prefix%/} prefix=${prefix#/} root=${root%/}
104 # xroot is for internal use and always points to the new system
105 xroot="$root"
106 if [ $stagelevel -le 2 ]; then
107 sysroot="$base/build/$SDECFG_ID" # always fresh sandbox
108 else
109 root=
110 sysroot=
114 if [ -z "$id" ]; then
115 id=`get_unique`
116 options="$options -id $id"
119 # more than one package is passed
120 if [ $# -gt 1 ]; then
121 for x; do
122 if ! scripts/Build-Pkg $options $x &&
123 [ $stagelevel -le $SDECFG_CONTINUE_ON_ERROR_AFTER ]; then
124 exit 1
126 done
127 exit 0
130 pkg="${1%=*}" xpkg="${1#*=}"
132 builddir="$base/src.$pkg"
133 [ $config != "default" ] && builddir="$builddir.$config"
134 builddir="$builddir.$id"
136 if [ "$chroot" = 1 ]; then
138 cd "$xroot" || exit 1
140 x_mknod() {
141 if [ ! -c "$1" -a ! -b "$1" ]; then
142 mknod "$@"
146 x_mknod dev/null c 1 3
147 x_mknod dev/zero c 1 5
148 x_mknod dev/random c 1 8
149 x_mknod dev/urandom c 1 9
150 x_mknod dev/loop0 b 7 0
151 x_mknod dev/loop1 b 7 1
152 x_mknod dev/loop2 b 7 2
153 x_mknod dev/loop3 b 7 3
154 #_mknod dev/tty c 5 0
156 if [ ! -L dev/fd ]; then
157 ln -s /proc/self/fd dev/fd
160 realconf=$(cd $base/config; pwd -P)
161 realdown=$(cd $base/download; pwd -P)
162 realbase=$(dirname $(cd $base/scripts; pwd -P))
164 if [ ! -e TOOLCHAIN/loop/scripts ]; then
165 mkdir -p TOOLCHAIN/{loop,config,download}
166 mount --bind $realbase TOOLCHAIN/loop
167 mount --bind $realconf TOOLCHAIN/config
168 mount --bind $realdown TOOLCHAIN/download
169 mount --bind /tmp tmp
172 if [ ! -f proc/mounts ]; then
173 mount -nt proc proc proc
176 for x in architecture kernel misc package scripts target; do
177 if [ ! -e TOOLCHAIN/$x ]; then ln -s "loop/$x" "TOOLCHAIN/$x"; fi
178 done
180 if [ ! -e "TOOLCHAIN/build/$SDECFG_ID" ]; then
181 mkdir -p "TOOLCHAIN/build"
182 ln -snf ../.. "TOOLCHAIN/build/$SDECFG_ID"
185 mkdir -p "TOOLCHAIN/src.$pkg.$config.$id"
186 ln -s "$PWD/TOOLCHAIN/src.$pkg.$config.$id" "$builddir"
188 cat > $builddir/chroot.sh <<- EOT
189 export SDE_THIS_IS_CHROOT=1; cd /TOOLCHAIN
190 scripts/Build-Pkg $options -chr-sub -root "/" "$1"
193 cat > $builddir/debug.sh <<- EOT
194 #!/usr/bin/env bash
195 if [ ! -f "$xroot/proc/mounts" ]; then
196 mount -nt proc proc "$xroot/proc"
198 if [ ! -e "$xroot/TOOLCHAIN/loop/scripts" ]; then
199 mkdir -p "$xroot/"TOOLCHAIN/{loop,config,download}
200 mount --bind $realbase "$xroot/TOOLCHAIN/loop"
201 mount --bind $realconf "$xroot/TOOLCHAIN/config"
202 mount --bind $realdown "$xroot/TOOLCHAIN/download"
205 export SDE_THIS_IS_CHROOT=1
206 chroot "$xroot" /bin/bash TOOLCHAIN/src.$pkg.$config.$id/debug_x.sh
208 if ! fuser -s "$xroot/TOOLCHAIN/"; then
209 echo "Loop mounts appear unused - un-mounting ..."
210 umount "$xroot/TOOLCHAIN/"{loop,config,download}
211 umount "$xroot/{proc,tmp}"
214 chmod +x $builddir/debug.sh
216 if [ "$TZ" ]; then
217 if [ "${TZ#/}" != "$TZ" ]; then
218 cp $TZ TOOLCHAIN/localtime
219 else
220 cp /usr/share/zoneinfo/$TZ TOOLCHAIN/localtime
222 else
223 if [ -f /etc/localtime ]; then
224 cp /etc/localtime TOOLCHAIN/localtime
225 else
226 ln -sf /usr/share/zoneinfo/Factory TOOLCHAIN/localtime
230 if [ "$SDECFG_PKG_DISTCC_HOST_RESOLV" = "1" ]; then
231 cat /etc/resolv.conf > etc/resolv.conf
234 TZ="/TOOLCHAIN/localtime" chroot . bin/bash TOOLCHAIN/src.$pkg.$config.$id/chroot.sh
235 returncode=$?
237 if [ ! -d "$builddir/." ]; then
238 rm "$builddir"
241 exit $returncode
244 scripts/Build-Tools -$stagelevel -cfg $config || exit 1
246 if [ "$SDECFG_FLIST" = "flwrapper" -a -z "$FLWRAPPER" ]; then
247 export FLWRAPPER_WLOG="$builddir/fl_wrapper.wlog"
248 export FLWRAPPER_RLOG="$builddir/fl_wrapper.rlog"
249 export FLWRAPPER_BASEPID=$$
250 export FLWRAPPER_FILTERDIR="/tmp/:$builddir"
251 [ "$LD_PRELOAD" ] && LD_PRELOAD="${LD_PRELOAD}:"
252 export FLWRAPPER="$base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so"
253 export LD_PRELOAD="${LD_PRELOAD}$FLWRAPPER"
255 export INSTALL_WRAPPER_LOGFILE="$builddir/install_wrapper.log"
256 export CMD_WRAPPER_LOGFILE="$builddir/cmd_wrapper.log"
258 if [ $norebuild = 1 -a -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
259 echo_pkg_deny $stagelevel $pkg "already built"
260 exit 0
263 # TODO: should we be pedantic and force rebuild of low stages even if $norebuild?
264 if [ "$SDECFG_RETRY_BROKEN" = 0 -a $norebuild = 1 -a \
265 -f $root/var/adm/logs/$stagelevel-$xpkg.err ]; then
266 echo_pkg_deny $stagelevel $pkg "already failed"
267 exit 1
270 archdir="$builddir/archdir"
272 detect_confdir
274 if [ -z "$confdir" ]; then
275 echo_pkg_deny $stagelevel $pkg "does not exist"; exit 1
278 mkdir -p $root/var/adm/{logs,flists,olists,md5sums,packages,dependencies,\
279 dep-debug,parse-config,cache,descs}
280 rm -f $root/var/adm/logs/$stagelevel-$xpkg.{out,log,err}
282 md5sum=md5sum
283 if ! type -p $md5sum > /dev/null; then
284 md5sum="md5 -r"
287 if [ $this_is_the_2nd_run = 0 ]; then
288 [ $stagelevel -gt 2 ] && . /etc/profile
289 options="-this_is_the_2nd_run $options $pkg=$xpkg"
290 if [ "$SDECFG_CREATE_CACHE" = 1 ]; then
291 mkdir -p $root/var/adm/cache
292 rm -f $root/var/adm/cache/$xpkg{,.tm}
294 /usr/bin/time -o "$root/var/adm/cache/$xpkg.tm" \
295 -f '%U %S' $0 $options
296 returncode=$?
297 [ ! -e "$root/var/adm/cache/$xpkg.tm" ] && exit $returncode
299 buildtime=$(grep -v '^Command ' < $root/var/adm/cache/$xpkg.tm |
300 gawk '{printf "%d", ($1 + $2) * 100 }')
301 rm -f $root/var/adm/cache/$xpkg.tm
303 # store reference time
304 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
305 if [ $pkg = binutils ]; then
306 echo $buildtime > $base/build/$SDECFG_ID/TOOLCHAIN/reftime
309 # estimate initial, non-binutils reference time from first in-system emerge
310 if [ ! -s $base/build/$SDECFG_ID/TOOLCHAIN/reftime -a \
311 $stagelevel = 9 -a $buildtime -gt 1000 -a \
312 -e $base/package/*/$pkg/$pkg.cache ]; then
313 reftime=$(sed -n "s/\[BUILDTIME\] \([^ ]*\).*/\1/p" $base/package/*/$pkg/$pkg.cache)
315 gawk "BEGIN {printf(\"%d\n\", int($buildtime * 100 / ($reftime > 0 ? $reftime : 1)));}" > \
316 $base/build/$SDECFG_ID/TOOLCHAIN/reftime
320 # compute relative build time to binutils (LFS-style)
321 if [ -s $base/build/$SDECFG_ID/TOOLCHAIN/reftime ]; then
322 reftime=$(< $base/build/$SDECFG_ID/TOOLCHAIN/reftime)
323 else
324 reftime=$buildtime # so until we have a ref all will be 100%
326 # quantize for less .cache update noise
327 buildtime=`gawk "BEGIN { buildtime = 100 * $buildtime / $reftime; \
328 if (buildtime <= 5) q = 1; else if (buildtime <= 20) q = 2; \
329 else if (buildtime <= 200) q = 5; else if (buildtime <= 500) q = 10; \
330 else if (buildtime <= 1000) q = 20; else q = 50; \
331 printf(\"%d\", int((buildtime + q/2) / q) * q); }"`
334 date '+[TIMESTAMP] %s %c'
336 [ -f $root/var/adm/logs/$stagelevel-$xpkg.err ] &&
337 x=" ERROR" || x=""
339 echo "[BUILDTIME] $buildtime ($stagelevel)$x"
341 x="$root/var/adm/packages/$xpkg"
342 if [ -f $x ]; then
343 echo "[SIZE] `grep "^Package Size: " $x |
344 cut -f3- -d' '`"
346 echo
348 x="$root/var/adm/dependencies/$xpkg"
349 [ "$pkg" != "t2-debug" -a -f $x ] &&
350 sed 's,^opt:,[OPT],; s,^:,[DEP],' $x
351 } > $root/var/adm/cache/$xpkg
353 exit $returncode
354 else
355 exec $0 $options
361 # ---- Setting Build Variables
364 flistroot="bin boot etc lib lib64 lib32 libx32 sbin usr var opt run"
366 # remove the obvious noise: ldconfig, our /var/adm as well as other noise
367 flistrfilter="ldconfig\..*: .*|.*: /bin/sh|.*: /bin/hostname|.*: /var/adm/.*|.*: .*/share/locale/.*"
368 # indirectly referenced .so
369 var_append flistrfilter '|' ".*: .*/lib.*\.so.*"
370 # everything configure tries randomly e.g. even bin/mt(-st)
371 var_append flistrfilter '|' ".*configure.*: .*"
372 var_append flistrfilter '|' ".*doxygen\..*dot.*: .*"
373 var_append flistrfilter '|' ".*cmake\..*: .*/lib.*/.*\.cmake"
374 var_append flistrfilter '|' ".*qmake\..*: .*/mkspecs/.*\.p.*"
375 var_append flistrfilter '|' ".*: .*/gettext/its/.*.loc"
376 # some packages just query all, if really used .h et al. are used anyway
377 var_append flistrfilter '|' ".*pkg-config.*: .*\.pc"
378 var_append flistrfilter '|' ".*: .*/gtk-doc/.*\.devhelp2"
379 # python registry
380 var_append flistrfilter '|' ".*/site-packages/.*(PKG-INFO|METADATA|egg-info|entry_points.txt|requires.txt)"
381 # x11 mkfontdir's mkfontscale
382 var_append flistrfilter '|' ".*mkfontscale\..*: .*"
383 # fc-cache
384 var_append flistrfilter '|' ".*fc-cache\..*: .*"
385 # wxrc & friends
386 var_append flistrfilter '|' ".*: .*\.desktop"
388 # ignore some written files, too
389 flistdel="etc/ld.so.cache|proc/[0-9]*/fd|etc/blkid.tab|var/tmp/.*|usr/tmp/.*|var/adm/logs/.*|.*\\.old"
391 # filter some cache and query updates
392 var_append flistdel '|' ".*/gio/modules/giomodule.cache|.*/schemas/gschemas.compiled"
393 var_append flistdel '|' ".*/share/icons/.*/icon-theme.cache|.*/share/applications/mimeinfo.cache"
394 var_append flistdel '|' ".*/lib.*gdk-pixbuf-.*/loaders.cache"
396 flistvalid="$base|/tmp|/var/backups|/proc|/dev"
397 foodirlist="bindir sbindir libdir datadir includedir sysconfdir localstatedir docdir"
399 init_vars_and_hooks
402 # ---- Read various config files
405 parse_desc $pkg
407 echo_pkg_start $stagelevel $repository $xpkg $ver "$extraver" "$(pkgbuildtime $pkg)" "$progress"
409 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
410 x="`scripts/Check-PkgFormat $pkg`"
411 [ "$x" ] && abort "$x\nDisable the 'Paranoia Check' config `
412 `option to ignore such errors."
415 targetdir="$base/target/$target"
417 detect_patchfiles
419 if [ $stagelevel -gt 2 ]; then
420 for pc_file in $xroot/var/adm/parse-config/*; do
421 if [ -s "$pc_file" -a "${pc_file##*/}" != "$xpkg" ]
422 then . "$pc_file"; fi
423 done
424 unset pc_file
426 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
428 set_confopt
430 hasflag OBJDIR && configscript="../configure" &&
431 hook_add preconf 3 "mkdir -p objs; cd objs"
433 if ! hasflag NOPARALLEL; then
434 var_append makeopt " " "-j${SDECFG_PARALLEL:-1}"
435 var_append makeinstopt " " "-j${SDECFG_PARALLEL:-1}"
438 # Erase positional parameters to prevent unintended parameter
439 # passing. We do not want to pass the current positional parameters
440 # to the loaded script.
441 set --
442 eval "$desc_O"
444 # include package pre config - if any
445 if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf ]; then
446 echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_pre.conf"
447 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf
450 # read the package configuration, $confdir might differ from package/*/$pkg ...
451 for x in $(get_expanded $base/target/%/pkg_$pkg.conf $targetchain) \
452 $targetdir/package/$pkg/$pkg.conf \
453 architecture/$arch/package/$pkg/$pkg.conf \
454 $confdir/$pkg.conf \
455 $base/package/*/$pkg/$pkg.conf; do
456 if [ -f $x ]; then
457 [ $x != $base/package/*/$pkg/$pkg.conf ] &&
458 echo_status "Reading package config: ${x#$base/}"
459 . $x
460 break
462 done
464 # include package post config - if any
465 if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf ]; then
466 echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_post.conf"
467 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf
470 if [ -f $base/architecture/$arch/pkg-header ]; then
471 echo_status "Reading overwrites from architecture/$arch/pkg-header."
472 . $base/architecture/$arch/pkg-header
475 for x in $(get_expanded $base/target/%/pkg-header `get_reverted $targetchain`); do
476 if [ -f $x ]; then
477 echo_status "Reading overwrites from ${x#$base/}."
478 . $x
480 done
483 # ---- Variable updates based on the configuration files read
486 if [ -z "$prefix" -o "${prefix#usr}" != "$prefix" ]; then
487 flistdel="$flistdel|usr/share/info/(dir|standards.info)"
488 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
489 flistdel="$flistdel|usr/share/locale/..[/_].*"
490 flistdel="$flistdel|usr/share/man/..[/_].*"
492 else
493 flistdel="$flistdel|$prefix/info/(dir|standards.info)"
494 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
495 flistdel="$flistdel|$prefix/share/locale/..[/_].*"
496 flistdel="$flistdel|$prefix/man/..[/_].*"
501 # ---- Build Package
503 if hasflag NOPARALLEL || [ "$SDECFG_PARALLEL" -le 1 ]; then
504 hasflag NOPARALLEL && [ "$SDECFG_PARALLEL" -gt 1 ] &&
505 echo_warning 'Parallel build disabled for this package'
506 echo_status "Building in ${builddir##*/}"
507 else
508 echo_status "Building in ${builddir##*/}, with $SDECFG_PARALLEL threads"
511 mkdir -p $builddir; chmod 755 $builddir
513 if [ "$SDECFG_TMPFS_MAX_SIZE" != 0 ]; then
514 x="$(match_source_file -p)"
515 [ "$x" ] && x="$(du -cm $x | tail -1 | cut -f 1)"
516 [ "$x" ] || x=0
517 [ "$x" -gt "${SDECFG_TMPFS_MAX_SIZE:-0}" ] && SDECFG_TMPFS=0
520 if [ $clear_src = 1 ]; then
521 if [ "$SDECFG_TMPFS" = 1 ]; then
522 mount -n -o remount,exec,$SDECFG_TMPFS_OPT /tmp
523 mkdir -p /tmp/${builddir##*/}
524 mount -n --bind /tmp/${builddir##*/} $builddir
528 export TMPDIR="$builddir/tmp"
529 mkdir -p "$TMPDIR"
531 if [ $update = 1 -a ! -f $xroot/var/adm/md5sums/$xpkg ]; then
532 #echo_warning "Ignoring update mode since package isn't installed already."
533 update=0
536 if [ $update = 1 ]; then
537 echo_status "Creating backup of old package data."
539 cd $xroot/
540 $md5sum --check var/adm/md5sums/$xpkg 2>&1 < /dev/null |
541 grep ': FAILED$' | cut -f1 -d:
542 ) > $builddir/backup_files.txt
543 if [ -s $builddir/backup_files.txt ]; then
544 mkdir -p "$xroot/var/adm/backup"
545 chmod 700 "$xroot/var/adm/backup"
546 backup_tar="$xroot/var/adm/backup/$(
547 date '+%Y%m%d%H%M%S')_$xpkg.tar.bz2"
548 (cd $xroot/; tar --no-recursion -cf - -T $builddir/`
549 `backup_files.txt || true) | bzip2 > $backup_tar
550 else
551 update=0
555 if [ "$SDECFG_FLIST" = "flwrapper" ]; then
556 rm -f $builddir/fl_wrapper.{rlog,wlog}
557 touch $builddir/fl_wrapper.{rlog,wlog}
558 elif [ "$SDECFG_FLIST" = "find" ]; then
559 touch $builddir/temp.time_stamp
560 sleep 2
563 hook_eval prepare
565 # define new abort function for errors while building
567 abort() {
568 [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
569 rm -vf $root/var/adm/logs/$stagelevel-$xpkg.log
570 false
574 trap 'echo "Got SIGINT (Ctrl-C). Aborting build."; exit 1' INT
575 exec < /dev/null
577 # Makes debugging build problems easier
579 hook_dump > $builddir/debug.hooks
582 dump_env
583 cat <<- EOT
584 PS1='\\[\\e[00m\\e[01;31m\\]debug-`
585 `$xpkg\\[\\e[00m\\]:[\\W]\\\$ '
586 alias cp="cp -i"; alias mv="mv -i"
587 alias rm="rm -i"; alias ls="ls --color=auto -a"
588 alias ..="cd .."; alias ...="cd ../.."
589 fixfile () {
590 # we use .vanilla to not rediff backup .orig from patch
591 for f; do [ -f \$f.vanilla ] || cp \$f{,.vanilla}; done
592 # maybe we do not have the editor yet?
593 which \$EDITOR > /dev/null || EDITOR=nvi
594 LD_PRELOAD= \$EDITOR "\$@"
596 fixfilediff() {
597 local p=\${1:+$confdir/\$1}
598 (find -name '*.vanilla' -printf '%P\n' | while read x; do
599 diff -u \$x \${x/.vanilla/}
600 done) | tee -a \${p:-/dev/null}
603 } > $builddir/debug.buildenv
605 cat > $builddir/debug_x.sh <<- EOT
606 #!/usr/bin/env bash
607 cd $builddir
608 [ -f ERROR-LOG ] && sed -n 's/^[rR]unning.*/# &/p' ERROR-LOG
609 exec bash --rcfile debug.buildenv 200>> build.pid
612 if [ "$SDE_THIS_IS_CHROOT" != 1 ]; then
613 mv $builddir/debug_x.sh $builddir/debug.sh
614 chmod +x $builddir/debug.sh
617 # Create PID file
619 # The builtin-variable '$$' is not this pid because this proc
620 # is just a sub-proc of $$. That's why the $builddir/strace.tmp
621 # hack is required to get the right pid to trace.
623 # We also conntect filedescriptor 3 with the pid file. So the command
624 # 'fuser' can be used to create a list of all processes which are part
625 # of this build process.
627 sh -c 'echo $PPID' > $builddir/build.pid
628 exec 200>> $builddir/build.pid
630 if [ "$SDECFG_DEBUG" != 0 ]; then
631 hasflag KERNEL && _CC=$KCC || _CC=$CC
632 echo "Command wrapper test: '${_CC} --version'"
633 type ${_CC}; CMD_WRAPPER_DEBUG=1 ${_CC} --version
634 unset _CC
635 echo "[ writing debug log to $builddir/cmd_wrapper.log ]"
638 if [ "$debug" = 1 ]; then
639 echo "Everything is set up. We are in debug mode - so exit now."
640 exit
643 if [ "$SDECFG_FLIST" = "strace" ]; then
644 strace -o $builddir/strace.out -F -f -q -e open,creat,mkdir,`
645 `mknod,link,symlink,rename,utime,chdir,execve,fork,`
646 `vfork,_exit,exit_group -p $(< $builddir/build.pid) &
647 strace_pid=$!; sleep 1; cd $base
651 set -e
653 mkdir -p "$builddir/archdir"
654 populate_archdir
656 echo "Running main build function '$mainfunction'"
657 if [ $xtrace -eq 1 -o $SDECFG_XTRACE -eq 1 ]; then
658 PS4=$'=[$FUNCNAME:$LINENO (last \\\$?=$?)> '; set -o xtrace
659 cd $builddir; eval "$mainfunction"
660 set +o xtrace
661 else
662 cd $builddir; eval "$mainfunction"
664 touch $root/var/adm/logs/$stagelevel-$xpkg.log
666 [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ||
667 abort "Due to previous errors, no $stagelevel-$xpkg.log file!
668 (Try enabling xtrace in the config to track an error inside the build system.)"
670 hook_eval postinstall
672 echo "Creating file list and doing final adaptions ... "
674 cd $xroot/
675 [ -s "var/adm/parse-config/$xpkg" ] &&
676 echo "var/adm/parse-config/$xpkg" >> $builddir/flist.txt
677 for x in var/adm/{flists,md5sums,packages,descs,dependencies}/$xpkg; do
678 touch $x; echo "$x" >> $builddir/flist.txt
679 done
681 if [ "$SDECFG_FLIST" = "strace" ]; then
682 sleep 1; kill -INT $strace_pid; sleep 1
683 fl_stparse -w $builddir/fl_wrapper.wlog \
684 -r $builddir/fl_wrapper.rlog < $builddir/strace.out
686 if [ "$SDECFG_FLIST" = "flwrapper" -o "$SDECFG_FLIST" = "strace" ]; then
687 if [ "$stagelevel" -le 2 ]; then
688 xbase="$(cd $xroot/ 2> /dev/null; pwd -P)"
689 flistvalid="$xbase|$flistvalid"
690 found_invalid=0
691 while read file; do
692 if [ -e "$file" ]; then
693 echo "Created file outside basedir: $file"
694 abort_soon=1
695 else # non fatal for now (configure junk)
696 echo "Warning: Created vanished file outside basedir: $file"
698 if [ "$found_invalid" = 0 ]; then
699 echo "base #1: $base"
700 echo "base #2: $xbase"
701 found_invalid=1
703 done < <(egrep -v " ($flistvalid)/" $builddir/fl_wrapper.wlog |
704 cut -f2- | sort -u)
706 [ "$abort_soon" = 1 ] && abort
709 fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog > $builddir/flist.txt.tmp
711 # check for file creation beside the allowed top-level
712 # directories - allow root since qt, wxwidgets, ... create some
713 # profile there ... - on stage 0 we have an ugly symlink hack
714 # so we get doc, $arch_machine, ... in the top level dir :-(
715 if [ $stagelevel -gt 0 ]; then
716 fr="$flistroot root TOOLCHAIN proc/[0-9]*/fd"
718 while read file; do
719 echo "Created file outside allowed top-level dir: $file"
720 abort_soon=1
721 done < <(egrep -v "^(${fr// /|})(/|$)" \
722 $builddir/flist.txt.tmp)
723 [ "$abort_soon" = 1 ] && abort
726 egrep "^(${flistroot// /|})(/|$)" $builddir/flist.txt.tmp >> $builddir/flist.txt
728 elif [ "$SDECFG_FLIST" = "find" ]; then
729 find $flistroot \
730 \( -not -type d -or -type d -empty \) \
731 -and \( -newer $builddir/temp.time_stamp -or \
732 -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> $builddir/flist.txt
735 # evaluate flistdel
736 egrep -v "^($flistdel)\$" $builddir/flist.txt > $builddir/flist.txt.new
737 mv $builddir/flist.txt{.new,}
739 hook_eval postflist
741 # save the old flist for later orphaned file check
742 [ -e var/adm/flists/$xpkg ] &&
743 cp -f var/adm/flists/$xpkg $builddir/flist.txt.old
745 fl_wrparse -D -p "$xpkg" -r "$xroot/" < $builddir/flist.txt |
746 sort -u > $builddir/flist.txt.new
748 # analyze which files have not been reinstalled and thus are (normally)
749 # no longer needed (orphaned)
750 if [ -e $builddir/flist.txt.old ]; then
751 echo "Searching for orphaned files ..."
752 diff --normal $builddir/flist.txt.{old,new} |
753 grep '^<' | cut -d ' ' -f 2- > $builddir/olist.txt.new
754 [ -e var/adm/olists/$xpkg ] &&
755 cp -f var/adm/olists/$xpkg $builddir/olist.txt.old ||
756 touch $builddir/olist.txt.old
757 cat $builddir/olist.txt.{old,new} | sort -u > var/adm/olists/$xpkg
760 # TODO: until all olist regressions are fixed merge the two lists ...
761 touch $builddir/flist.txt.old
762 if [ "$noorphaned" = 1 ]; then
763 cat $builddir/flist.txt.new > var/adm/flists/$xpkg
764 else
765 cat $builddir/flist.txt.{old,new} | egrep -v "^$xpkg: ($flistdel)\$" |
766 sort -u > var/adm/flists/$xpkg
768 echo Found `wc -l < var/adm/flists/$xpkg` "files for this package."
769 echo Found `wc -l < var/adm/olists/$xpkg` "orphaned files for this package."
771 if [ $stagelevel -gt 0 ] && [ "$SDECFG_FLIST" = "flwrapper" -o "$SDECFG_FLIST" = "strace" ]
772 then
773 echo "Calculating package dependencies ..."
775 # don't depend on shared, randomly 1st created directories
776 var_append flistrfilter '|' ".*\.mkdir: .*"
778 ! egrep -v "^($flistrfilter)\$" $builddir/fl_wrapper.[rw]log |
779 sort -u | fl_wrparse -D -s -r "$xroot/" -p '' | sort -u |
780 grep -v ' var/adm/' | gawk '
781 # read the var/adm/... file content in
782 ARGIND < ARGC-1 {
783 if ($1 != "'$xpkg':")
784 f[$2] = $1 " " f[$2];
786 # iterate over the read file list streamed to stdin
787 ARGIND == ARGC-1 {
788 file = $2;
789 if (f[file]) {
790 print f[file] " " file;
793 ' var/adm/flists/* - >> $builddir/dependencies.debug
795 awk 'BEGIN { FS=": "; } { print ": " $1; }' \
796 < $builddir/dependencies.debug >> $builddir/dependencies.txt
798 sort -u $builddir/dependencies.debug > var/adm/dep-debug/$xpkg
800 # alternatives handling, 1st so pkgs can enforce alternatives
801 alt_pattern=
802 while read basepkg alt; do
803 var_append alt_pattern ';' "s/$alt/$basepkg/"
804 done < <(< $base/misc/share/PKG-ALTERNATIVES)
805 sed "$alt_pattern" $builddir/dependencies.txt > $builddir/dependencies.txt.new
806 mv $builddir/dependencies.txt{.new,}
808 # remove dependencies as requested by the package
809 # TODO: goups are not used yet (and it is not easy here)
810 del_pattern=
811 for x in t2-src $SDECFG_LIBC $SDECFG_DEFAULT_CC ${compressor%% *} \
812 `echo "$desc_E" | sed -n 's/^del //p' `; do
813 del_pattern="$del_pattern -e \".*: $x\$\""
814 done
815 if [ -n "$del_pattern" ]; then
816 echo "Deleting dependencies, pattern: $del_pattern ..."
817 eval egrep -v $del_pattern \
818 $builddir/dependencies.txt > $builddir/dependencies.txt.new
819 mv $builddir/dependencies.txt{.new,}
822 # merge the dependencies defined by the package
823 echo -n "Adding dependencies"
824 for x in `echo "$desc_E" | egrep '^(add|opt) ' | sed 's/^[^ ]* //' `; do
825 echo -n ", $x"
826 echo ": $x" >> $builddir/dependencies.txt
827 done
828 echo
830 sort -u $builddir/dependencies.txt > $builddir/dependencies.txt.new
831 mv $builddir/dependencies.txt{.new,}
833 echo -n "Marking optional dependencies"
834 for x in `echo "$desc_E" | sed -n 's/^opt //p' `; do
835 echo -n ", $x"
836 sed -i "s/^: $x$/opt&/" $builddir/dependencies.txt
837 done
838 echo
840 cat $builddir/dependencies.txt > var/adm/dependencies/$xpkg
843 echo "Creating md5sum files ..."
844 getfiles < var/adm/flists/$xpkg > $builddir/files.lst
845 grep -v '^var/adm/' $builddir/files.lst | sed -e 's,^.*,"\0",' |
846 xargs -r $md5sum > var/adm/md5sums/$xpkg
848 echo "Creating package description ..."
850 buildend="`date '+%s'`"
851 buildlist="$(grep "^Build \[.\] at " var/adm/packages/$xpkg || true
852 echo "Build [$stagelevel] at `date --date=@$buildstart '+%Y-%m-%d from %T'`" \
853 "to `date --date=@$buildend '+%T'`" \
854 " `date --date=@$((buildend - buildstart)) --utc '+%H:%M:%S'`")"
856 srccksum=$(pkgchksum $base/package/*/$pkg)
857 cat > var/adm/packages/$xpkg << EOT
858 Package Name and Version: $xpkg $ver $extraver
859 Package Size: `getdu $root/ < var/adm/flists/$xpkg`, `
860 wc -l < var/adm/flists/$xpkg | tr -d ' '` files
861 T2 Package Source Checksum: $srccksum
862 T2 Version and Architecture: $sdever $arch
863 $buildlist
864 Prefix: $prefix
867 # Location libdir: /opt/*/lib
868 for x in $foodirlist; do
869 if [ "`eval echo \\$$x`" != "`pkggetdir $x`" ]; then
870 echo "Location $x: `eval echo \\$$x`" \
871 >> var/adm/packages/$xpkg
873 done
875 cat >> var/adm/packages/$xpkg << EOT
876 Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
878 ${desc_I:-$xpkg}
880 $(echo "${desc_T:-No description available.}" | sed 's,^, ,')
882 URL(s):
883 $(echo "${desc_U:-http://t2sde.org/packages/$pkg.html}" | sed 's,^, ,')
885 Original Author(s):
886 $(echo "${desc_A:-Unknown}" | sed 's,^, ,')
888 Package Maintainer(s):
889 $(echo "${desc_M:-Unknown}" | sed 's,^, ,')
891 Download URL(s):
892 $(echo "${desc_D:-None}" | gawk '{ print " " $3 $2; }')
895 echo "[CONFIG] ${SDECFG_ID#*-}"
896 descfile=$base/package/*/$pkg/$pkg.desc
897 while read x; do
898 if [ "${x#\[}" != "$x" ]; then
899 x="`echo ${x// */} | tr -d '[]'`"
900 y="${x/-/_}"
901 IFS='
903 eval lines=\"\${desc_$y}\"
904 for line in $lines; do
905 echo "[$x] $line"
906 done
908 done < $base/misc/share/PKG-DESC-FORMAT
909 ) > var/adm/descs/$xpkg
911 echo "Making post-install adaptions."
913 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
914 found_errors=0
915 found_dups=0
917 # check for files which are 'shared' with other packages
918 if [ "$check_shared" != "0" ]; then
919 while read _ file; do
920 # ignore shared directories
921 [ -d $root/$file ] && continue
923 if [ $found_dups = 0 ]; then
924 echo "Found shared files with other packages:"
925 found_errors=1 found_dups=1
927 echo "$file:" $(cd $root/var/adm/flists; grep -l " $file\$" *)
928 # sed $xpkg to . to have this pkg's duplicates sorted first
929 done < <(sed "s,^$xpkg:,.," $root/var/adm/flists/* |
930 sort -k2 | uniq -d -f1 | grep '^\. ')
933 found_local=0
935 # check for files in /usr/local
936 if [ "$check_usrlocal" != "0" ]; then
937 while read file; do
938 if [ $found_local = 0 ]; then
939 echo "Found files in /usr/local:"
940 found_errors=1 found_local=1
942 echo $file
943 done < <(sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg |
944 egrep "^/usr/local")
947 found_bad=0
949 # check for registered 'bad files'
950 if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
951 echo "$badfiles" > $builddir/badfiles.txt
952 while read x file; do
953 if [ $found_bad = 0 ]; then
954 echo "Found registered 'bad files' in package:"
955 found_errors=1 found_bad=1
957 desc="No description found!"
958 for ((x=0; x<badfiles_nr; x++)); do
959 if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
960 then desc="${badfiles_desc[x]#*$'\n'}"; fi
961 done
962 echo "$file: $desc"
963 done < <(grep -f $builddir/badfiles.txt $root/var/adm/flists/$xpkg)
966 [ $found_errors != 0 ] && abort "Due to previous errors."
969 } 2>&1 | {
971 trap '' INT
973 echo_status "Writing output to \$root/var/adm/logs/$stagelevel-$xpkg.out"
975 if [ "$SDECFG_VERBOSE" = 1 -o "$verbose" = 1 ]; then
976 tee $root/var/adm/logs/$stagelevel-$xpkg.out |
977 # possible without awk?
978 gawk "/$/ {print; printf \"\x1b[1;35m^${progress:+-$progress}-$xpkg\x1b[0m\r\"; fflush();}"
979 else
980 cat > $root/var/adm/logs/$stagelevel-$xpkg.out
984 hook_eval finish
986 if [ $update = 1 ]; then
987 echo_status "Restoring backup of old package data."
989 while read fn; do
990 [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
991 done < $builddir/backup_files.txt
993 tar --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
995 while read fn; do
996 cmp -s $fn $fn.new && rm -f $fn.new
997 done < $builddir/backup_files.txt
1000 cd $base
1002 umount -r -d -f $builddir/* 2> /dev/null
1003 umount -r -d -f -l $builddir/* 2> /dev/null
1005 if [ "$SDECFG_TMPFS" = 1 ]; then
1006 if [ -e $root/var/adm/logs/$stagelevel-$xpkg.log \
1007 -o "$SDECFG_TMPFS_KEEP_ON_ERROR" != 1 ]; then
1008 rm -rf /tmp/${builddir##*/}/*
1009 umount -n -r -d -f $builddir 2> /dev/null
1010 umount -n -r -d -f -l $builddir 2> /dev/null
1011 rm -rf /tmp/${builddir##*/}
1015 # cleanup_src <error code>
1016 # Cleanup the src.* directory the way configured.
1018 cleanup_src() {
1019 # cleaning the src disabled manually
1020 [ $clear_src = 0 ] && return
1022 case "$SDECFG_KEEP_SRC" in
1023 0) : # always clean, just fall-thru
1025 1) return # always keep, just return
1027 2) [ $1 != 0 ] && return # keep on error, just return
1029 3|4) # on error or if in the list
1030 [ "$SDECFG_KEEP_SRC" = 3 -a $1 != 0 ] && return
1032 local list=" $SDECFG_KEEP_SRC_LIST "
1033 list="${list//:/ }"
1034 list="${list//,/ }"
1036 # if package is in the list, just return
1037 [ "${list/ $pkg /}" != "$list" ] && return
1039 esac
1041 rm -rf $builddir/* $builddir
1044 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
1045 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/BUILD-LOG
1046 cleanup_src 0
1047 mv $root/var/adm/logs/$stagelevel-$xpkg.{out,log}
1048 echo_pkg_finish $stagelevel $repository $xpkg
1049 exit 0
1050 else
1051 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/ERROR-LOG
1052 cleanup_src 1
1053 if [ "$SDECFG_VERBOSE" != 1 -a "$verbose" != 1 ]; then
1054 echo_errorquote "$(grep -v 'make[^ ]*:' \
1055 $root/var/adm/logs/$stagelevel-$xpkg.out |
1056 grep -B8 -- '--- BUILD ERROR ---' |
1057 sed '/--- BUILD ERROR ---/d')"
1059 mv $root/var/adm/logs/$stagelevel-$xpkg.{out,err}
1060 echo_pkg_abort $stagelevel $repository $xpkg
1061 exit 1