Import 2.2.2pre5
[davej-history.git] / scripts / Configure
blob80eefc7e1e03eb675d5c72dd85c10e99775ace0c
1 #! /bin/sh
3 # This script is used to configure the Linux kernel.
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
8 # enough.
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
14 # with an empty IFS.
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
28 # arbitrary ranges
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
44 # texts.
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).
53 # Make sure we're really running bash.
55 # I would really have preferred to write this script in a language with
56 # better string handling, but alas, bash is the only scripting language
57 # that I can be reasonable sure everybody has on their linux machine.
59 [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
61 # Disable filename globbing once and for all.
62 # Enable function cacheing.
63 set -f -h
66 # Dummy functions for use with a config.in modified for menuconf
68 function mainmenu_option () {
71 function mainmenu_name () {
74 function endmenu () {
79 # help prints the corresponding help text from Configure.help to stdout
81 # help variable
83 function help () {
84 if [ -f Documentation/Configure.help ]
85 then
86 #first escape regexp special characters in the argument:
87 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
88 #now pick out the right help text:
89 text=$(sed -n "/^$var[ ]*\$/,\${
90 /^$var[ ]*\$/c\\
91 ${var}:\\
93 /^#/b
94 /^[^ ]/q
96 }" Documentation/Configure.help)
97 if [ -z "$text" ]
98 then
99 echo; echo " Sorry, no help available for this option yet.";echo
100 else
101 (echo; echo "$text") | ${PAGER:-more}
103 else
104 echo;
105 echo " Can't access the file Documentation/Configure.help which"
106 echo " should contain the help texts."
107 echo
113 # readln reads a line into $ans.
115 # readln prompt default oldval
117 function readln () {
118 if [ "$DEFAULT" = "-d" -a -n "$3" ]; then
119 echo "$1"
120 ans=$2
121 else
122 echo -n "$1"
123 [ -z "$3" ] && echo -n "(NEW) "
124 IFS='@' read ans || exit 1
125 [ -z "$ans" ] && ans=$2
130 # comment does some pretty-printing
132 # comment 'xxx'
134 function comment () {
135 echo "*"; echo "* $1" ; echo "*"
136 (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
137 (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
141 # define_bool sets the value of a boolean argument
143 # define_bool define value
145 function define_bool () {
146 case "$2" in
147 "y")
148 echo "$1=y" >>$CONFIG
149 echo "#define $1 1" >>$CONFIG_H
152 "m")
153 echo "$1=m" >>$CONFIG
154 echo "#undef $1" >>$CONFIG_H
155 echo "#define $1_MODULE 1" >>$CONFIG_H
158 "n")
159 echo "# $1 is not set" >>$CONFIG
160 echo "#undef $1" >>$CONFIG_H
162 esac
163 eval "$1=$2"
167 # bool processes a boolean argument
169 # bool question define
171 function bool () {
172 old=$(eval echo "\${$2}")
173 def=${old:-'n'}
174 case "$def" in
175 "y" | "m") defprompt="Y/n/?"
176 def="y"
178 "n") defprompt="N/y/?"
180 esac
181 while :; do
182 readln "$1 ($2) [$defprompt] " "$def" "$old"
183 case "$ans" in
184 [yY] | [yY]es ) define_bool "$2" "y"
185 break;;
186 [nN] | [nN]o ) define_bool "$2" "n"
187 break;;
188 * ) help "$2"
190 esac
191 done
195 # tristate processes a tristate argument
197 # tristate question define
199 function tristate () {
200 if [ "$CONFIG_MODULES" != "y" ]; then
201 bool "$1" "$2"
202 else
203 old=$(eval echo "\${$2}")
204 def=${old:-'n'}
205 case "$def" in
206 "y") defprompt="Y/m/n/?"
208 "m") defprompt="M/n/y/?"
210 "n") defprompt="N/y/m/?"
212 esac
213 while :; do
214 readln "$1 ($2) [$defprompt] " "$def" "$old"
215 case "$ans" in
216 [yY] | [yY]es ) define_bool "$2" "y"
217 break ;;
218 [nN] | [nN]o ) define_bool "$2" "n"
219 break ;;
220 [mM] ) define_bool "$2" "m"
221 break ;;
222 * ) help "$2"
224 esac
225 done
230 # dep_tristate processes a tristate argument that depends upon
231 # another option or options. If any of the options we depend upon is a
232 # module, then the only allowable options are M or N. If all are Y, then
233 # this is a normal tristate. This is used in cases where modules
234 # are nested, and one module requires the presence of something
235 # else in the kernel.
237 # dep_tristate question define default ...
239 function dep_tristate () {
240 old=$(eval echo "\${$2}")
241 def=${old:-'n'}
242 ques=$1
243 var=$2
244 need_module=0
245 shift 2
246 while [ $# -gt 0 ]; do
247 case "$1" in
249 define_bool "$var" "n"
250 return
253 need_module=1
255 esac
256 shift
257 done
259 if [ $need_module = 1 ]; then
260 if [ "$CONFIG_MODULES" = "y" ]; then
261 case "$def" in
262 "y" | "m") defprompt="M/n/?"
263 def="m"
265 "n") defprompt="N/m/?"
267 esac
268 while :; do
269 readln "$ques ($var) [$defprompt] " "$def" "$old"
270 case "$ans" in
271 [nN] | [nN]o ) define_bool "$var" "n"
272 break ;;
273 [mM] ) define_bool "$var" "m"
274 break ;;
275 [yY] | [yY]es ) echo
276 echo " This answer is not allowed, because it is not consistent with"
277 echo " your other choices."
278 echo " This driver depends on another one which you chose to compile"
279 echo " as a module. This means that you can either compile this one"
280 echo " as a module as well (with M) or leave it out altogether (N)."
281 echo
283 * ) help "$var"
285 esac
286 done
288 else
289 tristate "$ques" "$var"
294 # define_int sets the value of a integer argument
296 # define_int define value
298 function define_int () {
299 echo "$1=$2" >>$CONFIG
300 echo "#define $1 ($2)" >>$CONFIG_H
301 eval "$1=$2"
305 # int processes an integer argument with optional limits
307 # int question define default [min max]
309 function int () {
310 old=$(eval echo "\${$2}")
311 def=${old:-$3}
312 if [ $# -gt 3 ]; then
313 min=$4
314 else
315 min=-10000000 # !!
317 if [ $# -gt 4 ]; then
318 max=$5
319 else
320 max=10000000 # !!
322 while :; do
323 readln "$1 ($2) [$def] " "$def" "$old"
324 if expr \( \( $ans + 0 \) \>= $min \) \& \( $ans \<= $max \) >/dev/null 2>&1 ; then
325 define_int "$2" "$ans"
326 break
327 else
328 help "$2"
330 done
334 # define_hex sets the value of a hexadecimal argument
336 # define_hex define value
338 function define_hex () {
339 echo "$1=$2" >>$CONFIG
340 echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H
341 eval "$1=$2"
345 # hex processes an hexadecimal argument
347 # hex question define default
349 function hex () {
350 old=$(eval echo "\${$2}")
351 def=${old:-$3}
352 def=${def#*[x,X]}
353 while :; do
354 readln "$1 ($2) [$def] " "$def" "$old"
355 ans=${ans#*[x,X]}
356 if expr "$ans" : '[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then
357 define_hex "$2" "$ans"
358 break
359 else
360 help "$2"
362 done
366 # define_string sets the value of a string argument
368 # define_string define value
370 function define_string () {
371 echo "$1="'"'$2'"' >>$CONFIG
372 echo "#define $1 "'"'$2'"' >>$CONFIG_H
373 eval "$1=$2"
377 # string processes a string argument
379 # string question define default
381 function string () {
382 old=$(eval echo "\${$2}")
383 def=${old:-$3}
384 readln "$1 ($2) [$def] " "$def" "$old"
385 define_string "$2" "$ans"
388 # choice processes a choice list (1-out-of-n)
390 # choice question choice-list default
392 # The choice list has a syntax of:
393 # NAME WHITESPACE VALUE { WHITESPACE NAME WHITESPACE VALUE }
394 # The user may enter any unique prefix of one of the NAMEs and
395 # choice will define VALUE as if it were a boolean option.
396 # VALUE must be in all uppercase. Normally, VALUE is of the
397 # form CONFIG_<something>. Thus, if the user selects <something>,
398 # the CPP symbol CONFIG_<something> will be defined and the
399 # shell variable CONFIG_<something> will be set to "y".
401 function choice () {
402 question="$1"
403 choices="$2"
404 old=
405 def=$3
407 # determine default answer:
408 names=""
409 set -- $choices
410 firstvar=$2
411 while [ -n "$2" ]; do
412 if [ -n "$names" ]; then
413 names="$names, $1"
414 else
415 names="$1"
417 if [ "$(eval echo \"\${$2}\")" = "y" ]; then
418 old=$1
419 def=$1
421 shift; shift
422 done
424 val=""
425 while [ -z "$val" ]; do
426 ambg=n
427 readln "$question ($names) [$def] " "$def" "$old"
428 ans=$(echo $ans | tr a-z A-Z)
429 set -- $choices
430 while [ -n "$1" ]; do
431 name=$(echo $1 | tr a-z A-Z)
432 case "$name" in
433 "$ans"* )
434 if [ "$name" = "$ans" ]; then
435 val="$2"
436 break # stop on exact match
438 if [ -n "$val" ]; then
439 echo;echo \
440 " Sorry, \"$ans\" is ambiguous; please enter a longer string."
441 echo
442 val=""
443 ambg=y
444 break
445 else
446 val="$2"
447 fi;;
448 esac
449 shift; shift
450 done
451 if [ "$val" = "" -a "$ambg" = "n" ]; then
452 help "$firstvar"
454 done
455 set -- $choices
456 while [ -n "$2" ]; do
457 if [ "$2" = "$val" ]; then
458 echo " defined $val"
459 define_bool "$2" "y"
460 else
461 define_bool "$2" "n"
463 shift; shift
464 done
467 CONFIG=.tmpconfig
468 CONFIG_H=.tmpconfig.h
469 trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
472 # Make sure we start out with a clean slate.
474 echo "#" > $CONFIG
475 echo "# Automatically generated make config: don't edit" >> $CONFIG
476 echo "#" >> $CONFIG
478 echo "/*" > $CONFIG_H
479 echo " * Automatically generated C config: don't edit" >> $CONFIG_H
480 echo " */" >> $CONFIG_H
481 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
483 DEFAULT=""
484 if [ "$1" = "-d" ] ; then
485 DEFAULT="-d"
486 shift
489 CONFIG_IN=./config.in
490 if [ "$1" != "" ] ; then
491 CONFIG_IN=$1
494 DEFAULTS=arch/$ARCH/defconfig
495 if [ -f .config ]; then
496 DEFAULTS=.config
499 if [ -f $DEFAULTS ]; then
500 echo "#"
501 echo "# Using defaults found in" $DEFAULTS
502 echo "#"
503 . $DEFAULTS
504 sed -e 's/# \(.*\) is not.*/\1=n/' < $DEFAULTS > .config-is-not.$$
505 . .config-is-not.$$
506 rm .config-is-not.$$
507 else
508 echo "#"
509 echo "# No defaults found"
510 echo "#"
513 . $CONFIG_IN
515 rm -f .config.old
516 if [ -f .config ]; then
517 mv .config .config.old
519 mv .tmpconfig .config
520 mv .tmpconfig.h include/linux/autoconf.h
522 echo
523 echo "*** End of Linux kernel configuration."
524 echo "*** Check the top-level Makefile for additional configuration."
525 if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then
526 echo "*** Next, you must run 'make dep'."
527 else
528 echo "*** Next, you may run 'make zImage', 'make zdisk', or 'make zlilo'."
530 echo
532 exit 0