linux-old/scripts/Configure
<<
>>
Prefs
   1
   2#! /bin/sh
   3#
   4# This script is used to configure the linux kernel.
   5#
   6# It was inspired by the challenge in the original Configure script
   7# to ``do something better'', combined with the actual need to ``do
   8# something better'' because the old configure script wasn't flexible
   9# enough.
  10#
  11# Please send comments / questions / bug fixes to raymondc@microsoft.com.
  12#
  13#              ***** IMPORTANT COMPATIBILITY NOTE ****
  14# If configuration changes are made which might adversely effect 
  15# Menuconfig or xconfig, please notify the respective authors so that 
  16# those utilities can be updated in parallel.
  17#
  18# Menuconfig:  <roadcapw@cfw.com>
  19# xconfig:     <apenwarr@foxnet.net>  <eric@aib.com>
  20#              ****************************************
  21#
  22# Each line in the config file is a command.
  23#
  24# 050793 - use IFS='@' to get around a bug in a pre-version of bash-1.13
  25# with an empty IFS.
  26#
  27# 030995 (storner@osiris.ping.dk) - added support for tri-state answers,
  28# for selecting modules to compile.
  29#
  30# 180995 Bernhard Kaindl (bkaindl@ping.at) - added dummy functions for
  31# use with a config.in modified for make menuconfig.
  32#
  33# 301195 (boldt@math.ucsb.edu) - added help text support
  34#
  35# 281295 Paul Gortmaker - make tri_state functions collapse to boolean
  36# if module support is not enabled.
  37#
  38# 010296 Aaron Ucko (ucko@vax1.rockhurst.edu) - fix int and hex to accept
  39# arbitrary ranges
  40#
  41# 150296 Dick Streefland (dicks@tasking.nl) - report new configuration
  42# items and ask for a value even when doing a "make oldconfig"
  43#
  44# 200396 Tom Dyas (tdyas@eden.rutgers.edu) - when the module option is
  45# chosen for an item, define the macro <option_name>_MODULE
  46#
  47# 090397 Axel Boldt (boldt@math.ucsb.edu) - avoid ? and + in regular 
  48# expressions for GNU expr since version 1.15 and up use \? and \+.
  49#
  50# 300397 Phil Blundell (pjb27@cam.ac.uk) - added support for min/max 
  51# arguments to "int", allow dep_tristate to take a list of dependencies
  52# rather than just one.
  53
  54#
  55# Make sure we're really running bash.
  56#
  57# I would really have preferred to write this script in a language with
  58# better string handling, but alas, bash is the only scripting language
  59# that I can be reasonable sure everybody has on their linux machine.
  60#
  61[ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
  62
  63# Disable filename globbing once and for all.
  64# Enable function cacheing.
  65set -f -h
  66
  67#
  68# Dummy functions for use with a config.in modified for menuconf
  69#
  70function mainmenu_option () {
  71        :
  72}
  73function mainmenu_name () {
  74        :
  75}
  76function endmenu () {
  77        :
  78}
  79
  80#
  81# help prints the corresponding help text from Configure.help to stdout
  82#
  83#       help variable
  84#
  85function help () {
  86  if [ -f Documentation/Configure.help ]
  87  then
  88     #first escape regexp special characters in the argument:
  89     var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
  90     #now pick out the right help text:
  91     text=$(sed -n "/^$var[     ]*\$/,\${
  92                        /^$var[         ]*\$/b
  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"; echo) | ${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 </dev/tty || 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        case "$2" in
 147         "y")
 148                echo "$1=y" >>$CONFIG
 149                echo "#define $1 1" >>$CONFIG_H
 150                ;;
 151
 152         "m")
 153                echo "$1=m" >>$CONFIG
 154                echo "#undef  $1" >>$CONFIG_H
 155                echo "#define $1_MODULE 1" >>$CONFIG_H
 156                ;;
 157
 158         "n")
 159                echo "# $1 is not set" >>$CONFIG
 160                echo "#undef  $1" >>$CONFIG_H
 161                ;;
 162        esac
 163        eval "$1=$2"
 164}
 165
 166#
 167# bool processes a boolean argument
 168#
 169#       bool question define
 170#
 171function bool () {
 172        old=$(eval echo "\${$2}")
 173        def=${old:-'n'}
 174        case "$def" in
 175         "y" | "m") defprompt="Y/n/?"
 176              def="y"
 177              ;;
 178         "n") defprompt="N/y/?"
 179              ;;
 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"
 189                            ;;
 190          esac
 191        done
 192}
 193
 194#
 195# tristate processes a tristate argument
 196#
 197#       tristate question define
 198#
 199function 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/?"
 207                ;;
 208           "m") defprompt="M/n/y/?"
 209                ;;
 210           "n") defprompt="N/y/m/?"
 211                ;;
 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"
 223                              ;;
 224            esac
 225          done
 226        fi
 227}
 228
 229#
 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.
 236#
 237#       tristate question define default ...
 238#
 239function 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
 248            n)
 249              define_bool "$var" "n"
 250              return
 251              ;;
 252            m)
 253              need_module=1
 254              ;;
 255          esac
 256          shift
 257        done
 258
 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"
 264                      ;;
 265                 "n") defprompt="N/m/?"
 266                      ;;
 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
 282                                      ;;
 283                      * )             help "$var"
 284                                      ;;
 285                  esac
 286                done
 287           fi
 288        else
 289           tristate "$ques" "$var"
 290        fi
 291}
 292
 293#
 294# define_int sets the value of a integer argument
 295#
 296#       define_int define value
 297#
 298function define_int () {
 299        echo "$1=$2" >>$CONFIG
 300        echo "#define $1 ($2)" >>$CONFIG_H
 301        eval "$1=$2"
 302}
 303
 304#
 305# int processes an integer argument with optional limits
 306#
 307#       int question define default [min max]
 308#
 309function int () {
 310        old=$(eval echo "\${$2}")
 311        def=${old:-$3}
 312        if [ $# -gt 3 ]; then
 313          min=$4
 314        else
 315          min=-10000000    # !!
 316        fi
 317        if [ $# -gt 4 ]; then
 318          max=$5
 319        else
 320          max=10000000     # !!
 321        fi
 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"
 329          fi
 330        done
 331}
 332
 333#
 334# define_hex sets the value of a hexadecimal argument
 335#
 336#       define_hex define value
 337#
 338function define_hex () {
 339        echo "$1=$2" >>$CONFIG
 340        echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H
 341        eval "$1=$2"
 342}
 343
 344#
 345# hex processes an hexadecimal argument
 346#
 347#       hex question define default
 348#
 349function 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"
 361          fi
 362        done
 363}
 364
 365#
 366# define_string sets the value of a string argument
 367#
 368#       define_string define value
 369#
 370function define_string () {
 371        echo "$1="'"'$2'"' >>$CONFIG
 372        echo "#define $1 "'"'$2'"' >>$CONFIG_H
 373        eval "$1=$2"
 374}
 375
 376#
 377# string processes a string argument
 378#
 379#       string question define default
 380#
 381function string () {
 382        old=$(eval echo "\${$2}")
 383        def=${old:-$3}
 384        readln "$1 ($2) [$def] " "$def" "$old"
 385        define_string "$2" "$ans"
 386}
 387#
 388# choice processes a choice list (1-out-of-n)
 389#
 390#       choice question choice-list default
 391#
 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".
 400#
 401function choice () {
 402        question="$1"
 403        choices="$2"
 404        old=
 405        def=$3
 406
 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"
 416                fi
 417                if [ "$(eval echo \"\${$2}\")" = "y" ]; then
 418                        old=$1
 419                        def=$1
 420                fi
 421                shift; shift
 422        done
 423
 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
 437                                        fi
 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"
 453                fi
 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"
 462                fi
 463                shift; shift
 464        done
 465}
 466
 467CONFIG=.tmpconfig
 468CONFIG_H=.tmpconfig.h
 469trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
 470
 471#
 472# Make sure we start out with a clean slate.
 473#
 474echo "#" > $CONFIG
 475echo "# Automatically generated make config: don't edit" >> $CONFIG
 476echo "#" >> $CONFIG
 477
 478echo "/*" > $CONFIG_H
 479echo " * Automatically generated C config: don't edit" >> $CONFIG_H
 480echo " */" >> $CONFIG_H
 481echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
 482
 483DEFAULT=""
 484if [ "$1" = "-d" ] ; then
 485        DEFAULT="-d"
 486        shift
 487fi
 488
 489CONFIG_IN=./config.in
 490if [ "$1" != "" ] ; then
 491        CONFIG_IN=$1
 492fi
 493
 494DEFAULTS=arch/$ARCH/defconfig
 495if [ -f .config ]; then
 496  DEFAULTS=.config
 497fi
 498
 499if [ -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 > /tmp/conf.$$
 505  . /tmp/conf.$$
 506  rm /tmp/conf.$$
 507else
 508  echo "#"
 509  echo "# No defaults found"
 510  echo "#"
 511fi
 512
 513. $CONFIG_IN
 514
 515rm -f .config.old
 516if [ -f .config ]; then
 517        mv .config .config.old
 518fi
 519mv .tmpconfig .config
 520mv .tmpconfig.h include/linux/autoconf.h
 521
 522echo
 523echo "The linux kernel is now hopefully configured for your setup."
 524echo "Check the top-level Makefile for additional configuration,"
 525echo "and do a 'make dep ; make clean' if you want to be sure all"
 526echo "the files are correctly re-made"
 527echo
 528
 529exit 0
 530
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.