3 # This script is used to configure an Aversive project. It is mainly
4 # coming from the Linux Kernel Configure script. Thanks to the authors.
9 # Make sure we're really running bash.
11 # I would really have preferred to write this script in a language with
12 # better string handling, but alas, bash is the only scripting language
13 # that I can be reasonable sure everybody has on their linux machine.
15 [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
17 # Disable filename globbing once and for all.
18 # Enable function cacheing.
22 # Dummy functions for use with a config.in modified for menuconf
24 function mainmenu_option () {
27 function mainmenu_name () {
35 # help prints the corresponding help text from ${HELP_FILE} to stdout
40 if [ -f ${HELP_FILE} ]
42 #first escape regexp special characters in the argument:
43 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
44 #now pick out the right help text:
45 text=$(sed -n "/^$var[ ]*\$/,\${
55 echo; echo " Sorry, no help available for this option yet.";echo
57 (echo; echo "$text") | ${PAGER:-more}
61 echo " Can't access the file ${HELP_FILE} which"
62 echo " should contain the help texts."
69 # readln reads a line into $ans.
71 # readln prompt default oldval
74 if [ "$DEFAULT" = "-d" ]; then
79 [ -z "$3" ] && echo -n "(NEW) "
80 IFS='@' read ans || exit 1
81 [ -z "$ans" ] && ans=$2
86 # comment does some pretty-printing
91 echo "*"; echo "* $1" ; echo "*"
92 (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
93 (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
97 # define_bool sets the value of a boolean argument
99 # define_bool define value
102 function define_bool () {
105 echo "$1=y" >>$CONFIG
106 echo "#define $1 1" >>$CONFIG_H
110 echo "# $1 is not set" >>$CONFIG
111 echo "#undef $1" >>$CONFIG_H
118 # bool processes a boolean argument
120 # bool question define
123 old=$(eval echo "\${$2}")
126 "y" | "m") defprompt="Y/n/?"
129 "n") defprompt="N/y/?"
133 readln "$1 ($2) [$defprompt] " "$def" "$old"
135 [yY] | [yY]es ) define_bool "$2" "y"
137 [nN] | [nN]o ) define_bool "$2" "n"
145 function dep_bool () {
149 while [ $# -gt 0 ]; do
152 define_bool "$var" "n"
164 # define_int sets the value of a integer argument
166 # define_int define value
168 function define_int () {
169 echo "$1=$2" >>$CONFIG
170 echo "#define $1 ($2)" >>$CONFIG_H
175 # int processes an integer argument with optional limits
177 # int question define default [min max]
180 old=$(eval echo "\${$2}")
182 if [ $# -gt 3 ]; then
187 if [ $# -gt 4 ]; then
193 readln "$1 ($2) [$def] " "$def" "$old"
195 if expr \( \( $ans + 0 \) \>= $min \) \& \( $ans \<= $max \) >/dev/null 2>&1 ; then
196 define_int "$2" "$ans"
205 # define_hex sets the value of a hexadecimal argument
207 # define_hex define value
209 function define_hex () {
210 echo "$1=$2" >>$CONFIG
211 echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H
216 # hex processes an hexadecimal argument
218 # hex question define default
221 old=$(eval echo "\${$2}")
225 readln "$1 ($2) [$def] " "$def" "$old"
227 if expr "$ans" : '[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then
228 define_hex "$2" "$ans"
237 # define_string sets the value of a string argument
239 # define_string define value
241 function define_string () {
242 echo "$1=\"$2\"" >>$CONFIG
243 echo "#define $1 \"$2\"" >>$CONFIG_H
248 # string processes a string argument
250 # string question define default
253 old=$(eval echo "\${$2}")
256 if [ "$old" = "?" ]; then
257 readln "$1 ($2) [$def] " "$def" ""
259 readln "$1 ($2) [$def] " "$def" "$old"
261 if [ "$ans" = "?" ]; then
267 define_string "$2" "$ans"
270 # choice processes a choice list (1-out-of-n)
272 # choice question choice-list default
274 # The choice list has a syntax of:
275 # NAME WHITESPACE VALUE { WHITESPACE NAME WHITESPACE VALUE }
276 # The user may enter any unique prefix of one of the NAMEs and
277 # choice will define VALUE as if it were a boolean option.
278 # VALUE must be in all uppercase. Normally, VALUE is of the
279 # form CONFIG_<something>. Thus, if the user selects <something>,
280 # the CPP symbol CONFIG_<something> will be defined and the
281 # shell variable CONFIG_<something> will be set to "y".
289 # determine default answer:
293 while [ -n "$2" ]; do
294 if [ -n "$names" ]; then
299 if [ "$(eval echo \"\${$2}\")" = "y" ]; then
307 while [ -z "$val" ]; do
309 readln "$question ($names) [$def] " "$def" "$old"
310 ans=$(echo $ans | tr a-z A-Z)
312 while [ -n "$1" ]; do
313 name=$(echo $1 | tr a-z A-Z)
315 "$ans"* | */"$ans"* )
317 "$ans" | */"$ans"/* | \
318 "$ans"/* | */"$ans" )
323 if [ -n "$val" ]; then
325 " Sorry, \"$ans\" is ambiguous; please enter a longer string."
336 if [ "$val" = "" -a "$ambg" = "n" ]; then
341 while [ -n "$2" ]; do
342 if [ "$2" = "$val" ]; then
353 CONFIG_H=.tmpconfig.h
354 trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
355 if [ -z "$HELP_FILE" ]
357 HELP_FILE="Documentation/Configure.help"
361 # Make sure we start out with a clean slate.
364 echo "# Automatically generated make config: don't edit" >> $CONFIG
367 echo "/*" > $CONFIG_H
368 echo " * Automatically generated C config: don't edit" >> $CONFIG_H
369 echo " */" >> $CONFIG_H
370 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
373 if [ "$1" = "-d" ] ; then
378 CONFIG_IN=./config.in
379 if [ "$1" != "" ] ; then
383 DEFAULTS=$AVERSIVE_DIR/config/.config
384 if [ -f .config ]; then
388 if [ -f $DEFAULTS ]; then
390 echo "# Using defaults found in" $DEFAULTS
393 sed -e 's/# \(CONFIG_[^ ]*\) is not.*/\1=n/' <$DEFAULTS >.config-is-not.$$
398 echo "# No defaults found"
405 if [ -f .config ]; then
406 mv .config .config.old
408 mv .tmpconfig .config
409 if [ -w "`dirname ${AUTOCONF_FILE:=include/linux/autoconf.h}`" ]; then
410 mv .tmpconfig.h ${AUTOCONF_FILE:-include/linux/autoconf.h}
413 $AVERSIVE_DIR/config/generate_aversive_config .config .aversive_conf
416 echo "*** End of Aversive project configuration."
417 echo "*** Next, you should run 'make clean, then make'."