* updated libkdcraw (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / scripts / config-functions.in
blobdfaa9a6b08a2ab882b2e8b921bc097086d96c9d6
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: scripts/config-functions.in
3 # Copyright (C) 2004 - 2021 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
5
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 . scripts/core-functions.in
15 # Function to cache config.in and subconfig.in file lists
17 create_configin_list() {
18         bprof cache_configin_list start
19         if [ ! -f $cfgtmpdir/noexpert-config.in -o ! -f $cfgtmpdir/expert-config.in ]; then
20                 local file= prio= name=
22                 rm -f $cfgtmpdir/{no,}expert-config.in{,.$$}
23                 rm -f $cfgtmpdir/subconfig-*.in{,.$$}
25                 touch $cfgtmpdir/{no,}expert-config.in{,.$$}
27                 # config.in
28                 # FIXME: this expression may produce duplicated entries!! //mnemoc
29                 ls -1 {package/*,misc}/*/config{,-[a-z]*}{,-[0-9]*}.in 2> /dev/null | while read file; do
30                         prio="$( echo "${file##*/}" | sed -n -e "s,.*-\([0-9]*\).in,\1,p" )"
31                         if [ ${prio:-750} -le 500 ]; then
32                                 echo "$prio $file" >> $cfgtmpdir/noexpert-config.in.$$
33                         else
34                                 echo "${prio:-750} $file" >> $cfgtmpdir/expert-config.in.$$
35                         fi
36                 done
37                 sort -u $cfgtmpdir/noexpert-config.in.$$ | sed 's,^[^ ]* ,. ,g' > $cfgtmpdir/noexpert-config.in
38                 sort -u $cfgtmpdir/expert-config.in.$$   | sed 's,^[^ ]* ,. ,g' > $cfgtmpdir/expert-config.in
40                 rm -f $cfgtmpdir/{no,}expert-config.in.$$
42                 # subconfig.in
43                 ls -1 package/*/*/subconfig-[a-z]*.in 2> /dev/null | while read file; do
44                         prio="$( echo "${file##*/}" | sed -n -e "s,.*-\([0-9]*\).in,\1,p" )"
45                         name="$( echo "${file##*/}" | sed -e "s,-\([0-9]*\).in,.in," )"
46                         echo "${prio:-750} $file" >> $cfgtmpdir/$name.$$
47                 done
48                 for file in $cfgtmpdir/subconfig-[a-z]*.in.$$; do
49                         sort -n $file | sed 's,^[^ ]* ,. ,g' > ${file%.$$}
50                         rm -f $file
51                 done
52         fi
53         bprof cache_configin_list stop
56 # Function to cache config.in and subconfig.in file lists
58 create_dot_in_lists() {
59         local file= x= y=
60         # {architecture,misc,target,package/*}/*/{pre,post}config.in
61         bprof cache_dotin_list start
62         for x in preconfig.in postconfig.in; do
63                 for y in architecture kernel misc target; do
64                         file=$cfgtmpdir/$y-$x
65                         if [ ! -f $file ]; then
66                                 ls -1 $y/*/$x 2> /dev/null | sed 's,^,. ,' > $file
67                         fi
68                 done
69                 y=package
70                 file=$cfgtmpdir/$y-$x
71                 if [ ! -f $file ]; then
72                         ls -1 $y/*/*/$x 2> /dev/null | sed 's,^,. ,' > $file
73                 fi
74         done
75         bprof cache_dotin_list stop
77         # and {sub,}config.in, which is more complex
78         create_configin_list
81 # Functions for working with config/$config/packages
83 #       pkgenable       package-list
84 #       pkgdisable      package-list
85 #       pkgremove       package-list
86 #       pkgcheck        package|oacjage X|O|.
87 #       pkgfilter       cmd arg1 ...
88 #       pkgsel_parse    parse pkgsel file
90 pkgin() { pkglistread config/$config/packages; }
91 pkgout() { pkglistwrite config/$config/packages; }
92 pkgfilter() {
93         bprof pkgfilter start
94         pkglistwrite $cfgtmpdir/packages.tmp
95         "$@" < $cfgtmpdir/packages.tmp > config/$config/packages
96         pkglistread config/$config/packages
97         bprof pkgfilter stop
100 # pkgchecklicense -- checks for files with license issues
101 pkgchecklicense() {
102         rm -f config/$config/license-issue.*
103         while read a b c repo pkg dummy; do
104                 if grep -E "\[(L|LICENSE)\][ ]*(Commercial|Restricted)" \
105                         package/$repo/$pkg/$pkg.desc &> /dev/null; then
106                         echo $pkg >> config/$config/license-issue.ask
107                 fi
108         done < <(grep "^X" config/$config/packages)
111 comment() {
112         bprof comment start
113         if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
114            [ $menu_current = $menu_this ]; then
115                 (( commentnr++ ))
116                 echo "COMMENT_$commentnr '$spacer$1'" >> $cfgtmpdir/config.dialog
118                 if [ "$2" != "" ]; then
119                         set_help "COMMENT_$commentnr" "$2"
120                 fi
121         fi
122         bprof comment stop
125 comment_id() {
126         bprof comment_id start
127         if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
128            [ $menu_current = $menu_this ]; then
129                 echo "$2 '$spacer$1'" >> $cfgtmpdir/config.dialog
131                 if [ "$3" != "" ]; then
132                         set_help "$2" "$3"
133                 fi
134         fi
135         bprof comment_id stop
138 const() {
139         bprof const start
140         local q="'"
141         local v="${2//$q/$q\\$q$q}"
142         eval "$1=\"\$2\""
143         echo "export $1='$v'" >> config/$config/config
144         bprof const stop
147 # Usage: set_data NAME DEFAULT
149 set_data() {
150         bprof set_data start
151         local q="'" set_name="SDECFGSET_${1#SDECFG_}"
153         if eval "[ \"\$$set_name\" ]"; then
154                 eval "data=\"\$$set_name\""
155                 eval "$1=\"\$data\""
156                 if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ]
157                 then menumode=2; else menumode=0; fi
159         elif [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ]; then
160                 eval "data=\"\${$1:-$2}\""
161                 eval "$1=\"\$data\""
162                 menumode=1
163         else
164                 data="$2"; eval "$1=\"\$data\""
165                 menumode=0
166         fi
168         item="$1"
169         echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config/config
170         bprof set_data stop
173 choice() {
174         bprof choice start
176         # desired default value
177         #
178         local defval="$2"
180         # reset to default if current value is not in list
181         # and default to first element if it's not in list
182         #
183         eval $(
184                 eval "value=\$$1"; name=$1; dval=$defval; shift; shift
185                 while [ "$#" != 0 ]; do
186                         [ "$dval"  = "$1" ] && dval=""
187                         [ "$value" = "$1" ] && name=""; shift; shift
188                 done
189                 [ "$dval" ] && echo "unset defval;"
190                 [ "$name" ] && echo "unset $name"
191         )
193         set_data "$1" "${defval:-$3}"
195         if [ "$menumode" -eq 1 -a $menu_current = $menu_this ]; then
196                 { echo -en "$item\tchoice_action '$1' '$data'"; shift; shift
197                 for x; do echo -n " '$x'"; done; echo; } >> $cfgtmpdir/config.data
198         fi
200         if [ "$menumode" -gt 0 -a $menu_current = $menu_this ]; then
201                 if [ "$menumode" -eq 1 ]; then xdata="($data)"
202                 else xdata="=$data="; fi
204                 while [ "$1" -a "$1" != "$data" ]; do shift; shift; done
205                 printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" \
206                        "$xdata" >> $cfgtmpdir/config.dialog
207         fi
209         bprof choice stop
212 choice_action() {
213         command="./src/confdialog.bin --title 'Build Config' \
214                 --backtitle '$configtitle' \
215                 --radiolist 'Arrow keys navigate the menu.  Press <Enter> to activate menu items.  Highlighted letters are hotkeys.' \
216                 $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))"
217         default=$2; item=$1; shift; shift
218         while [ "$1" ]; do
219                 if [ "$1" = "$default" ]
220                 then command="$command '$1' '${2//_/ }' ON"
221                 else command="$command '$1' '${2//_/ }' OFF"; fi
222                 shift; shift
223         done
224         eval "$command" 2> $cfgtmpdir/config.out
226         case "$?" in
227                 0|6)
228                         eval "$item='$(< $cfgtmpdir/config.out)'"
229                         ;;
230                 1|255) return 0 ;;
231                 2) echo "No help."; sleep 1 ;;
232                 *) echo "unknown returncode: $?"; exit 1 ;;
233         esac
236 text() {
237         bprof text start
238         local q="'"
239         set_data "$2" "$3"
241         if [ "$menumode" -eq 1 -a $menu_current = $menu_this ]; then
242                 echo -e "$2\ttext_action '$1' '$2'" \
243                                 "'${data//$q/$q\\$q$q}'" >> $cfgtmpdir/config.data
244         fi
246         if [ "$menumode" -gt 0 -a $menu_current = $menu_this ]; then
247                 xdata="$( printf "%-${tabspace}s" \
248                                 "$(echo $data | cut -c1-20)")"
249                 if [ "$menumode" -eq 1 ]; then xdata="($xdata)"
250                 else xdata="=$xdata="; fi
252                 printf "'$2' '$spacer%s $1'\n" \
253                         "${xdata//$q/$q\\$q$q}" >> $cfgtmpdir/config.dialog
255                 if [ "$4" != "" ]; then
256                         set_help "$2" "$4"
257                 fi
258         fi
259         bprof text stop
262 text_action() {
263         ./src/confdialog.bin --title 'Build Config' \
264                 --backtitle "$configtitle" \
265                 --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> $cfgtmpdir/config.out
266         [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(< $cfgtmpdir/config.out)\""
269 bool() {
270         bprof bool start
271         local x
272         set_data "$2" "$3"
274         if [ "$menumode" -eq 1 -a $menu_current = $menu_this ]; then
275                 echo -e "$2\tbool_action '$1' '$2' '$data'" >> $cfgtmpdir/config.data
276         fi
278         if [ "$menumode" -gt 0 -a $menu_current = $menu_this ]; then
279                 if [ "$menumode" -eq 1 ]; then
280                         if [ $data -eq 0 ]; then x='[ ]'; else x='[*]'; fi
281                 else
282                         if [ $data -eq 0 ]; then x='= ='; else x='=*='; fi
283                 fi
284                 printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" \
285                        "$x" >> $cfgtmpdir/config.dialog
287                 if [ "$4" != "" ]; then
288                         set_help "$2" "$4"
289                 fi
290         fi
291         bprof bool stop
294 bool_action() {
295         if [ $3 -eq 0 ]; then eval "$2=1"
296         else eval "$2=0"; fi
299 editfile() {
300     bprof editfile start
301     if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ]; then
302         local x="$spacer" q="'"
303         comment ",----< $3 >----."
304         block_begin 0; spacer="${spacer%??}| "
306         touch "$2"
307         line_nr=1
308         while read line; do
309                 line="${line//$q/$q\\$q$q}"
310                 if [ $menu_current = $menu_this ]; then
311                         printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
312                             `printf "%03d:" $line_nr` "$line" >> $cfgtmpdir/config.dialog
314                         echo -e "$1:${editfilenr}\teditfile_action $2" \
315                                 "$line_nr '$3'" >> $cfgtmpdir/config.data
316                 fi
318                 (( editfilenr++ ))
319                 (( line_nr++ ))
320         done < "$2"
322         if [ $menu_current = $menu_this ]; then
323                 printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
324                        `printf "%03d:" $line_nr` "<add new rule>" >> $cfgtmpdir/config.dialog
326                 echo -e "$1:${editfilenr}\teditfile_action $2" \
327                         "$line_nr '$3'" >> $cfgtmpdir/config.data
328         fi
330         (( editfilenr++ ))
332         block_end
333         comment "\`------${3//?/-}------'\''"
334         spacer="$x"
335     else
336         rm -f "$2"
337     fi
338     bprof editfile stop
341 editfile_action() {
342         line="`tail -n +$2 $1 | head -n 1`"
344         ./src/confdialog.bin --title 'Build Config' \
345                 --backtitle "$configtitle" \
346                 --inputbox "$3 - Line $3"  \
347                 9 $(( $columns - 5 )) "$line" 2> $cfgtmpdir/config.out
349         head -n $(( $2 - 1 )) $1 > $1.new
350         [ -s $cfgtmpdir/config.out ] && echo "$(< $cfgtmpdir/config.out)" >> $1.new
351         tail -n +$(( $2 + 1 )) $1 >> $1.new
353         mv $1.new $1
356 startprog() {
357         bprof startprog start
358         if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
359            [ $menu_current = $menu_this ]; then
360                 printf "$1 '$spacer%-${tabspace}s %s'\n" \
361                        "-->" "$2" >> $cfgtmpdir/config.dialog
362                 echo -e "$1\t$3" >> $cfgtmpdir/config.data
363         fi
364         bprof startprog stop
367 block_begin() {
368         bprof block_begin start
369         if [ $menu_current = $menu_this ]; then
370                 [ "$tabspace_list" ] && spacer="$spacer  "
371                 tabspace_list="$tabspace $tabspace_list"
372                 tabspace="$(( $tabspace + $1 - 2 ))"
373         fi
374         bprof block_begin stop
377 block_end() {
378         bprof block_end start
379         if [ $menu_current = $menu_this ]; then
380                 spacer="${spacer%??}"
381                 tabspace="${tabspace_list%% *}"
382                 tabspace_list="${tabspace_list#* }"
383         fi
384         bprof block_end stop
387 expert_begin() {
388         expert=$(( $exprt + 1 ))
391 expert_end() {
392         expert=$(( $exprt - 1 ))
395 menu_begin() {
396         bprof menu_begin start
397         menu_counter=$(( $menu_counter + 1 ))
399         if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
400            [ $menu_current = $menu_this ]; then
401                 printf "$1 '$spacer%-${tabspace}s %s'\n" \
402                         "===>" "$2" >> $cfgtmpdir/config.dialog
403                 echo -e "$1\tmenu_current=$menu_counter" >> $cfgtmpdir/config.data
404         fi
405         if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
406            [ $menu_current = $menu_counter ]; then
407                 echo "$1 '===> $2'" >> $cfgtmpdir/config.dialog
408                 echo -e "$1\tmenu_current=$menu_this" >> $cfgtmpdir/config.data
409         fi
411         if [ $menu_current = $menu_counter ]; then
412                 menu_back=$menu_this
413                 menu_backpos=$1
414         fi
416         menu_stack="$menu_this $menu_stack"
417         menu_this=$menu_counter
419         block_begin 3
420         bprof menu_begin stop
423 menu_end() {
424         bprof menu_end start
425         block_end
426         menu_this="${menu_stack%% *}"
427         menu_stack="${menu_stack#* }"
428         bprof menu_end stop
431 set_help() {
432         bprof set_help start
433         (echo -ne "$1 '$1:\n\n$2'" | sed 's,$,\\n,' |
434                 tr -d '\n' | sed 's,\\n$,,'; echo ) >> $cfgtmpdir/config.help
435         bprof set_help stop
438 get_help() {
439         bprof get_help start
440         # Create standard help output ...
441         default_text="
442 There is no help on '$1' available.
444 This is the T2 $sdever Configuration Tool.
446 Please read the Quick Start and the Handbook on
447 http://t2sde.org/buildintro.html    and
448 http://t2sde.org/t2-handbook/ respectively
449 before building T2.
451 More information can be found on the T2 Homepage:
453                http://t2sde.org/
455 Subscribe to the mailing list by sending an e-mail with the
456 subject 'subscribe t2' to <lists@t2sde.org>."
457         
458         # Ok let us find a help for the current item ...
460         # First of all mask all special chars in the item name
461         # Comment: this is sick. You can't get any \n this way !!!
462         item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' )
463         # Now search *.hlp files
464         hlp_text=$( sed -n "/^$item_name[       ]*\$/,\${
465                         /^$item_name[   ]*\$/c\\
466 $item_name:\\
468                         /^#/d
469                         /^[^    ]/q
470                         s/^  //
471                         p
472                         }" scripts/config*.hlp architecture/*/config*.hlp \
473 package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp \
474 misc/config/config*.hlp 2>/dev/null )
475         
476         # Get help strings out of the temporary file.
477         tmp_text=$(grep "^$item_name" $cfgtmpdir/config.help | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
479         # Let us see what we have ...
480         if [ "$hlp_text" -a "$tmp_text" ]; then
481                 echo "
482 There are two help text's... one in one of the config.in files and one
483 in one of the config.hlp files. Please remove one of them to get rid of
484 this message here.
486 Here the one out of config.in:
488 $tmp_text
490 Here the one out of config.hlp:
492 $hlp_text"
493         elif [ "$hlp_text" ]; then
494                 echo "$hlp_text"
495         elif [ "$tmp_text" ]; then
496                 echo "$tmp_text"
497         else
498                 echo "$default_text"
499         fi
500         bprof get_help stop