* fixed dosbox glu.h header include path
[t2.git] / scripts / Emerge-Pkg
blobcccfa57b5300cedcffcca9203710cb290ed9c626
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # This copyright note is auto-generated by scripts/Create-CopyPatch.
5 #
6 # T2 SDE: scripts/Emerge-Pkg
7 # Copyright (C) 2004 - 2020 The T2 SDE Project
8 # Copyright (C) 2004 - 2006 Rene Rebe <rene@exactcode.de>
9 #
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 exec 2>&1
20 blacklist=' 00-dirtree binutils gcc glibc glibc32 uclibc linux linux-header clang llvm musl dietlibc '
22 options=
23 config='default'
24 deps='fast'
25 debug=0
26 downloadonly=0
27 verbose=1
28 ignore_chksum=1
29 backup=1
30 dryrun=0
31 force=0
32 rebuild=1
33 repositories=
34 system=0
35 depth=0
36 missing='yes'
38 deptree=
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 ]"
51 echo "$spacer [ -deps=none|fast|indirect ] [ -missing=yes|no|only ] [ -download-only ]"
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 -dry-run) dryrun=1 ;;
73 -force) force=1 ;;
74 -debug) debug=1 ;;
75 -nobackup) backup=0 ;;
76 -consider-chksum) ignore_chksum=0 ;;
77 -norebuild) rebuild=0 ;;
78 -download-only) downloadonly=1 ;;
79 -repository) repositories="$repositories $2"
80 deps=none; depth=1; 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 . scripts/parse-config
92 add_if_req()
94 [ "$verbose" = 1 ] && echo -n "$1"
96 # some more check for packages not manually specified
97 if [ $depth != 0 ]; then
98 # blacklist
99 if [ "$blacklist" != "${blacklist/ $package /}" ]; then
100 [ $verbose = 1 ] && echo " Automatic update avoided."
101 return
104 # missing ones? yes, no, only
105 if [ ! -f /var/adm/packages/$package ]; then
106 if [ "$missing" = 'no' ]; then
107 [ $verbose = 1 ] && echo " Not missing, skipped."
108 return
110 elif [ "$missing" = 'only' ]; then
111 [ $verbose = 1 ] && echo " Only missing selected, skipped."
112 return
116 [ $verbose = 1 ] && echo " Added."
117 var_append deplist " " "$package"
118 [ "$deps" = indirect ] && dep4pkg "$package"
121 add_if_updated()
123 local package=$1
125 # some variable name mangling ...
126 local var="__BEEN_HERE_${package//[^a-zA-Z0-9]/_}"
127 eval local x=\$$var
128 if [ "$x" = 1 ]; then
129 [ $debug = 1 ] && echo "already been at $package ..."
130 return
131 else
132 eval $var=1
135 [ $verbose = 1 ] && echo -n "$deptree> $package ..."
136 confdir=""
137 for x in package/*/$package/$package.desc; do
138 if [ -f "$x" ]; then
139 if [ "$confdir" ]; then
140 echo " Error: Package in multiple trees!"
141 return
143 confdir=${x/$package.desc/}
145 done
146 if [ -z "$confdir" ]; then
147 echo " Error: No such package."
148 return
151 if [ ! -f /var/adm/packages/$package ]; then
152 add_if_req ' Not installed.'
153 return
156 o_ver=$(grep '^Package Name and Version' \
157 /var/adm/packages/$package | cut -f6 -d' ')
158 # we avoid parse_desc here, because it takes approx. 50 slower
159 n_ver=$(grep '^\[V\] ' $confdir/$package.desc \
160 architecture/$SDECFG_ARCH/package/$package/$package.desc \
161 target/$SDECFG_TARGET/package/$package/$package.desc \
162 2> /dev/null | cut -f2 -d' ' | tail -n 1)
163 if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ]; then
164 add_if_req " New version ($o_ver -> $n_ver)."
165 return
168 o_ck=$(grep '^\(ROCK Linux\|T2\) Package Source Checksum' \
169 /var/adm/packages/$package | sed 's,.*: ,,')
170 n_ck=$( pkgchksum package/*/$package )
171 if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ]; then
172 add_if_req " New source checksum."
173 return
176 if [ -f /var/adm/cache/$package ] &&
177 grep -q '\[BUILDTIME\] .* ERROR' \
178 /var/adm/cache/$package; then
179 [ $verbose = 1 ] && echo -n " Former build was broken."
180 if [ $rebuild = 1 ]; then
181 add_if_req ''
182 else
183 [ $verbose = 1 ] && echo " Skipped."
185 return
188 if [ $force = 1 -a $depth = 0 ]; then
189 add_if_req ' Build forced.'
190 return
193 if [ $debug = 1 ]; then
194 echo " Installed and up-to-date."
195 else
196 echo -ne \
197 "\r \r"
201 dep4pkg()
203 : $(( depth++ ))
204 var_append deptree '>' "$1"
205 for x in `grep '\[DEP\]' package/*/$1/$1.cache 2>/dev/null |
206 cut -d ' ' -f 2`; do
207 add_if_updated $x
208 done
209 var_remove deptree '>' "$1" # or cache the previous value?
210 : $(( depth-- ))
213 # the remaining arguments are packages to be built
214 for x in $*; do
215 add_if_updated $x
216 done
218 # packages from repositories
219 for x in $repositories; do
220 for x in `egrep "^X .* $x .*" config/$config/packages |
221 cut -d ' ' -f 5`; do
222 add_if_updated $x
223 done
224 done
226 # all installed packages if a system update
227 if [ $system -eq 1 ]; then
228 for x in `cd /var/adm/packages/; ls *`; do
229 add_if_updated $x
230 done
233 case "$deps" in
234 fast|indirect)
235 # we have to create a complete dependency graph ...
236 tmp=`mktemp`
237 for x in $deplist; do
238 dep4pkg $x
239 done
241 none)
244 echo "Unknown dependency resolution mode. Valid are none, fast and indirect."
245 exit 1
246 esac
248 # The deplist is quite unsorted (in alphabetically sorted chunks)
249 # so we need to work arround this here ...
250 # Sort by priority.
252 deplist=`echo -n $deplist | tr '\n' ' ' | tr -s ' '`
253 deplist=$(grep "^. .* .* .* \\(${deplist// /\\|}\\) " \
254 config/$config/packages | sort -k 3 | cut -d ' ' -f 5 | tr '\n' ' ')
256 if [ "$deplist" ]; then
257 echo "$(echo "$deplist" |
258 wc -w) packages scheduled to build: $deplist" | fold -s
259 echo
260 else
261 echo "0 packages scheduled to build."
264 [ $dryrun = 1 ] && exit
266 [ $backup = 1 ] && options="$options -update"
268 . config/$config/config
270 for package in $deplist; do
271 if scripts/Download -cfg $config $package; then [ $downloadonly != 1 ] &&
272 if ! scripts/Build-Pkg $options $package; then
273 if [ $SDECFG_CONTINUE_ON_ERROR_AFTER -gt 8 ]; then
274 echo "Aborting further builds due to config setting CONTINUE_ON_ERROR_AFTER."
275 exit 1
278 else
279 echo "The download for package $package failed!"
280 exit 1
282 done