port more changes to make PCI work
[linux-2.4.git] / scripts / Configure
1 #! /bin/sh
2 #
3 # This script is used to configure the Linux kernel.
4 #
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.
9 #
10 # Raymond Chen was the original author of Configure.
11 # Michael Elizabeth Chastain (mec@shout.net) is the current maintainer.
12 #
13 # 050793 - use IFS='@' to get around a bug in a pre-version of bash-1.13
14 # with an empty IFS.
15 #
16 # 030995 (storner@osiris.ping.dk) - added support for tri-state answers,
17 # for selecting modules to compile.
18 #
19 # 180995 Bernhard Kaindl (bkaindl@ping.at) - added dummy functions for
20 # use with a config.in modified for make menuconfig.
21 #
22 # 301195 (boldt@math.ucsb.edu) - added help text support
23 #
24 # 281295 Paul Gortmaker - make tri_state functions collapse to boolean
25 # if module support is not enabled.
26 #
27 # 010296 Aaron Ucko (ucko@vax1.rockhurst.edu) - fix int and hex to accept
28 # arbitrary ranges
29 #
30 # 150296 Dick Streefland (dicks@tasking.nl) - report new configuration
31 # items and ask for a value even when doing a "make oldconfig"
32 #
33 # 200396 Tom Dyas (tdyas@eden.rutgers.edu) - when the module option is
34 # chosen for an item, define the macro <option_name>_MODULE
35 #
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 \+.
38 #
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.
42 #
43 # 090398 Axel Boldt (boldt@math.ucsb.edu) - allow for empty lines in help
44 # texts.
45 #
46 # 102598 Michael Chastain (mec@shout.net) - put temporary files in
47 # current directory, not in /tmp.
48 #
49 # 24 January 1999, Michael Elizabeth Chastain, <mec@shout.net>
50 # - Improve the exit message (Jeff Ronne).
51
52 #
53 # Make sure we're really running bash.
54 #
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.
58 #
59 [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
60
61 # Disable filename globbing once and for all.
62 # Enable function cacheing.
63 set -f -h
64
65 #
66 # Dummy functions for use with a config.in modified for menuconf
67 #
68 function mainmenu_option () {
69         :
70 }
71 function mainmenu_name () {
72         :
73 }
74 function endmenu () {
75         :
76 }
77
78 #
79 # help prints the corresponding help text from Configure.help to stdout
80 #
81 #       help variable
82 #
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}:\\
92
93                         /^#/b
94                         /^[^    ]/q
95                         /<file:\\([^>]*\\)>/s//\\1/g
96                         p
97                     }" Documentation/Configure.help)
98      if [ -z "$text" ]
99      then
100           echo; echo "  Sorry, no help available for this option yet.";echo
101      else
102           (echo; echo "$text") | ${PAGER:-more}
103      fi
104   else
105      echo;
106      echo "  Can't access the file Documentation/Configure.help which"
107      echo "  should contain the help texts."
108      echo
109   fi
110 }
111
112
113 #
114 # readln reads a line into $ans.
115 #
116 #       readln prompt default oldval
117 #
118 function readln () {
119         if [ "$DEFAULT" = "-d" -a -n "$3" ]; then
120                 echo "$1"
121                 ans=$2
122         else
123                 echo -n "$1"
124                 [ -z "$3" ] && echo -n "(NEW) "
125                 IFS='@' read ans || exit 1
126                 [ -z "$ans" ] && ans=$2
127         fi
128 }
129
130 #
131 # comment does some pretty-printing
132 #
133 #       comment 'xxx'
134
135 function comment () {
136         echo "*"; echo "* $1" ; echo "*"
137         (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
138         (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
139 }
140
141 #
142 # define_bool sets the value of a boolean argument
143 #
144 #       define_bool define value
145 #
146 function define_bool () {
147         define_tristate $1 $2
148 }
149
150 function define_tristate () {
151         case "$2" in
152          "y")
153                 echo "$1=y" >>$CONFIG
154                 echo "#define $1 1" >>$CONFIG_H
155                 ;;
156
157          "m")
158                 echo "$1=m" >>$CONFIG
159                 echo "#undef  $1" >>$CONFIG_H
160                 echo "#define $1_MODULE 1" >>$CONFIG_H
161                 ;;
162
163          "n")
164                 echo "# $1 is not set" >>$CONFIG
165                 echo "#undef  $1" >>$CONFIG_H
166                 ;;
167         esac
168         eval "$1=$2"
169 }
170
171 #
172 # bool processes a boolean argument
173 #
174 #       bool question define
175 #
176 function bool () {
177         old=$(eval echo "\${$2}")
178         def=${old:-'n'}
179         case "$def" in
180          "y" | "m") defprompt="Y/n/?"
181               def="y"
182               ;;
183          "n") defprompt="N/y/?"
184               ;;
185         esac
186         while :; do
187           readln "$1 ($2) [$defprompt] " "$def" "$old"
188           case "$ans" in
189             [yY] | [yY]es ) define_bool "$2" "y"
190                             break;;
191             [nN] | [nN]o )  define_bool "$2" "n"
192                             break;;
193             * )             help "$2"
194                             ;;
195           esac
196         done
197 }
198
199 #
200 # tristate processes a tristate argument
201 #
202 #       tristate question define
203 #
204 function tristate () {
205         if [ "$CONFIG_MODULES" != "y" ]; then
206           bool "$1" "$2"
207         else 
208           old=$(eval echo "\${$2}")
209           def=${old:-'n'}
210           case "$def" in
211            "y") defprompt="Y/m/n/?"
212                 ;;
213            "m") defprompt="M/n/y/?"
214                 ;;
215            "n") defprompt="N/y/m/?"
216                 ;;
217           esac
218           while :; do
219             readln "$1 ($2) [$defprompt] " "$def" "$old"
220             case "$ans" in
221               [yY] | [yY]es ) define_tristate "$2" "y"
222                               break ;;
223               [nN] | [nN]o )  define_tristate "$2" "n"
224                               break ;;
225               [mM] )          define_tristate "$2" "m"
226                               break ;;
227               * )             help "$2"
228                               ;;
229             esac
230           done
231         fi
232 }
233
234 #
235 # dep_tristate processes a tristate argument that depends upon
236 # another option or options.  If any of the options we depend upon is a
237 # module, then the only allowable options are M or N.  If all are Y, then
238 # this is a normal tristate.  This is used in cases where modules
239 # are nested, and one module requires the presence of something
240 # else in the kernel.
241 #
242 #       dep_tristate question define default ...
243 #
244 function dep_tristate () {
245         old=$(eval echo "\${$2}")
246         def=${old:-'n'}
247         ques=$1
248         var=$2
249         need_module=0
250         shift 2
251         while [ $# -gt 0 ]; do
252           case "$1" in
253             n)
254               define_tristate "$var" "n"
255               return
256               ;;
257             m)
258               need_module=1
259               ;;
260           esac
261           shift
262         done
263
264         if [ $need_module = 1 ]; then
265            if [ "$CONFIG_MODULES" = "y" ]; then
266                 case "$def" in
267                  "y" | "m") defprompt="M/n/?"
268                       def="m"
269                       ;;
270                  "n") defprompt="N/m/?"
271                       ;;
272                 esac
273                 while :; do
274                   readln "$ques ($var) [$defprompt] " "$def" "$old"
275                   case "$ans" in
276                       [nN] | [nN]o )  define_tristate "$var" "n"
277                                       break ;;
278                       [mM] )          define_tristate "$var" "m"
279                                       break ;;
280                       [yY] | [yY]es ) echo 
281    echo "  This answer is not allowed, because it is not consistent with"
282    echo "  your other choices."
283    echo "  This driver depends on another one which you chose to compile"
284    echo "  as a module. This means that you can either compile this one"
285    echo "  as a module as well (with M) or leave it out altogether (N)."
286                                       echo
287                                       ;;
288                       * )             help "$var"
289                                       ;;
290                   esac
291                 done
292            fi
293         else
294            tristate "$ques" "$var"
295         fi
296 }
297
298 function dep_bool () {
299         ques=$1
300         var=$2
301         shift 2
302         while [ $# -gt 0 ]; do
303           case "$1" in
304             m | n)
305               define_bool "$var" "n"
306               return
307               ;;
308           esac
309           shift
310         done
311
312         bool "$ques" "$var"
313 }
314
315 function dep_mbool () {
316         ques=$1
317         var=$2
318         shift 2
319         while [ $# -gt 0 ]; do
320           case "$1" in
321             n)
322               define_bool "$var" "n"
323               return
324               ;;
325           esac
326           shift
327         done
328
329         bool "$ques" "$var"
330 }
331
332 #
333 # define_int sets the value of a integer argument
334 #
335 #       define_int define value
336 #
337 function define_int () {
338         echo "$1=$2" >>$CONFIG
339         echo "#define $1 ($2)" >>$CONFIG_H
340         eval "$1=$2"
341 }
342
343 #
344 # int processes an integer argument with optional limits
345 #
346 #       int question define default
347 #
348 function int () {
349         old=$(eval echo "\${$2}")
350         def=${old:-$3}
351         while :; do
352           readln "$1 ($2) [$def] " "$def" "$old"
353           if expr "$ans" : '[0-9]*$' > /dev/null; then
354             define_int "$2" "$ans"
355             break
356           else
357             help "$2"
358           fi
359         done
360 }
361
362 #
363 # define_hex sets the value of a hexadecimal argument
364 #
365 #       define_hex define value
366 #
367 function define_hex () {
368         echo "$1=$2" >>$CONFIG
369         echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H
370         eval "$1=$2"
371 }
372
373 #
374 # hex processes an hexadecimal argument
375 #
376 #       hex question define default
377 #
378 function hex () {
379         old=$(eval echo "\${$2}")
380         def=${old:-$3}
381         while :; do
382           readln "$1 ($2) [$def] " "$def" "$old"
383           if expr "$ans" : '0x[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then
384             define_hex "$2" "$ans"
385             break
386           else
387             if expr "$ans" : '[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then
388               define_hex "$2" "0x$ans"
389               break
390             else
391               help "$2"
392             fi
393           fi
394         done
395 }
396
397 #
398 # define_string sets the value of a string argument
399 #
400 #       define_string define value
401 #
402 function define_string () {
403         echo "$1=\"$2\"" >>$CONFIG
404         echo "#define $1 \"$2\"" >>$CONFIG_H
405         eval "$1=\"$2\""
406 }
407
408 #
409 # string processes a string argument
410 #
411 #       string question define default
412 #
413 function string () {
414         old=$(eval echo "\${$2}")
415         def=${old:-$3}
416         while :; do
417           if [ "$old" = "?" ]; then
418              readln "$1 ($2) [$def] " "$def" ""
419           else
420              readln "$1 ($2) [$def] " "$def" "$old"
421           fi
422           if [ "$ans" = "?" ]; then
423             help "$2"
424           else
425             break
426           fi
427         done
428         define_string "$2" "$ans"
429 }
430 #
431 # choice processes a choice list (1-out-of-n)
432 #
433 #       choice question choice-list default
434 #
435 # The choice list has a syntax of:
436 #       NAME WHITESPACE VALUE { WHITESPACE NAME WHITESPACE VALUE }
437 # The user may enter any unique prefix of one of the NAMEs and
438 # choice will define VALUE as if it were a boolean option.
439 # VALUE must be in all uppercase.  Normally, VALUE is of the
440 # form CONFIG_<something>.  Thus, if the user selects <something>,
441 # the CPP symbol CONFIG_<something> will be defined and the
442 # shell variable CONFIG_<something> will be set to "y".
443 #
444 function choice () {
445         question="$1"
446         choices="$2"
447         old=
448         def=$3
449
450         # determine default answer:
451         names=""
452         set -- $choices
453         firstvar=$2
454         while [ -n "$2" ]; do
455                 if [ -n "$names" ]; then
456                         names="$names, $1"
457                 else
458                         names="$1"
459                 fi
460                 if [ "$(eval echo \"\${$2}\")" = "y" ]; then
461                         old=$1
462                         def=$1
463                 fi
464                 shift; shift
465         done
466
467         val=""
468         while [ -z "$val" ]; do
469                 ambg=n
470                 readln "$question ($names) [$def] " "$def" "$old"
471                 ans=$(echo $ans | tr a-z A-Z)
472                 set -- $choices
473                 while [ -n "$1" ]; do
474                         name=$(echo $1 | tr a-z A-Z)
475                         case "$name" in
476                                 "$ans"* | */"$ans"* )
477                                         case "$name" in
478                                                 "$ans" | */"$ans"/* | \
479                                                 "$ans"/* | */"$ans" )
480                                                         val="$2"
481                                                         break # exact match
482                                                 ;;
483                                         esac
484                                         if [ -n "$val" ]; then
485                                                 echo;echo \
486                 "  Sorry, \"$ans\" is ambiguous; please enter a longer string."
487                                                 echo
488                                                 val=""
489                                                 ambg=y
490                                                 break
491                                         else
492                                                 val="$2"
493                                         fi;;
494                         esac
495                         shift; shift
496                 done
497                 if [ "$val" = "" -a "$ambg" = "n" ]; then
498                         help "$firstvar"
499                 fi
500         done
501         set -- $choices
502         while [ -n "$2" ]; do
503                 if [ "$2" = "$val" ]; then
504                         echo "  defined $val"
505                         define_bool "$2" "y"
506                 else
507                         define_bool "$2" "n"
508                 fi
509                 shift; shift
510         done
511 }
512
513 CONFIG=.tmpconfig
514 CONFIG_H=.tmpconfig.h
515 trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
516
517 #
518 # Make sure we start out with a clean slate.
519 #
520 echo "#" > $CONFIG
521 echo "# Automatically generated make config: don't edit" >> $CONFIG
522 echo "#" >> $CONFIG
523
524 echo "/*" > $CONFIG_H
525 echo " * Automatically generated C config: don't edit" >> $CONFIG_H
526 echo " */" >> $CONFIG_H
527 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
528
529 DEFAULT=""
530 if [ "$1" = "-d" ] ; then
531         DEFAULT="-d"
532         shift
533 fi
534
535 CONFIG_IN=./config.in
536 if [ "$1" != "" ] ; then
537         CONFIG_IN=$1
538 fi
539
540 DEFAULTS=arch/$ARCH/defconfig
541 if [ -f .config ]; then
542   DEFAULTS=.config
543 fi
544
545 if [ -f $DEFAULTS ]; then
546   echo "#"
547   echo "# Using defaults found in" $DEFAULTS
548   echo "#"
549   . $DEFAULTS
550   sed -e 's/# \(CONFIG_[^ ]*\) is not.*/\1=n/' <$DEFAULTS >.config-is-not.$$
551   . .config-is-not.$$
552   rm .config-is-not.$$
553 else
554   echo "#"
555   echo "# No defaults found"
556   echo "#"
557 fi
558
559 . $CONFIG_IN
560
561 rm -f .config.old
562 if [ -f .config ]; then
563         mv .config .config.old
564 fi
565 mv .tmpconfig .config
566 mv .tmpconfig.h include/linux/autoconf.h
567
568 echo
569 echo "*** End of Linux kernel configuration."
570 echo "*** Check the top-level Makefile for additional configuration."
571 if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then
572     echo "*** Next, you must run 'make dep'."
573 else
574     echo "*** Next, you may run 'make bzImage', 'make bzdisk', or 'make install'."
575 fi
576 echo
577
578 exit 0