linux-old/Configure
<<
>>
Prefs
   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# Please send comments / questions / bug fixes to raymondc@microsoft.com.
  11#
  12# Each line in the config file is a command.
  13#
  14#       # internal comment
  15#
  16#               Lines beginning with a `#' are ignored.
  17#
  18#       : message
  19#
  20#               `:' causes the line to be echoed to the screen.
  21#
  22#       * external comment
  23#
  24#               `*' causes the line to be placed in the output
  25#               configuration file as a comment as well as being
  26#               echoed to the screen.
  27#
  28#       if condition
  29#               ... commands ...
  30#       else
  31#               ... commands ...
  32#       fi
  33#
  34#               This does the obvious thing.  The `else' clause is
  35#               optional.  Conditionals can be nested.
  36#
  37#               The `condition' can be any valid bash expression.
  38#               They typically involve tests against environment
  39#               variables set by configuration options.  For example,
  40#
  41#               if [ "$CONFIG_SCSI" = "y" ]
  42#                       ...More stuff...
  43#               fi
  44#
  45#               Note!  That there is no `then' keyword.
  46#
  47#       bool 'prompt' CONFIG_VARIABLE default
  48#
  49#               This prompts the user for a boolean value.
  50#               The prompt may not contain an apostrophe.
  51#               `default' should be either `y' or `n'.
  52#               The user's response is recorded in four places.
  53#
  54#               In .config, if `y'
  55#                       CONFIG_VARIABLE = CONFIG_VARIABLE
  56#               In .config, if `n'
  57#                       # CONFIG_VARIABLE is not set
  58#                       
  59#               In autoconf.h, if `y'
  60#                       #define CONFIG_VARIABLE 1
  61#               In autoconf.h, if `n'
  62#                       #undef CONFIG_VARIABLE
  63#
  64#               In config.in, if `y'
  65#                       bool 'prompt' CONFIG_VARIABLE y
  66#               In config.in, if `n'
  67#                       bool 'prompt' CONFIG_VARIABLE n
  68#
  69#               In the environment of the Configure script, if `y'
  70#                       CONFIG_VARIABLE = y
  71#               In the environment of the Configure script, if `n'
  72#                       CONFIG_VARIABLE = n
  73#
  74#               The value is placed into the environment of the Configure
  75#               script so that later parts of config.in can use the `if'
  76#               command to inspect the results of previous queries.
  77#
  78#       int 'prompt' CONFIG_VARIABLE default
  79#
  80#               This prompts the user for an integer value.
  81#               The prompt may not contain an apostrophe.
  82#               `default' should be an integer.
  83#
  84#               The response is recorded as follows.
  85#
  86#               In .config
  87#                       CONFIG_VARIABLE = response
  88#               In autoconf.h
  89#                       #define CONFIG_VARIABLE (response)
  90#               In config.in
  91#                       int 'prompt' CONFIG_VARIABLE response
  92#               In the environment of the Configure script
  93#                       CONFIG_VARIABLE = response
  94#
  95# 050793 - use IFS='@' to get around a bug in a pre-version of bash-1.13
  96# with an empty IFS.
  97
  98#
  99# Make sure we're really running bash.
 100#
 101# I would really have preferred to write this script in a language with
 102# better string handling, but alas, bash is the only scripting language
 103# that I can be reasonable sure everybody has on their linux machine.
 104#
 105[ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
 106
 107# Disable filename globbing once and for all.
 108# Enable function cacheing.
 109set -f -h
 110
 111#
 112# readln reads a line into $ans.
 113#
 114#       readln prompt default
 115#
 116function readln () {
 117        echo -n "$1"
 118        IFS='@' read ans </dev/tty || exit 1
 119        [ -z "$ans" ] && ans=$2
 120}
 121
 122# bool processes a boolean argument
 123#
 124#       bool tail
 125#
 126function bool () {
 127        # Slimier hack to get bash to rescan a line.
 128        eval "set -- $1"
 129        ans=""
 130        while [ "$ans" != "y" -a "$ans" != "n" ]; do
 131                readln "$1 ($2) [$3] " "$3"
 132        done
 133        if [ "$ans" = "y" ]; then
 134                echo "$2 = $2" >>$CONFIG
 135                echo "#define $2 1" >>$CONFIG_H
 136        else
 137                echo "# $2 is not set" >>$CONFIG
 138                echo "#undef $2" >>$CONFIG_H
 139        fi
 140        raw_input_line="bool '$1' $2 $ans"
 141        eval "$2=$ans"
 142}
 143
 144# int processes an integer argument
 145#
 146#       int tail
 147#
 148function int () {
 149        # Slimier hack to get bash to rescan a line.
 150        eval "set -- $1"
 151        ans="x"
 152        while [ $[$ans+0] != "$ans" ]; do
 153                readln "$1 ($2) [$3] " "$3"
 154        done
 155        echo "$2 = $ans" >>$CONFIG
 156        echo "#define $2 ($ans)" >>$CONFIG_H
 157        raw_input_line="int '$1' $2 $ans"
 158        eval "$2=$ans"
 159}
 160
 161CONFIG=.tmpconfig
 162CONFIG_H=include/linux/autoconf.h
 163trap "rm -f $CONFIG $CONFIG_H config.new ; exit 1" 1 2
 164
 165#
 166# Make sure we start out with a clean slate.
 167#
 168> config.new
 169echo "#" > $CONFIG
 170echo "# Automatically generated make config: don't edit" >> $CONFIG
 171echo "#" >> $CONFIG
 172
 173echo "/*" > $CONFIG_H
 174echo " * Automatically generated C config: don't edit" >> $CONFIG_H
 175echo " */" >> $CONFIG_H
 176
 177stack=''
 178branch='t'
 179
 180while IFS='@' read raw_input_line
 181do
 182        # Slimy hack to get bash to rescan a line.
 183        read cmd rest <<-END_OF_COMMAND
 184                $raw_input_line
 185        END_OF_COMMAND
 186
 187        if [ "$cmd" = "*" ]; then
 188                if [ "$branch" = "t" ]; then
 189                        echo "$raw_input_line"
 190                        echo "# $rest" >>$CONFIG
 191                        if [ "$prevcmd" != "*" ]; then
 192                                echo >>$CONFIG_H
 193                                echo "/* $rest" >>$CONFIG_H
 194                        else
 195                                echo " * $rest" >>$CONFIG_H
 196                        fi
 197                        prevcmd="*"
 198                fi
 199        else
 200                [ "$prevcmd" = "*" ] && echo " */" >>$CONFIG_H
 201                prevcmd=""
 202                case "$cmd" in
 203                :)      [ "$branch" = "t" ] && echo "$raw_input_line" ;;
 204                int)    [ "$branch" = "t" ] && int "$rest" ;;
 205                bool)   [ "$branch" = "t" ] && bool "$rest" ;;
 206                exec)   [ "$branch" = "t" ] && ( sh -c "$rest" ) ;;
 207                if)     stack="$branch $stack"
 208                        if [ "$branch" = "t" ] && eval "$rest"; then
 209                                branch=t
 210                        else
 211                                branch=f
 212                        fi ;;
 213                else)   if [ "$branch" = "t" ]; then
 214                                branch=f
 215                        else
 216                                read branch rest <<-END_OF_STACK
 217                                        $stack
 218                                END_OF_STACK
 219                        fi ;;
 220                fi)     [ -z "$stack" ] && echo "Error!  Extra fi." 1>&2
 221                        read branch stack <<-END_OF_STACK
 222                                $stack
 223                        END_OF_STACK
 224                        ;;
 225                esac
 226        fi
 227        echo "$raw_input_line" >>config.new
 228done
 229[ "$prevcmd" = "*" ] && echo " */" >>$CONFIG_H
 230
 231[ -z "$stack" ] || echo "Error!  Untermiated if." 1>&2
 232
 233mv config.in config.old
 234mv config.new config.in
 235
 236echo
 237echo "The linux kernel is now hopefully configured for your setup."
 238echo "Check the top-level Makefile for additional configuration,"
 239echo "and do a 'make dep ; make clean' if you want to be sure all"
 240echo "the files are correctly re-made"
 241echo
 242
 243exit 0
 244
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.