blob: 84302075d3374d1ea6cc77d58247c5c16a5bc2dc [file] [log] [blame]
Eric Andersenbdfd0d72001-10-24 05:00:29 +00001#! /bin/sh
2#
3# This script is used to configure BusyBox.
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# 7 October 2000, Ghozlane Toumi, <gtoumi@messel.emse.fr>
53# added switches for "random" , "all yes" and "all modules"
54#
55
56#
57# Make sure we're really running bash.
58#
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.
62#
63[ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
64
65# Disable filename globbing once and for all.
66# Enable function cacheing.
67set -f -h
68
69#
70# Dummy functions for use with a config.in modified for menuconf
71#
72function mainmenu_option () {
73 :
74}
75function mainmenu_name () {
76 :
77}
78function endmenu () {
79 :
80}
81
82#
83# returns a random number between 1 and $1
84#
85function rnd () {
86 rnd=$[ $RANDOM % $1 + 1 ]
87}
88
89#
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"
94#
95# rndval CONFIG_NAME
96#
97
98function rndval () {
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}")
103
104 if [ -n "$def_list" ]; then
105 set -- $(echo $def_list | sed 's/,/ /g')
106 rnd $#
107 while [ $rnd -le $# ] ; do
108 def=$1
109 shift
110 done
111 return
112 fi
113 if [ -n "$def_min" -a -n "$def_max" ]; then
114 rnd $[ $def_max - $def_min ]
115 def=$[ $def_min + $rnd ]
116 fi
117}
118
119#
120# help prints the corresponding help text from Configure.help to stdout
121#
122# help variable
123#
124function help () {
Eric Andersenf46999f2001-10-31 11:12:25 +0000125 if [ -f docs/Configure.help ]
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000126 then
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[ ]*\$/,\${
131 /^$var[ ]*\$/c\\
132${var}:\\
133
134 /^#/b
135 /^[^ ]/q
136 /<file:\\([^>]*\\)>/s//\\1/g
137 p
Eric Andersenf46999f2001-10-31 11:12:25 +0000138 }" docs/Configure.help)
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000139 if [ -z "$text" ]
140 then
141 echo; echo " Sorry, no help available for this option yet.";echo
142 else
143 (echo; echo "$text") | ${PAGER:-more}
144 fi
145 else
146 echo;
Eric Andersenf46999f2001-10-31 11:12:25 +0000147 echo " Can't access the file docs/Configure.help which"
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000148 echo " should contain the help texts."
149 echo
150 fi
151}
152
153
154#
155# readln reads a line into $ans.
156#
157# readln prompt default oldval
158#
159function readln () {
160 if [ "$AUTO" = "yes" ]; then
161 echo -n "$1"
162 ans=$2
163 echo $ans
164 elif [ "$DEFAULT" = "-d" -a -n "$3" ]; then
165 echo "$1"
166 ans=$2
167 else
168 echo -n "$1"
169 [ -z "$3" ] && echo -n "(NEW) "
170 IFS='@' read ans || exit 1
171 [ -z "$ans" ] && ans=$2
172 fi
173}
174
175#
176# comment does some pretty-printing
177#
178# comment 'xxx'
179#
180function comment () {
181 echo "*"; echo "* $1" ; echo "*"
182 (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
183 (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
184}
185
186#
187# define_bool sets the value of a boolean argument
188#
189# define_bool define value
190#
191function define_bool () {
192 define_tristate $1 $2
193}
194
195function define_tristate () {
196 case "$2" in
197 "y")
198 echo "$1=y" >>$CONFIG
199 echo "#define $1 1" >>$CONFIG_H
200 ;;
201
202 "m")
203 echo "$1=m" >>$CONFIG
204 echo "#undef $1" >>$CONFIG_H
205 echo "#define $1_MODULE 1" >>$CONFIG_H
206 ;;
207
208 "n")
209 echo "# $1 is not set" >>$CONFIG
210 echo "#undef $1" >>$CONFIG_H
211 ;;
212 esac
213 eval "$1=$2"
214}
215
216#
217# bool processes a boolean argument
218#
219# bool question define
220#
221function bool () {
222 old=$(eval echo "\${$2}")
223 def=${old:-'n'}
224 if [ "$AUTO" = "yes" -a -z "$old" ]; then
225 if [ "$RND" = "-r" ]; then
226 rnd 2
227 case $rnd in
228 "1") def="y" ;;
229 "2") def="n" ;;
230 esac
231 else
232 def=$DEF_ANS;
233 fi
234 fi
235 case "$def" in
236 "y" | "m") defprompt="Y/n/?"
237 def="y"
238 ;;
239 "n") defprompt="N/y/?"
240 ;;
241 esac
242 while :; do
243 readln "$1 ($2) [$defprompt] " "$def" "$old"
244 case "$ans" in
245 [yY] | [yY]es ) define_bool "$2" "y"
246 break;;
247 [nN] | [nN]o ) define_bool "$2" "n"
248 break;;
249 * ) help "$2"
250 ;;
251 esac
252 done
253}
254
255#
256# tristate processes a tristate argument
257#
258# tristate question define
259#
260function tristate () {
261 if [ "$CONFIG_MODULES" != "y" ]; then
262 bool "$1" "$2"
263 else
264 old=$(eval echo "\${$2}")
265 def=${old:-'n'}
266 if [ "$AUTO" = "yes" -a -z "$old" ]; then
267 if [ "$RND" = "-r" ]; then
268 rnd 3
269 case $rnd in
270 "1") def="y" ;;
271 "2") def="n" ;;
272 "3") def="m" ;;
273 esac
274 else
275 def=$DEF_ANS
276 fi
277 fi
278 case "$def" in
279 "y") defprompt="Y/m/n/?"
280 ;;
281 "m") defprompt="M/n/y/?"
282 ;;
283 "n") defprompt="N/y/m/?"
284 ;;
285 esac
286 while :; do
287 readln "$1 ($2) [$defprompt] " "$def" "$old"
288 case "$ans" in
289 [yY] | [yY]es ) define_tristate "$2" "y"
290 break ;;
291 [nN] | [nN]o ) define_tristate "$2" "n"
292 break ;;
293 [mM] ) define_tristate "$2" "m"
294 break ;;
295 * ) help "$2"
296 ;;
297 esac
298 done
299 fi
300}
301
302#
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.
309#
310# dep_tristate question define default ...
311#
312function dep_tristate () {
313 old=$(eval echo "\${$2}")
314 def=${old:-'n'}
315 ques=$1
316 var=$2
317 need_module=0
318 shift 2
319 while [ $# -gt 0 ]; do
320 case "$1" in
321 n)
322 define_tristate "$var" "n"
323 return
324 ;;
325 m)
326 need_module=1
327 ;;
328 esac
329 shift
330 done
331
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
336 rnd 2
337 case $rnd in
338 "1") def="m" ;;
339 "2") def="n" ;;
340 esac
341 else
342 def=$DEF_ANS
343 fi
344 fi
345 case "$def" in
346 "y" | "m") defprompt="M/n/?"
347 def="m"
348 ;;
349 "n") defprompt="N/m/?"
350 ;;
351 esac
352 while :; do
353 readln "$ques ($var) [$defprompt] " "$def" "$old"
354 case "$ans" in
355 [nN] | [nN]o ) define_tristate "$var" "n"
356 break ;;
357 [mM] ) define_tristate "$var" "m"
358 break ;;
359 [yY] | [yY]es ) echo
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)."
365 echo
366 ;;
367 * ) help "$var"
368 ;;
369 esac
370 done
371 fi
372 else
373 tristate "$ques" "$var"
374 fi
375}
376
377function dep_bool () {
378 ques=$1
379 var=$2
380 shift 2
381 while [ $# -gt 0 ]; do
382 case "$1" in
383 m | n)
384 define_bool "$var" "n"
385 return
386 ;;
387 esac
388 shift
389 done
390
391 bool "$ques" "$var"
392}
393
394function dep_mbool () {
395 ques=$1
396 var=$2
397 shift 2
398 while [ $# -gt 0 ]; do
399 case "$1" in
400 n)
401 define_bool "$var" "n"
402 return
403 ;;
404 esac
405 shift
406 done
407
408 bool "$ques" "$var"
409}
410
411#
412# define_int sets the value of a integer argument
413#
414# define_int define value
415#
416function define_int () {
417 echo "$1=$2" >>$CONFIG
418 echo "#define $1 ($2)" >>$CONFIG_H
419 eval "$1=$2"
420}
421
422#
423# int processes an integer argument with optional limits
424#
425# int question define default [min max]
426#
427function int () {
428 old=$(eval echo "\${$2}")
429 def=${old:-$3}
430 if [ $# -gt 3 ]; then
431 min=$4
432 else
433 min=-10000000 # !!
434 fi
435 if [ $# -gt 4 ]; then
436 max=$5
437 else
438 max=10000000 # !!
439 fi
440 rndval $2
441 while :; do
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"
445 break
446 else
447 help "$2"
448 fi
449 done
450}
451
452#
453# define_hex sets the value of a hexadecimal argument
454#
455# define_hex define value
456#
457function define_hex () {
458 echo "$1=$2" >>$CONFIG
459 echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H
460 eval "$1=$2"
461}
462
463#
464# hex processes an hexadecimal argument
465#
466# hex question define default
467#
468function hex () {
469 old=$(eval echo "\${$2}")
470 def=${old:-$3}
471 def=${def#*[x,X]}
472 rndval $2
473 while :; do
474 readln "$1 ($2) [$def] " "$def" "$old"
475 ans=${ans#*[x,X]}
476 if expr "$ans" : '[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then
477 define_hex "$2" "$ans"
478 break
479 else
480 help "$2"
481 fi
482 done
483}
484
485#
486# define_string sets the value of a string argument
487#
488# define_string define value
489#
490function define_string () {
491 echo "$1=\"$2\"" >>$CONFIG
492 echo "#define $1 \"$2\"" >>$CONFIG_H
493 eval "$1=\"$2\""
494}
495
496#
497# string processes a string argument
498#
499# string question define default
500#
501function string () {
502 old=$(eval echo "\${$2}")
503 def=${old:-$3}
504 while :; do
505 if [ "$old" = "?" ]; then
506 readln "$1 ($2) [$def] " "$def" ""
507 else
508 readln "$1 ($2) [$def] " "$def" "$old"
509 fi
510 if [ "$ans" = "?" ]; then
511 help "$2"
512 else
513 break
514 fi
515 done
516 define_string "$2" "$ans"
517}
518#
519# choice processes a choice list (1-out-of-n)
520#
521# choice question choice-list default
522#
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".
531#
532function choice () {
533 question="$1"
534 choices="$2"
535 old=
536 def=$3
537
538 # determine default answer:
539 names=""
540 set -- $choices
541 firstvar=$2
542 while [ -n "$2" ]; do
543 if [ -n "$names" ]; then
544 names="$names, $1"
545 else
546 names="$1"
547 fi
548 if [ "$(eval echo \"\${$2}\")" = "y" ]; then
549 old=$1
550 def=$1
551 fi
552 shift; shift
553 done
554
555 if [ "$RND" = "-r" -a -z "$old" ] ; then
556 set -- $choices
557 rnd $#
558 while [ $rnd -le $# ] ; do
559 def=$1
560 shift ; shift
561 done
562 fi
563
564 val=""
565 while [ -z "$val" ]; do
566 ambg=n
567 readln "$question ($names) [$def] " "$def" "$old"
568 ans=$(echo $ans | tr a-z A-Z)
569 set -- $choices
570 while [ -n "$1" ]; do
571 name=$(echo $1 | tr a-z A-Z)
572 case "$name" in
573 "$ans"* | */"$ans"* )
574 case "$name" in
575 "$ans" | */"$ans"/* | \
576 "$ans"/* | */"$ans" )
577 val="$2"
578 break # exact match
579 ;;
580 esac
581 if [ -n "$val" ]; then
582 echo;echo \
583 " Sorry, \"$ans\" is ambiguous; please enter a longer string."
584 echo
585 val=""
586 ambg=y
587 break
588 else
589 val="$2"
590 fi;;
591 esac
592 shift; shift
593 done
594 if [ "$val" = "" -a "$ambg" = "n" ]; then
595 help "$firstvar"
596 fi
597 done
598 set -- $choices
599 while [ -n "$2" ]; do
600 if [ "$2" = "$val" ]; then
601 echo " defined $val"
602 define_bool "$2" "y"
603 else
604 define_bool "$2" "n"
605 fi
606 shift; shift
607 done
608}
609
610CONFIG=.tmpconfig
611CONFIG_H=.tmpconfig.h
612FORCE_DEFAULT=.force_default
613trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
614
615#
616# Make sure we start out with a clean slate.
617#
618echo "#" > $CONFIG
619echo "# Automatically generated make config: don't edit" >> $CONFIG
620echo "#" >> $CONFIG
621
622echo "/*" > $CONFIG_H
623echo " * Automatically generated C config: don't edit" >> $CONFIG_H
624echo " */" >> $CONFIG_H
625echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
626
627DEFAULT=""
628if [ "$1" = "-d" ] ; then
629 DEFAULT="-d"
630 shift
631fi
632
633RND=""
634DEF_ANS=""
635AUTO=""
636case "$1" in
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 ;;
641esac
642
643CONFIG_IN=./config.in
644if [ "$1" != "" ] ; then
645 CONFIG_IN=$1
646fi
647
648DEFAULTS=sysdeps/$TARGET_OS/defconfig
649if [ -f .config ]; then
650 DEFAULTS=.config
651fi
652
653if [ "$AUTO" != "yes" ]; then
654 if [ -f $DEFAULTS ]; then
655 echo "#"
656 echo "# Using defaults found in" $DEFAULTS
657 echo "#"
658 . $DEFAULTS
659 sed -e 's/# \(CONFIG_[^ ]*\) is not.*/\1=n/' <$DEFAULTS >.config-is-not.$$
660 . .config-is-not.$$
661 rm .config-is-not.$$
662 else
663 echo "#"
664 echo "# No defaults found"
665 echo "#"
666 fi
667else
668 if [ -f $FORCE_DEFAULT ]; then
669 echo "#"
670 echo "# Forcing defaults found in $FORCE_DEFAULT"
671 echo "#"
672 sed -e '
673s/# \(CONFIG_[^ ]*\) is not.*/\1=n/;
674s/# range \(CONFIG_[^ ]*\) \([^ ][^ ]*\) \([^ ][^ ]*\)/MIN_\1=\2; MAX_\1=\3/;
675s/# list \(CONFIG_[^ ]*\) \([^ ][^ ]*\)/LIST_\1=\2/
676' <$FORCE_DEFAULT >.default_val.$$
677 . .default_val.$$
678 rm .default_val.$$
679 else
680 echo "#"
681 echo "# No defaults found"
682 echo "#"
683 fi
684fi
685
686. $CONFIG_IN
687
688rm -f .config.old
689if [ -f .config ]; then
690 mv .config .config.old
691fi
692mv .tmpconfig .config
693mv .tmpconfig.h include/config.h
694
695echo
696echo "*** End of BusyBox configuration."
697echo "*** Check the top-level Makefile for additional configuration."
698if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then
699 echo "*** Next, you must run 'make dep'."
700else
701 echo "*** Next, you may run 'make bzImage', 'make bzdisk', or 'make install'."
702fi
703echo
704
705exit 0