2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: scripts/Build-Target
6 # Copyright (C) 2006 - 2008 The OpenSDE Project
7 # Copyright (C) 2004 - 2006 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 Clifford Wolf
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 # --- SDE-COPYRIGHT-NOTE-END ---
18 # Run this command from the ROCK directory as ./scripts/Build-Target
19 # after running the ./scripts/Config and ./scripts/Download commands.
21 # It compiles/builds all the packages and stores them tar balls suitable
24 # This script is the ROCK work-horse. It builds in a chroot environment
25 # (stage 2..9) and goes through a number of build stages:
35 while [ $# -gt 0 ] ; do
37 -cfg) config
=$2 ; shift ;;
38 -job) build_only_this_job
=$2 ; shift ;;
39 -daemon) daemon_mode
=1 ;;
40 -nodaemon) daemon_mode
=0 ;;
41 -nodownload) autodownload
=0 ;;
42 *) echo "Usage: $0 [ -daemon ] [ -nodownload ] [ -cfg config ]" \
43 "[ -job <stage>-<package> ]" ; exit 1 ;;
48 .
/lib
/sde-config
/migrate.sh
"$config" ||
exit 1
50 if [ "$daemon_mode" = 1 ] ; then
51 . config
/$config/config
52 echo "Running $0 in the background (messages go to logfile only).."
53 echo "Logfile: build/$SDECFG_ID/TOOLCHAIN/logs/build_target.log"
54 nohup
$0 $options -nodaemon > /dev
/null
2> /dev
/null
< /dev
/null
&
61 build_root
="$base/build/$SDECFG_ID"
62 build_toolchain
="$base/build/$SDECFG_ID/TOOLCHAIN"
63 build_logs
="$build_toolchain/logs" ; mkdir
-p "${build_logs}"
64 build_pkgs
="$build_toolchain/pkgs" ; mkdir
-p "${build_root}"
66 if [ "$SDECFG_PARANOIA_CHECK" = 1 ] ; then
67 .
/bin
/sde-check-system ||
exit 1
70 # Package Build loop - executed by build-target
75 if [ "$SDECFG_NOBROKENDEPS" = 1 ]; then
76 nobrokendeps
="-nobrokendeps"
80 if [ -z "$build_only_this_job" ]; then
82 if [ "`ls ${build_root}/var/adm/logs/*.err 2> /dev/null`" ] ; then
83 echo_header
"Removing old error logs ..."
84 for y
in 0 1 2 3 4 5 6 7 8 9; do
85 if [ "$SDECFG_RETRY_BROKEN" -eq 1 -o $y -le "$SDECFG_CONTINUE_ON_ERROR_AFTER" ]; then
86 for x
in ${build_root}/var
/adm
/logs
/$y-*.err
; do
88 echo_status
"Removing ${x#$build_root/} ..."
95 if [ "`ls ${build_root}/var/adm/logs/*.out 2> /dev/null`" ] ; then
96 echo_header
"Removing old output logs ..."
97 for x
in ${build_root}/var
/adm
/logs
/*.out
; do
98 echo_status
"Removing ${x#$build_root/} ..."
104 next
="`./scripts/Create-PkgQueue \
105 -cfg "$config" -single $nobrokendeps`"
108 pkgloop_package
$next
112 rm -f "${build_root}"/var
/adm
/logs
/${build_only_this_job}.log
"
113 rm -f "${build_root}"/var/adm/logs/${build_only_this_job}.err"
114 next
="$( awk 'BEGIN { FS=" "; }
115 $5 == "'${build_only_this_job#*-}'" && \
116 $2 ~ /'${build_only_this_job%%-*}'/ \
117 { $1="'${build_only_this_job%%-*}' 0";
118 print; exit; }' < config/$config/packages )"
119 [ "$next" ] && pkgloop_package
$next
123 local pkglst
=`mktemp` errors
=0; rm -f tmp
/invalid-files.lst
124 echo_header
"Searching for old lingering files ..."
125 sed '/^[^X]/d ; s,.*=,,' config
/$config/packages | cut
-d' ' -f5 |
126 if [ $SDECFG_PKGFILE_VER = 1 ] ; then
128 v
=$
( grep '^Package Name and Version:' \
129 build
/$SDECFG_ID/var
/adm
/packages
/$p \
130 2>/dev
/null | cut
-f6 -d' ' )
136 for file in $
( ls build
/$SDECFG_ID/TOOLCHAIN
/pkgs
/ 2> /dev
/null
) ; do
138 case $SDECFG_PKGFILE_TYPE in
139 tar.
*) x
=${x%.$SDECFG_PKGFILE_TYPE} ;;
142 if ! grep -qx "$x" $pkglst && ! test "$x" = packages.db
; then
143 file="build/$SDECFG_ID/TOOLCHAIN/pkgs/$file"
144 echo_error
"$file should not be present" \
145 "(now in tmp/invalid-files.lst)!"
146 mkdir
-p tmp
; echo "$file" >> tmp
/invalid-files.lst
150 for dir
in build
/$SDECFG_ID/var
/adm
/{cache
,cksums
,dependencies
,descs
,flists
,md5sums
,packages
} ; do
151 for file in $
( ls $dir 2> /dev
/null
) ; do
152 if [ $SDECFG_PKGFILE_VER = 1 ] ; then
157 if ! grep -q "$x" $pkglst ; then
158 echo_error
"$dir/$file should not be present (now in tmp/invalid-files.lst)!"
159 mkdir
-p tmp
; echo "$dir/$file" >> tmp
/invalid-files.lst
164 for file in $
( ls build
/$SDECFG_ID/var
/adm
/logs
/ ) ; do
165 x
="`echo $file | sed -e 's/^.-//' -e 's/\.log//' -e 's/\.err//' -e s'/\.out//'`"
166 if [ $SDECFG_PKGFILE_VER = 1 ] ; then
172 if ! grep -q "$x" $pkglst ; then
173 file="build/$SDECFG_ID/var/adm/logs/$file"
174 echo_error
"$file should not be present (now in tmp/invalid-files.lst)!"
175 mkdir
-p tmp
; echo "$file" >> tmp
/invalid-files.lst
179 [ $errors = 0 ] && echo_status
"None found."
183 # Process one line of output generated by Create-PkgQueue
186 for x
in stagelevel pkg_depnr pkg_stages pkg_pri pkg_tree \
187 pkg_name pkg_ver pkg_prefix pkg_extra
188 do eval "$x=\$1" ; shift ; done
190 [ "$build_only_this_job" -a \
191 "$stagelevel-$pkg_name" != "$build_only_this_job" ] && return
193 [ $
(expr "$pkg_stages" : ".*$stagelevel.*") -eq 0 ] && return
194 pkg_laststage
=$
(echo "$pkg_stages" |
sed "s,-,,g; s,.*\(.\),\1,")
196 cmd_root
="-root auto"
197 [ $stagelevel -gt 1 ] && cmd_root
="$cmd_root -chroot"
199 if [ "$pkg_prefix" != "/" ] ; then
200 cmd_prefix
="-prefix $pkg_prefix"
201 else cmd_prefix
= ; fi
203 if [ "$autodownload" = 1 ]; then
204 .
/bin
/sde-download
-cfg $config $downloadopt $pkg_name
207 cmd_buildpkg
="./scripts/Build-Pkg -$stagelevel -cfg $config"
208 cmd_buildpkg
="$cmd_buildpkg $cmd_root $cmd_prefix $pkg_name"
210 # Execute action handler
211 if ! pkgloop_action
&& \
212 [ $stagelevel -le "$SDECFG_CONTINUE_ON_ERROR_AFTER" ] ; then
216 if [ ! -f ${build_root}/var
/adm
/logs
/$stagelevel-$pkg_name.log
-a \
217 ! -f ${build_root}/var
/adm
/logs
/$stagelevel-$pkg_name.err
]
219 echo_header
"Package build ended abnormally!"
220 echo_error
"Usually a package build creates either a *.log"
221 echo_error
"or a *.err file. Neither the 1st nor the 2nd is"
222 echo_error
"there. So I'm going to create a *.err file now"
223 echo_error
"and abort the build process."
224 touch ${build_root}/var
/adm
/logs
/$stagelevel-$pkg_name.err
228 if [ $stagelevel -gt 0 -a $pkg_laststage -eq $stagelevel -a "$SDECFG_PKGFILE_TYPE" != none
]; then
229 if [ -f ${build_root}/var
/adm
/logs
/$stagelevel-$pkg_name.err
]; then
230 echo_error
"Creation of binary package isn't possible, because the package was not"
231 echo_error
"built successfully in (at least) the current stage."
233 .
/lib
/sde-binary
/package.sh
--type "$SDECFG_PKGFILE_TYPE" \
234 $
( if [ "${SDECFG_PKGFILE_VER}" = 1 ]; then echo '--versioned'; fi ) \
235 --root "${build_root}" --output "${build_pkgs}" ${pkg_name}
240 # Action executed by pkgloop(). This function may be redefined
241 # before calling pkgloop().
247 # Try to umount any directories mounted by Build-Pkg -chroot
248 # if we are the last process using them.
252 if ! ( cd ${build_logs}; fuser *.log > /dev/null 2>&1 ); then
253 echo_status "Unmounting loop mounts ...
"
254 umount -d -f $build_toolchain/{loop,config,download} 2> /dev/null
255 umount -d -f -l $build_toolchain/{loop,config,download} 2> /dev/null
256 umount -d -f $build_root/proc 2> /dev/null
257 umount -d -f -l $build_root/proc 2> /dev/null
261 # must trap outside the group command
262 trap 'umount_chroot' EXIT
265 ln -sf build_target_$$.log ${build_logs}/build_target.log
266 ./bin/sde-build-tools -1 -c $config
268 for x in $( get_expanded ./target/%/build.sh $targetchain ); do
275 [ $_built = 1 ] || echo_warning "No target
/*/build.sh controlling the build
!"
276 } 2>&1 201>> "${build_logs}/build_target_$$.log
" | \
277 tee -a "${build_logs}/build_target_$$.log
"