* updated gtk (4.14.4 -> 4.15.2)
[t2sde.git] / scripts / Build-Pkg
blob7c9af2320a1b888ee0faafcc5b3a6dea5bfbb890
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_MAX:-1}"
436 var_append makeinstopt " " "-j${SDECFG_PARALLEL_MAX:-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_MAX" -le 1 ]; then
505 hasflag NOPARALLEL && [ "$SDECFG_PARALLEL_MAX" -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_MAX threads"
512 mkdir -p $builddir; chmod 755 $builddir
514 if [ "$SDECFG_SRC_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" -ge "${SDECFG_SRC_TMPFS_MAX_SIZE:-0}" ] && SDECFG_SRC_TMPFS=0
521 if [ $clear_src = 1 ]; then
522 if [ "$SDECFG_SRC_TMPFS" = 1 ]; then
523 mount -n -o remount,exec,$SDECFG_SRC_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 hasflag KERNEL && _CC=$KCC || _CC=$CC
632 echo "Command wrapper test: '${_CC} --version'"
633 type ${_CC}; CMD_WRAPPER_DEBUG=1 ${_CC} --version
634 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
685 if [ "$SDECFG_FLIST" = "flwrapper" -o \
686 "$SDECFG_FLIST" = "strace" ]; then
687 if [ "$stagelevel" -le 2 ]
688 then
689 xbase="$(cd $xroot/ 2> /dev/null; pwd -P)"
690 flistvalid="$xbase|$flistvalid"
691 found_invalid=0
692 while read file; do
693 if [ -e "$file" ]; then
694 echo "Created file outside basedir: $file"
695 abort_soon=1
696 else # non fatal for now (configure junk)
697 echo "Warning: Created vanished file outside basedir: $file"
699 if [ "$found_invalid" = 0 ]; then
700 echo "base #1: $base"
701 echo "base #2: $xbase"
702 found_invalid=1
704 done < <(egrep -v " ($flistvalid)/" $builddir/fl_wrapper.wlog |
705 cut -f2- | sort -u)
707 [ "$abort_soon" = 1 ] && abort
710 fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog > \
711 $builddir/flist.txt.tmp
713 # check for file creation beside the allowed top-level
714 # directories - allow root since qt, wxwidgets, ... create some
715 # profile there ... - on stage 0 we have an ugly symlink hack
716 # so we get doc, $arch_machine, ... in the top level dir :-(
717 if [ $stagelevel -gt 0 ]; then
718 fr="$flistroot root TOOLCHAIN proc/[0-9]*/fd"
720 while read file; do
721 echo "Created file outside allowed top-level dir: $file"
722 abort_soon=1
723 done < <(egrep -v "^(${fr// /|})(/|$)" \
724 $builddir/flist.txt.tmp)
725 [ "$abort_soon" = 1 ] && abort
728 egrep "^(${flistroot// /|})(/|$)" $builddir/flist.txt.tmp >> \
729 $builddir/flist.txt
731 elif [ "$SDECFG_FLIST" = "find" ]; then
732 find $flistroot \
733 \( -not -type d -or -type d -empty \) \
734 -and \( -newer $builddir/temp.time_stamp -or \
735 -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> \
736 $builddir/flist.txt
739 # evaluate flistdel
740 egrep -v "^($flistdel)\$" $builddir/flist.txt > $builddir/flist.txt.new
741 mv $builddir/flist.txt{.new,}
743 hook_eval postflist
745 # save the old flist for later orphaned file check
746 [ -e var/adm/flists/$xpkg ] &&
747 cp -f var/adm/flists/$xpkg $builddir/flist.txt.old
749 fl_wrparse -D -p "$xpkg" -r "$xroot/" < $builddir/flist.txt |
750 sort -u > $builddir/flist.txt.new
752 # analyze which files have not been reinstalled and thus are (normally)
753 # no longer needed (orphaned)
754 if [ -e $builddir/flist.txt.old ]; then
755 echo "Searching for orphaned files ..."
756 diff --normal $builddir/flist.txt.{old,new} |
757 grep '^<' | cut -d ' ' -f 2- > $builddir/olist.txt.new
758 [ -e var/adm/olists/$xpkg ] &&
759 cp -f var/adm/olists/$xpkg $builddir/olist.txt.old ||
760 touch $builddir/olist.txt.old
761 cat $builddir/olist.txt.{old,new} | sort -u > \
762 var/adm/olists/$xpkg
765 # TODO: until all olist regressions are fixed merge the two lists ...
766 touch $builddir/flist.txt.old
767 if [ "$noorphaned" = 1 ]; then
768 cat $builddir/flist.txt.new > var/adm/flists/$xpkg
769 else
770 cat $builddir/flist.txt.{old,new} | egrep -v "^$xpkg: ($flistdel)\$" |
771 sort -u > var/adm/flists/$xpkg
773 echo Found `wc -l < var/adm/flists/$xpkg` "files for this package."
774 echo Found `wc -l < var/adm/olists/$xpkg` "orphaned files for this package."
776 if [ "$SDECFG_FLIST" = "flwrapper" -o \
777 "$SDECFG_FLIST" = "strace" ] && [ $stagelevel -gt 0 ]; then
778 echo "Calculating package dependencies ..."
780 ! egrep -v "^($flistrfilter)\$" $builddir/fl_wrapper.[rw]log |
781 sort -u | fl_wrparse -D -s -r "$xroot/" -p '' | sort -u |
782 grep -v ' var/adm/' | gawk '
783 # read the var/adm/... file content in
784 ARGIND < ARGC-1 {
785 if ($1 != "'$xpkg':")
786 f[$2] = $1 " " f[$2];
788 # iterate over the read file list streamed to stdin
789 ARGIND == ARGC-1 {
790 file = $2;
791 if (f[file]) {
792 print f[file] " " file;
795 ' var/adm/flists/* - >> $builddir/dependencies.debug
797 awk 'BEGIN { FS=": "; } { print ": " $1; }' \
798 < $builddir/dependencies.debug >> $builddir/dependencies.txt
800 sort -u $builddir/dependencies.debug > var/adm/dep-debug/$xpkg
802 # remove dependencies as requested by the package
803 # TODO: goups are not used yet (and it is not easy here)
804 del_pattern=
805 for x in t2-src $SDECFG_LIBC $SDECFG_DEFAULT_CC ${compressor%% *} \
806 `echo "$desc_E" | sed -n 's/^del //p' `; do
807 del_pattern="$del_pattern -e \".*: $x\$\""
808 done
809 if [ -n "$del_pattern" ]; then
810 echo "Deleting dependencies, pattern: $del_pattern ..."
811 eval egrep -v $del_pattern \
812 $builddir/dependencies.txt > $builddir/dependencies.txt.new
813 mv $builddir/dependencies.txt{.new,}
816 # merge the dependencies defined by the package
817 for x in `echo "$desc_E" | egrep '^(add|opt) ' | sed 's/^[^ ]* //' `; do
818 echo "Adding dependency: $x"
819 echo ": $x" >> $builddir/dependencies.txt
820 done
822 sort -u $builddir/dependencies.txt > $builddir/dependencies.txt.new
823 mv $builddir/dependencies.txt{.new,}
825 for x in `echo "$desc_E" | sed -n 's/^opt //p' `; do
826 echo "Marking optional dependency: $x"
827 sed -i "s/^: $x$/opt&/" $builddir/dependencies.txt
828 done
830 cat $builddir/dependencies.txt > var/adm/dependencies/$xpkg
833 echo "Creating md5sum files ..."
834 getfiles < var/adm/flists/$xpkg > $builddir/files.lst
835 grep -v '^var/adm/' $builddir/files.lst | sed -e 's,^.*,"\0",' |
836 xargs -r $md5sum > var/adm/md5sums/$xpkg
838 echo "Creating package description ..."
840 buildend="`date '+%s'`"
841 buildlist="$(grep "^Build \[.\] at " var/adm/packages/$xpkg || true
842 echo "Build [$stagelevel] at `date --date=@$buildstart '+%Y-%m-%d from %T'`" \
843 "to `date --date=@$buildend '+%T'`" \
844 " `date --date=@$((buildend - buildstart)) --utc '+%H:%M:%S'`")"
846 srccksum=$(pkgchksum $base/package/*/$pkg)
847 cat > var/adm/packages/$xpkg << EOT
848 Package Name and Version: $xpkg $ver $extraver
849 Package Size: `getdu $root/ < var/adm/flists/$xpkg`, `
850 wc -l < var/adm/flists/$xpkg | tr -d ' '` files
851 T2 Package Source Checksum: $srccksum
852 T2 Version and Architecture: $sdever $arch
853 $buildlist
854 Prefix: $prefix
857 # Location libdir: /opt/*/lib
858 for x in $foodirlist; do
859 if [ "`eval echo \\$$x`" != "`pkggetdir $x`" ]; then
860 echo "Location $x: `eval echo \\$$x`" \
861 >> var/adm/packages/$xpkg
863 done
865 cat >> var/adm/packages/$xpkg << EOT
866 Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
868 ${desc_I:-$xpkg}
870 $(echo "${desc_T:-No description available.}" | sed 's,^, ,')
872 URL(s):
873 $(echo "${desc_U:-http://t2sde.org/packages/$pkg.html}" | sed 's,^, ,')
875 Original Author(s):
876 $(echo "${desc_A:-Unknown}" | sed 's,^, ,')
878 Package Maintainer(s):
879 $(echo "${desc_M:-Unknown}" | sed 's,^, ,')
881 Download URL(s):
882 $(echo "${desc_D:-None}" | gawk '{ print " " $3 $2; }')
885 echo "[CONFIG] ${SDECFG_ID#*-}"
886 descfile=$base/package/*/$pkg/$pkg.desc
887 while read x; do
888 if [ "${x#\[}" != "$x" ]; then
889 x="`echo ${x// */} | tr -d '[]'`"
890 y="${x/-/_}"
891 IFS='
893 eval lines=\"\${desc_$y}\"
894 for line in $lines; do
895 echo "[$x] $line"
896 done
898 done < $base/misc/share/PKG-DESC-FORMAT
899 ) > var/adm/descs/$xpkg
901 echo "Making post-install adaptions."
903 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
904 found_errors=0
905 found_dups=0
907 # check for files which are 'shared' with other packages
908 if [ "$check_shared" != "0" ]; then
909 while read _ file; do
910 # ignore shared directories
911 [ -d $root/$file ] && continue
913 if [ $found_dups = 0 ]; then
914 echo "Found shared files with other packages:"
915 found_errors=1 found_dups=1
917 echo "$file:" $(cd $root/var/adm/flists; grep -l " $file\$" *)
918 # sed $xpkg to . to have this pkg's duplicates sorted first
919 done < <(sed "s,^$xpkg:,.," $root/var/adm/flists/* |
920 sort -k2 | uniq -d -f1 | grep '^\. ')
923 found_local=0
925 # check for files in /usr/local
926 if [ "$check_usrlocal" != "0" ]; then
927 while read file; do
928 if [ $found_local = 0 ]; then
929 echo "Found files in /usr/local:"
930 found_errors=1 found_local=1
932 echo $file
933 done < <(sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg |
934 egrep "^/usr/local")
937 found_bad=0
939 # check for registered 'bad files'
940 if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
941 echo "$badfiles" > $builddir/badfiles.txt
942 while read x file; do
943 if [ $found_bad = 0 ]; then
944 echo "Found registered 'bad files' in package:"
945 found_errors=1 found_bad=1
947 desc="No description found!"
948 for ((x=0; x<badfiles_nr; x++)); do
949 if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
950 then desc="${badfiles_desc[x]#*$'\n'}"; fi
951 done
952 echo "$file: $desc"
953 done < <(grep -f $builddir/badfiles.txt $root/var/adm/flists/$xpkg)
956 [ $found_errors != 0 ] && abort "Due to previous errors."
959 } 2>&1 | {
961 trap '' INT
963 echo_status "Writing output to \$root/var/adm/logs/$stagelevel-$xpkg.out"
965 if [ "$SDECFG_VERBOSE" = 1 -o "$verbose" = 1 ]; then
966 tee $root/var/adm/logs/$stagelevel-$xpkg.out |
967 # possible without awk?
968 gawk "/$/ {print; printf \"\x1b[1;35m^$stagelevel-$xpkg\x1b[0m\r\"; fflush();}"
969 else
970 cat > $root/var/adm/logs/$stagelevel-$xpkg.out
974 hook_eval finish
976 if [ $update = 1 ]; then
977 echo_status "Restoring backup of old package data."
979 while read fn; do
980 [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
981 done < $builddir/backup_files.txt
983 tar --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
985 while read fn; do
986 cmp -s $fn $fn.new && rm -f $fn.new
987 done < $builddir/backup_files.txt
990 cd $base
992 umount -r -d -f $builddir/* 2> /dev/null
993 umount -r -d -f -l $builddir/* 2> /dev/null
995 if [ "$SDECFG_SRC_TMPFS" = 1 ]; then
996 if [ -e $root/var/adm/logs/$stagelevel-$xpkg.log \
997 -o "$SDECFG_SRC_TMPFS_KEEP_ON_ERROR" != 1 ]; then
998 rm -rf /tmp/${builddir##*/}/*
999 umount -n -r -d -f $builddir 2> /dev/null
1000 umount -n -r -d -f -l $builddir 2> /dev/null
1001 rm -rf /tmp/${builddir##*/}
1005 # cleanup_src <error code>
1006 # Cleanup the src.* directory the way configured.
1008 cleanup_src() {
1009 # cleaning the src disabled manually
1010 [ $clear_src = 0 ] && return
1012 case "$SDECFG_KEEP_SRC" in
1013 0) : # always clean, just fall-thru
1015 1) return # always keep, just return
1017 2) [ $1 != 0 ] && return # keep on error, just return
1019 3|4) # on error or if in the list
1020 [ "$SDECFG_KEEP_SRC" = 3 -a $1 != 0 ] && return
1022 local list=" $SDECFG_KEEP_SRC_LIST "
1023 list="${list//:/ }"
1024 list="${list//,/ }"
1026 # if package is in the list, just return
1027 [ "${list/ $pkg /}" != "$list" ] && return
1029 esac
1031 rm -rf $builddir/* $builddir
1034 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
1035 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/BUILD-LOG
1036 cleanup_src 0
1037 mv $root/var/adm/logs/$stagelevel-$xpkg.{out,log}
1038 echo_pkg_finish $stagelevel $repository $xpkg
1039 exit 0
1040 else
1041 cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/ERROR-LOG
1042 cleanup_src 1
1043 if [ "$SDECFG_VERBOSE" != 1 -a "$verbose" != 1 ]; then
1044 echo_errorquote "$(grep -v 'make[^ ]*:' \
1045 $root/var/adm/logs/$stagelevel-$xpkg.out |
1046 grep -B8 -- '--- BUILD ERROR ---' |
1047 sed '/--- BUILD ERROR ---/d')"
1049 mv $root/var/adm/logs/$stagelevel-$xpkg.{out,err}
1050 echo_pkg_abort $stagelevel $repository $xpkg
1051 exit 1