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. 63set -f -h 64 65# 66# Dummy functions for use with a config.in modified for menuconf 67# 68function mainmenu_option () { 69 : 70} 71function mainmenu_name () { 72 : 73} 74function endmenu () { 75 : 76} 77 78# 79# help prints the corresponding help text from Configure.help to stdout 80# 81# help variable 82# 83function 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 p 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} 102 fi 103 else 104 echo; 105 echo " Can't access the file Documentation/Configure.help which" 106 echo " should contain the help texts." 107 echo 108 fi 109} 110 111 112# 113# readln reads a line into $ans. 114# 115# readln prompt default oldval 116# 117function 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 126 fi 127} 128 129# 130# comment does some pretty-printing 131# 132# comment 'xxx' 133# 134function comment () { 135 echo "*"; echo "* $1" ; echo "*" 136 (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG 137 (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H 138} 139 140# 141# define_bool sets the value of a boolean argument 142# 143# define_bool define value 144# 145function define_bool () { 146 define_tristate $1 $2 147} 148 149function define_tristate () { 150 case "$2" in 151 "y") 152 echo "$1=y" >>$CONFIG 153 echo "#define $1 1" >>$CONFIG_H 154 ;; 155 156 "m") 157 echo "$1=m" >>$CONFIG 158 echo "#undef $1" >>$CONFIG_H 159 echo "#define $1_MODULE 1" >>$CONFIG_H 160 ;; 161 162 "n") 163 echo "# $1 is not set" >>$CONFIG 164 echo "#undef $1" >>$CONFIG_H 165 ;; 166 esac 167 eval "$1=$2" 168} 169 170# 171# bool processes a boolean argument 172# 173# bool question define 174# 175function bool () { 176 old=$(eval echo "\${$2}") 177 def=${old:-'n'} 178 case "$def" in 179 "y" | "m") defprompt="Y/n/?" 180 def="y" 181 ;; 182 "n") defprompt="N/y/?" 183 ;; 184 esac 185 while :; do 186 readln "$1 ($2) [$defprompt] " "$def" "$old" 187 case "$ans" in 188 [yY] | [yY]es ) define_bool "$2" "y" 189 break;; 190 [nN] | [nN]o ) define_bool "$2" "n" 191 break;; 192 * ) help "$2" 193 ;; 194 esac 195 done 196} 197 198# 199# tristate processes a tristate argument 200# 201# tristate question define 202# 203function tristate () { 204 if [ "$CONFIG_MODULES" != "y" ]; then 205 bool "$1" "$2" 206 else 207 old=$(eval echo "\${$2}") 208 def=${old:-'n'} 209 case "$def" in 210 "y") defprompt="Y/m/n/?" 211 ;; 212 "m") defprompt="M/n/y/?" 213 ;; 214 "n") defprompt="N/y/m/?" 215 ;; 216 esac 217 while :; do 218 readln "$1 ($2) [$defprompt] " "$def" "$old" 219 case "$ans" in 220 [yY] | [yY]es ) define_tristate "$2" "y" 221 break ;; 222 [nN] | [nN]o ) define_tristate "$2" "n" 223 break ;; 224 [mM] ) define_tristate "$2" "m" 225 break ;; 226 * ) help "$2" 227 ;; 228 esac 229 done 230 fi 231} 232 233# 234# dep_tristate processes a tristate argument that depends upon 235# another option or options. If any of the options we depend upon is a 236# module, then the only allowable options are M or N. If all are Y, then 237# this is a normal tristate. This is used in cases where modules 238# are nested, and one module requires the presence of something 239# else in the kernel. 240# 241# dep_tristate question define default ... 242# 243function dep_tristate () { 244 old=$(eval echo "\${$2}") 245 def=${old:-'n'} 246 ques=$1 247 var=$2 248 need_module=0 249 shift 2 250 while [ $# -gt 0 ]; do 251 case "$1" in 252 n) 253 define_tristate "$var" "n" 254 return 255 ;; 256 m) 257 need_module=1 258 ;; 259 esac 260 shift 261 done 262 263 if [ $need_module = 1 ]; then 264 if [ "$CONFIG_MODULES" = "y" ]; then 265 case "$def" in 266 "y" | "m") defprompt="M/n/?" 267 def="m" 268 ;; 269 "n") defprompt="N/m/?" 270 ;; 271 esac 272 while :; do 273 readln "$ques ($var) [$defprompt] " "$def" "$old" 274 case "$ans" in 275 [nN] | [nN]o ) define_tristate "$var" "n" 276 break ;; 277 [mM] ) define_tristate "$var" "m" 278 break ;; 279 [yY] | [yY]es ) echo 280 echo " This answer is not allowed, because it is not consistent with" 281 echo " your other choices." 282 echo " This driver depends on another one which you chose to compile" 283 echo " as a module. This means that you can either compile this one" 284 echo " as a module as well (with M) or leave it out altogether (N)." 285 echo 286 ;; 287 * ) help "$var" 288 ;; 289 esac 290 done 291 fi 292 else 293 tristate "$ques" "$var" 294 fi 295} 296 297function dep_bool () { 298 ques=$1 299 var=$2 300 shift 2 301 while [ $# -gt 0 ]; do 302 case "$1" in 303 m | n) 304 define_bool "$var" "n" 305 return 306 ;; 307 esac 308 shift 309 done 310 311 bool "$ques" "$var" 312} 313 314function dep_mbool () { 315 ques=$1 316 var=$2 317 shift 2 318 while [ $# -gt 0 ]; do 319 case "$1" in 320 n) 321 define_bool "$var" "n" 322 return 323 ;; 324 m) 325 eval "$var=y" 326 ;; 327 esac 328 shift 329 done 330 331 bool "$ques" "$var" 332} 333 334# 335# define_int sets the value of a integer argument 336# 337# define_int define value 338# 339function define_int () { 340 echo "$1=$2" >>$CONFIG 341 echo "#define $1 ($2)" >>$CONFIG_H 342 eval "$1=$2" 343} 344 345# 346# int processes an integer argument with optional limits 347# 348# int question define default [min max] 349# 350function int () { 351 old=$(eval echo "\${$2}") 352 def=${old:-$3} 353 if [ $# -gt 3 ]; then 354 min=$4 355 else 356 min=-10000000 # !! 357 fi 358 if [ $# -gt 4 ]; then 359 max=$5 360 else 361 max=10000000 # !! 362 fi 363 while :; do 364 readln "$1 ($2) [$def] " "$def" "$old" 365 if expr \( \( $ans + 0 \) \>= $min \) \& \( $ans \<= $max \) >/dev/null 2>&1 ; then 366 define_int "$2" "$ans" 367 break 368 else 369 help "$2" 370 fi 371 done 372} 373 374# 375# define_hex sets the value of a hexadecimal argument 376# 377# define_hex define value 378# 379function define_hex () { 380 echo "$1=$2" >>$CONFIG 381 echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H 382 eval "$1=$2" 383} 384 385# 386# hex processes an hexadecimal argument 387# 388# hex question define default 389# 390function hex () { 391 old=$(eval echo "\${$2}") 392 def=${old:-$3} 393 def=${def#*[x,X]} 394 while :; do 395 readln "$1 ($2) [$def] " "$def" "$old" 396 ans=${ans#*[x,X]} 397 if expr "$ans" : '[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then 398 define_hex "$2" "$ans" 399 break 400 else 401 help "$2" 402 fi 403 done 404} 405 406# 407# define_string sets the value of a string argument 408# 409# define_string define value 410# 411function define_string () { 412 echo "$1=\"$2\"" >>$CONFIG 413 echo "#define $1 \"$2\"" >>$CONFIG_H 414 eval "$1=\"$2\"" 415} 416 417# 418# string processes a string argument 419# 420# string question define default 421# 422function string () { 423 old=$(eval echo "\${$2}") 424 def=${old:-$3} 425 while :; do 426 if [ "$old" = "?" ]; then 427 readln "$1 ($2) [$def] " "$def" "" 428 else 429 readln "$1 ($2) [$def] " "$def" "$old" 430 fi 431 if [ "$ans" = "?" ]; then 432 help "$2" 433 else 434 break 435 fi 436 done 437 define_string "$2" "$ans" 438} 439# 440# choice processes a choice list (1-out-of-n) 441# 442# choice question choice-list default 443# 444# The choice list has a syntax of: 445# NAME WHITESPACE VALUE { WHITESPACE NAME WHITESPACE VALUE } 446# The user may enter any unique prefix of one of the NAMEs and 447# choice will define VALUE as if it were a boolean option. 448# VALUE must be in all uppercase. Normally, VALUE is of the 449# form CONFIG_<something>. Thus, if the user selects <something>, 450# the CPP symbol CONFIG_<something> will be defined and the 451# shell variable CONFIG_<something> will be set to "y". 452# 453function choice () { 454 question="$1" 455 choices="$2" 456 old= 457 def=$3 458 459 # determine default answer: 460 names="" 461 set -- $choices 462 firstvar=$2 463 while [ -n "$2" ]; do 464 if [ -n "$names" ]; then 465 names="$names, $1" 466 else 467 names="$1" 468 fi 469 if [ "$(eval echo \"\${$2}\")" = "y" ]; then 470 old=$1 471 def=$1 472 fi 473 shift; shift 474 done 475 476 val="" 477 while [ -z "$val" ]; do 478 ambg=n 479 readln "$question ($names) [$def] " "$def" "$old" 480 ans=$(echo $ans | tr a-z A-Z) 481 set -- $choices 482 while [ -n "$1" ]; do 483 name=$(echo $1 | tr a-z A-Z) 484 case "$name" in 485 "$ans"* ) 486 if [ "$name" = "$ans" ]; then 487 val="$2" 488 break # stop on exact match 489 fi 490 if [ -n "$val" ]; then 491 echo;echo \ 492 " Sorry, \"$ans\" is ambiguous; please enter a longer string." 493 echo 494 val="" 495 ambg=y 496 break 497 else 498 val="$2" 499 fi;; 500 esac 501 shift; shift 502 done 503 if [ "$val" = "" -a "$ambg" = "n" ]; then 504 help "$firstvar" 505 fi 506 done 507 set -- $choices 508 while [ -n "$2" ]; do 509 if [ "$2" = "$val" ]; then 510 echo " defined $val" 511 define_bool "$2" "y" 512 else 513 define_bool "$2" "n" 514 fi 515 shift; shift 516 done 517} 518 519CONFIG=.tmpconfig 520CONFIG_H=.tmpconfig.h 521trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2 522 523# 524# Make sure we start out with a clean slate. 525# 526echo "#" > $CONFIG 527echo "# Automatically generated make config: don't edit" >> $CONFIG 528echo "#" >> $CONFIG 529 530echo "/*" > $CONFIG_H 531echo " * Automatically generated C config: don't edit" >> $CONFIG_H 532echo " */" >> $CONFIG_H 533echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H 534 535DEFAULT="" 536if [ "$1" = "-d" ] ; then 537 DEFAULT="-d" 538 shift 539fi 540 541CONFIG_IN=./config.in 542if [ "$1" != "" ] ; then 543 CONFIG_IN=$1 544fi 545 546DEFAULTS=arch/$ARCH/defconfig 547if [ -f .config ]; then 548 DEFAULTS=.config 549fi 550 551if [ -f $DEFAULTS ]; then 552 echo "#" 553 echo "# Using defaults found in" $DEFAULTS 554 echo "#" 555 . $DEFAULTS 556 sed -e 's/# \(CONFIG_[^ ]*\) is not.*/\1=n/' <$DEFAULTS >.config-is-not.$$ 557 . .config-is-not.$$ 558 rm .config-is-not.$$ 559else 560 echo "#" 561 echo "# No defaults found" 562 echo "#" 563fi 564 565. $CONFIG_IN 566 567rm -f .config.old 568if [ -f .config ]; then 569 mv .config .config.old 570fi 571mv .tmpconfig .config 572mv .tmpconfig.h include/linux/autoconf.h 573 574echo 575echo "*** End of Linux kernel configuration." 576echo "*** Check the top-level Makefile for additional configuration." 577if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then 578 echo "*** Next, you must run 'make dep'." 579else 580 echo "*** Next, you may run 'make zImage', 'make zdisk', or 'make zlilo'." 581fi 582echo 583 584exit 0 585

