* updated libxspf (1.2.0 -> 1.2.1)
[t2-trunk.git] / scripts / Config
blob65a1616840f59e88cf43e363fc246a01f3dd819a
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Config
5 # Copyright (C) 2004 - 2022 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
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 if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ]; then
16 if [ "$( type -p stty )" ]; then
17 lines="$( stty size 2> /dev/null | cut -d' ' -f1 )"
18 columns="$( stty size 2> /dev/null | cut -d' ' -f2 )"
20 [ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
21 [ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
24 eval "$(egrep '^sdever=' scripts/parse-config)"
26 config=default
27 do_config_cycle=0
28 delete_mode=0
29 oldconfig=''
30 cfgtmpdir=''
31 profile=""
33 show_usage() {
34 echo
35 echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
36 echo
37 echo "Other options:"
38 echo " -profile create a config.profile with profiling data"
39 echo
42 while [ "$1" ]; do
43 case "$1" in
44 -cycle) do_config_cycle=1; shift ;;
45 -delete) delete_mode=1 ; shift ;;
46 -profile) profile='-profile' ; shift ;;
47 -oldconfig) oldconfig='-oldconfig' ; shift ;;
48 -cfg) config="$2" ; shift; shift ;;
50 *) show_usage
51 exit 1 ;;
52 esac
53 done
55 if [ -z "$config" ]; then
56 show_usage
57 exit 1
60 if [ ! -d config/$config -a -n "$oldconfig" ]; then
61 echo "Abort: -oldconfig is not supported for new configs"
62 echo
63 exit 1
66 if [ ! -d config/$config -a -e /etc/SDE-CONFIG/config ]; then
67 echo "Using /etc/SDE-CONFIG/ as default config"
68 mkdir -p config/$config
69 cp -vf /etc/SDE-CONFIG/* config/$config/
70 sed -i -E '/SDECFG_(PARALLEL_MAX|CROSSBUILD|PKGSEL_TMPL)/d' \
71 config/$config/config
74 if [ $delete_mode = 1 ]; then
75 rm -rv config/$config
76 exit $?
79 cfgtmpdir=src/$config
81 if [ $do_config_cycle = 0 ]; then
82 set -e
83 mkdir -p config/$config
84 touch config/$config/{config,packages}
85 set +e
87 echo "Aquiring config write lock (may take until other configs finished)"
88 # aquire lock
89 exec 200>> config/$config/lock.pid
90 flock 200
91 echo $$ > config/$config/lock.pid
93 rm -rf $cfgtmpdir
94 mkdir -p $cfgtmpdir # src
96 if [ -z "$oldconfig" -a ! -f src/confdialog.bin ]; then
97 echo "Creating confdialog tool"
98 command="cc misc/confdialog/*.c `
99 `-Imisc/confdialog -lncurses -o src/confdialog.bin"
100 echo "$command"
101 if ! eval "$command.$$"; then
102 echo "Compilation of the dialog tool failed, ncurses-devel missing?"
103 exit 1
105 mv src/confdialog.bin.$$ src/confdialog.bin
108 # don't let Ctrl-C interrupt, because it destroys the configurations
109 trap '' INT
111 echo "T2 $sdever configuration"
112 while "$0" -cfg $config $oldconfig $profile -cycle; do :; done
114 trap INT
116 rm config/$config/lock.pid
117 exit 0
120 echo "Building src/bash/luabash"
121 j="$(nproc 2>/dev/null)"
122 make -j${j:-1} --no-print-directory -C misc/luabash \
123 X_OUTARCH=$PWD/src ${HOSTCC:+CC=$HOSTCC} ${HOSTCC:+LD=ld}
124 unset j
126 if [ ! -f src/bash/luabash.??* ]; then
127 echo "Error building the Lua bash accelerator"
128 exit 1
131 if ! enable -f $PWD/src/bash/luabash.??* luabash; then
132 echo "Failed to enable the Lua bash accelerator"
133 exit 1
136 luabash load scripts/config-functions.lua || exit 1
138 if [ -z "$profile" ]; then
139 bprof() { :; }
140 bprof_print() { :; }
141 else
142 if [ ! -f src/bash_profiler.so -o misc/tools-source/bash_profiler.c -nt src/bash_profiler.so ]; then
143 echo "Building src/bash_profiler.so"
144 cc -shared -fPIC -Wall -o src/bash_profiler.so misc/tools-source/bash_profiler.c || exit 1
146 enable -f src/bash_profiler.so bprof || exit 1
147 bprof_print() {
148 local cprof=$cfgtmpdir/config.profile
149 bprof all print >> $cprof
150 awk '
151 $4 == "profiled" { next; }
152 $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
153 { count[$4]+=$1; time[$4]+=$2; }
154 END {
155 for (id in count)
156 printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
158 ' < $cprof | sort -n -k2 > $cprof.new
159 mv $cprof.net $cprof
163 bprof main start
165 . scripts/config-functions.in
166 arch=`uname -m | uname2arch`
167 current=""; export SDECFG_ARCH="$arch"; export SDECFG_KERNEL="linux"; export SDECFG_EXPERT=0
168 menu_this=0; menu_current=0; menu_counter=0
169 menu_stack=x; menu_back=-1; menu_backpos=-1
171 configtitle="$(printf ' %-50s %6s active packages ]' \
172 "T2 $sdever Configuration - $config" \
173 "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )"
175 bprof main stop
177 . ./config/$config/config
178 bprof main start
180 rm -f $cfgtmpdir/config.{dialog,data,help}
181 touch $cfgtmpdir/config.{dialog,data,help}
182 echo -e "#\n# T2 $sdever Config File\n#" > config/$config/config
183 spacer=""; expert=0; tabspace="5"; tabspace_list=""
184 commentnr=0; editfilenr=0
186 bprof mkpkglist start
187 cmd="scripts/Create-PkgList $SDECFG_ARCH"
188 if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ]; then
189 eval "$cmd" | tee $cfgtmpdir/config.pcache.data > config/$config/packages
190 echo "$cmd" > $cfgtmpdir/config.pcache.cmd
191 else
192 cat $cfgtmpdir/config.pcache.data > config/$config/packages
194 bprof mkpkglist stop
196 # Create lists of .in files
197 create_dot_in_lists
199 export SDECFG_ID="$sdever"; pkgin; . scripts/config.in; pkgout
200 echo "export SDECFG_ID='$SDECFG_ID'" >> config/$config/config
201 rm -f $cfgtmpdir/*.tmp
203 cut -f1,2,4,5,8- -d' ' config/$config/packages | sed 's, [^ ]*$,,' | \
204 tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
206 configtitle="$(printf ' %-50s %6s active packages ]' \
207 "T2 $sdever Configuration - $config" \
208 "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )"
210 bprof main stop
212 if [ -z "$oldconfig" ]; then
213 eval "./src/confdialog.bin --title 'Build Config' \
214 --backtitle '$configtitle' \
215 --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
216 $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
217 '$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
218 returncode=$?; item="$(< $cfgtmpdir/config.out)"
219 else
220 returncode=1
223 bprof main start
225 [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
227 case "$returncode" in
228 0|6)
229 command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
230 { echo -e "\n# Remember menu position:\ncurrent='$item'"
231 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
232 echo -e "\n# Execute this config command:\n$command"
233 } >> config/$config/config
235 menu-back)
236 { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
237 echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
238 } >> config/$config/config
240 1|255)
241 rm -rf $cfgtmpdir
242 echo "New config written to: config/$config/"
243 bprof main stop
244 bprof_print
245 exit 1 ;;
247 tempitem=$item
248 item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
249 { echo -e "\n# Remember menu position:\ncurrent='$item'"
250 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
251 } >> config/$config/config
253 get_help $item > $cfgtmpdir/config.dialog
255 bprof main stop
256 ./src/confdialog.bin --title 'T2 Config - Help' \
257 --backtitle "T2 $sdever Configuration" \
258 --textbox $cfgtmpdir/config.dialog \
259 $(( $lines - 4 )) $(( $columns - 5 ))
260 bprof main start
263 echo "unknown returncode: $returncode"
264 bprof main stop
265 bprof_print
266 exit 1 ;;
267 esac
269 bprof main stop
270 bprof_print
272 exit 0