* updated ktuberling (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / scripts / Build-Pkg
blob20bcdafe075280d7702dab85ef1a8b0a00fff2c4
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Build-Pkg
5 # Copyright (C) 2004 - 2021 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 exec 2>&1
17 buildstart="`date '+%s'`"
19 options=''
20 config=default
22 clear_src=1
23 norebuild=0
24 update=0
26 make_tar=''
27 prefix="usr"
28 prefix_auto=1
29 verbose=0
30 xtrace=0
31 debug=0
32 chroot=0
33 root=""
34 id=''
36 stagelevel=9
37 this_is_the_2nd_run=0
40 # ---- Functions
44 help_msg() {
45 spacer=" "
46 echo
47 echo "Usage: scripts/Build-Pkg" \
48 "[ -0 | -1 | -2 ... | -8 | -9 ] \\"
49 echo "$spacer [ -v ] [ -xtrace ] [ -chroot ] \\"
50 echo "$spacer [ -root { <rootdir> | auto } ] \\"
51 echo "$spacer [ -cfg <config> ] [ -update ] \\"
52 echo "$spacer [ -prefix <prefix-dir> ] [ -norebuild ] \\"
53 echo "$spacer [ -noclearsrc ] \\"
54 echo "$spacer [ -id <id> ] [ -debug ] pkg-name(s)"
55 echo
60 # ---- Parse options + config and make Build-Pkg sub-calls
63 while [ "$1" ]; do
64 case "$1" in
65 -this_is_the_2nd_run) this_is_the_2nd_run=1 ;;
66 -[0-9]) options="$options $1" ; stagelevel=${1#-} ;;
67 -v) options="$options $1" ; verbose=1 ;;
68 -xtrace) options="$options $1" ; xtrace=1 ;;
69 -debug) options="$options $1" ; debug=1; clear_src=0 ;;
70 -update) options="$options $1" ; update=1 ;;
71 -chroot) options="$options $1" ; chroot=1 ;;
72 -chr-sub) options="$options $1" ; chroot=0 ;;
73 -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
74 -root) options="$options $1 $2" ; root="$2" ; shift ;;
75 -prefix) options="$options $1 $2" ;
76 prefix_auto=0 ; prefix="$2" ; shift ;;
77 -id) options="$options $1 $2" ; id="$2" ; shift ;;
78 -noclearsrc) options="$options $1" ; clear_src=0 ;;
79 -norebuild) options="$options $1" ; norebuild=1 ;;
80 -*) help_msg; exit 1 ;;
81 *) break ;;
82 esac
83 shift
84 done
86 # check if arguments are left as package names
87 if [ $# = 0 ]; then
88 help_msg; exit 1
91 . scripts/functions.in
92 . scripts/parse-config
94 if [ -z "$root" -a $stagelevel -le 2 ] ||
95 [ -z "$root" -a $chroot -eq 1 ] ||
96 [ "$root" = auto ]; then
97 # stage 0 cross compiler build
98 if [ $stagelevel -eq 0 ]; then root="build/$SDECFG_ID/TOOLCHAIN/$toolsdir"
99 # the new systems root
100 else root="build/$SDECFG_ID"; fi
103 [ "$root" -a "${root#/}" = "$root" ] && root="$base/$root"
105 # remove leading and trailing / on prefix and root
106 prefix=${prefix%/}; prefix=${prefix#/}; root=${root%/}
108 # xroot is for internal use and always points to the new system
109 xroot="$root"
110 if [ $stagelevel -le 2 ]; then
111 sysroot="$base/build/$SDECFG_ID" # always fresh sandbox
112 else
113 root=
114 sysroot=
118 if [ -z "$id" ]; then
119 id=`get_unique`
120 options="$options -id $id"
123 # more than one package is passed
124 if [ $# -gt 1 ]; then
125 for x; do
126 if ! scripts/Build-Pkg $options $x &&
127 [ $stagelevel -le $SDECFG_CONTINUE_ON_ERROR_AFTER ]; then
128 exit 1
130 done
131 exit 0
133 pkg="${1%=*}"; xpkg="${1#*=}"
134 builddir="$base/src.$pkg.$config.$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 none 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 #!/bin/bash
195 if [ ! -f "$xroot/proc/mounts" ]; then
196 mount -nt proc none "$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 i be pedantic and force rebuild of low stages even if $norebuild? /mnemoc
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 if [ $this_is_the_2nd_run = 0 ]; then
283 [ $stagelevel -gt 2 ] && . /etc/profile
284 options="-this_is_the_2nd_run $options $pkg=$xpkg"
285 if [ "$SDECFG_CREATE_CACHE" = 1 -a $stagelevel -gt 0 ]; then
286 mkdir -p $root/var/adm/cache
287 rm -f $root/var/adm/cache/$xpkg{,.tm}
289 /usr/bin/time -o "$root/var/adm/cache/$xpkg.tm" \
290 -f 'buildtime=$(qcalc %U + %S)' $0 $options
291 returncode=$?
292 [ ! -e "$root/var/adm/cache/$xpkg.tm" ] && exit $returncode
294 qcalc() { gawk "BEGIN { printf(\"%d\n\", ($*)*100); }"; }
295 eval "`grep -v '^Command ' < $root/var/adm/cache/$xpkg.tm`"
296 rm -f $root/var/adm/cache/$xpkg.tm
298 # store reference time
299 if [ $pkg = binutils ]; then
300 echo $buildtime > $sysroot/TOOLCHAIN/reftime
302 # compute relative build time to binutils (LFS-style)
303 if [ -e $root/TOOLCHAIN/reftime ]; then
304 reftime=$(< $root/TOOLCHAIN/reftime)
305 else
306 reftime=$buildtime # so until we have a ref all will be 100%
308 # quantized to 5% steps
309 buildtime=`gawk "BEGIN { printf(\"%d\n\", int($buildtime * 20 / $reftime) * 5 ); }"`
312 date '+%n[TIMESTAMP] %s %c'
314 [ -f $root/var/adm/logs/$stagelevel-$xpkg.err ] &&
315 x=" ERROR" || x=""
317 echo "[BUILDTIME] $buildtime ($stagelevel)$x"
319 x="$root/var/adm/packages/$xpkg"
320 if [ -f $x ]; then
321 echo "[SIZE] `grep "^Package Size: " $x |
322 cut -f3- -d' '`"
324 echo
326 x="$root/var/adm/dependencies/$xpkg"
327 [ "$pkg" != "t2-debug" -a -f $x ] &&
328 sed 's,^[^:]*:,[DEP],' $x
329 } > $root/var/adm/cache/$xpkg
331 exit $returncode
332 else
333 exec $0 $options
339 # ---- Setting Build Variables
342 flistroot="bin boot etc lib lib64 lib32 libx32 sbin usr var opt"
344 # remove the obvious noise: ldconfig and our /var/adm as well as due to
345 # rare i18n locale directories ...
346 flistrfilter="ldconfig\..*: .*|.*: /var/adm/.*|.*: .*/share/locale/.*"
348 flistdel="etc/ld.so.cache|etc/blkid.tab|var/tmp/.*|usr/tmp/.*|var/adm/logs/.*|.*\\.old"
349 # filter some cache and query updates
350 var_append flistdel '|' ".*/share/icons/[^/]*|.*gio/modules/giomodule.cache"
351 flistvalid="$base|/tmp|/var/backups|/proc|/dev"
352 foodirlist="bindir sbindir libdir datadir includedir sysconfdir localstatedir docdir"
354 init_vars_and_hooks
357 # ---- Read various config files
360 parse_desc $pkg
362 echo_pkg_start $stagelevel $repository $xpkg $ver $extraver
364 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
365 x="`scripts/Check-PkgFormat $pkg`"
366 [ "$x" ] && abort "$x\nDisable the 'Paranoia Check' config `
367 `option to ignore such errors."
370 targetdir="$base/target/$target"
372 detect_patchfiles
374 if [ $stagelevel -gt 2 ]; then
375 for pc_file in $xroot/var/adm/parse-config/*; do
376 if [ -s "$pc_file" -a "${pc_file##*/}" != "$xpkg" ]
377 then . "$pc_file"; fi
378 done
379 unset pc_file
381 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
383 set_confopt
385 hasflag OBJDIR && configscript="../configure" &&
386 hook_add preconf 3 "mkdir -p objdir; cd objdir"
388 # Erase positional parameters to prevent unintended parameter
389 # passing. We do not want to pass the current positional parameters
390 # to the loaded script.
391 set --
392 eval "$desc_O"
394 # include package pre config - if any
395 if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf ]; then
396 echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_pre.conf"
397 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf
400 # read the package configuration, $confdir might differ from package/*/$pkg ...
401 for x in $( get_expanded $base/target/%/pkg_$pkg.conf $targetchain ) \
402 $targetdir/package/$pkg/$pkg.conf \
403 architecture/$arch/package/$pkg/$pkg.conf \
404 $confdir/$pkg.conf \
405 $base/package/*/$pkg/$pkg.conf; do
406 if [ -f $x ]; then
407 echo_status "Reading package config: ${x#$base/}"
408 . $x
409 break
411 done
413 # include package post config - if any
414 if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf ]; then
415 echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_post.conf"
416 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf
419 if [ -f $base/architecture/$arch/pkg-header ]; then
420 echo_status "Reading overwrites from architecture/$arch/pkg-header."
421 . $base/architecture/$arch/pkg-header
424 for x in $( get_expanded $base/target/%/pkg-header `get_reverted $targetchain` ); do
425 if [ -f $x ]; then
426 echo_status "Reading overwrites from ${x#$base/}."
427 . $x
429 done
432 # ---- Variable updates based on the configuration files read
435 if [ -z "$prefix" -o "${prefix#usr}" != "$prefix" ]; then
436 flistdel="$flistdel|usr/share/info/(dir|standards.info)"
437 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
438 flistdel="$flistdel|usr/share/locale/..[/_].*"
439 flistdel="$flistdel|usr/share/man/..[/_].*"
441 else
442 flistdel="$flistdel|$prefix/info/(dir|standards.info)"
443 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
444 flistdel="$flistdel|$prefix/share/locale/..[/_].*"
445 flistdel="$flistdel|$prefix/man/..[/_].*"
450 # ---- Build Package
453 echo_status "Preparing build in ${builddir##*/}"
454 mkdir -p $builddir; chmod 755 $builddir
455 if [ $clear_src = 1 ]; then
456 if [ "$SDECFG_SRC_TMPFS" = 1 ]; then
457 mount -n -o remount,exec,$SDECFG_SRC_TMPFS_OPT /tmp
458 mkdir -p /tmp/${builddir##*/}
459 mount -n --bind /tmp/${builddir##*/} $builddir
463 export TMPDIR="$builddir/tmp"
464 mkdir -p "$TMPDIR"
466 if [ $update = 1 -a ! -f $xroot/var/adm/md5sums/$xpkg ]; then
467 echo_status "Ignoring update mode since package isn't installed already."
468 update=0
471 if [ $update = 1 ]; then
472 echo_status "Creating backup of old package data."
474 cd $xroot/
475 md5sum --check var/adm/md5sums/$xpkg 2>&1 < /dev/null |
476 grep ': FAILED$' | cut -f1 -d:
477 ) > $builddir/backup_files.txt
478 if [ -s $builddir/backup_files.txt ]; then
479 mkdir -p "$xroot/var/adm/backup"
480 chmod 700 "$xroot/var/adm/backup"
481 backup_tar="$xroot/var/adm/backup/$(
482 date '+%Y%m%d%H%M%S')_$xpkg.tar.bz2"
483 ( cd $xroot/; tar --no-recursion -cf - -T $builddir/`
484 `backup_files.txt || true; ) | bzip2 > $backup_tar
485 else
486 update=0
490 if [ "$SDECFG_FLIST" = "flwrapper" ]; then
491 rm -f $builddir/fl_wrapper.wlog $builddir/fl_wrapper.rlog
492 touch $builddir/fl_wrapper.wlog $builddir/fl_wrapper.rlog
493 elif [ "$SDECFG_FLIST" = "find" ]; then
494 touch $builddir/temp.time_stamp
495 sleep 2
498 hook_eval prepare
500 # define new abort function for errors while building
502 abort() {
503 [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
504 rm -vf $root/var/adm/logs/$stagelevel-$xpkg.log
505 false
509 trap 'echo "Got SIGINT (Ctrl-C). Aborting build."; exit 1' INT
510 exec < /dev/null
512 # Makes debugging build problems easier
514 hook_dump > $builddir/debug.hooks
517 dump_env
518 cat <<- EOT
519 PS1='\\[\\e[00m\\e[01;31m\\]debug-`
520 `$xpkg\\[\\e[00m\\]:[\\W]\\\$ '
521 alias cp="cp -i"; alias mv="mv -i"
522 alias rm="rm -i"; alias ls="ls --color=auto -a"
523 alias ..="cd .."; alias ...="cd ../.."
524 fixfile () {
525 # we use .vanilla to not rediff backup .orig from patch
526 for f; do [ -f \$f.vanilla ] || cp \$f{,.vanilla}; done
527 # maybe we do not have the editor yet?
528 which \$EDITOR > /dev/null || EDITOR=nvi
529 \$EDITOR "\$@"
531 fixfilediff() {
532 local p=\${1:+$confdir/\$1}
533 (find -name '*.vanilla' -printf '%P\n' | while read x; do
534 diff -u \$x \${x/.vanilla/}
535 done) | tee -a \${p:-/dev/null}
538 } > $builddir/debug.buildenv
540 cat > $builddir/debug_x.sh <<- EOT
541 #!/bin/bash
542 cd $builddir; exec bash --rcfile debug.buildenv 200>> build.pid
545 if [ "$SDE_THIS_IS_CHROOT" != 1 ]; then
546 mv $builddir/debug_x.sh $builddir/debug.sh
547 chmod +x $builddir/debug.sh
550 # Create PID file
552 # The builtin-variable '$$' is not this pid because this proc
553 # is just a sub-proc of $$. That's why the $builddir/strace.tmp
554 # hack is required to get the right pid to trace.
556 # We also conntect filedescriptor 3 with the pid file. So the command
557 # 'fuser' can be used to create a list of all processes which are part
558 # of this build process.
560 sh -c 'echo $PPID' > $builddir/build.pid
561 exec 200>> $builddir/build.pid
563 echo "Command Wrapper Debug: running '${CC} --version' .."
564 type ${CC}; CMD_WRAPPER_DEBUG=1 ${CC} --version
565 echo "[ writing debug log to $builddir/cmd_wrapper.log ]"
567 if [ "$debug" = 1 ]; then
568 echo "Everything is set up." \
569 "We are in debug mode - so exit now."
570 exit
573 if [ "$SDECFG_FLIST" = "strace" ]; then
574 strace -o $builddir/strace.out -F -f -q -e open,creat,mkdir,`
575 `mknod,link,symlink,rename,utime,chdir,execve,fork,`
576 `vfork,_exit,exit_group -p $(< $builddir/build.pid) &
577 strace_pid=$!; sleep 1; cd $base
581 set -e
583 mkdir -p "$builddir/archdir"
584 populate_archdir
586 echo "Running main build function '$mainfunction'"
587 if [ $xtrace -eq 1 -o $SDECFG_XTRACE -eq 1 ]; then
588 PS4=$'=[$FUNCNAME:$LINENO (last \\\$?=$?)> '; set -o xtrace
589 cd $builddir; eval "$mainfunction"
590 set +o xtrace
591 else
592 cd $builddir; eval "$mainfunction"
594 touch $root/var/adm/logs/$stagelevel-$xpkg.log
596 [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ||
597 abort "Due to previous errors, no $stagelevel-$xpkg.log file!
598 (Try enabling xtrace in the config to track an error inside the build system.)"
600 hook_eval postinstall
602 echo "Creating file list and doing final adaptions ... "
604 cd $xroot/
605 [ -s "var/adm/parse-config/$xpkg" ] &&
606 echo "var/adm/parse-config/$xpkg" >> $builddir/flist.txt
607 for x in var/adm/{flists,md5sums,packages,descs,dependencies}/$xpkg; do
608 touch $x; echo "$x" >> $builddir/flist.txt
609 done
611 if [ "$SDECFG_FLIST" = "strace" ]; then
612 sleep 1; kill -INT $strace_pid; sleep 1
613 fl_stparse -w $builddir/fl_wrapper.wlog \
614 -r $builddir/fl_wrapper.rlog < $builddir/strace.out
617 if [ "$SDECFG_FLIST" = "flwrapper" -o \
618 "$SDECFG_FLIST" = "strace" ]; then
619 if [ "$stagelevel" -le 2 ]
620 then
621 xbase="$( cd $xroot/ 2> /dev/null; pwd -P )"
622 flistvalid="$xbase|$flistvalid"
623 found_invalid=0
624 while read file; do
625 if [ -e "$file" ]; then
626 echo "Created file outside basedir: $file"
627 abort_soon=1
628 else # non fatal for now (configure junk)
629 echo "Created vanished file outside basedir: $file (ignored)"
631 if [ "$found_invalid" = 0 ]; then
632 echo "base #1: $base"
633 echo "base #2: $xbase"
634 found_invalid=1
636 done < <( egrep -v " ($flistvalid)/" $builddir/fl_wrapper.wlog |
637 cut -f2- | sort -u )
639 [ "$abort_soon" = 1 ] && abort
642 fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog > \
643 $builddir/flist.txt.tmp
645 # check for file creation beside the allowed top-level
646 # directories - allow root since qt, wxwidgets, ... create some
647 # profile there ... - on stage 0 we have an ugly symlink hack
648 # so we get doc, $arch_machine, ... in the top level dir :-(
649 if [ $stagelevel -gt 0 ]; then
650 fr="$flistroot root TOOLCHAIN"
652 while read file; do
653 echo "Created file outside allowed top-level dir: $file"
654 abort_soon=1
655 done < <( egrep -v "^(${fr// /|})(/|$)" \
656 $builddir/flist.txt.tmp )
657 [ "$abort_soon" = 1 ] && abort
660 egrep "^(${flistroot// /|})(/|$)" $builddir/flist.txt.tmp >> \
661 $builddir/flist.txt
663 elif [ "$SDECFG_FLIST" = "find" ]; then
664 find $flistroot \
665 \( -not -type d -or -type d -empty \) \
666 -and \( -newer $builddir/temp.time_stamp -or \
667 -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> \
668 $builddir/flist.txt
671 # evaluate flistdel
672 egrep -v "^($flistdel)\$" $builddir/flist.txt > $builddir/flist.txt.new
673 mv $builddir/flist.txt{.new,}
675 hook_eval postflist
677 # save the old flist for later orphaned file check
678 [ -e var/adm/flists/$xpkg ] &&
679 cp -f var/adm/flists/$xpkg $builddir/flist.txt.old
681 fl_wrparse -D -p "$xpkg" -r "$xroot/" < $builddir/flist.txt |
682 sort -u > $builddir/flist.txt.new
684 # analyze which files have not been reinstalled and thus are (normally)
685 # no longer needed (orphaned)
686 if [ -e $builddir/flist.txt.old ]; then
687 echo "Searching for orphaned files ..."
688 diff --normal $builddir/flist.txt.{old,new} |
689 grep '^<' | cut -d ' ' -f 2- > $builddir/olist.txt.new
690 [ -e var/adm/olists/$xpkg ] &&
691 cp -f var/adm/olists/$xpkg $builddir/olist.txt.old ||
692 touch $builddir/olist.txt.old
693 cat $builddir/olist.txt.{old,new} | sort -u > \
694 var/adm/olists/$xpkg
697 # until all olist regressions are fixed merge the two lists ... :-(
698 touch $builddir/flist.txt.old
699 cat $builddir/flist.txt.{old,new} | egrep -v "^$xpkg: ($flistdel)\$" |
700 sort -u > var/adm/flists/$xpkg
701 echo Found `wc -l < var/adm/flists/$xpkg` "files for this package."
702 echo Found `wc -l < var/adm/olists/$xpkg` "orphaned files for this package."
704 echo "Clear (old) md5sums ..."
705 echo -n > var/adm/md5sums/$xpkg
707 if [ "$SDECFG_FLIST" = "flwrapper" -o \
708 "$SDECFG_FLIST" = "strace" ] && [ $stagelevel -gt 0 ]; then
709 echo "Calculating package dependencies ..."
711 ! egrep -v "^($flistrfilter)\$" $builddir/fl_wrapper.[rw]log |
712 sort -u | fl_wrparse -D -s -r "$xroot/" -p '' | sort -u |
713 grep -v ' var/adm/' | awk '
714 # read the var/adm/... file content in
715 ARGIND < ARGC-1 {
716 if ( $1 != "'$xpkg':" )
717 f[$2] = $1 " " f[$2];
719 # iterate over the read file list streamed to stdin
720 ARGIND == ARGC-1 {
721 file = $2;
722 if ( f[file] ) {
723 print f[file] " " file;
726 ' var/adm/flists/* - >> $builddir/dependencies.debug
728 awk 'BEGIN { FS=": "; } { print "'$xpkg': " $1; }' \
729 < $builddir/dependencies.debug \
730 >> $builddir/dependencies.txt
732 sort -u $builddir/dependencies.debug > var/adm/dep-debug/$xpkg
734 # merge the dependencies defined by the package
735 for x in `echo "$desc_E" | egrep '^add ' | sed 's/^add //' `; do
736 echo "Adding dependency: $x ..."
737 echo "$xpkg: $x" >> $builddir/dependencies.txt
738 done
740 # remove dependencies as requested by the package
741 # TODO: goups are not used yet (and it is not easy here)
742 del_pattern=""
743 for x in $SDECFG_LIBC $SDECFG_DEFAULT_CC ${compressor%% *} \
744 `echo "$desc_E" | egrep '^del ' | sed 's/^del //' `; do
745 del_pattern="$del_pattern -e \".*: $x\$\""
746 done
747 if [ -n "$del_pattern" ]; then
748 echo "Deleting dependencies, pattern: $del_pattern ..."
749 eval egrep -v $del_pattern \
750 $builddir/dependencies.txt > \
751 $builddir/dependencies.txt.new
752 mv $builddir/dependencies.txt{.new,}
755 sort -u $builddir/dependencies.txt > var/adm/dependencies/$xpkg
758 echo -n "Creating md5sum files ..."
759 getfiles < var/adm/flists/$xpkg > $builddir/files.lst
760 if [ -s $builddir/files.lst ]; then
761 grep -v '^var/adm/' $builddir/files.lst | sed -e 's,^.*,"\0",' |
762 xargs -r md5sum > var/adm/md5sums/$xpkg
764 echo ' done.'
766 echo "Creating package description ..."
768 buildend="`date '+%s'`"
769 buildlist="$(grep "^Build \[.\] at " var/adm/packages/$xpkg || true
770 echo "Build [$stagelevel] at `date --date=@$buildstart '+%m/%d/%Y from %T'`" \
771 "to `date --date=@$buildend '+%T'`" \
772 " `date --date=@$((buildend - buildstart)) --utc '+%H:%M:%S'`")"
774 srccksum=$(pkgchksum $base/package/*/$pkg)
775 cat > var/adm/packages/$xpkg << EOT
776 Package Name and Version: $xpkg $ver $extraver
777 Package Size: `getdu $root/ < var/adm/flists/$xpkg`, `
778 wc -l < var/adm/flists/$xpkg | tr -d ' '` files
779 T2 Package Source Checksum: $srccksum
780 T2 Version and Architecture: $sdever $arch
781 $buildlist
782 Prefix: $prefix
785 # Location libdir: /opt/*/lib
786 for x in $foodirlist; do
787 if [ "`eval echo \\$$x`" != "`pkggetdir $x`" ]; then
788 echo "Location $x: `eval echo \\$$x`" \
789 >> var/adm/packages/$xpkg
791 done
793 cat >> var/adm/packages/$xpkg << EOT
794 Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
796 ${desc_I:-$xpkg}
798 $( echo "${desc_T:-No description available.}" | sed 's,^, ,' )
800 URL(s):
801 $( echo "${desc_U:-http://t2sde.org/packages/$pkg.html}" | sed 's,^, ,' )
803 Original Author(s):
804 $( echo "${desc_A:-Unknown}" | sed 's,^, ,' )
806 Package Maintainer(s):
807 $( echo "${desc_M:-Unknown}" | sed 's,^, ,' )
809 Download URL(s):
810 $( echo "${desc_D:-None}" | awk '{ print " " $3 $2; }' )
813 echo "[CONFIG] ${SDECFG_ID#*-}"
814 descfile=$base/package/*/$pkg/$pkg.desc
815 while read x; do
816 if [ "${x#\[}" != "$x" ]; then
817 x="`echo ${x// */} | tr -d '[]'`"
818 y="${x/-/_}"
819 IFS='
821 eval lines=\"\${desc_$y}\"
822 for line in $lines; do
823 echo "[$x] $line"
824 done
826 done < $base/misc/share/PKG-DESC-FORMAT
827 ) > var/adm/descs/$xpkg
829 echo "Making post-install adaptions."
831 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
832 found_errors=0
833 found_dups=0
835 # check for files which are 'shared' with other packages
836 if [ "$check_shared" != "0" ]; then
837 while read _ file; do
838 # ignore shared directories
839 [ -d $root/$file ] && continue
841 if [ $found_dups = 0 ]; then
842 echo "Found shared files with other packages:"
843 found_errors=1; found_dups=1
845 echo "$file:" $( cd $root/var/adm/flists
846 grep -l " $file\$" * )
847 # sed $xpkg to . to have this pkg's duplicates sorted first
848 done < <( sed "s,^$xpkg:,.," $root/var/adm/flists/* |
849 sort -k2 | uniq -d -f1 | grep '^\. ' )
852 found_local=0
854 # check for files in /usr/local
855 if [ "$check_usrlocal" != "0" ]; then
856 while read file; do
857 if [ $found_local = 0 ]; then
858 echo "Found files in /usr/local:"
859 found_errors=1; found_local=1
861 echo $file
862 done < <( sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg | \
863 egrep "^/usr/local" )
866 found_bad=0
868 # check for registered 'bad files'
869 if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
870 echo "$badfiles" > $builddir/badfiles.txt
871 while read x file; do
872 if [ $found_bad = 0 ]; then
873 echo "Found registered 'bad files' in package:"
874 found_errors=1; found_bad=1
876 desc="No description found!"
877 for ((x=0; x<badfiles_nr; x++)); do
878 if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
879 then desc="${badfiles_desc[x]#*$'\n'}"; fi
880 done
881 echo "$file: $desc"
882 done < <( grep -f $builddir/badfiles.txt $root/var/adm/flists/$xpkg )
885 [ $found_errors != 0 ] && abort "Due to previous errors."
888 } 2>&1 | {
890 trap '' INT
892 echo_status "Building. Writing output to" \
893 "\$root/var/adm/logs/$stagelevel-$xpkg.out"
895 if [ "$SDECFG_VERBOSE" = 1 -o "$verbose" = 1 ]; then
896 tee $root/var/adm/logs/$stagelevel-$xpkg.out |
897 gawk "/$/ {print; printf \"^$stagelevel-$xpkg\r\"; fflush();}"
898 else
899 cat > $root/var/adm/logs/$stagelevel-$xpkg.out
903 hook_eval finish
905 if [ $update = 1 ]; then
906 echo_status "Restoring backup of old package data."
908 while read fn; do
909 [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
910 done < $builddir/backup_files.txt
912 tar --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
914 while read fn; do
915 cmp -s $fn $fn.new && rm -f $fn.new
916 done < $builddir/backup_files.txt
919 cd $base
921 umount -r -d -f $builddir/* 2> /dev/null
922 umount -r -d -f -l $builddir/* 2> /dev/null
924 if [ "$SDECFG_SRC_TMPFS" = 1 ]; then
925 if [ -e $root/var/adm/logs/$stagelevel-$xpkg.log \
926 -o "$SDECFG_SRC_TMPFS_KEEP_ON_ERROR" != 1 ]; then
927 rm -rf /tmp/${builddir##*/}/*
928 umount -n -r -d -f $builddir 2> /dev/null
929 umount -n -r -d -f -l $builddir 2> /dev/null
930 rm -rf /tmp/${builddir##*/}
934 # cleanup_src <error code>
935 # Cleanup the src.* directory the way configured.
937 cleanup_src () {
938 # cleaning the src disabled manually
939 [ $clear_src = 0 ] && return
941 case "$SDECFG_KEEP_SRC" in
942 0) : # always clean, just fall-thru
944 1) [ $1 != 0 ] && return # keep on error, just return
946 2|3) # on error or if in the list
947 [ "$SDECFG_KEEP_SRC" = 3 -a $1 != 0 ] && return
949 local list=" $SDECFG_KEEP_SRC_LIST "
950 list="${list//:/ }"
951 list="${list//,/ }"
953 # if package is in the list, just return
954 [ "${list/ $pkg /}" != "$list" ] && return
956 esac
958 rm -rf $builddir/* $builddir
961 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
962 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/BUILD-LOG
963 cleanup_src 0
964 mv $root/var/adm/logs/$stagelevel-$xpkg.out \
965 $root/var/adm/logs/$stagelevel-$xpkg.log
966 echo_pkg_finish $stagelevel $repository $xpkg
967 exit 0
968 else
969 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/ERROR-LOG
970 cleanup_src 1
971 if [ "$SDECFG_VERBOSE" != 1 -a "$verbose" != 1 ]; then
972 echo_errorquote "$( grep -v 'make[^ ]*:' \
973 $root/var/adm/logs/$stagelevel-$xpkg.out |
974 grep -B8 -- '--- BUILD ERROR ---' |
975 sed '/--- BUILD ERROR ---/d' )"
977 mv $root/var/adm/logs/$stagelevel-$xpkg.out \
978 $root/var/adm/logs/$stagelevel-$xpkg.err
979 echo_pkg_abort $stagelevel $repository $xpkg
980 exit 1