3 # This script is used to configure BusyBox.
5 # It was inspired by the challenge in the original Configure script
6 # to ``do something better'', combined with the actual need to ``do
7 # something better'' because the old configure script wasn't flexible
10 # Raymond Chen was the original author of Configure.
11 # Michael Elizabeth Chastain (mec@shout.net) is the current maintainer.
13 # 050793 - use IFS='@' to get around a bug in a pre-version of bash-1.13
16 # 030995 (storner@osiris.ping.dk) - added support for tri-state answers,
17 # for selecting modules to compile.
19 # 180995 Bernhard Kaindl (bkaindl@ping.at) - added dummy functions for
20 # use with a config.in modified for make menuconfig.
22 # 301195 (boldt@math.ucsb.edu) - added help text support
24 # 281295 Paul Gortmaker - make tri_state functions collapse to boolean
25 # if module support is not enabled.
27 # 010296 Aaron Ucko (ucko@vax1.rockhurst.edu) - fix int and hex to accept
30 # 150296 Dick Streefland (dicks@tasking.nl) - report new configuration
31 # items and ask for a value even when doing a "make oldconfig"
33 # 200396 Tom Dyas (tdyas@eden.rutgers.edu) - when the module option is
34 # chosen for an item, define the macro <option_name>_MODULE
36 # 090397 Axel Boldt (boldt@math.ucsb.edu) - avoid ? and + in regular
37 # expressions for GNU expr since version 1.15 and up use \? and \+.
39 # 300397 Phil Blundell (pjb27@cam.ac.uk) - added support for min/max
40 # arguments to "int", allow dep_tristate to take a list of dependencies
41 # rather than just one.
43 # 090398 Axel Boldt (boldt@math.ucsb.edu) - allow for empty lines in help
46 # 102598 Michael Chastain (mec@shout.net) - put temporary files in
47 # current directory, not in /tmp.
49 # 24 January 1999, Michael Elizabeth Chastain, <mec@shout.net>
50 # - Improve the exit message (Jeff Ronne).
52 # 7 October 2000, Ghozlane Toumi, <gtoumi@messel.emse.fr>
53 # added switches for "random" , "all yes" and "all modules"
57 # Make sure we're really running bash.
59 # I would really have preferred to write this script in a language with
60 # better string handling, but alas, bash is the only scripting language
61 # that I can be reasonable sure everybody has on their linux machine.
63 [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
65 # Disable filename globbing once and for all.
66 # Enable function cacheing.
70 # Dummy functions for use with a config.in modified for menuconf
72 function mainmenu_option () {
75 function mainmenu_name () {
83 # returns a random number between 1 and $1
86 rnd=$[ $RANDOM % $1 + 1 ]
90 # randomly chose a number in a config list (LIST_CONFIG_NAME)
91 # or in a range ( MIN_CONFIG_NAME MAX_CONFIG_NAME )
92 # ONLY if there is no forced default (and we are in an "auto" mode)
93 # we are limited by the range of values taken by "$RANDOM"
99 [ "$AUTO" != "yes" -o -n "$old" ] && return
100 def_list=$(eval echo "\${LIST_$1}")
101 def_min=$(eval echo "\${MIN_$1}")
102 def_max=$(eval echo "\${MAX_$1}")
104 if [ -n "$def_list" ]; then
105 set -- $(echo $def_list | sed 's/,/ /g')
107 while [ $rnd -le $# ] ; do
113 if [ -n "$def_min" -a -n "$def_max" ]; then
114 rnd $[ $def_max - $def_min ]
115 def=$[ $def_min + $rnd ]
120 # help prints the corresponding help text from Configure.help to stdout
125 if [ -f docs/Configure.help ]
127 #first escape regexp special characters in the argument:
128 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
129 #now pick out the right help text:
130 text=$(sed -n "/^$var[ ]*\$/,\${
136 /<file:\\([^>]*\\)>/s//\\1/g
138 }" docs/Configure.help)
141 echo; echo " Sorry, no help available for this option yet.";echo
143 (echo; echo "$text") | ${PAGER:-more}
147 echo " Can't access the file docs/Configure.help which"
148 echo " should contain the help texts."
155 # readln reads a line into $ans.
157 # readln prompt default oldval
160 if [ "$AUTO" = "yes" ]; then
164 elif [ "$DEFAULT" = "-d" -a -n "$3" ]; then
169 [ -z "$3" ] && echo -n "(NEW) "
170 IFS='@' read ans || exit 1
171 [ -z "$ans" ] && ans=$2
176 # comment does some pretty-printing
180 function comment () {
181 echo "*"; echo "* $1" ; echo "*"
182 (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
183 (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
187 # define_bool sets the value of a boolean argument
189 # define_bool define value
191 function define_bool () {
192 define_tristate $1 $2
195 function define_tristate () {
198 echo "$1=y" >>$CONFIG
199 echo "#define $1 1" >>$CONFIG_H
203 echo "$1=m" >>$CONFIG
204 echo "#undef $1" >>$CONFIG_H
205 echo "#define $1_MODULE 1" >>$CONFIG_H
209 echo "# $1 is not set" >>$CONFIG
210 echo "#undef $1" >>$CONFIG_H
217 # bool processes a boolean argument
219 # bool question define
222 old=$(eval echo "\${$2}")
224 if [ "$AUTO" = "yes" -a -z "$old" ]; then
225 if [ "$RND" = "-r" ]; then
236 "y" | "m") defprompt="Y/n/?"
239 "n") defprompt="N/y/?"
243 readln "$1 ($2) [$defprompt] " "$def" "$old"
245 [yY] | [yY]es ) define_bool "$2" "y"
247 [nN] | [nN]o ) define_bool "$2" "n"
256 # tristate processes a tristate argument
258 # tristate question define
260 function tristate () {
261 if [ "$CONFIG_MODULES" != "y" ]; then
264 old=$(eval echo "\${$2}")
266 if [ "$AUTO" = "yes" -a -z "$old" ]; then
267 if [ "$RND" = "-r" ]; then
279 "y") defprompt="Y/m/n/?"
281 "m") defprompt="M/n/y/?"
283 "n") defprompt="N/y/m/?"
287 readln "$1 ($2) [$defprompt] " "$def" "$old"
289 [yY] | [yY]es ) define_tristate "$2" "y"
291 [nN] | [nN]o ) define_tristate "$2" "n"
293 [mM] ) define_tristate "$2" "m"
303 # dep_tristate processes a tristate argument that depends upon
304 # another option or options. If any of the options we depend upon is a
305 # module, then the only allowable options are M or N. If all are Y, then
306 # this is a normal tristate. This is used in cases where modules
307 # are nested, and one module requires the presence of something
308 # else in the kernel.
310 # dep_tristate question define default ...
312 function dep_tristate () {
313 old=$(eval echo "\${$2}")
319 while [ $# -gt 0 ]; do
322 define_tristate "$var" "n"
332 if [ $need_module = 1 ]; then
333 if [ "$CONFIG_MODULES" = "y" ]; then
334 if [ "$AUTO" = "yes" -a -z "$old" ]; then
335 if [ "$RND" = "-r" ]; then
346 "y" | "m") defprompt="M/n/?"
349 "n") defprompt="N/m/?"
353 readln "$ques ($var) [$defprompt] " "$def" "$old"
355 [nN] | [nN]o ) define_tristate "$var" "n"
357 [mM] ) define_tristate "$var" "m"
360 echo " This answer is not allowed, because it is not consistent with"
361 echo " your other choices."
362 echo " This driver depends on another one which you chose to compile"
363 echo " as a module. This means that you can either compile this one"
364 echo " as a module as well (with M) or leave it out altogether (N)."
373 tristate "$ques" "$var"
377 function dep_bool () {
381 while [ $# -gt 0 ]; do
384 define_bool "$var" "n"
394 function dep_mbool () {
398 while [ $# -gt 0 ]; do
401 define_bool "$var" "n"
412 # define_int sets the value of a integer argument
414 # define_int define value
416 function define_int () {
417 echo "$1=$2" >>$CONFIG
418 echo "#define $1 ($2)" >>$CONFIG_H
423 # int processes an integer argument with optional limits
425 # int question define default [min max]
428 old=$(eval echo "\${$2}")
430 if [ $# -gt 3 ]; then
435 if [ $# -gt 4 ]; then
442 readln "$1 ($2) [$def] " "$def" "$old"
443 if expr \( \( $ans + 0 \) \>= $min \) \& \( $ans \<= $max \) >/dev/null 2>&1 ; then
444 define_int "$2" "$ans"
453 # define_hex sets the value of a hexadecimal argument
455 # define_hex define value
457 function define_hex () {
458 echo "$1=$2" >>$CONFIG
459 echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H
464 # hex processes an hexadecimal argument
466 # hex question define default
469 old=$(eval echo "\${$2}")
474 readln "$1 ($2) [$def] " "$def" "$old"
476 if expr "$ans" : '[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then
477 define_hex "$2" "$ans"
486 # define_string sets the value of a string argument
488 # define_string define value
490 function define_string () {
491 echo "$1=\"$2\"" >>$CONFIG
492 echo "#define $1 \"$2\"" >>$CONFIG_H
497 # string processes a string argument
499 # string question define default
502 old=$(eval echo "\${$2}")
505 if [ "$old" = "?" ]; then
506 readln "$1 ($2) [$def] " "$def" ""
508 readln "$1 ($2) [$def] " "$def" "$old"
510 if [ "$ans" = "?" ]; then
516 define_string "$2" "$ans"
519 # choice processes a choice list (1-out-of-n)
521 # choice question choice-list default
523 # The choice list has a syntax of:
524 # NAME WHITESPACE VALUE { WHITESPACE NAME WHITESPACE VALUE }
525 # The user may enter any unique prefix of one of the NAMEs and
526 # choice will define VALUE as if it were a boolean option.
527 # VALUE must be in all uppercase. Normally, VALUE is of the
528 # form CONFIG_<something>. Thus, if the user selects <something>,
529 # the CPP symbol CONFIG_<something> will be defined and the
530 # shell variable CONFIG_<something> will be set to "y".
538 # determine default answer:
542 while [ -n "$2" ]; do
543 if [ -n "$names" ]; then
548 if [ "$(eval echo \"\${$2}\")" = "y" ]; then
555 if [ "$RND" = "-r" -a -z "$old" ] ; then
558 while [ $rnd -le $# ] ; do
565 while [ -z "$val" ]; do
567 readln "$question ($names) [$def] " "$def" "$old"
568 ans=$(echo $ans | tr a-z A-Z)
570 while [ -n "$1" ]; do
571 name=$(echo $1 | tr a-z A-Z)
573 "$ans"* | */"$ans"* )
575 "$ans" | */"$ans"/* | \
576 "$ans"/* | */"$ans" )
581 if [ -n "$val" ]; then
583 " Sorry, \"$ans\" is ambiguous; please enter a longer string."
594 if [ "$val" = "" -a "$ambg" = "n" ]; then
599 while [ -n "$2" ]; do
600 if [ "$2" = "$val" ]; then
611 CONFIG_H=.tmpconfig.h
612 FORCE_DEFAULT=.force_default
613 trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
616 # Make sure we start out with a clean slate.
619 echo "# Automatically generated make config: don't edit" >> $CONFIG
622 echo "/*" > $CONFIG_H
623 echo " * Automatically generated C config: don't edit" >> $CONFIG_H
624 echo " */" >> $CONFIG_H
625 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
628 if [ "$1" = "-d" ] ; then
637 -r) RND="-r" ; AUTO="yes" ; shift ;;
638 -y) DEF_ANS="y" ; AUTO="yes" ; shift ;;
639 -m) DEF_ANS="m" ; AUTO="yes" ; shift ;;
640 -n) DEF_ANS="n" ; AUTO="yes" ; shift ;;
643 CONFIG_IN=./config.in
644 if [ "$1" != "" ] ; then
648 DEFAULTS=sysdeps/$TARGET_OS/defconfig
649 if [ -f .config ]; then
653 if [ "$AUTO" != "yes" ]; then
654 if [ -f $DEFAULTS ]; then
656 echo "# Using defaults found in" $DEFAULTS
659 sed -e 's/# \(CONFIG_[^ ]*\) is not.*/\1=n/' <$DEFAULTS >.config-is-not.$$
664 echo "# No defaults found"
668 if [ -f $FORCE_DEFAULT ]; then
670 echo "# Forcing defaults found in $FORCE_DEFAULT"
673 s/# \(CONFIG_[^ ]*\) is not.*/\1=n/;
674 s/# range \(CONFIG_[^ ]*\) \([^ ][^ ]*\) \([^ ][^ ]*\)/MIN_\1=\2; MAX_\1=\3/;
675 s/# list \(CONFIG_[^ ]*\) \([^ ][^ ]*\)/LIST_\1=\2/
676 ' <$FORCE_DEFAULT >.default_val.$$
681 echo "# No defaults found"
689 if [ -f .config ]; then
690 mv .config .config.old
692 mv .tmpconfig .config
693 mv .tmpconfig.h include/config.h
696 echo "*** End of BusyBox configuration."
697 echo "*** Check the top-level Makefile for additional configuration."
698 if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then
699 echo "*** Next, you must run 'make dep'."
701 echo "*** Next, you may run 'make', or 'make install'."