* fixed lightdm to build when gobject-introspection is not installed
[t2sde.git] / scripts / Config
blob931fe84806f8046340fd86722a1d7d65a24dd6ca
1 #!/usr/bin/env bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Config
5 # Copyright (C) 2004 - 2024 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 -e /etc/SDE-CONFIG/config -a $config = default ]; then
61 echo "Using /etc/SDE-CONFIG/ as default config"
62 mkdir -p config/$config
63 cp -vf /etc/SDE-CONFIG/* config/$config/
64 sed -i -E '/SDECFG_(CROSSBUILD|OPT|LTO|PARALLEL_MAX|PKGSEL_TMPL|SRC_TMPFS|C_FLAGS)/d' \
65 config/$config/config
68 if [ ! -d config/$config -a -n "$oldconfig" ]; then
69 echo "Error: -oldconfig is not supported for a new config"
70 echo
71 exit 1
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 echo "T2 $sdever configuration"
84 set -e
85 mkdir -p config/$config
86 touch config/$config/{config,packages}
87 set +e
89 echo "Aquiring config lock ..."
90 # aquire lock
91 exec 200>> config/$config/lock.pid
92 flock 200
93 echo $$ > config/$config/lock.pid
95 rm -rf $cfgtmpdir
96 mkdir -p $cfgtmpdir # src
98 if [ -z "$oldconfig" -a ! -f src/confdialog.bin ]; then
99 echo "Creating confdialog tool"
100 command="cc -O2 misc/confdialog/*.c `
101 `-Imisc/confdialog -lncurses -o src/confdialog.bin"
102 echo "$command"
103 if ! eval "$command.$$"; then
104 echo "Compilation of the dialog tool failed, ncurses-devel missing?"
105 exit 1
107 mv src/confdialog.bin.$$ src/confdialog.bin
110 # don't let Ctrl-C interrupt, because it destroys the configurations
111 trap '' INT
113 while "$0" -cfg $config $oldconfig $profile -cycle; do :; done
115 trap INT
117 rm config/$config/lock.pid
118 exit 0
121 if [ ! -f src/bash/luabash.??* ]; then
122 echo "Building src/bash/luabash"
123 j="$(nproc 2>/dev/null)"
124 make -j${j:-1} --no-print-directory -C misc/luabash \
125 X_OUTARCH=$PWD/src ${HOSTCC:+CC=$HOSTCC} ${HOSTCC:+LD=ld}
126 unset j
129 if [ ! -f src/bash/luabash.??* ]; then
130 echo "Error building the Lua bash accelerator"
131 exit 1
134 if ! enable -f $PWD/src/bash/luabash.??* luabash; then
135 echo "Error enabling the Lua bash accelerator: bash built with plugin support?"
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 -O2 -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=""
171 export SDECFG_ARCH="$arch" SDECFG_KERNEL="linux" SDECFG_EXPERT=0
172 menu_this=0 menu_current=0 menu_counter=0
173 menu_stack=x menu_back=-1 menu_backpos=-1
175 configtitle="$(printf ' %-50s %6s active packages ]' \
176 "T2 $sdever Configuration - $config" \
177 "[ $(echo `grep '^X' config/$config/packages | wc -l`)")"
179 bprof main stop
181 . config/$config/config
182 bprof main start
184 rm -f $cfgtmpdir/config.{dialog,data,help}
185 touch $cfgtmpdir/config.{dialog,data,help}
186 echo -e "#\n# T2 $sdever Config File\n#" > config/$config/config
187 spacer="" expert=0 tabspace="5" tabspace_list=""
188 commentnr=0 editfilenr=0
190 bprof mkpkglist start
191 cmd="scripts/Create-PkgList $SDECFG_ARCH $SDECFG_KERNEL"
192 if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ]; then
193 $cmd | tee $cfgtmpdir/config.pcache.data > config/$config/packages
194 echo "$cmd" > $cfgtmpdir/config.pcache.cmd
195 else
196 cat $cfgtmpdir/config.pcache.data > config/$config/packages
198 bprof mkpkglist stop
200 # Create lists of .in files
201 create_dot_in_lists
203 export SDECFG_ID="$sdever"; pkgin; . scripts/config.in; pkgout
204 echo "export SDECFG_ID='$SDECFG_ID'" >> config/$config/config
205 rm -f $cfgtmpdir/*.tmp
207 cut -f1,2,4,5,8- -d' ' config/$config/packages | sed 's, [^ ]*$,,' | \
208 tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
210 configtitle="$(printf ' %-50s %6s active packages ]' \
211 "T2 $sdever Configuration - $config" \
212 "[ $(echo `grep '^X' config/$config/packages | wc -l`)")"
214 bprof main stop
216 if [ -z "$oldconfig" ]; then
217 eval "src/confdialog.bin --title 'Build Config' \
218 --backtitle '$configtitle' \
219 --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
220 $(($lines - 4)) $(($columns - 5)) $(($lines - 12)) \
221 '$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
222 returncode=$? item="$(< $cfgtmpdir/config.out)"
223 else
224 returncode=1
227 bprof main start
229 [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
231 case "$returncode" in
232 0|6)
233 command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
234 { echo -e "\n# Remember menu position:\ncurrent='$item'"
235 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
236 echo -e "\n# Execute this config command:\n$command"
237 } >> config/$config/config
239 menu-back)
240 { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
241 echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
242 } >> config/$config/config
244 1|255)
245 rm -rf $cfgtmpdir
246 echo "New config written to: config/$config/"
247 bprof main stop
248 bprof_print
249 exit 1 ;;
251 tempitem=$item
252 item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
253 { echo -e "\n# Remember menu position:\ncurrent='$item'"
254 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
255 } >> config/$config/config
257 get_help $item > $cfgtmpdir/config.dialog
259 bprof main stop
260 src/confdialog.bin --title 'T2 Config - Help' \
261 --backtitle "T2 $sdever Configuration" \
262 --textbox $cfgtmpdir/config.dialog \
263 $(($lines - 4)) $(($columns - 5))
264 bprof main start
267 echo "unknown returncode: $returncode"
268 bprof main stop
269 bprof_print
270 exit 1 ;;
271 esac
273 bprof main stop
274 bprof_print
276 exit 0