3 # --- T2-COPYRIGHT-BEGIN ---
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 ---
12 buildstart
="`date '+%s'`"
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)"
55 # ---- Parse options + config and make Build-Pkg sub-calls
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 ;;
80 # check if arguments are left as package names
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
104 if [ $stagelevel -le 2 ]; then
105 sysroot
="$base/build/$SDECFG_ID" # always fresh sandbox
112 if [ -z "$id" ]; then
114 options
="$options -id $id"
117 # more than one package is passed
118 if [ $# -gt 1 ]; then
120 if ! scripts
/Build-Pkg
$options $x &&
121 [ $stagelevel -le $SDECFG_CONTINUE_ON_ERROR_AFTER ]; then
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
139 if [ ! -c "$1" -a ! -b "$1" ]; then
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
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
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
215 if [ "${TZ#/}" != "$TZ" ]; then
216 cp $TZ TOOLCHAIN
/localtime
218 cp /usr
/share
/zoneinfo
/$TZ TOOLCHAIN
/localtime
221 if [ -f /etc
/localtime
]; then
222 cp /etc
/localtime TOOLCHAIN
/localtime
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
235 if [ ! -d "$builddir/." ]; then
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"
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"
268 archdir
="$builddir/archdir"
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
}
281 if ! type -p $md5sum > /dev
/null
; then
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
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
)
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
] &&
337 echo "[BUILDTIME] $buildtime ($stagelevel)$x"
339 x
="$root/var/adm/packages/$xpkg"
341 echo "[SIZE] `grep "^Package Size
: " $x |
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
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"
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\..*: .*"
382 var_append flistrfilter
'|' ".*fc-cache\..*: .*"
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"
400 # ---- Read various config files
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"
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
424 .
$base/build
/$SDECFG_ID/TOOLCHAIN
/$toolsdir/lib
/parse-config
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.
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 \
453 $base/package
/*/$pkg/$pkg.conf
; do
455 [ $x != $base/package
/*/$pkg/$pkg.conf
] &&
456 echo_status
"Reading package config: ${x#$base/}"
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
475 echo_status
"Reading overwrites from ${x#$base/}."
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/..[/_].*"
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/..[/_].*"
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##*/}"
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)"
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"
529 if [ $update = 1 -a ! -f $xroot/var
/adm
/md5sums
/$xpkg ]; then
530 #echo_warning "Ignoring update mode since package isn't installed already."
534 if [ $update = 1 ]; then
535 echo_status
"Creating backup of old package data."
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
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
563 # define new abort function for errors while building
566 [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
567 rm -vf $root/var
/adm
/logs
/$stagelevel-$xpkg.log
572 trap 'echo "Got SIGINT (Ctrl-C). Aborting build."; exit 1' INT
575 # Makes debugging build problems easier
577 hook_dump
> $builddir/debug.hooks
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 ../.."
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 "\$@"
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
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
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
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."
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
651 mkdir
-p "$builddir/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"
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 ... "
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
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"
690 if [ -e "$file" ]; then
691 echo "Created file outside basedir: $file"
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"
701 done < <(egrep -v " ($flistvalid)/" $builddir/fl_wrapper.wlog |
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"
717 echo "Created file outside allowed top-level dir: $file"
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
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
734 egrep -v "^($flistdel)\$" $builddir/flist.txt
> $builddir/flist.txt.new
735 mv $builddir/flist.txt
{.new
,}
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
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" ]
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
781 if ($1 != "'$xpkg':")
782 f[$2] = $1 " " f[$2];
784 # iterate over the read file list streamed to stdin
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
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)
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\$\""
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
824 echo ": $x" >> $builddir/dependencies.txt
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
834 sed -i "s/^: $x$/opt&/" $builddir/dependencies.txt
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
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
873 cat >> var
/adm
/packages
/$xpkg << EOT
874 Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
878 $(echo "${desc_T:-No description available.}" | sed 's,^, ,')
881 $(echo "${desc_U:-http://t2sde.org/packages/$pkg.html}" | sed 's,^, ,')
884 $(echo "${desc_A:-Unknown}" | sed 's,^, ,')
886 Package Maintainer(s):
887 $(echo "${desc_M:-Unknown}" | sed 's,^, ,')
890 $(echo "${desc_D:-None}" | gawk '{ print " " $3 $2; }')
893 echo "[CONFIG] ${SDECFG_ID#*-}"
894 descfile
=$base/package
/*/$pkg/$pkg.desc
896 if [ "${x#\[}" != "$x" ]; then
897 x
="`echo ${x// */} | tr -d '[]'`"
901 eval lines
=\"\
${desc_$y}\"
902 for line
in $lines; do
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
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 '^\. ')
933 # check for files in /usr/local
934 if [ "$check_usrlocal" != "0" ]; then
936 if [ $found_local = 0 ]; then
937 echo "Found files in /usr/local:"
938 found_errors
=1 found_local
=1
941 done < <(sed "s,^$xpkg: ,/," $root/var
/adm
/flists
/$xpkg |
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
961 done < <(grep -f $builddir/badfiles.txt
$root/var
/adm
/flists
/$xpkg)
964 [ $found_errors != 0 ] && abort
"Due to previous errors."
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();}"
978 cat > $root/var
/adm
/logs
/$stagelevel-$xpkg.out
984 if [ $update = 1 ]; then
985 echo_status
"Restoring backup of old package data."
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
994 cmp -s $fn $fn.new
&& rm -f $fn.new
995 done < $builddir/backup_files.txt
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.
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 "
1034 # if package is in the list, just return
1035 [ "${list/ $pkg /}" != "$list" ] && return
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
1045 mv $root/var
/adm
/logs
/$stagelevel-$xpkg.
{out
,log
}
1046 echo_pkg_finish
$stagelevel $repository $xpkg
1049 cp $root/var
/adm
/logs
/$stagelevel-$xpkg.out
$builddir/ERROR-LOG
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