* updated x264 (4121277 -> 4613ac3c)
[t2sde.git] / scripts / Emerge-Pkg
blob61f41d889f78384d6a6c9b109aa7c36006f3a850
1 #!/usr/bin/env bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Emerge-Pkg
5 # Copyright (C) 2004 - 2024 The T2 SDE Project
6 # Copyright (C) 2004 - 2006 Rene Rebe <rene@exactcode.de>
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 noautolist=' 00-dirtree binutils gcc glibc glibc32 uclibc musl linux linux-header clang llvm rustc cargo dietlibc busybox toybox '
19 options=
20 dloptions=
21 config='default'
22 deps='indirect2'
23 debug=0
24 downloadonly=0
25 verbose=1
26 ignore_chksum=1
27 backup=1
28 dryrun=0
29 force=0
30 rebuild=1
31 repositories=
32 system=0
33 depth=0
34 missing='only'
35 optional='ask'
37 deptree=
38 esttime=0
41 # ---- Functions
44 . scripts/functions.in
46 help_msg() {
47 spacer=" "
48 echo
49 echo "Usage: Emerge-Pkg [ -cfg <config> ] [ -dry-run ] [ -force ] [ -nobackup ]"
50 echo "$spacer [ -consider-chksum ] [ -norebuild ] [ -deps=none|fast|indirect ]"
51 echo "$spacer [ -missing=yes|no|only ] [ -optional-deps=yes|no|ask ] [ -download ]"
52 echo "$spacer [ -repository repository-name ] [ -system ] [ pkg-name(s) ]"
53 echo
54 echo "pkg-name(s) are only optional if a repository is specified."
55 echo
59 # ---- Parse options + config
62 if [ $# = 0 ]; then
63 help_msg
64 exit 1
67 while [ "$1" ]; do
68 case "$1" in
69 -cfg) options="$options $1 $2" config="$2"; shift ;;
70 -deps=*) deps=${1/-deps=/} ;;
71 -missing=*) missing=${1/-missing=/} ;;
72 -optional-deps=*) optional=${1/-optional-deps=/} ;;
73 -dry-run) dryrun=1 ;;
74 -f|-force) force=1 ;;
75 -debug) debug=1 ;;
76 -nobackup) backup=0 ;;
77 -consider-chksum) ignore_chksum=0 ;;
78 -norebuild) rebuild=0 ;;
79 -download|-download-only) downloadonly=1 ;;
80 -repository) repositories="$repositories $2"; shift ;;
81 -prefix) options="$options -prefix $2"; shift ;;
82 -v) options="$options -v" ;;
83 -system) system=1 deps=none depth=1 ;;
84 -*) help_msg; exit 1 ;;
85 *) break ;;
86 esac
87 shift
88 done
90 if [ ! -f config/$config/config -a $config = "default" ]; then
91 scripts/Config -oldconfig
94 . scripts/parse-config
96 add_if_req() {
97 local pkg=$1 msg="$2" typ=$3
98 local buildtime=$(pkgbuildtime $pkg)
100 [ "$verbose" = 1 ] && echo -n "$msg"
102 # some more check for packages not manually specified
103 if [ $depth != 0 ]; then
104 # no auto update list
105 if [ "$noautolist" != "${noautolist/ $pkg /}" ]; then
106 [ $verbose = 1 ] && echo " Vital, skipped by default."
107 return
110 # optional dep, not yet installed?
111 if [ "$typ" = '[OPT]' ]; then
112 if [ "$optional" = ask ]; then
113 echo -n " Add optional dep? (y/n$(fmt_time $buildtime)) "
114 read in
115 else
116 in="$optional"
117 [[ "$in" = y* ]] &&
118 echo " Optional added. $(fmt_time $buildtime)" ||
119 echo " Optional, skipped."
122 if [[ "$in" = y* ]]; then
123 var_append deplist " " "$pkg"
124 esttime=$((esttime + buildtime))
125 [ "$deps" = indirect ] && dep4pkg "$pkg"
126 [ "$deps" = indirect2 -a $depth -le 2 ] && dep4pkg "$pkg"
128 return
131 # missing ones? yes, no, only TODO: maybe delete
132 if [ ! -f /var/adm/packages/$pkg ]; then
133 if [ "$missing" = 'no' ]; then
134 [ $verbose = 1 ] && echo " Not missing, skipped."
135 return
137 elif [ "$missing" = 'only' ]; then
138 [ $verbose = 1 ] && echo " Only missing selected, skipped."
139 return
143 [ $verbose = 1 ] && echo " Added.$(fmt_time $buildtime)"
144 var_append deplist " " "$pkg"
145 esttime=$((esttime + buildtime))
146 [ "$deps" = indirect ] && dep4pkg "$pkg"
147 [ "$deps" = indirect2 -a $depth -le 2 ] && dep4pkg "$pkg"
150 declare -A scanned
152 add_if_updated() {
153 local pkg=$1
154 local typ=$2
156 local x="${scanned[$pkg]}"
157 if [ "$x" = 1 ]; then
158 [ $debug = 1 ] && echo "already been at $pkg ..."
159 return
160 else
161 scanned[$pkg]=1
164 [ $verbose = 1 ] && echo -n "$deptree> $pkg ..."
165 confdir=""
166 for x in package/*/$pkg/$pkg.desc; do
167 if [ -f "$x" ]; then
168 if [ "$confdir" ]; then
169 echo " Warning: Package in multiple trees! Skipped."
170 return
172 confdir=${x/$pkg.desc/}
174 done
175 if [ -z "$confdir" ]; then
176 if [ $depth = 0 ]; then
177 echo " Error: No such package."
178 exit 1
179 else
180 echo " Warning: No such package."
181 return
185 if [ ! -f /var/adm/packages/$pkg ]; then
186 if [ "$typ" = "[OPT]" ]; then
187 add_if_req $pkg ' Not installed.' $typ
188 else
189 add_if_req $pkg ' Not installed.'
191 return
194 o_ver=$(grep -a '^Package Name and Version' \
195 /var/adm/packages/$pkg | cut -f6 -d' ')
196 # we avoid parse_desc here, because it is ~50x slower
197 n_ver=$(grep -a '^\[V\] ' $confdir/$pkg.desc \
198 architecture/$SDECFG_ARCH/package/$pkg/$pkg.desc \
199 target/$SDECFG_TARGET/package/$pkg/$pkg.desc \
200 2> /dev/null | cut -f2 -d' ' | tail -n 1)
201 if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ]; then
202 add_if_req $pkg " New version ($o_ver -> $n_ver)."
203 return
206 o_ck=$(grep -a '^\(ROCK Linux\|T2\) Package Source Checksum' \
207 /var/adm/packages/$pkg | sed 's,.*: ,,')
208 n_ck=$(pkgchksum package/*/$pkg)
209 if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ]; then
210 add_if_req $pkg " New source checksum."
211 return
214 if [ -f /var/adm/cache/$pkg ] &&
215 grep -a -q '\[BUILDTIME\] .* ERROR' \
216 /var/adm/cache/$pkg; then
217 [ $verbose = 1 ] && echo -n " Former build was broken."
218 if [ $rebuild = 1 ]; then
219 add_if_req $pkg ''
220 else
221 [ $verbose = 1 ] && echo " Skipped."
223 return
226 if [ $force = 1 -a $depth = 0 ]; then
227 add_if_req $pkg ' Build forced.'
228 return
231 if [ $debug = 1 ]; then
232 echo " Installed and up-to-date."
233 else
234 echo -ne \
235 "\r \r"
239 dep4pkg() {
240 ((depth++))
241 local _deptree="$deptree"
242 var_append deptree '>' "$1"
244 local IFS=$'\n'
245 for dep in `grep -a '\[\(DEP\|OPT\)\]' package/*/$1/$1.cache 2>/dev/null`; do
246 add_if_updated ${dep#* } ${dep% *}
247 done
249 deptree="$_deptree"
250 ((depth--))
253 # the remaining arguments are packages to be built
254 for x in $*; do
255 add_if_updated $x
256 done
258 # packages from repositories
259 for x in $repositories; do
260 for x in `egrep -a "^X .* $x .*" config/$config/packages |
261 cut -d ' ' -f 5`; do
262 add_if_updated $x
263 done
264 done
266 # all installed packages if a system update
267 if [ $system -eq 1 ]; then
268 for x in `cd /var/adm/packages/; ls *`; do
269 add_if_updated $x
270 done
273 case "$deps" in
274 fast|indirect*)
275 # we have to create a complete dependency graph ...
276 for x in $deplist; do
277 dep4pkg $x
278 done
280 none)
283 echo "Unknown dependency resolution mode. Valid are none, fast and indirect."
284 exit 1
285 esac
287 # The deplist is quite unsorted (in alphabetically sorted chunks)
288 # so we need to work arround this here ...
289 # Sort by priority.
291 deplist=`echo -n $deplist | tr '\n' ' ' | tr -s ' '`
292 deplist=$(grep -a "^. .* .* .* \\(${deplist// /\\|}\\) " \
293 config/$config/packages | sort -k 3 | cut -d ' ' -f 5 | tr '\n' ' ')
295 if [ "$deplist" ]; then
296 echo "$(echo "$deplist" |
297 wc -w) packages scheduled to build$(fmt_time $esttime): $deplist" | fold -s
298 echo
299 else
300 echo "No package scheduled to build."
303 [ $dryrun = 1 ] && exit
305 [ $backup = 1 ] && options="$options -update"
307 . config/$config/config
309 for pkg in $deplist; do
310 if scripts/Download -cfg $config $dloptions $pkg; then
311 if [ $downloadonly != 1 ] &&
312 ! scripts/Build-Pkg $options $pkg; then
313 if [ $SDECFG_CONTINUE_ON_ERROR_AFTER -gt 8 ]; then
314 echo "Aborting further builds due to config setting CONTINUE_ON_ERROR_AFTER."
315 exit 1
318 else
319 echo "The download for package $pkg failed!"
320 #exit 1
323 [ "${dloptions/-quiet-mirror/}" = "$dloptions" ] &&
324 var_append dloptions " " "-quiet-mirror"
325 done