* rebased llvm/hotfix-sparcv9-not-64.diff
[t2sde.git] / scripts / Build-Pkg
bloba60cd3461398fb6bed3f1c251ce7a2e531f1f0d2
1 #!/usr/bin/env bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Build-Pkg
5 # Copyright (C) 2004 - 2024 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # This Copyright note is generated by scripts/Create-CopyPatch,
9 # more information can be found in the files COPYING and README.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License version 2.
13 # --- T2-COPYRIGHT-NOTE-END ---
15 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" prefix="$2" prefix_auto=0 ; shift ;;
76 -id) options="$options $1 $2" id="$2" ; shift ;;
77 -noclearsrc) options="$options $1" clear_src=0 ;;
78 -norebuild) options="$options $1" norebuild=1 ;;
79 -*) help_msg; exit 1 ;;
80 *) break ;;
81 esac
82 shift
83 done
85 # check if arguments are left as package names
86 if [ $# = 0 ]; then
87 help_msg; exit 1
90 . scripts/functions.in
91 . scripts/parse-config
93 if [ -z "$root" -a $stagelevel -le 2 ] ||
94 [ -z "$root" -a $chroot -eq 1 ] ||
95 [ "$root" = auto ]; then
96 # stage 0 cross compiler build
97 if [ $stagelevel -eq 0 ]; then root="build/$SDECFG_ID/TOOLCHAIN/$toolsdir"
98 # the new systems root
99 else root="build/$SDECFG_ID"; fi
102 [ "$root" -a "${root#/}" = "$root" ] && root="$base/$root"
104 # remove leading and trailing / on prefix and root
105 prefix=${prefix%/} prefix=${prefix#/} root=${root%/}
107 # xroot is for internal use and always points to the new system
108 xroot="$root"
109 if [ $stagelevel -le 2 ]; then
110 sysroot="$base/build/$SDECFG_ID" # always fresh sandbox
111 else
112 root=
113 sysroot=
117 if [ -z "$id" ]; then
118 id=`get_unique`
119 options="$options -id $id"
122 # more than one package is passed
123 if [ $# -gt 1 ]; then
124 for x; do
125 if ! scripts/Build-Pkg $options $x &&
126 [ $stagelevel -le $SDECFG_CONTINUE_ON_ERROR_AFTER ]; then
127 exit 1
129 done
130 exit 0
133 pkg="${1%=*}" xpkg="${1#*=}"
135 builddir="$base/src.$pkg"
136 [ $config != "default" ] && builddir="$builddir.$config"
137 builddir="$builddir.$id"
139 if [ "$chroot" = 1 ]; then
141 cd "$xroot" || exit 1
143 x_mknod() {
144 if [ ! -c "$1" -a ! -b "$1" ]; then
145 mknod "$@"
149 x_mknod dev/null c 1 3
150 x_mknod dev/zero c 1 5
151 x_mknod dev/random c 1 8
152 x_mknod dev/urandom c 1 9
153 x_mknod dev/loop0 b 7 0
154 x_mknod dev/loop1 b 7 1
155 x_mknod dev/loop2 b 7 2
156 x_mknod dev/loop3 b 7 3
157 #_mknod dev/tty c 5 0
159 if [ ! -L dev/fd ]; then
160 ln -s /proc/self/fd dev/fd
163 realconf=$(cd $base/config; pwd -P)
164 realdown=$(cd $base/download; pwd -P)
165 realbase=$(dirname $(cd $base/scripts; pwd -P))
167 if [ ! -e TOOLCHAIN/loop/scripts ]; then
168 mkdir -p TOOLCHAIN/{loop,config,download}
169 mount --bind $realbase TOOLCHAIN/loop
170 mount --bind $realconf TOOLCHAIN/config
171 mount --bind $realdown TOOLCHAIN/download
172 mount --bind /tmp tmp
175 if [ ! -f proc/mounts ]; then
176 mount -nt proc none proc
179 for x in architecture kernel misc package scripts target; do
180 if [ ! -e TOOLCHAIN/$x ]; then ln -s "loop/$x" "TOOLCHAIN/$x"; fi
181 done
183 if [ ! -e "TOOLCHAIN/build/$SDECFG_ID" ]; then
184 mkdir -p "TOOLCHAIN/build"
185 ln -snf ../.. "TOOLCHAIN/build/$SDECFG_ID"
188 mkdir -p "TOOLCHAIN/src.$pkg.$config.$id"
189 ln -s "$PWD/TOOLCHAIN/src.$pkg.$config.$id" "$builddir"
191 cat > $builddir/chroot.sh <<- EOT
192 export SDE_THIS_IS_CHROOT=1; cd /TOOLCHAIN
193 scripts/Build-Pkg $options -chr-sub -root "/" "$1"
196 cat > $builddir/debug.sh <<- EOT
197 #!/usr/bin/env bash
198 if [ ! -f "$xroot/proc/mounts" ]; then
199 mount -nt proc none "$xroot/proc"
201 if [ ! -e "$xroot/TOOLCHAIN/loop/scripts" ]; then
202 mkdir -p "$xroot/"TOOLCHAIN/{loop,config,download}
203 mount --bind $realbase "$xroot/TOOLCHAIN/loop"
204 mount --bind $realconf "$xroot/TOOLCHAIN/config"
205 mount --bind $realdown "$xroot/TOOLCHAIN/download"
208 export SDE_THIS_IS_CHROOT=1
209 chroot "$xroot" /bin/bash TOOLCHAIN/src.$pkg.$config.$id/debug_x.sh
211 if ! fuser -s "$xroot/TOOLCHAIN/"; then
212 echo "Loop mounts appear unused - un-mounting ..."
213 umount "$xroot/TOOLCHAIN/"{loop,config,download}
214 umount "$xroot/{proc,tmp}"
217 chmod +x $builddir/debug.sh
219 if [ "$TZ" ]; then
220 if [ "${TZ#/}" != "$TZ" ]; then
221 cp $TZ TOOLCHAIN/localtime
222 else
223 cp /usr/share/zoneinfo/$TZ TOOLCHAIN/localtime
225 else
226 if [ -f /etc/localtime ]; then
227 cp /etc/localtime TOOLCHAIN/localtime
228 else
229 ln -sf /usr/share/zoneinfo/Factory TOOLCHAIN/localtime
233 if [ "$SDECFG_PKG_DISTCC_HOST_RESOLV" = "1" ]; then
234 cat /etc/resolv.conf > etc/resolv.conf
237 TZ="/TOOLCHAIN/localtime" chroot . bin/bash TOOLCHAIN/src.$pkg.$config.$id/chroot.sh
238 returncode=$?
240 if [ ! -d "$builddir/." ]; then
241 rm "$builddir"
244 exit $returncode
247 scripts/Build-Tools -$stagelevel -cfg $config || exit 1
249 if [ "$SDECFG_FLIST" = "flwrapper" -a -z "$FLWRAPPER" ]; then
250 export FLWRAPPER_WLOG="$builddir/fl_wrapper.wlog"
251 export FLWRAPPER_RLOG="$builddir/fl_wrapper.rlog"
252 export FLWRAPPER_BASEPID=$$
253 export FLWRAPPER_FILTERDIR="/tmp/:$builddir"
254 [ "$LD_PRELOAD" ] && LD_PRELOAD="${LD_PRELOAD}:"
255 export FLWRAPPER="$base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so"
256 export LD_PRELOAD="${LD_PRELOAD}$FLWRAPPER"
258 export INSTALL_WRAPPER_LOGFILE="$builddir/install_wrapper.log"
259 export CMD_WRAPPER_LOGFILE="$builddir/cmd_wrapper.log"
261 if [ $norebuild = 1 -a -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
262 echo_pkg_deny $stagelevel $pkg "already built"
263 exit 0
266 # TODO: should we be pedantic and force rebuild of low stages even if $norebuild?
267 if [ "$SDECFG_RETRY_BROKEN" = 0 -a $norebuild = 1 -a \
268 -f $root/var/adm/logs/$stagelevel-$xpkg.err ]; then
269 echo_pkg_deny $stagelevel $pkg "already failed"
270 exit 1
273 archdir="$builddir/archdir"
275 detect_confdir
277 if [ -z "$confdir" ]; then
278 echo_pkg_deny $stagelevel $pkg "does not exist"; exit 1
281 mkdir -p $root/var/adm/{logs,flists,olists,md5sums,packages,dependencies,\
282 dep-debug,parse-config,cache,descs}
283 rm -f $root/var/adm/logs/$stagelevel-$xpkg.{out,log,err}
285 md5sum=md5sum
286 if ! type -p $md5sum > /dev/null; then
287 md5sum="md5 -r"
290 if [ $this_is_the_2nd_run = 0 ]; then
291 [ $stagelevel -gt 2 ] && . /etc/profile
292 options="-this_is_the_2nd_run $options $pkg=$xpkg"
293 if [ "$SDECFG_CREATE_CACHE" = 1 ]; then
294 mkdir -p $root/var/adm/cache
295 rm -f $root/var/adm/cache/$xpkg{,.tm}
297 /usr/bin/time -o "$root/var/adm/cache/$xpkg.tm" \
298 -f '%U %S' $0 $options
299 returncode=$?
300 [ ! -e "$root/var/adm/cache/$xpkg.tm" ] && exit $returncode
302 buildtime=$(grep -v '^Command ' < $root/var/adm/cache/$xpkg.tm |
303 gawk '{printf "%d", ($1 + $2) * 100 }')
304 rm -f $root/var/adm/cache/$xpkg.tm
306 # store reference time
307 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
308 if [ $pkg = binutils ]; then
309 echo $buildtime > $base/build/$SDECFG_ID/TOOLCHAIN/reftime
312 # estimate initial, non-binutils reference time from first in-system emerge
313 if [ ! -s $base/build/$SDECFG_ID/TOOLCHAIN/reftime -a \
314 $stagelevel = 9 -a $buildtime -gt 1000 -a \
315 -e $base/package/*/$pkg/$pkg.cache ]; then
316 reftime=$(sed -n "s/\[BUILDTIME\] \([^ ]*\).*/\1/p" $base/package/*/$pkg/$pkg.cache)
318 gawk "BEGIN {printf(\"%d\n\", int($buildtime * 100 / ($reftime > 0 ? $reftime : 1)));}" > \
319 $base/build/$SDECFG_ID/TOOLCHAIN/reftime
323 # compute relative build time to binutils (LFS-style)
324 if [ -s $base/build/$SDECFG_ID/TOOLCHAIN/reftime ]; then
325 reftime=$(< $base/build/$SDECFG_ID/TOOLCHAIN/reftime)
326 else
327 reftime=$buildtime # so until we have a ref all will be 100%
329 # quantize for less .cache update noise
330 buildtime=`gawk "BEGIN { buildtime = 100 * $buildtime / $reftime; \
331 if (buildtime <= 5) q = 1; else if (buildtime <= 20) q = 2; \
332 else if (buildtime <= 200) q = 5; else if (buildtime <= 500) q = 10; \
333 else if (buildtime <= 1000) q = 20; else q = 50; \
334 printf(\"%d\", int((buildtime + q/2) / q) * q); }"`
337 date '+%n[TIMESTAMP] %s %c'
339 [ -f $root/var/adm/logs/$stagelevel-$xpkg.err ] &&
340 x=" ERROR" || x=""
342 echo "[BUILDTIME] $buildtime ($stagelevel)$x"
344 x="$root/var/adm/packages/$xpkg"
345 if [ -f $x ]; then
346 echo "[SIZE] `grep "^Package Size: " $x |
347 cut -f3- -d' '`"
349 echo
351 x="$root/var/adm/dependencies/$xpkg"
352 [ "$pkg" != "t2-debug" -a -f $x ] &&
353 sed 's,^opt:,[OPT],; s,^:,[DEP],' $x
354 } > $root/var/adm/cache/$xpkg
356 exit $returncode
357 else
358 exec $0 $options
364 # ---- Setting Build Variables
367 flistroot="bin boot etc lib lib64 lib32 libx32 sbin usr var opt"
369 # remove the obvious noise: ldconfig, our /var/adm as well as other noise
370 flistrfilter="ldconfig\..*: .*|.*: /bin/sh|.*: /bin/hostname|.*: /var/adm/.*|.*: .*/share/locale/.*"
371 # indirectly referenced .so
372 var_append flistrfilter '|' ".*: .*/lib.*\.so.*"
373 # everything configure tries randomly e.g. even bin/mt(-st)
374 var_append flistrfilter '|' ".*configure.*: .*"
375 var_append flistrfilter '|' ".*cmake\..*: .*/lib.*/.*\.cmake"
376 var_append flistrfilter '|' ".*qmake\..*: .*/mkspecs/.*\.p.*"
377 # some packages just query all, if really used .h et al. are used anyway
378 var_append flistrfilter '|' ".*pkg-config.*: .*\.pc"
379 var_append flistrfilter '|' ".*: .*/gtk-doc/.*\.devhelp2"
380 # python registry
381 var_append flistrfilter '|' ".*/site-packages/.*(PKG-INFO|METADATA|egg-info|entry_points.txt|requires.txt)"
382 # x11 mkfontdir's mkfontscale
383 var_append flistrfilter '|' ".*mkfontscale\..*: .*"
384 # fc-cache
385 var_append flistrfilter '|' ".*fc-cache\..*: .*"
386 # wxrc & friends
387 var_append flistrfilter '|' ".*: .*\.desktop"
389 # ignore some written files, too
390 flistdel="etc/ld.so.cache|proc/[0-9]*/fd|etc/blkid.tab|var/tmp/.*|usr/tmp/.*|var/adm/logs/.*|.*\\.old"
392 # filter some cache and query updates
393 var_append flistdel '|' ".*/gio/modules/giomodule.cache|.*/schemas/gschemas.compiled"
394 var_append flistdel '|' ".*/share/icons/.*/icon-theme.cache|.*/share/applications/mimeinfo.cache"
395 var_append flistdel '|' ".*/lib.*gdk-pixbuf-.*/loaders.cache"
397 flistvalid="$base|/tmp|/var/backups|/proc|/dev"
398 foodirlist="bindir sbindir libdir datadir includedir sysconfdir localstatedir docdir"
400 init_vars_and_hooks
403 # ---- Read various config files
406 parse_desc $pkg
408 echo_pkg_start $stagelevel $repository $xpkg $ver "$extraver" "$(pkgbuildtime $pkg)"
410 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
411 x="`scripts/Check-PkgFormat $pkg`"
412 [ "$x" ] && abort "$x\nDisable the 'Paranoia Check' config `
413 `option to ignore such errors."
416 targetdir="$base/target/$target"
418 detect_patchfiles
420 if [ $stagelevel -gt 2 ]; then
421 for pc_file in $xroot/var/adm/parse-config/*; do
422 if [ -s "$pc_file" -a "${pc_file##*/}" != "$xpkg" ]
423 then . "$pc_file"; fi
424 done
425 unset pc_file
427 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
429 set_confopt
431 hasflag OBJDIR && configscript="../configure" &&
432 hook_add preconf 3 "mkdir -p objs; cd objs"
434 if ! hasflag NOPARALLEL; then
435 var_append makeopt " " "-j${SDECFG_PARALLEL:-1}"
436 var_append makeinstopt " " "-j${SDECFG_PARALLEL:-1}"
439 # Erase positional parameters to prevent unintended parameter
440 # passing. We do not want to pass the current positional parameters
441 # to the loaded script.
442 set --
443 eval "$desc_O"
445 # include package pre config - if any
446 if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf ]; then
447 echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_pre.conf"
448 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf
451 # read the package configuration, $confdir might differ from package/*/$pkg ...
452 for x in $(get_expanded $base/target/%/pkg_$pkg.conf $targetchain) \
453 $targetdir/package/$pkg/$pkg.conf \
454 architecture/$arch/package/$pkg/$pkg.conf \
455 $confdir/$pkg.conf \
456 $base/package/*/$pkg/$pkg.conf; do
457 if [ -f $x ]; then
458 [ $x != $base/package/*/$pkg/$pkg.conf ] &&
459 echo_status "Reading package config: ${x#$base/}"
460 . $x
461 break
463 done
465 # include package post config - if any
466 if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf ]; then
467 echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_post.conf"
468 . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf
471 if [ -f $base/architecture/$arch/pkg-header ]; then
472 echo_status "Reading overwrites from architecture/$arch/pkg-header."
473 . $base/architecture/$arch/pkg-header
476 for x in $(get_expanded $base/target/%/pkg-header `get_reverted $targetchain`); do
477 if [ -f $x ]; then
478 echo_status "Reading overwrites from ${x#$base/}."
479 . $x
481 done
484 # ---- Variable updates based on the configuration files read
487 if [ -z "$prefix" -o "${prefix#usr}" != "$prefix" ]; then
488 flistdel="$flistdel|usr/share/info/(dir|standards.info)"
489 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
490 flistdel="$flistdel|usr/share/locale/..[/_].*"
491 flistdel="$flistdel|usr/share/man/..[/_].*"
493 else
494 flistdel="$flistdel|$prefix/info/(dir|standards.info)"
495 if [ "$SDECFG_DISABLE_NLS" = 1 ]; then
496 flistdel="$flistdel|$prefix/share/locale/..[/_].*"
497 flistdel="$flistdel|$prefix/man/..[/_].*"
502 # ---- Build Package
504 if hasflag NOPARALLEL || [ "$SDECFG_PARALLEL" -le 1 ]; then
505 hasflag NOPARALLEL && [ "$SDECFG_PARALLEL" -gt 1 ] &&
506 echo_warning 'Parallel build disabled for this package'
507 echo_status "Building in ${builddir##*/}"
508 else
509 echo_status "Building in ${builddir##*/}, with $SDECFG_PARALLEL threads"
512 mkdir -p $builddir; chmod 755 $builddir
514 if [ "$SDECFG_TMPFS_MAX_SIZE" != 0 ]; then
515 x="$(match_source_file -p)"
516 [ "$x" ] && x="$(du -cm $x | tail -1 | cut -f 1)"
517 [ "$x" ] || x=0
518 [ "$x" -gt "${SDECFG_TMPFS_MAX_SIZE:-0}" ] && SDECFG_TMPFS=0
521 if [ $clear_src = 1 ]; then
522 if [ "$SDECFG_TMPFS" = 1 ]; then
523 mount -n -o remount,exec,$SDECFG_TMPFS_OPT /tmp
524 mkdir -p /tmp/${builddir##*/}
525 mount -n --bind /tmp/${builddir##*/} $builddir
529 export TMPDIR="$builddir/tmp"
530 mkdir -p "$TMPDIR"
532 if [ $update = 1 -a ! -f $xroot/var/adm/md5sums/$xpkg ]; then
533 #echo_warning "Ignoring update mode since package isn't installed already."
534 update=0
537 if [ $update = 1 ]; then
538 echo_status "Creating backup of old package data."
540 cd $xroot/
541 $md5sum --check var/adm/md5sums/$xpkg 2>&1 < /dev/null |
542 grep ': FAILED$' | cut -f1 -d:
543 ) > $builddir/backup_files.txt
544 if [ -s $builddir/backup_files.txt ]; then
545 mkdir -p "$xroot/var/adm/backup"
546 chmod 700 "$xroot/var/adm/backup"
547 backup_tar="$xroot/var/adm/backup/$(
548 date '+%Y%m%d%H%M%S')_$xpkg.tar.bz2"
549 (cd $xroot/; tar --no-recursion -cf - -T $builddir/`
550 `backup_files.txt || true) | bzip2 > $backup_tar
551 else
552 update=0
556 if [ "$SDECFG_FLIST" = "flwrapper" ]; then
557 rm -f $builddir/fl_wrapper.{rlog,wlog}
558 touch $builddir/fl_wrapper.{rlog,wlog}
559 elif [ "$SDECFG_FLIST" = "find" ]; then
560 touch $builddir/temp.time_stamp
561 sleep 2
564 hook_eval prepare
566 # define new abort function for errors while building
568 abort() {
569 [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
570 rm -vf $root/var/adm/logs/$stagelevel-$xpkg.log
571 false
575 trap 'echo "Got SIGINT (Ctrl-C). Aborting build."; exit 1' INT
576 exec < /dev/null
578 # Makes debugging build problems easier
580 hook_dump > $builddir/debug.hooks
583 dump_env
584 cat <<- EOT
585 PS1='\\[\\e[00m\\e[01;31m\\]debug-`
586 `$xpkg\\[\\e[00m\\]:[\\W]\\\$ '
587 alias cp="cp -i"; alias mv="mv -i"
588 alias rm="rm -i"; alias ls="ls --color=auto -a"
589 alias ..="cd .."; alias ...="cd ../.."
590 fixfile () {
591 # we use .vanilla to not rediff backup .orig from patch
592 for f; do [ -f \$f.vanilla ] || cp \$f{,.vanilla}; done
593 # maybe we do not have the editor yet?
594 which \$EDITOR > /dev/null || EDITOR=nvi
595 LD_PRELOAD= \$EDITOR "\$@"
597 fixfilediff() {
598 local p=\${1:+$confdir/\$1}
599 (find -name '*.vanilla' -printf '%P\n' | while read x; do
600 diff -u \$x \${x/.vanilla/}
601 done) | tee -a \${p:-/dev/null}
604 } > $builddir/debug.buildenv
606 cat > $builddir/debug_x.sh <<- EOT
607 #!/usr/bin/env bash
608 cd $builddir
609 [ -f ERROR-LOG ] && sed -n 's/^[rR]unning.*/# &/p' ERROR-LOG
610 exec bash --rcfile debug.buildenv 200>> build.pid
613 if [ "$SDE_THIS_IS_CHROOT" != 1 ]; then
614 mv $builddir/debug_x.sh $builddir/debug.sh
615 chmod +x $builddir/debug.sh
618 # Create PID file
620 # The builtin-variable '$$' is not this pid because this proc
621 # is just a sub-proc of $$. That's why the $builddir/strace.tmp
622 # hack is required to get the right pid to trace.
624 # We also conntect filedescriptor 3 with the pid file. So the command
625 # 'fuser' can be used to create a list of all processes which are part
626 # of this build process.
628 sh -c 'echo $PPID' > $builddir/build.pid
629 exec 200>> $builddir/build.pid
631 if [ "$SDECFG_DEBUG" != 0 ]; then
632 hasflag KERNEL && _CC=$KCC || _CC=$CC
633 echo "Command wrapper test: '${_CC} --version'"
634 type ${_CC}; CMD_WRAPPER_DEBUG=1 ${_CC} --version
635 unset _CC
636 echo "[ writing debug log to $builddir/cmd_wrapper.log ]"
639 if [ "$debug" = 1 ]; then
640 echo "Everything is set up. We are in debug mode - so exit now."
641 exit
644 if [ "$SDECFG_FLIST" = "strace" ]; then
645 strace -o $builddir/strace.out -F -f -q -e open,creat,mkdir,`
646 `mknod,link,symlink,rename,utime,chdir,execve,fork,`
647 `vfork,_exit,exit_group -p $(< $builddir/build.pid) &
648 strace_pid=$!; sleep 1; cd $base
652 set -e
654 mkdir -p "$builddir/archdir"
655 populate_archdir
657 echo "Running main build function '$mainfunction'"
658 if [ $xtrace -eq 1 -o $SDECFG_XTRACE -eq 1 ]; then
659 PS4=$'=[$FUNCNAME:$LINENO (last \\\$?=$?)> '; set -o xtrace
660 cd $builddir; eval "$mainfunction"
661 set +o xtrace
662 else
663 cd $builddir; eval "$mainfunction"
665 touch $root/var/adm/logs/$stagelevel-$xpkg.log
667 [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ||
668 abort "Due to previous errors, no $stagelevel-$xpkg.log file!
669 (Try enabling xtrace in the config to track an error inside the build system.)"
671 hook_eval postinstall
673 echo "Creating file list and doing final adaptions ... "
675 cd $xroot/
676 [ -s "var/adm/parse-config/$xpkg" ] &&
677 echo "var/adm/parse-config/$xpkg" >> $builddir/flist.txt
678 for x in var/adm/{flists,md5sums,packages,descs,dependencies}/$xpkg; do
679 touch $x; echo "$x" >> $builddir/flist.txt
680 done
682 if [ "$SDECFG_FLIST" = "strace" ]; then
683 sleep 1; kill -INT $strace_pid; sleep 1
684 fl_stparse -w $builddir/fl_wrapper.wlog \
685 -r $builddir/fl_wrapper.rlog < $builddir/strace.out
688 if [ "$SDECFG_FLIST" = "flwrapper" -o \
689 "$SDECFG_FLIST" = "strace" ]; then
690 if [ "$stagelevel" -le 2 ]
691 then
692 xbase="$(cd $xroot/ 2> /dev/null; pwd -P)"
693 flistvalid="$xbase|$flistvalid"
694 found_invalid=0
695 while read file; do
696 if [ -e "$file" ]; then
697 echo "Created file outside basedir: $file"
698 abort_soon=1
699 else # non fatal for now (configure junk)
700 echo "Warning: Created vanished file outside basedir: $file"
702 if [ "$found_invalid" = 0 ]; then
703 echo "base #1: $base"
704 echo "base #2: $xbase"
705 found_invalid=1
707 done < <(egrep -v " ($flistvalid)/" $builddir/fl_wrapper.wlog |
708 cut -f2- | sort -u)
710 [ "$abort_soon" = 1 ] && abort
713 fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog > \
714 $builddir/flist.txt.tmp
716 # check for file creation beside the allowed top-level
717 # directories - allow root since qt, wxwidgets, ... create some
718 # profile there ... - on stage 0 we have an ugly symlink hack
719 # so we get doc, $arch_machine, ... in the top level dir :-(
720 if [ $stagelevel -gt 0 ]; then
721 fr="$flistroot root TOOLCHAIN proc/[0-9]*/fd"
723 while read file; do
724 echo "Created file outside allowed top-level dir: $file"
725 abort_soon=1
726 done < <(egrep -v "^(${fr// /|})(/|$)" \
727 $builddir/flist.txt.tmp)
728 [ "$abort_soon" = 1 ] && abort
731 egrep "^(${flistroot// /|})(/|$)" $builddir/flist.txt.tmp >> \
732 $builddir/flist.txt
734 elif [ "$SDECFG_FLIST" = "find" ]; then
735 find $flistroot \
736 \( -not -type d -or -type d -empty \) \
737 -and \( -newer $builddir/temp.time_stamp -or \
738 -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> \
739 $builddir/flist.txt
742 # evaluate flistdel
743 egrep -v "^($flistdel)\$" $builddir/flist.txt > $builddir/flist.txt.new
744 mv $builddir/flist.txt{.new,}
746 hook_eval postflist
748 # save the old flist for later orphaned file check
749 [ -e var/adm/flists/$xpkg ] &&
750 cp -f var/adm/flists/$xpkg $builddir/flist.txt.old
752 fl_wrparse -D -p "$xpkg" -r "$xroot/" < $builddir/flist.txt |
753 sort -u > $builddir/flist.txt.new
755 # analyze which files have not been reinstalled and thus are (normally)
756 # no longer needed (orphaned)
757 if [ -e $builddir/flist.txt.old ]; then
758 echo "Searching for orphaned files ..."
759 diff --normal $builddir/flist.txt.{old,new} |
760 grep '^<' | cut -d ' ' -f 2- > $builddir/olist.txt.new
761 [ -e var/adm/olists/$xpkg ] &&
762 cp -f var/adm/olists/$xpkg $builddir/olist.txt.old ||
763 touch $builddir/olist.txt.old
764 cat $builddir/olist.txt.{old,new} | sort -u > \
765 var/adm/olists/$xpkg
768 # TODO: until all olist regressions are fixed merge the two lists ...
769 touch $builddir/flist.txt.old
770 if [ "$noorphaned" = 1 ]; then
771 cat $builddir/flist.txt.new > var/adm/flists/$xpkg
772 else
773 cat $builddir/flist.txt.{old,new} | egrep -v "^$xpkg: ($flistdel)\$" |
774 sort -u > var/adm/flists/$xpkg
776 echo Found `wc -l < var/adm/flists/$xpkg` "files for this package."
777 echo Found `wc -l < var/adm/olists/$xpkg` "orphaned files for this package."
779 if [ "$SDECFG_FLIST" = "flwrapper" -o \
780 "$SDECFG_FLIST" = "strace" ] && [ $stagelevel -gt 0 ]; then
781 echo "Calculating package dependencies ..."
783 ! egrep -v "^($flistrfilter)\$" $builddir/fl_wrapper.[rw]log |
784 sort -u | fl_wrparse -D -s -r "$xroot/" -p '' | sort -u |
785 grep -v ' var/adm/' | gawk '
786 # read the var/adm/... file content in
787 ARGIND < ARGC-1 {
788 if ($1 != "'$xpkg':")
789 f[$2] = $1 " " f[$2];
791 # iterate over the read file list streamed to stdin
792 ARGIND == ARGC-1 {
793 file = $2;
794 if (f[file]) {
795 print f[file] " " file;
798 ' var/adm/flists/* - >> $builddir/dependencies.debug
800 awk 'BEGIN { FS=": "; } { print ": " $1; }' \
801 < $builddir/dependencies.debug >> $builddir/dependencies.txt
803 sort -u $builddir/dependencies.debug > var/adm/dep-debug/$xpkg
805 # remove dependencies as requested by the package
806 # TODO: goups are not used yet (and it is not easy here)
807 del_pattern=
808 for x in t2-src $SDECFG_LIBC $SDECFG_DEFAULT_CC ${compressor%% *} \
809 `echo "$desc_E" | sed -n 's/^del //p' `; do
810 del_pattern="$del_pattern -e \".*: $x\$\""
811 done
812 if [ -n "$del_pattern" ]; then
813 echo "Deleting dependencies, pattern: $del_pattern ..."
814 eval egrep -v $del_pattern \
815 $builddir/dependencies.txt > $builddir/dependencies.txt.new
816 mv $builddir/dependencies.txt{.new,}
819 # merge the dependencies defined by the package
820 echo -n "Adding dependencies"
821 for x in `echo "$desc_E" | egrep '^(add|opt) ' | sed 's/^[^ ]* //' `; do
822 echo -n ", $x"
823 echo ": $x" >> $builddir/dependencies.txt
824 done
825 echo
827 sort -u $builddir/dependencies.txt > $builddir/dependencies.txt.new
828 mv $builddir/dependencies.txt{.new,}
830 echo -n "Marking optional dependencies"
831 for x in `echo "$desc_E" | sed -n 's/^opt //p' `; do
832 echo -n ", $x"
833 sed -i "s/^: $x$/opt&/" $builddir/dependencies.txt
834 done
835 echo
837 cat $builddir/dependencies.txt > var/adm/dependencies/$xpkg
840 echo "Creating md5sum files ..."
841 getfiles < var/adm/flists/$xpkg > $builddir/files.lst
842 grep -v '^var/adm/' $builddir/files.lst | sed -e 's,^.*,"\0",' |
843 xargs -r $md5sum > var/adm/md5sums/$xpkg
845 echo "Creating package description ..."
847 buildend="`date '+%s'`"
848 buildlist="$(grep "^Build \[.\] at " var/adm/packages/$xpkg || true
849 echo "Build [$stagelevel] at `date --date=@$buildstart '+%Y-%m-%d from %T'`" \
850 "to `date --date=@$buildend '+%T'`" \
851 " `date --date=@$((buildend - buildstart)) --utc '+%H:%M:%S'`")"
853 srccksum=$(pkgchksum $base/package/*/$pkg)
854 cat > var/adm/packages/$xpkg << EOT
855 Package Name and Version: $xpkg $ver $extraver
856 Package Size: `getdu $root/ < var/adm/flists/$xpkg`, `
857 wc -l < var/adm/flists/$xpkg | tr -d ' '` files
858 T2 Package Source Checksum: $srccksum
859 T2 Version and Architecture: $sdever $arch
860 $buildlist
861 Prefix: $prefix
864 # Location libdir: /opt/*/lib
865 for x in $foodirlist; do
866 if [ "`eval echo \\$$x`" != "`pkggetdir $x`" ]; then
867 echo "Location $x: `eval echo \\$$x`" \
868 >> var/adm/packages/$xpkg
870 done
872 cat >> var/adm/packages/$xpkg << EOT
873 Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
875 ${desc_I:-$xpkg}
877 $(echo "${desc_T:-No description available.}" | sed 's,^, ,')
879 URL(s):
880 $(echo "${desc_U:-http://t2sde.org/packages/$pkg.html}" | sed 's,^, ,')
882 Original Author(s):
883 $(echo "${desc_A:-Unknown}" | sed 's,^, ,')
885 Package Maintainer(s):
886 $(echo "${desc_M:-Unknown}" | sed 's,^, ,')
888 Download URL(s):
889 $(echo "${desc_D:-None}" | gawk '{ print " " $3 $2; }')
892 echo "[CONFIG] ${SDECFG_ID#*-}"
893 descfile=$base/package/*/$pkg/$pkg.desc
894 while read x; do
895 if [ "${x#\[}" != "$x" ]; then
896 x="`echo ${x// */} | tr -d '[]'`"
897 y="${x/-/_}"
898 IFS='
900 eval lines=\"\${desc_$y}\"
901 for line in $lines; do
902 echo "[$x] $line"
903 done
905 done < $base/misc/share/PKG-DESC-FORMAT
906 ) > var/adm/descs/$xpkg
908 echo "Making post-install adaptions."
910 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
911 found_errors=0
912 found_dups=0
914 # check for files which are 'shared' with other packages
915 if [ "$check_shared" != "0" ]; then
916 while read _ file; do
917 # ignore shared directories
918 [ -d $root/$file ] && continue
920 if [ $found_dups = 0 ]; then
921 echo "Found shared files with other packages:"
922 found_errors=1 found_dups=1
924 echo "$file:" $(cd $root/var/adm/flists; grep -l " $file\$" *)
925 # sed $xpkg to . to have this pkg's duplicates sorted first
926 done < <(sed "s,^$xpkg:,.," $root/var/adm/flists/* |
927 sort -k2 | uniq -d -f1 | grep '^\. ')
930 found_local=0
932 # check for files in /usr/local
933 if [ "$check_usrlocal" != "0" ]; then
934 while read file; do
935 if [ $found_local = 0 ]; then
936 echo "Found files in /usr/local:"
937 found_errors=1 found_local=1
939 echo $file
940 done < <(sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg |
941 egrep "^/usr/local")
944 found_bad=0
946 # check for registered 'bad files'
947 if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
948 echo "$badfiles" > $builddir/badfiles.txt
949 while read x file; do
950 if [ $found_bad = 0 ]; then
951 echo "Found registered 'bad files' in package:"
952 found_errors=1 found_bad=1
954 desc="No description found!"
955 for ((x=0; x<badfiles_nr; x++)); do
956 if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
957 then desc="${badfiles_desc[x]#*$'\n'}"; fi
958 done
959 echo "$file: $desc"
960 done < <(grep -f $builddir/badfiles.txt $root/var/adm/flists/$xpkg)
963 [ $found_errors != 0 ] && abort "Due to previous errors."
966 } 2>&1 | {
968 trap '' INT
970 echo_status "Writing output to \$root/var/adm/logs/$stagelevel-$xpkg.out"
972 if [ "$SDECFG_VERBOSE" = 1 -o "$verbose" = 1 ]; then
973 tee $root/var/adm/logs/$stagelevel-$xpkg.out |
974 # possible without awk?
975 gawk "/$/ {print; printf \"\x1b[1;35m^$stagelevel-$xpkg\x1b[0m\r\"; fflush();}"
976 else
977 cat > $root/var/adm/logs/$stagelevel-$xpkg.out
981 hook_eval finish
983 if [ $update = 1 ]; then
984 echo_status "Restoring backup of old package data."
986 while read fn; do
987 [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
988 done < $builddir/backup_files.txt
990 tar --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
992 while read fn; do
993 cmp -s $fn $fn.new && rm -f $fn.new
994 done < $builddir/backup_files.txt
997 cd $base
999 umount -r -d -f $builddir/* 2> /dev/null
1000 umount -r -d -f -l $builddir/* 2> /dev/null
1002 if [ "$SDECFG_TMPFS" = 1 ]; then
1003 if [ -e $root/var/adm/logs/$stagelevel-$xpkg.log \
1004 -o "$SDECFG_TMPFS_KEEP_ON_ERROR" != 1 ]; then
1005 rm -rf /tmp/${builddir##*/}/*
1006 umount -n -r -d -f $builddir 2> /dev/null
1007 umount -n -r -d -f -l $builddir 2> /dev/null
1008 rm -rf /tmp/${builddir##*/}
1012 # cleanup_src <error code>
1013 # Cleanup the src.* directory the way configured.
1015 cleanup_src() {
1016 # cleaning the src disabled manually
1017 [ $clear_src = 0 ] && return
1019 case "$SDECFG_KEEP_SRC" in
1020 0) : # always clean, just fall-thru
1022 1) return # always keep, just return
1024 2) [ $1 != 0 ] && return # keep on error, just return
1026 3|4) # on error or if in the list
1027 [ "$SDECFG_KEEP_SRC" = 3 -a $1 != 0 ] && return
1029 local list=" $SDECFG_KEEP_SRC_LIST "
1030 list="${list//:/ }"
1031 list="${list//,/ }"
1033 # if package is in the list, just return
1034 [ "${list/ $pkg /}" != "$list" ] && return
1036 esac
1038 rm -rf $builddir/* $builddir
1041 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
1042 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/BUILD-LOG
1043 cleanup_src 0
1044 mv $root/var/adm/logs/$stagelevel-$xpkg.{out,log}
1045 echo_pkg_finish $stagelevel $repository $xpkg
1046 exit 0
1047 else
1048 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/ERROR-LOG
1049 cleanup_src 1
1050 if [ "$SDECFG_VERBOSE" != 1 -a "$verbose" != 1 ]; then
1051 echo_errorquote "$(grep -v 'make[^ ]*:' \
1052 $root/var/adm/logs/$stagelevel-$xpkg.out |
1053 grep -B8 -- '--- BUILD ERROR ---' |
1054 sed '/--- BUILD ERROR ---/d')"
1056 mv $root/var/adm/logs/$stagelevel-$xpkg.{out,err}
1057 echo_pkg_abort $stagelevel $repository $xpkg
1058 exit 1