[PATCH] v4l: w9966 update
[linux-2.6/history.git] / scripts / Configure
blob9d9574f12b215b01050d1df7971d08bc0246675a
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 #first escape regexp special characters in the argument:
85 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
86 #now pick out the right help text:
87 text=$(cat /dev/null $(find . -name Config.help) |
88 sed -n "/^$var[ ]*\$/,\${
89 /^$var[ ]*\$/c\\
90 ${var}:\\
92 /^#/b
93 /^[^ ]/q
94 /<file:\\([^>]*\\)>/s//\\1/g
96 }")
97 if [ -z "$text" ]
98 then
99 echo; echo " Sorry, no help available for this option yet.";echo
100 else
101 (echo; echo "$text"; echo) | ${PAGER:-more}
107 # readln reads a line into $ans.
109 # readln prompt default oldval
111 function readln () {
112 if [ "$DEFAULT" = "-d" -a -n "$3" ]; then
113 echo "$1"
114 ans=$2
115 else
116 echo -n "$1"
117 [ -z "$3" ] && echo -n "(NEW) "
118 IFS='@' read ans || exit 1
119 [ -z "$ans" ] && ans=$2
124 # comment does some pretty-printing
126 # comment 'xxx'
128 function comment () {
129 echo "*"; echo "* $1" ; echo "*"
130 (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
131 (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
135 # define_bool sets the value of a boolean argument
137 # define_bool define value
139 function define_bool () {
140 define_tristate $1 $2
143 function define_tristate () {
144 case "$2" in
145 "y")
146 echo "$1=y" >>$CONFIG
147 echo "#define $1 1" >>$CONFIG_H
150 "m")
151 echo "$1=m" >>$CONFIG
152 echo "#undef $1" >>$CONFIG_H
153 echo "#define $1_MODULE 1" >>$CONFIG_H
156 "n")
157 echo "# $1 is not set" >>$CONFIG
158 echo "#undef $1" >>$CONFIG_H
160 esac
161 eval "$1=$2"
165 # bool processes a boolean argument
167 # bool question define
169 function bool () {
170 old=$(eval echo "\${$2}")
171 def=${old:-'n'}
172 case "$def" in
173 "y" | "m") defprompt="Y/n/?"
174 def="y"
176 "n") defprompt="N/y/?"
178 esac
179 while :; do
180 readln "$1 ($2) [$defprompt] " "$def" "$old"
181 case "$ans" in
182 [yY] | [yY]es ) define_bool "$2" "y"
183 break;;
184 [nN] | [nN]o ) define_bool "$2" "n"
185 break;;
186 * ) help "$2"
188 esac
189 done
193 # tristate processes a tristate argument
195 # tristate question define
197 function tristate () {
198 if [ "$CONFIG_MODULES" != "y" ]; then
199 bool "$1" "$2"
200 else
201 old=$(eval echo "\${$2}")
202 def=${old:-'n'}
203 case "$def" in
204 "y") defprompt="Y/m/n/?"
206 "m") defprompt="M/n/y/?"
208 "n") defprompt="N/y/m/?"
210 esac
211 while :; do
212 readln "$1 ($2) [$defprompt] " "$def" "$old"
213 case "$ans" in
214 [yY] | [yY]es ) define_tristate "$2" "y"
215 break ;;
216 [nN] | [nN]o ) define_tristate "$2" "n"
217 break ;;
218 [mM] ) define_tristate "$2" "m"
219 break ;;
220 * ) help "$2"
222 esac
223 done
228 # dep_tristate processes a tristate argument that depends upon
229 # another option or options. If any of the options we depend upon is a
230 # module, then the only allowable options are M or N. If all are Y, then
231 # this is a normal tristate. This is used in cases where modules
232 # are nested, and one module requires the presence of something
233 # else in the kernel.
235 # dep_tristate question define default ...
237 function dep_tristate () {
238 old=$(eval echo "\${$2}")
239 def=${old:-'n'}
240 ques=$1
241 var=$2
242 need_module=0
243 shift 2
244 while [ $# -gt 0 ]; do
245 case "$1" in
247 define_tristate "$var" "n"
248 return
251 need_module=1
253 esac
254 shift
255 done
257 if [ $need_module = 1 ]; then
258 if [ "$CONFIG_MODULES" = "y" ]; then
259 case "$def" in
260 "y" | "m") defprompt="M/n/?"
261 def="m"
263 "n") defprompt="N/m/?"
265 esac
266 while :; do
267 readln "$ques ($var) [$defprompt] " "$def" "$old"
268 case "$ans" in
269 [nN] | [nN]o ) define_tristate "$var" "n"
270 break ;;
271 [mM] ) define_tristate "$var" "m"
272 break ;;
273 [yY] | [yY]es ) echo
274 echo " This answer is not allowed, because it is not consistent with"
275 echo " your other choices."
276 echo " This driver depends on another one which you chose to compile"
277 echo " as a module. This means that you can either compile this one"
278 echo " as a module as well (with M) or leave it out altogether (N)."
279 echo
281 * ) help "$var"
283 esac
284 done
286 else
287 tristate "$ques" "$var"
291 function dep_bool () {
292 ques=$1
293 var=$2
294 shift 2
295 while [ $# -gt 0 ]; do
296 case "$1" in
297 m | n)
298 define_bool "$var" "n"
299 return
301 esac
302 shift
303 done
305 bool "$ques" "$var"
308 function dep_mbool () {
309 ques=$1
310 var=$2
311 shift 2
312 while [ $# -gt 0 ]; do
313 case "$1" in
315 define_bool "$var" "n"
316 return
318 esac
319 shift
320 done
322 bool "$ques" "$var"
326 # define_int sets the value of a integer argument
328 # define_int define value
330 function define_int () {
331 echo "$1=$2" >>$CONFIG
332 echo "#define $1 ($2)" >>$CONFIG_H
333 eval "$1=$2"
337 # int processes an integer argument with optional limits
339 # int question define default [min max]
341 function int () {
342 old=$(eval echo "\${$2}")
343 def=${old:-$3}
344 if [ $# -gt 3 ]; then
345 min=$4
346 else
347 min=-10000000 # !!
349 if [ $# -gt 4 ]; then
350 max=$5
351 else
352 max=10000000 # !!
354 while :; do
355 readln "$1 ($2) [$def] " "$def" "$old"
356 if expr \( \( $ans + 0 \) \>= $min \) \& \( $ans \<= $max \) >/dev/null 2>&1 ; then
357 define_int "$2" "$ans"
358 break
359 else
360 help "$2"
362 done
366 # define_hex sets the value of a hexadecimal argument
368 # define_hex define value
370 function define_hex () {
371 echo "$1=$2" >>$CONFIG
372 echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H
373 eval "$1=$2"
377 # hex processes an hexadecimal argument
379 # hex question define default
381 function hex () {
382 old=$(eval echo "\${$2}")
383 def=${old:-$3}
384 def=${def#*[x,X]}
385 while :; do
386 readln "$1 ($2) [$def] " "$def" "$old"
387 ans=${ans#*[x,X]}
388 if expr "$ans" : '[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then
389 define_hex "$2" "$ans"
390 break
391 else
392 help "$2"
394 done
398 # define_string sets the value of a string argument
400 # define_string define value
402 function define_string () {
403 echo "$1=\"$2\"" >>$CONFIG
404 echo "#define $1 \"$2\"" >>$CONFIG_H
405 eval "$1=\"$2\""
409 # string processes a string argument
411 # string question define default
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"
422 if [ "$ans" = "?" ]; then
423 help "$2"
424 else
425 break
427 done
428 define_string "$2" "$ans"
431 # choice processes a choice list (1-out-of-n)
433 # choice question choice-list default
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".
444 function choice () {
445 question="$1"
446 choices="$2"
447 old=
448 def=$3
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"
460 if [ "$(eval echo \"\${$2}\")" = "y" ]; then
461 old=$1
462 def=$1
464 shift; shift
465 done
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
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"
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"
509 shift; shift
510 done
513 CONFIG=.tmpconfig
514 CONFIG_H=.tmpconfig.h
515 trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
518 # Make sure we start out with a clean slate.
520 echo "#" > $CONFIG
521 echo "# Automatically generated make config: don't edit" >> $CONFIG
522 echo "#" >> $CONFIG
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
529 DEFAULT=""
530 if [ "$1" = "-d" ] ; then
531 DEFAULT="-d"
532 shift
535 CONFIG_IN=./config.in
536 if [ "$1" != "" ] ; then
537 CONFIG_IN=$1
540 DEFAULTS=arch/$ARCH/defconfig
541 if [ -f .config ]; then
542 DEFAULTS=.config
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 "#"
559 . $CONFIG_IN
561 rm -f .config.old
562 if [ -f .config ]; then
563 mv .config .config.old
565 mv .tmpconfig .config
566 mv .tmpconfig.h include/linux/autoconf.h
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'."
576 echo
578 exit 0