* mark python sqlite DEP opt and update .cache
[t2sde.git] / scripts / Build-Pkg
blobb02fe0c671820ce51814e0f87931fb4ef0b7e5a0
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=''
31 stagelevel=9
32 this_is_the_2nd_run=0
35 # ---- Functions
39 help_msg() {
40 spacer=" "
41 echo
42 echo "Usage: scripts/Build-Pkg" \
43 "[ -0 | -1 | -2 ... | -8 | -9 ] \\"
44 echo "$spacer [ -v ] [ -xtrace ] [ -chroot ] \\"
45 echo "$spacer [ -root { <rootdir> | auto } ] \\"
46 echo "$spacer [ -cfg <config> ] [ -update ] \\"
47 echo "$spacer [ -prefix <prefix-dir> ] [ -norebuild ] \\"
48 echo "$spacer [ -noclearsrc ] \\"
49 echo "$spacer [ -id <id> ] [ -debug ] pkg-name(s)"
50 echo
55 # ---- Parse options + config and make Build-Pkg sub-calls
58 while [ "$1" ]; do
59 case "$1" in
60 -this_is_the_2nd_run) this_is_the_2nd_run=1 ;;
61 -[0-9]) options="$options $1" stagelevel=${1#-} ;;
62 -v) options="$options $1" verbose=1 ;;
63 -xtrace) options="$options $1" xtrace=1 ;;
64 -debug) options="$options $1" debug=1 clear_src=0 ;;
65 -update) options="$options $1" update=1 ;;
66 -chroot) options="$options $1" chroot=1 ;;
67 -chr-sub) options="$options $1" chroot=0 ;;
68 -cfg) options="$options $1 $2" config="$2" ; shift ;;
69 -root) options="$options $1 $2" root="$2" ; shift ;;
70 -prefix) options="$options $1 $2" prefix="$2" prefix_auto=0 ; shift ;;
71 -id) options="$options $1 $2" id="$2" ; shift ;;
72 -noclearsrc) options="$options $1" clear_src=0 ;;
73 -norebuild) options="$options $1" norebuild=1 ;;
74 -*) help_msg; exit 1 ;;
75 *) break ;;
76 esac
77 shift
78 done
80 # check if arguments are left as package names
81 if [ $# = 0 ]; then
82 help_msg; exit 1
85 . scripts/functions.in
86 . scripts/parse-config
88 if [ -z "$root" -a $stagelevel -le 2 ] ||
89 [ -z "$root" -a $chroot -eq 1 ] ||
90 [ "$root" = auto ]; then
91 # stage 0 cross compiler build
92 if [ $stagelevel -eq 0 ]; then root="build/$SDECFG_ID/TOOLCHAIN/$toolsdir"
93 # the new systems root
94 else root="build/$SDECFG_ID"; fi
97 [ "$root" -a "${root#/}" = "$root" ] && root="$base/$root"
99 # remove leading and trailing / on prefix and root
100 prefix=${prefix%/} prefix=${prefix#/} root=${root%/}
102 # xroot is for internal use and always points to the new system
103 xroot="$root"
104 if [ $stagelevel -le 2 ]; then
105 sysroot="$base/build/$SDECFG_ID" # always fresh sandbox
106 else
107 root=
108 sysroot=
112 if [ -z "$id" ]; then
113 id=`get_unique`
114 options="$options -id $id"
117 # more than one package is passed
118 if [ $# -gt 1 ]; then
119 for x; do
120 if ! scripts/Build-Pkg $options $x &&
121 [ $stagelevel -le $SDECFG_CONTINUE_ON_ERROR_AFTER ]; then
122 exit 1
124 done
125 exit 0
128 pkg="${1%=*}" xpkg="${1#*=}"
130 builddir="$base/src.$pkg"
131 [ $config != "default" ] && builddir="$builddir.$config"
132 builddir="$builddir.$id"
134 if [ "$chroot" = 1 ]; then
136 cd "$xroot" || exit 1
138 x_mknod() {
139 if [ ! -c "$1" -a ! -b "$1" ]; then
140 mknod "$@"
144 x_mknod dev/null c 1 3
145 x_mknod dev/zero c 1 5
146 x_mknod dev/random c 1 8
147 x_mknod dev/urandom c 1 9
148 x_mknod dev/loop0 b 7 0
149 x_mknod dev/loop1 b 7 1
150 x_mknod dev/loop2 b 7 2
151 x_mknod dev/loop3 b 7 3
152 #_mknod dev/tty c 5 0
154 if [ ! -L dev/fd ]; then
155 ln -s /proc/self/fd dev/fd
158 realconf=$(cd $base/config; pwd -P)
159 realdown=$(cd $base/download; pwd -P)
160 realbase=$(dirname $(cd $base/scripts; pwd -P))
162 if [ ! -e TOOLCHAIN/loop/scripts ]; then
163 mkdir -p TOOLCHAIN/{loop,config,download}
164 mount --bind $realbase TOOLCHAIN/loop
165 mount --bind $realconf TOOLCHAIN/config
166 mount --bind $realdown TOOLCHAIN/download
167 mount --bind /tmp tmp
170 if [ ! -f proc/mounts ]; then
171 mount -nt proc proc proc
174 for x in architecture kernel misc package scripts target; do
175 if [ ! -e TOOLCHAIN/$x ]; then ln -s "loop/$x" "TOOLCHAIN/$x"; fi
176 done
178 if [ ! -e "TOOLCHAIN/build/$SDECFG_ID" ]; then
179 mkdir -p "TOOLCHAIN/build"
180 ln -snf ../.. "TOOLCHAIN/build/$SDECFG_ID"
183 mkdir -p "TOOLCHAIN/src.$pkg.$config.$id"
184 ln -s "$PWD/TOOLCHAIN/src.$pkg.$config.$id" "$builddir"
186 cat > $builddir/chroot.sh <<- EOT
187 export SDE_THIS_IS_CHROOT=1; cd /TOOLCHAIN
188 scripts/Build-Pkg $options -chr-sub -root "/" "$1"
191 cat > $builddir/debug.sh <<- EOT
192 #!/usr/bin/env bash
193 if [ ! -f "$xroot/proc/mounts" ]; then
194 mount -nt proc proc "$xroot/proc"
196 if [ ! -e "$xroot/TOOLCHAIN/loop/scripts" ]; then
197 mkdir -p "$xroot/"TOOLCHAIN/{loop,config,download}
198 mount --bind $realbase "$xroot/TOOLCHAIN/loop"
199 mount --bind $realconf "$xroot/TOOLCHAIN/config"
200 mount --bind $realdown "$xroot/TOOLCHAIN/download"
203 export SDE_THIS_IS_CHROOT=1
204 chroot "$xroot" /bin/bash TOOLCHAIN/src.$pkg.$config.$id/debug_x.sh
206 if ! fuser -s "$xroot/TOOLCHAIN/"; then
207 echo "Loop mounts appear unused - un-mounting ..."
208 umount "$xroot/TOOLCHAIN/"{loop,config,download}
209 umount "$xroot/{proc,tmp}"
212 chmod +x $builddir/debug.sh
214 if [ "$TZ" ]; then
215 if [ "${TZ#/}" != "$TZ" ]; then
216 cp $TZ TOOLCHAIN/localtime
217 else
218 cp /usr/share/zoneinfo/$TZ TOOLCHAIN/localtime
220 else
221 if [ -f /etc/localtime ]; then
222 cp /etc/localtime TOOLCHAIN/localtime
223 else
224 ln -sf /usr/share/zoneinfo/Factory TOOLCHAIN/localtime
228 if [ "$SDECFG_PKG_DISTCC_HOST_RESOLV" = "1" ]; then
229 cat /etc/resolv.conf > etc/resolv.conf
232 TZ="/TOOLCHAIN/localtime" chroot . bin/bash TOOLCHAIN/src.$pkg.$config.$id/chroot.sh
233 returncode=$?
235 if [ ! -d "$builddir/." ]; then
236 rm "$builddir"
239 exit $returncode
242 scripts/Build-Tools -$stagelevel -cfg $config || exit 1
244 if [ "$SDECFG_FLIST" = "flwrapper" -a -z "$FLWRAPPER" ]; then
245 export FLWRAPPER_WLOG="$builddir/fl_wrapper.wlog"
246 export FLWRAPPER_RLOG="$builddir/fl_wrapper.rlog"
247 export FLWRAPPER_BASEPID=$$
248 export FLWRAPPER_FILTERDIR="/tmp/:$builddir"
249 [ "$LD_PRELOAD" ] && LD_PRELOAD="${LD_PRELOAD}:"
250 export FLWRAPPER="$base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so"
251 export LD_PRELOAD="${LD_PRELOAD}$FLWRAPPER"
253 export INSTALL_WRAPPER_LOGFILE="$builddir/install_wrapper.log"
254 export CMD_WRAPPER_LOGFILE="$builddir/cmd_wrapper.log"
256 if [ $norebuild = 1 -a -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
257 echo_pkg_deny $stagelevel $pkg "already built"
258 exit 0
261 # TODO: should we be pedantic and force rebuild of low stages even if $norebuild?
262 if [ "$SDECFG_RETRY_BROKEN" = 0 -a $norebuild = 1 -a \
263 -f $root/var/adm/logs/$stagelevel-$xpkg.err ]; then
264 echo_pkg_deny $stagelevel $pkg "already failed"
265 exit 1
268 archdir="$builddir/archdir"
270 detect_confdir
272 if [ -z "$confdir" ]; then
273 echo_pkg_deny $stagelevel $pkg "does not exist"; exit 1
276 mkdir -p $root/var/adm/{logs,flists,olists,md5sums,packages,dependencies,\
277 dep-debug,parse-config,cache,descs}
278 rm -f $root/var/adm/logs/$stagelevel-$xpkg.{out,log,err}
280 md5sum=md5sum
281 if ! type -p $md5sum > /dev/null; then
282 md5sum="md5 -r"
285 if [ $this_is_the_2nd_run = 0 ]; then
286 [ $stagelevel -gt 2 ] && . /etc/profile
287 options="-this_is_the_2nd_run $options $pkg=$xpkg"
288 if [ "$SDECFG_CREATE_CACHE" = 1 ]; then
289 mkdir -p $root/var/adm/cache
290 rm -f $root/var/adm/cache/$xpkg{,.tm}
292 /usr/bin/time -o "$root/var/adm/cache/$xpkg.tm" \
293 -f '%U %S' $0 $options
294 returncode=$?
295 [ ! -e "$root/var/adm/cache/$xpkg.tm" ] && exit $returncode
297 buildtime=$(grep -v '^Command ' < $root/var/adm/cache/$xpkg.tm |
298 gawk '{printf "%d", ($1 + $2) * 100 }')
299 rm -f $root/var/adm/cache/$xpkg.tm
301 # store reference time
302 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
303 if [ $pkg = binutils ]; then
304 echo $buildtime > $base/build/$SDECFG_ID/TOOLCHAIN/reftime
307 # estimate initial, non-binutils reference time from first in-system emerge
308 if [ ! -s $base/build/$SDECFG_ID/TOOLCHAIN/reftime -a \
309 $stagelevel = 9 -a $buildtime -gt 1000 -a \
310 -e $base/package/*/$pkg/$pkg.cache ]; then
311 reftime=$(sed -n "s/\[BUILDTIME\] \([^ ]*\).*/\1/p" $base/package/*/$pkg/$pkg.cache)
313 gawk "BEGIN {printf(\"%d\n\", int($buildtime * 100 / ($reftime > 0 ? $reftime : 1)));}" > \
314 $base/build/$SDECFG_ID/TOOLCHAIN/reftime
318 # compute relative build time to binutils (LFS-style)
319 if [ -s $base/build/$SDECFG_ID/TOOLCHAIN/reftime ]; then
320 reftime=$(< $base/build/$SDECFG_ID/TOOLCHAIN/reftime)
321 else
322 reftime=$buildtime # so until we have a ref all will be 100%
324 # quantize for less .cache update noise
325 buildtime=`gawk "BEGIN { buildtime = 100 * $buildtime / $reftime; \
326 if (buildtime <= 5) q = 1; else if (buildtime <= 20) q = 2; \
327 else if (buildtime <= 200) q = 5; else if (buildtime <= 500) q = 10; \
328 else if (buildtime <= 1000) q = 20; else q = 50; \
329 printf(\"%d\", int((buildtime + q/2) / q) * q); }"`
332 date '+[TIMESTAMP] %s %c'
334 [ -f $root/var/adm/logs/$stagelevel-$xpkg.err ] &&
335 x=" ERROR" || x=""
337 echo "[BUILDTIME] $buildtime ($stagelevel)$x"
339 x="$root/var/adm/packages/$xpkg"
340 if [ -f $x ]; then
341 echo "[SIZE] `grep "^Package Size: " $x |
342 cut -f3- -d' '`"
344 echo
346 x="$root/var/adm/dependencies/$xpkg"
347 [ "$pkg" != "t2-debug" -a -f $x ] &&
348 sed 's,^opt:,[OPT],; s,^:,[DEP],' $x
349 } > $root/var/adm/cache/$xpkg
351 exit $returncode
352 else
353 exec $0 $options
359 # ---- Setting Build Variables
362 flistroot="bin boot etc lib lib64 lib32 libx32 sbin usr var opt run"
364 # remove the obvious noise: ldconfig, our /var/adm as well as other noise
365 flistrfilter="ldconfig\..*: .*|.*: /bin/sh|.*: /bin/hostname|.*: /var/adm/.*|.*: .*/share/locale/.*"
366 # indirectly referenced .so
367 var_append flistrfilter '|' ".*: .*/lib.*\.so.*"
368 # everything configure tries randomly e.g. even bin/mt(-st)
369 var_append flistrfilter '|' ".*configure.*: .*"
370 var_append flistrfilter '|' ".*doxygen\..*dot.*: .*"
371 var_append flistrfilter '|' ".*cmake\..*: .*/lib.*/.*\.cmake"
372 var_append flistrfilter '|' ".*qmake\..*: .*/mkspecs/.*\.p.*"
373 var_append flistrfilter '|' ".*: .*/gettext/its/.*.loc"
374 # some packages just query all, if really used .h et al. are used anyway
375 var_append flistrfilter '|' ".*pkg-config.*: .*\.pc"
376 var_append flistrfilter '|' ".*: .*/gtk-doc/.*\.devhelp2"
377 # python registry
378 var_append flistrfilter '|' ".*/site-packages/.*(PKG-INFO|METADATA|egg-info|entry_points.txt|requires.txt)"
379 # x11 mkfontdir's mkfontscale
380 var_append flistrfilter '|' ".*mkfontscale\..*: .*"
381 # fc-cache
382 var_append flistrfilter '|' ".*fc-cache\..*: .*"
383 # wxrc & friends
384 var_append flistrfilter '|' ".*: .*\.desktop"
386 # ignore some written files, too
387 flistdel="etc/ld.so.cache|proc/[0-9]*/fd|etc/blkid.tab|var/tmp/.*|usr/tmp/.*|var/adm/logs/.*|.*\\.old"
389 # filter some cache and query updates
390 var_append flistdel '|' ".*/gio/modules/giomodule.cache|.*/schemas/gschemas.compiled"
391 var_append flistdel '|' ".*/share/icons/.*/icon-theme.cache|.*/share/applications/mimeinfo.cache"
392 var_append flistdel '|' ".*/lib.*gdk-pixbuf-.*/loaders.cache"
394 flistvalid="$base|/tmp|/var/backups|/proc|/dev"
395 foodirlist="bindir sbindir libdir datadir includedir sysconfdir localstatedir docdir"
397 init_vars_and_hooks
400 # ---- Read various config files
403 parse_desc $pkg
405 echo_pkg_start $stagelevel $repository $xpkg $ver "$extraver" "$(pkgbuildtime $pkg)"
407 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
408 x="`scripts/Check-PkgFormat $pkg`"
409 [ "$x" ] && abort "$x\nDisable the 'Paranoia Check' config `
410 `option to ignore such errors."
413 targetdir="$base/target/$target"
415 detect_patchfiles
417 if [ $stagelevel -gt 2 ]; then
418 for pc_file in $xroot/var/adm/parse-config/*; do
419 if [ -s "$pc_file" -a "${pc_file##*/}" != "$xpkg" ]
420 then . "$pc_file"; fi
421 done
422 unset pc_file
424 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
426 set_confopt
428 hasflag OBJDIR && configscript="../configure" &&
429 hook_add preconf 3 "mkdir -p objs; cd objs"
431 if ! hasflag NOPARALLEL; then
432 var_append makeopt " " "-j${SDECFG_PARALLEL:-1}"
433 var_append makeinstopt " " "-j${SDECFG_PARALLEL:-1}"
436 # Erase positional parameters to prevent unintended parameter
437 # passing. We do not want to pass the current positional parameters
438 # to the loaded script.
439 set --
440 eval "$desc_O"
442 # include package pre config - if any
443 if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf ]; then
444 echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_pre.conf"
445 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf
448 # read the package configuration, $confdir might differ from package/*/$pkg ...
449 for x in $(get_expanded $base/target/%/pkg_$pkg.conf $targetchain) \
450 $targetdir/package/$pkg/$pkg.conf \
451 architecture/$arch/package/$pkg/$pkg.conf \
452 $confdir/$pkg.conf \
453 $base/package/*/$pkg/$pkg.conf; do
454 if [ -f $x ]; then
455 [ $x != $base/package/*/$pkg/$pkg.conf ] &&
456 echo_status "Reading package config: ${x#$base/}"
457 . $x
458 break
460 done
462 # include package post config - if any
463 if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf ]; then
464 echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_post.conf"
465 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf
468 if [ -f $base/architecture/$arch/pkg-header ]; then
469 echo_status "Reading overwrites from architecture/$arch/pkg-header."
470 . $base/architecture/$arch/pkg-header
473 for x in $(get_expanded $base/target/%/pkg-header `get_reverted $targetchain`); do
474 if [ -f $x ]; then
475 echo_status "Reading overwrites from ${x#$base/}."
476 . $x
478 done
481 # ---- Variable updates based on the configuration files read
484 if [ -z "$prefix" -o "${prefix#usr}" != "$prefix" ]; then
485 flistdel="$flistdel|usr/share/info/(dir|standards.info)"
486 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
487 flistdel="$flistdel|usr/share/locale/..[/_].*"
488 flistdel="$flistdel|usr/share/man/..[/_].*"
490 else
491 flistdel="$flistdel|$prefix/info/(dir|standards.info)"
492 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
493 flistdel="$flistdel|$prefix/share/locale/..[/_].*"
494 flistdel="$flistdel|$prefix/man/..[/_].*"
499 # ---- Build Package
501 if hasflag NOPARALLEL || [ "$SDECFG_PARALLEL" -le 1 ]; then
502 hasflag NOPARALLEL && [ "$SDECFG_PARALLEL" -gt 1 ] &&
503 echo_warning 'Parallel build disabled for this package'
504 echo_status "Building in ${builddir##*/}"
505 else
506 echo_status "Building in ${builddir##*/}, with $SDECFG_PARALLEL threads"
509 mkdir -p $builddir; chmod 755 $builddir
511 if [ "$SDECFG_TMPFS_MAX_SIZE" != 0 ]; then
512 x="$(match_source_file -p)"
513 [ "$x" ] && x="$(du -cm $x | tail -1 | cut -f 1)"
514 [ "$x" ] || x=0
515 [ "$x" -gt "${SDECFG_TMPFS_MAX_SIZE:-0}" ] && SDECFG_TMPFS=0
518 if [ $clear_src = 1 ]; then
519 if [ "$SDECFG_TMPFS" = 1 ]; then
520 mount -n -o remount,exec,$SDECFG_TMPFS_OPT /tmp
521 mkdir -p /tmp/${builddir##*/}
522 mount -n --bind /tmp/${builddir##*/} $builddir
526 export TMPDIR="$builddir/tmp"
527 mkdir -p "$TMPDIR"
529 if [ $update = 1 -a ! -f $xroot/var/adm/md5sums/$xpkg ]; then
530 #echo_warning "Ignoring update mode since package isn't installed already."
531 update=0
534 if [ $update = 1 ]; then
535 echo_status "Creating backup of old package data."
537 cd $xroot/
538 $md5sum --check var/adm/md5sums/$xpkg 2>&1 < /dev/null |
539 grep ': FAILED$' | cut -f1 -d:
540 ) > $builddir/backup_files.txt
541 if [ -s $builddir/backup_files.txt ]; then
542 mkdir -p "$xroot/var/adm/backup"
543 chmod 700 "$xroot/var/adm/backup"
544 backup_tar="$xroot/var/adm/backup/$(
545 date '+%Y%m%d%H%M%S')_$xpkg.tar.bz2"
546 (cd $xroot/; tar --no-recursion -cf - -T $builddir/`
547 `backup_files.txt || true) | bzip2 > $backup_tar
548 else
549 update=0
553 if [ "$SDECFG_FLIST" = "flwrapper" ]; then
554 rm -f $builddir/fl_wrapper.{rlog,wlog}
555 touch $builddir/fl_wrapper.{rlog,wlog}
556 elif [ "$SDECFG_FLIST" = "find" ]; then
557 touch $builddir/temp.time_stamp
558 sleep 2
561 hook_eval prepare
563 # define new abort function for errors while building
565 abort() {
566 [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
567 rm -vf $root/var/adm/logs/$stagelevel-$xpkg.log
568 false
572 trap 'echo "Got SIGINT (Ctrl-C). Aborting build."; exit 1' INT
573 exec < /dev/null
575 # Makes debugging build problems easier
577 hook_dump > $builddir/debug.hooks
580 dump_env
581 cat <<- EOT
582 PS1='\\[\\e[00m\\e[01;31m\\]debug-`
583 `$xpkg\\[\\e[00m\\]:[\\W]\\\$ '
584 alias cp="cp -i"; alias mv="mv -i"
585 alias rm="rm -i"; alias ls="ls --color=auto -a"
586 alias ..="cd .."; alias ...="cd ../.."
587 fixfile () {
588 # we use .vanilla to not rediff backup .orig from patch
589 for f; do [ -f \$f.vanilla ] || cp \$f{,.vanilla}; done
590 # maybe we do not have the editor yet?
591 which \$EDITOR > /dev/null || EDITOR=nvi
592 LD_PRELOAD= \$EDITOR "\$@"
594 fixfilediff() {
595 local p=\${1:+$confdir/\$1}
596 (find -name '*.vanilla' -printf '%P\n' | while read x; do
597 diff -u \$x \${x/.vanilla/}
598 done) | tee -a \${p:-/dev/null}
601 } > $builddir/debug.buildenv
603 cat > $builddir/debug_x.sh <<- EOT
604 #!/usr/bin/env bash
605 cd $builddir
606 [ -f ERROR-LOG ] && sed -n 's/^[rR]unning.*/# &/p' ERROR-LOG
607 exec bash --rcfile debug.buildenv 200>> build.pid
610 if [ "$SDE_THIS_IS_CHROOT" != 1 ]; then
611 mv $builddir/debug_x.sh $builddir/debug.sh
612 chmod +x $builddir/debug.sh
615 # Create PID file
617 # The builtin-variable '$$' is not this pid because this proc
618 # is just a sub-proc of $$. That's why the $builddir/strace.tmp
619 # hack is required to get the right pid to trace.
621 # We also conntect filedescriptor 3 with the pid file. So the command
622 # 'fuser' can be used to create a list of all processes which are part
623 # of this build process.
625 sh -c 'echo $PPID' > $builddir/build.pid
626 exec 200>> $builddir/build.pid
628 if [ "$SDECFG_DEBUG" != 0 ]; then
629 hasflag KERNEL && _CC=$KCC || _CC=$CC
630 echo "Command wrapper test: '${_CC} --version'"
631 type ${_CC}; CMD_WRAPPER_DEBUG=1 ${_CC} --version
632 unset _CC
633 echo "[ writing debug log to $builddir/cmd_wrapper.log ]"
636 if [ "$debug" = 1 ]; then
637 echo "Everything is set up. We are in debug mode - so exit now."
638 exit
641 if [ "$SDECFG_FLIST" = "strace" ]; then
642 strace -o $builddir/strace.out -F -f -q -e open,creat,mkdir,`
643 `mknod,link,symlink,rename,utime,chdir,execve,fork,`
644 `vfork,_exit,exit_group -p $(< $builddir/build.pid) &
645 strace_pid=$!; sleep 1; cd $base
649 set -e
651 mkdir -p "$builddir/archdir"
652 populate_archdir
654 echo "Running main build function '$mainfunction'"
655 if [ $xtrace -eq 1 -o $SDECFG_XTRACE -eq 1 ]; then
656 PS4=$'=[$FUNCNAME:$LINENO (last \\\$?=$?)> '; set -o xtrace
657 cd $builddir; eval "$mainfunction"
658 set +o xtrace
659 else
660 cd $builddir; eval "$mainfunction"
662 touch $root/var/adm/logs/$stagelevel-$xpkg.log
664 [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ||
665 abort "Due to previous errors, no $stagelevel-$xpkg.log file!
666 (Try enabling xtrace in the config to track an error inside the build system.)"
668 hook_eval postinstall
670 echo "Creating file list and doing final adaptions ... "
672 cd $xroot/
673 [ -s "var/adm/parse-config/$xpkg" ] &&
674 echo "var/adm/parse-config/$xpkg" >> $builddir/flist.txt
675 for x in var/adm/{flists,md5sums,packages,descs,dependencies}/$xpkg; do
676 touch $x; echo "$x" >> $builddir/flist.txt
677 done
679 if [ "$SDECFG_FLIST" = "strace" ]; then
680 sleep 1; kill -INT $strace_pid; sleep 1
681 fl_stparse -w $builddir/fl_wrapper.wlog \
682 -r $builddir/fl_wrapper.rlog < $builddir/strace.out
684 if [ "$SDECFG_FLIST" = "flwrapper" -o "$SDECFG_FLIST" = "strace" ]; then
685 if [ "$stagelevel" -le 2 ]; then
686 xbase="$(cd $xroot/ 2> /dev/null; pwd -P)"
687 flistvalid="$xbase|$flistvalid"
688 found_invalid=0
689 while read file; do
690 if [ -e "$file" ]; then
691 echo "Created file outside basedir: $file"
692 abort_soon=1
693 else # non fatal for now (configure junk)
694 echo "Warning: Created vanished file outside basedir: $file"
696 if [ "$found_invalid" = 0 ]; then
697 echo "base #1: $base"
698 echo "base #2: $xbase"
699 found_invalid=1
701 done < <(egrep -v " ($flistvalid)/" $builddir/fl_wrapper.wlog |
702 cut -f2- | sort -u)
704 [ "$abort_soon" = 1 ] && abort
707 fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog > $builddir/flist.txt.tmp
709 # check for file creation beside the allowed top-level
710 # directories - allow root since qt, wxwidgets, ... create some
711 # profile there ... - on stage 0 we have an ugly symlink hack
712 # so we get doc, $arch_machine, ... in the top level dir :-(
713 if [ $stagelevel -gt 0 ]; then
714 fr="$flistroot root TOOLCHAIN proc/[0-9]*/fd"
716 while read file; do
717 echo "Created file outside allowed top-level dir: $file"
718 abort_soon=1
719 done < <(egrep -v "^(${fr// /|})(/|$)" \
720 $builddir/flist.txt.tmp)
721 [ "$abort_soon" = 1 ] && abort
724 egrep "^(${flistroot// /|})(/|$)" $builddir/flist.txt.tmp >> $builddir/flist.txt
726 elif [ "$SDECFG_FLIST" = "find" ]; then
727 find $flistroot \
728 \( -not -type d -or -type d -empty \) \
729 -and \( -newer $builddir/temp.time_stamp -or \
730 -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> $builddir/flist.txt
733 # evaluate flistdel
734 egrep -v "^($flistdel)\$" $builddir/flist.txt > $builddir/flist.txt.new
735 mv $builddir/flist.txt{.new,}
737 hook_eval postflist
739 # save the old flist for later orphaned file check
740 [ -e var/adm/flists/$xpkg ] &&
741 cp -f var/adm/flists/$xpkg $builddir/flist.txt.old
743 fl_wrparse -D -p "$xpkg" -r "$xroot/" < $builddir/flist.txt |
744 sort -u > $builddir/flist.txt.new
746 # analyze which files have not been reinstalled and thus are (normally)
747 # no longer needed (orphaned)
748 if [ -e $builddir/flist.txt.old ]; then
749 echo "Searching for orphaned files ..."
750 diff --normal $builddir/flist.txt.{old,new} |
751 grep '^<' | cut -d ' ' -f 2- > $builddir/olist.txt.new
752 [ -e var/adm/olists/$xpkg ] &&
753 cp -f var/adm/olists/$xpkg $builddir/olist.txt.old ||
754 touch $builddir/olist.txt.old
755 cat $builddir/olist.txt.{old,new} | sort -u > var/adm/olists/$xpkg
758 # TODO: until all olist regressions are fixed merge the two lists ...
759 touch $builddir/flist.txt.old
760 if [ "$noorphaned" = 1 ]; then
761 cat $builddir/flist.txt.new > var/adm/flists/$xpkg
762 else
763 cat $builddir/flist.txt.{old,new} | egrep -v "^$xpkg: ($flistdel)\$" |
764 sort -u > var/adm/flists/$xpkg
766 echo Found `wc -l < var/adm/flists/$xpkg` "files for this package."
767 echo Found `wc -l < var/adm/olists/$xpkg` "orphaned files for this package."
769 if [ $stagelevel -gt 0 ] && [ "$SDECFG_FLIST" = "flwrapper" -o "$SDECFG_FLIST" = "strace" ]
770 then
771 echo "Calculating package dependencies ..."
773 # don't depend on shared, randomly 1st created directories
774 var_append flistrfilter '|' ".*\.mkdir: .*"
776 ! egrep -v "^($flistrfilter)\$" $builddir/fl_wrapper.[rw]log |
777 sort -u | fl_wrparse -D -s -r "$xroot/" -p '' | sort -u |
778 grep -v ' var/adm/' | gawk '
779 # read the var/adm/... file content in
780 ARGIND < ARGC-1 {
781 if ($1 != "'$xpkg':")
782 f[$2] = $1 " " f[$2];
784 # iterate over the read file list streamed to stdin
785 ARGIND == ARGC-1 {
786 file = $2;
787 if (f[file]) {
788 print f[file] " " file;
791 ' var/adm/flists/* - >> $builddir/dependencies.debug
793 awk 'BEGIN { FS=": "; } { print ": " $1; }' \
794 < $builddir/dependencies.debug >> $builddir/dependencies.txt
796 sort -u $builddir/dependencies.debug > var/adm/dep-debug/$xpkg
798 # alternatives handling, 1st so pkgs can enforce alternatives
799 alt_pattern=
800 while read basepkg alt; do
801 var_append alt_pattern ';' "s/$alt/$basepkg/"
802 done < <(< $base/misc/share/PKG-ALTERNATIVES)
803 sed "$alt_pattern" $builddir/dependencies.txt > $builddir/dependencies.txt.new
804 mv $builddir/dependencies.txt{.new,}
806 # remove dependencies as requested by the package
807 # TODO: goups are not used yet (and it is not easy here)
808 del_pattern=
809 for x in t2-src $SDECFG_LIBC $SDECFG_DEFAULT_CC ${compressor%% *} \
810 `echo "$desc_E" | sed -n 's/^del //p' `; do
811 del_pattern="$del_pattern -e \".*: $x\$\""
812 done
813 if [ -n "$del_pattern" ]; then
814 echo "Deleting dependencies, pattern: $del_pattern ..."
815 eval egrep -v $del_pattern \
816 $builddir/dependencies.txt > $builddir/dependencies.txt.new
817 mv $builddir/dependencies.txt{.new,}
820 # merge the dependencies defined by the package
821 echo -n "Adding dependencies"
822 for x in `echo "$desc_E" | egrep '^(add|opt) ' | sed 's/^[^ ]* //' `; do
823 echo -n ", $x"
824 echo ": $x" >> $builddir/dependencies.txt
825 done
826 echo
828 sort -u $builddir/dependencies.txt > $builddir/dependencies.txt.new
829 mv $builddir/dependencies.txt{.new,}
831 echo -n "Marking optional dependencies"
832 for x in `echo "$desc_E" | sed -n 's/^opt //p' `; do
833 echo -n ", $x"
834 sed -i "s/^: $x$/opt&/" $builddir/dependencies.txt
835 done
836 echo
838 cat $builddir/dependencies.txt > var/adm/dependencies/$xpkg
841 echo "Creating md5sum files ..."
842 getfiles < var/adm/flists/$xpkg > $builddir/files.lst
843 grep -v '^var/adm/' $builddir/files.lst | sed -e 's,^.*,"\0",' |
844 xargs -r $md5sum > var/adm/md5sums/$xpkg
846 echo "Creating package description ..."
848 buildend="`date '+%s'`"
849 buildlist="$(grep "^Build \[.\] at " var/adm/packages/$xpkg || true
850 echo "Build [$stagelevel] at `date --date=@$buildstart '+%Y-%m-%d from %T'`" \
851 "to `date --date=@$buildend '+%T'`" \
852 " `date --date=@$((buildend - buildstart)) --utc '+%H:%M:%S'`")"
854 srccksum=$(pkgchksum $base/package/*/$pkg)
855 cat > var/adm/packages/$xpkg << EOT
856 Package Name and Version: $xpkg $ver $extraver
857 Package Size: `getdu $root/ < var/adm/flists/$xpkg`, `
858 wc -l < var/adm/flists/$xpkg | tr -d ' '` files
859 T2 Package Source Checksum: $srccksum
860 T2 Version and Architecture: $sdever $arch
861 $buildlist
862 Prefix: $prefix
865 # Location libdir: /opt/*/lib
866 for x in $foodirlist; do
867 if [ "`eval echo \\$$x`" != "`pkggetdir $x`" ]; then
868 echo "Location $x: `eval echo \\$$x`" \
869 >> var/adm/packages/$xpkg
871 done
873 cat >> var/adm/packages/$xpkg << EOT
874 Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
876 ${desc_I:-$xpkg}
878 $(echo "${desc_T:-No description available.}" | sed 's,^, ,')
880 URL(s):
881 $(echo "${desc_U:-http://t2sde.org/packages/$pkg.html}" | sed 's,^, ,')
883 Original Author(s):
884 $(echo "${desc_A:-Unknown}" | sed 's,^, ,')
886 Package Maintainer(s):
887 $(echo "${desc_M:-Unknown}" | sed 's,^, ,')
889 Download URL(s):
890 $(echo "${desc_D:-None}" | gawk '{ print " " $3 $2; }')
893 echo "[CONFIG] ${SDECFG_ID#*-}"
894 descfile=$base/package/*/$pkg/$pkg.desc
895 while read x; do
896 if [ "${x#\[}" != "$x" ]; then
897 x="`echo ${x// */} | tr -d '[]'`"
898 y="${x/-/_}"
899 IFS='
901 eval lines=\"\${desc_$y}\"
902 for line in $lines; do
903 echo "[$x] $line"
904 done
906 done < $base/misc/share/PKG-DESC-FORMAT
907 ) > var/adm/descs/$xpkg
909 echo "Making post-install adaptions."
911 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
912 found_errors=0
913 found_dups=0
915 # check for files which are 'shared' with other packages
916 if [ "$check_shared" != "0" ]; then
917 while read _ file; do
918 # ignore shared directories
919 [ -d $root/$file ] && continue
921 if [ $found_dups = 0 ]; then
922 echo "Found shared files with other packages:"
923 found_errors=1 found_dups=1
925 echo "$file:" $(cd $root/var/adm/flists; grep -l " $file\$" *)
926 # sed $xpkg to . to have this pkg's duplicates sorted first
927 done < <(sed "s,^$xpkg:,.," $root/var/adm/flists/* |
928 sort -k2 | uniq -d -f1 | grep '^\. ')
931 found_local=0
933 # check for files in /usr/local
934 if [ "$check_usrlocal" != "0" ]; then
935 while read file; do
936 if [ $found_local = 0 ]; then
937 echo "Found files in /usr/local:"
938 found_errors=1 found_local=1
940 echo $file
941 done < <(sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg |
942 egrep "^/usr/local")
945 found_bad=0
947 # check for registered 'bad files'
948 if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
949 echo "$badfiles" > $builddir/badfiles.txt
950 while read x file; do
951 if [ $found_bad = 0 ]; then
952 echo "Found registered 'bad files' in package:"
953 found_errors=1 found_bad=1
955 desc="No description found!"
956 for ((x=0; x<badfiles_nr; x++)); do
957 if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
958 then desc="${badfiles_desc[x]#*$'\n'}"; fi
959 done
960 echo "$file: $desc"
961 done < <(grep -f $builddir/badfiles.txt $root/var/adm/flists/$xpkg)
964 [ $found_errors != 0 ] && abort "Due to previous errors."
967 } 2>&1 | {
969 trap '' INT
971 echo_status "Writing output to \$root/var/adm/logs/$stagelevel-$xpkg.out"
973 if [ "$SDECFG_VERBOSE" = 1 -o "$verbose" = 1 ]; then
974 tee $root/var/adm/logs/$stagelevel-$xpkg.out |
975 # possible without awk?
976 gawk "/$/ {print; printf \"\x1b[1;35m^$stagelevel-$xpkg\x1b[0m\r\"; fflush();}"
977 else
978 cat > $root/var/adm/logs/$stagelevel-$xpkg.out
982 hook_eval finish
984 if [ $update = 1 ]; then
985 echo_status "Restoring backup of old package data."
987 while read fn; do
988 [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
989 done < $builddir/backup_files.txt
991 tar --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
993 while read fn; do
994 cmp -s $fn $fn.new && rm -f $fn.new
995 done < $builddir/backup_files.txt
998 cd $base
1000 umount -r -d -f $builddir/* 2> /dev/null
1001 umount -r -d -f -l $builddir/* 2> /dev/null
1003 if [ "$SDECFG_TMPFS" = 1 ]; then
1004 if [ -e $root/var/adm/logs/$stagelevel-$xpkg.log \
1005 -o "$SDECFG_TMPFS_KEEP_ON_ERROR" != 1 ]; then
1006 rm -rf /tmp/${builddir##*/}/*
1007 umount -n -r -d -f $builddir 2> /dev/null
1008 umount -n -r -d -f -l $builddir 2> /dev/null
1009 rm -rf /tmp/${builddir##*/}
1013 # cleanup_src <error code>
1014 # Cleanup the src.* directory the way configured.
1016 cleanup_src() {
1017 # cleaning the src disabled manually
1018 [ $clear_src = 0 ] && return
1020 case "$SDECFG_KEEP_SRC" in
1021 0) : # always clean, just fall-thru
1023 1) return # always keep, just return
1025 2) [ $1 != 0 ] && return # keep on error, just return
1027 3|4) # on error or if in the list
1028 [ "$SDECFG_KEEP_SRC" = 3 -a $1 != 0 ] && return
1030 local list=" $SDECFG_KEEP_SRC_LIST "
1031 list="${list//:/ }"
1032 list="${list//,/ }"
1034 # if package is in the list, just return
1035 [ "${list/ $pkg /}" != "$list" ] && return
1037 esac
1039 rm -rf $builddir/* $builddir
1042 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
1043 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/BUILD-LOG
1044 cleanup_src 0
1045 mv $root/var/adm/logs/$stagelevel-$xpkg.{out,log}
1046 echo_pkg_finish $stagelevel $repository $xpkg
1047 exit 0
1048 else
1049 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/ERROR-LOG
1050 cleanup_src 1
1051 if [ "$SDECFG_VERBOSE" != 1 -a "$verbose" != 1 ]; then
1052 echo_errorquote "$(grep -v 'make[^ ]*:' \
1053 $root/var/adm/logs/$stagelevel-$xpkg.out |
1054 grep -B8 -- '--- BUILD ERROR ---' |
1055 sed '/--- BUILD ERROR ---/d')"
1057 mv $root/var/adm/logs/$stagelevel-$xpkg.{out,err}
1058 echo_pkg_abort $stagelevel $repository $xpkg
1059 exit 1