added CheckVersion info for dyncall
[t2.git] / scripts / Config
blobd0821fc826c7f1d1f21e9db69f0a4fa6ac368fbd
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # This copyright note is auto-generated by scripts/Create-CopyPatch.
5 #
6 # T2 SDE: scripts/Config
7 # Copyright (C) 2004 - 2021 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 ROCK Linux Project
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 if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ]; then
19 if [ "$( type -p stty )" ]; then
20 lines="$( stty size 2> /dev/null | cut -d' ' -f1 )"
21 columns="$( stty size 2> /dev/null | cut -d' ' -f2 )"
23 [ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
24 [ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
27 eval "$(egrep '^sdever=' scripts/parse-config)"
29 config=default
30 do_config_cycle=0
31 delete_mode=0
32 oldconfig=''
33 cfgtmpdir=''
34 profile=""
36 show_usage() {
37 echo
38 echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
39 echo
40 echo "Other options:"
41 echo " -profile create a config.profile with profiling data"
42 echo
45 while [ "$1" ]; do
46 case "$1" in
47 -cycle) do_config_cycle=1; shift ;;
48 -delete) delete_mode=1 ; shift ;;
49 -profile) profile='-profile' ; shift ;;
50 -oldconfig) oldconfig='-oldconfig' ; shift ;;
51 -cfg) config="$2" ; shift; shift ;;
53 *) show_usage
54 exit 1 ;;
55 esac
56 done
58 if [ -z "$config" ]; then
59 show_usage
60 exit 1
63 if [ ! -d config/$config -a -n "$oldconfig" ]; then
64 echo "Abort: -oldconfig is not supported for new configs"
65 echo
66 exit 1
69 if [ ! -d config/$config -a -e /etc/SDE-CONFIG/config ]; then
70 echo "Using /etc/SDE-CONFIG/ as default config"
71 mkdir -p config/$config
72 cp -vf /etc/SDE-CONFIG/* config/$config/
73 sed -i -E '/SDECFG_(PARALLEL_MAX|CROSSBUILD)/d' \
74 config/$config/config
77 if [ $delete_mode = 1 ]; then
78 rm -rv config/$config
79 exit $?
82 cfgtmpdir=src/$config
84 if [ $do_config_cycle = 0 ]; then
85 set -e
86 mkdir -p config/$config
87 touch config/$config/{config,packages}
88 set +e
90 echo "Aquiring config write lock (may take until other configs finished)"
91 # aquire lock
92 exec 200>> config/$config/lock.pid
93 flock 200
94 echo $$ > config/$config/lock.pid
96 rm -rf $cfgtmpdir
97 mkdir -p $cfgtmpdir # src
99 if [ -z "$oldconfig" -a ! -f src/confdialog.bin ]; then
100 echo "Creating confdialog tool"
101 command="cc misc/confdialog/*.c `
102 `-Imisc/confdialog -lncurses -o src/confdialog.bin"
103 echo "$command"
104 if ! eval "$command.$$"; then
105 echo "Compilation of the dialog tool failed, ncurses-devel missing?"
106 exit 1
108 mv src/confdialog.bin.$$ src/confdialog.bin
111 # don't let Ctrl-C interrupt, because it destroys the configurations
112 trap '' INT
114 echo "T2 $sdever configuration"
115 while "$0" -cfg $config $oldconfig $profile -cycle; do :; done
117 trap INT
119 rm config/$config/lock.pid
120 exit 0
123 echo "Building src/luabash.so"
124 rm -rf src/luabash.so
125 j="$(nproc 2>/dev/null)"
126 make -j${j:-1} --no-print-directory -C misc/luabash X_OUTTOP=$PWD/src install
127 unset j
129 if [ ! -f src/luabash.so ]; then
130 echo "Error building the Lua bash accelerator"
131 exit 1
134 if ! enable -f src/luabash.so luabash; then
135 echo "Failed to enable the Lua bash accelerator"
136 exit 1
139 luabash load scripts/config-functions.lua || exit 1
141 if [ -z "$profile" ]; then
142 bprof() { :; }
143 bprof_print() { :; }
144 else
145 if [ ! -f src/bash_profiler.so -o misc/tools-source/bash_profiler.c -nt src/bash_profiler.so ]; then
146 echo "Building src/bash_profiler.so"
147 cc -shared -fPIC -Wall -o src/bash_profiler.so misc/tools-source/bash_profiler.c || exit 1
149 enable -f src/bash_profiler.so bprof || exit 1
150 bprof_print() {
151 local cprof=$cfgtmpdir/config.profile
152 bprof all print >> $cprof
153 awk '
154 $4 == "profiled" { next; }
155 $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
156 { count[$4]+=$1; time[$4]+=$2; }
157 END {
158 for (id in count)
159 printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
161 ' < $cprof | sort -n -k2 > $cprof.new
162 mv $cprof.net $cprof
166 bprof main start
168 . scripts/config-functions.in
169 arch=`uname -m | uname2arch`
170 current=""; export SDECFG_ARCH="$arch"; export SDECFG_KERNEL="linux"; export SDECFG_EXPERT=0
171 menu_this=0; menu_current=0; menu_counter=0
172 menu_stack=x; menu_back=-1; menu_backpos=-1
174 configtitle="$(printf ' %-50s %6s active packages ]' \
175 "T2 $sdever Configuration - $config" \
176 "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )"
178 bprof main stop
180 . ./config/$config/config
181 bprof main start
183 rm -f $cfgtmpdir/config.{dialog,data,help}
184 touch $cfgtmpdir/config.{dialog,data,help}
185 echo -e "#\n# T2 $sdever Config File\n#" > config/$config/config
186 spacer=""; expert=0; tabspace="5"; tabspace_list=""
187 commentnr=0; editfilenr=0
189 bprof mkpkglist start
190 cmd="scripts/Create-PkgList $SDECFG_ARCH"
191 if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ]; then
192 eval "$cmd" | tee $cfgtmpdir/config.pcache.data > config/$config/packages
193 echo "$cmd" > $cfgtmpdir/config.pcache.cmd
194 else
195 cat $cfgtmpdir/config.pcache.data > config/$config/packages
197 bprof mkpkglist stop
199 # Create lists of .in files
200 create_dot_in_lists
202 export SDECFG_ID="$sdever"; pkgin; . scripts/config.in; pkgout
203 echo "export SDECFG_ID='$SDECFG_ID'" >> config/$config/config
204 rm -f $cfgtmpdir/*.tmp
206 cut -f1,2,4,5,8- -d' ' config/$config/packages | sed 's, [^ ]*$,,' | \
207 tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
209 configtitle="$(printf ' %-50s %6s active packages ]' \
210 "T2 $sdever Configuration - $config" \
211 "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )"
213 bprof main stop
215 if [ -z "$oldconfig" ]; then
216 eval "./src/confdialog.bin --title 'Build Config' \
217 --backtitle '$configtitle' \
218 --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
219 $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
220 '$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
221 returncode=$?; item="$(< $cfgtmpdir/config.out)"
222 else
223 returncode=1
226 bprof main start
228 [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
230 case "$returncode" in
231 0|6)
232 command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
233 { echo -e "\n# Remember menu position:\ncurrent='$item'"
234 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
235 echo -e "\n# Execute this config command:\n$command"
236 } >> config/$config/config
238 menu-back)
239 { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
240 echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
241 } >> config/$config/config
243 1|255)
244 rm -rf $cfgtmpdir
245 echo "New config written to: config/$config/"
246 bprof main stop
247 bprof_print
248 exit 1 ;;
250 tempitem=$item
251 item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
252 { echo -e "\n# Remember menu position:\ncurrent='$item'"
253 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
254 } >> config/$config/config
256 get_help $item > $cfgtmpdir/config.dialog
258 bprof main stop
259 ./src/confdialog.bin --title 'T2 Config - Help' \
260 --backtitle "T2 $sdever Configuration" \
261 --textbox $cfgtmpdir/config.dialog \
262 $(( $lines - 4 )) $(( $columns - 5 ))
263 bprof main start
266 echo "unknown returncode: $returncode"
267 bprof main stop
268 bprof_print
269 exit 1 ;;
270 esac
272 bprof main stop
273 bprof_print
275 exit 0