3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # This copyright note is auto-generated by scripts/Create-CopyPatch.
6 # T2 SDE: scripts/Build-Target
7 # Copyright (C) 2004 - 2021 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 ROCK Linux Project
10 # More information can be found in the files COPYING and README.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; version 2 of the License. A copy of the
15 # GNU General Public License can be found in the file COPYING.
16 # --- T2-COPYRIGHT-NOTE-END ---
18 # Run this command from the T2 SDE base directory as scripts/Build-Target
19 # after running the scripts/Config and the now optional
20 # scripts/Download commands.
22 # It compiles/builds all the packages and stores their binary package
23 # ssuitable for distribution.
25 # This script (and Build-Pkg) is T2 SDE's work-horse. It builds in a
26 # chroot environment (stage 0..1) and goes through a number of build
27 # stages (stage 2..9).
38 while [ $# -gt 0 ]; do
40 -cfg) config
=$2; shift ;;
41 -job) build_only_this_job
=$2; shift ;;
42 -daemon) daemon_mode
=1 ;;
43 -nodaemon) daemon_mode
=0 ;;
44 -nodownload) autodownload
=0 ;;
46 *) echo "Usage: $0 [ -daemon ] [ -nodownload ] [ -cfg config ]" \
47 "[ -job <stage>-<package> ]"; exit 1 ;;
52 if [ "$daemon_mode" = 1 ]; then
53 . config
/$config/config
54 echo "Running $0 in the background (messages go to logfile only)"
55 echo "Logfile: build/$SDECFG_ID/TOOLCHAIN/logs/build_target.log"
56 nohup
$0 $options -nodaemon > /dev
/null
2> /dev
/null
< /dev
/null
&
60 .
scripts
/parse-config
61 .
scripts
/functions.
in
63 build_root
="$base/build/$SDECFG_ID"
64 build_toolchain
="$base/build/$SDECFG_ID/TOOLCHAIN"
65 build_logs
="$build_toolchain/logs"; mkdir
-p "${build_logs}"
66 build_pkgs
="$build_toolchain/pkgs"; mkdir
-p "${build_root}"
68 if [ "$SDECFG_PARANOIA_CHECK" = 1 ]; then
69 scripts
/Check-System ||
exit 1
72 # Package Build loop - executed by build-target
77 if [ "$SDECFG_NOBROKENDEPS" = 1 ]; then
78 nobrokendeps
="-nobrokendeps"
82 if [ -z "$build_only_this_job" ]; then
84 if [ "`ls ${build_root}/var/adm/logs/*.err 2> /dev/null`" ]; then
85 echo_header
"Removing old error logs ..."
86 for y
in 0 1 2 3 4 5 6 7 8 9; do
87 if [ "$SDECFG_RETRY_BROKEN" -eq 1 -o $y -le $SDECFG_CONTINUE_ON_ERROR_AFTER ]; then
88 for x
in ${build_root}/var
/adm
/logs
/$y-*.err
; do
90 echo_status
"Removing ${x#$build_root/} ..."
97 if [ "`ls ${build_root}/var/adm/logs/*.out 2> /dev/null`" ]; then
98 echo_header
"Removing old output logs ..."
99 for x
in ${build_root}/var
/adm
/logs
/*.out
; do
100 echo_status
"Removing ${x#$build_root/} ..."
106 next
="`scripts/Create-PkgQueue \
107 -cfg "$config" -single $nobrokendeps`"
110 pkgloop_package
$next
114 rm -f "${build_root}"/var
/adm
/logs
/${build_only_this_job}.log
"
115 rm -f "${build_root}"/var/adm/logs/${build_only_this_job}.err"
116 next
="$( awk 'BEGIN { FS=" "; }
117 $5 == "'${build_only_this_job#*-}'" &&
118 $2 ~ /'${build_only_this_job%%-*}'/ \
119 { $1="'${build_only_this_job%%-*}' 0";
120 print; exit; }' < config/$config/packages )"
121 if [ ! "$next" ]; then
122 echo_error
"No job matching job spec: $build_only_this_job"
126 pkgloop_package
$next
130 # wait for background compression jobs to finish
131 for j
in $
(jobs -p); do wait $j; done
133 local pkglst
=`mktemp` errors
=0; rm -f src
/invalid-files.lst
134 echo_header
"Searching for old lingering files ..."
135 sed '/^[^X]/d; s,.*=,,' config
/$config/packages | cut
-d' ' -f5 |
136 if [ $SDECFG_PKGFILE_VER = 1 ]; then
138 v
=$
( grep '^Package Name and Version:' \
139 build
/$SDECFG_ID/var
/adm
/packages
/$p \
140 2>/dev
/null | cut
-f6 -d' ' )
146 for file in $
( ls build
/$SDECFG_ID/TOOLCHAIN
/pkgs
/ 2> /dev
/null
); do
148 case $SDECFG_PKGFILE_TYPE in
149 tar.
*) x
=${x%.$SDECFG_PKGFILE_TYPE} ;;
152 if ! grep -qx "$x" $pkglst && ! test "$x" = packages.db
; then
153 file="build/$SDECFG_ID/TOOLCHAIN/pkgs/$file"
154 echo_error
"$file should not be present" \
155 "(now in src/invalid-files.lst)!"
156 mkdir
-p src
; echo "$file" >> src
/invalid-files.lst
160 for dir
in build
/$SDECFG_ID/var
/adm
/{cache
,dependencies
,descs
,flists
,md5sums
,packages
}; do
161 for file in $
( ls $dir 2> /dev
/null
); do
162 if [ $SDECFG_PKGFILE_VER = 1 ]; then
167 if ! grep -q "$x" $pkglst; then
168 echo_error
"$dir/$file should not be present (now in src/invalid-files.lst)!"
169 mkdir
-p src
; echo "$dir/$file" >> src
/invalid-files.lst
174 for file in $
( ls build
/$SDECFG_ID/var
/adm
/logs
/ ); do
175 x
="`echo $file | sed -e 's/^.-//' -e 's/\.log//' -e 's/\.err//' -e s'/\.out//'`"
176 if [ $SDECFG_PKGFILE_VER = 1 ]; then
182 if ! grep -q "$x" $pkglst; then
183 file="build/$SDECFG_ID/var/adm/logs/$file"
184 echo_error
"$file should not be present (now in src/invalid-files.lst)!"
185 mkdir
-p src
; echo "$file" >> src
/invalid-files.lst
189 [ $errors = 0 ] && echo_status
"None found."
193 # Process one line of output generated by Create-PkgQueue
196 for x
in stagelevel pkg_depnr pkg_stages pkg_pri pkg_tree \
197 pkg_name pkg_ver pkg_prefix pkg_extra
198 do eval "$x=\$1"; shift; done
200 [ "$build_only_this_job" -a \
201 "$stagelevel-$pkg_name" != "$build_only_this_job" ] && return
203 [ $
(expr "$pkg_stages" : ".*$stagelevel.*") -eq 0 ] && return
204 pkg_laststage
=$
(echo "$pkg_stages" |
sed "s,-,,g; s,.*\(.\),\1,")
206 cmd_root
="-root auto"
207 [ $stagelevel -gt 2 ] && cmd_root
="$cmd_root -chroot"
209 if [ "$pkg_prefix" != "/" ]; then
210 cmd_prefix
="-prefix $pkg_prefix"
211 else cmd_prefix
=""; fi
213 if [ "$autodownload" == 1 ]; then
214 scripts
/Download
-cfg $config $downloadopt $pkg_name
217 cmd_buildpkg
="scripts/Build-Pkg -$stagelevel -cfg $config $verbose"
218 cmd_buildpkg
="$cmd_buildpkg $cmd_root $cmd_prefix $pkg_name"
220 # Execute action handler
221 if ! pkgloop_action
&&
222 [ $stagelevel -le $SDECFG_CONTINUE_ON_ERROR_AFTER ]; then
226 if [ ! -f ${build_root}/var
/adm
/logs
/$stagelevel-$pkg_name.log
-a \
227 ! -f ${build_root}/var
/adm
/logs
/$stagelevel-$pkg_name.err
]
229 echo_header
"Package build ended abnormally!"
230 echo_error
"Usually a package build creates either a *.log"
231 echo_error
"or a *.err file. Neither the 1st nor the 2nd is"
232 echo_error
"there. So I'm going to create a *.err file now"
233 echo_error
"and abort the build process."
234 touch ${build_root}/var
/adm
/logs
/$stagelevel-$pkg_name.err
238 if [ $stagelevel -gt 0 -a $pkg_laststage -eq $stagelevel -a \
239 "$SDECFG_PKGFILE_TYPE" != none
]
241 if [ -f ${build_root}/var
/adm
/logs
/$stagelevel-$pkg_name.err
]
242 then echo_error
"Creation of binary package isn't possible, \
243 because the package was not"
244 echo_error
"built successfully in (at least) the current \
247 mkdir
-p "${build_pkgs}"
250 if [ "$SDECFG_PKGFILE_VER" = 1 ]; then
251 v
="$( grep '^Package Name and Version:' \
252 ${build_root}/var/adm/packages/$pkg_name | cut -f6 -d' ' )"
256 [[ $SDECFG_PKGFILE_TYPE = tar.
* ]] &&
257 file=$file.
$SDECFG_PKGFILE_TYPE
258 compressor
=${SDECFG_PKGFILE_TYPE#tar.}
260 gz
) compressor
=gzip ;;
261 bz2
) compressor
=bzip2 ;;
262 lzo
) comrpessor
=lzop
;;
263 zst
) compressor
="zstd --ultra -20 -T0" ;;
264 # lzma, xz et al. are named after the extension
265 gem
) compressor
=bzip2; file=$file.
tar.bz2
;;
268 echo_status
"Creating binary package build/.../pkgs/$file"
270 # sort var/adm before the rest - so they can be extracted, quickly
272 (grep ' var/adm' var
/adm
/flists
/$pkg_name
273 grep -v ' var/adm' var
/adm
/flists
/$pkg_name) | cut
-f2- -d' ' |
274 tar -cf- --no-recursion --files-from=- |
$compressor
275 ) > ${build_pkgs}/$file.tmp
276 mv ${build_pkgs}/$file{.tmp
,}
278 if [ "$SDECFG_PKGFILE_TYPE" = gem
]; then
279 mine
-C "$build_root/var/adm" $build_pkgs/$file $pkg_name \
280 $build_pkgs/${file%.tar.bz2}.gem.tmp
281 mv $build_pkgs/${file%.tar.bz2}.gem
{.tmp
,}
283 echo_status
"Removing temporary tar.bz2."
284 rm -f $build_pkgs/$file
291 # Action executed by pkgloop(). This function may be redefined
292 # before calling pkgloop().
298 # Try to umount any directories mounted by Build-Pkg -chroot
299 # if we are the last process using them.
303 if ! ( cd ${build_logs}; fuser
*.log
> /dev
/null
2>&1 ); then
304 echo_status
"Unmounting loop mounts ..."
305 umount
-d -f $build_toolchain/{loop
,config
,download
} 2> /dev
/null
306 umount
-d -f -l $build_toolchain/{loop
,config
,download
} 2> /dev
/null
307 umount
-d -f $build_root/proc
2> /dev
/null
308 umount
-d -f -l $build_root/proc
2> /dev
/null
312 # must trap outside the group command
313 trap 'umount_chroot' EXIT
316 ln -sf build_target_$$.log
${build_logs}/build_target.log
317 scripts
/Build-Tools
-1 -cfg $config
319 for x
in $
( get_expanded .
/target
/%/build.sh
$targetchain ); do
326 [ $_built = 1 ] || echo_warning
"No target/*/build.sh controlling the build!"
327 } 2>&1 201>> "${build_logs}/build_target_$$.log" | \
328 tee -a "${build_logs}/build_target_$$.log"