home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / Configure < prev    next >
Encoding:
Text File  |  1994-06-05  |  6.1 KB  |  279 lines

  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.
  109. set -f -h
  110.  
  111. #
  112. # readln reads a line into $ans.
  113. #
  114. #    readln prompt default
  115. #
  116. readln () {
  117.     echo -n "$1"
  118.     if [ -n "$Kickstart" ]
  119.     then
  120.          ans=$2; echo $2
  121.     else
  122.         IFS='@' read ans </dev/tty || exit 1
  123.     fi
  124.     [ -z "$ans" ] && ans=$2
  125. }
  126.  
  127. # bool processes a boolean argument
  128. #
  129. #    bool tail
  130. #
  131. bool () {
  132.     # Slimier hack to get bash to rescan a line.
  133.     eval "set -- $1"
  134.     ans=""
  135.     while [ "$ans" != "y" -a "$ans" != "n" ]; do
  136.         readln "$1 ($2) [$3] " "$3"
  137.     done
  138.     if [ "$ans" = "y" ]; then
  139.         echo "$2 = $2" >>$CONFIG
  140.         echo "#define $2 1" >>$CONFIG_H
  141.     else
  142.         echo "# $2 is not set" >>$CONFIG
  143.         echo "#undef $2" >>$CONFIG_H
  144.     fi
  145.     raw_input_line="bool '$1' $2 $ans"
  146.     eval "$2=$ans"
  147. }
  148.  
  149. # int processes an integer argument
  150. #
  151. #    int tail
  152. #
  153. int () {
  154.     # Slimier hack to get bash to rescan a line.
  155.     eval "set -- $1"
  156.     ans="x"
  157.     while [ $[$ans+0] != "$ans" ]; do
  158.         readln "$1 ($2) [$3] " "$3"
  159.     done
  160.     echo "$2 = $ans" >>$CONFIG
  161.     echo "#define $2 ($ans)" >>$CONFIG_H
  162.     raw_input_line="int '$1' $2 $ans"
  163.     eval "$2=$ans"
  164. }
  165.  
  166. # split a line into the command and the rest
  167. #
  168. split () {
  169.     set -- $1
  170.     cmd=$1
  171.     if [ $# -gt 1 ]; then
  172.         shift
  173.         rest=$*
  174.     else
  175.         rest=
  176.     fi
  177. }
  178.  
  179. # pull something off the branch stack
  180. #
  181. getstack () {
  182.     var=$1
  183.     eval "set -- $stack"
  184.     branch=$1
  185.     if [ $# -gt 1 ]; then
  186.         shift
  187.         eval "$var=$*"
  188.     else
  189.         eval "$var="
  190.     fi
  191. }
  192.  
  193.  
  194. CONFIG=.config~
  195. CONFIG_H=include/linux/autoconf.h
  196.  
  197. #
  198. # Make sure we start out with a clean slate.
  199. #
  200. > config.new
  201. echo "#" > $CONFIG
  202. echo "# Automatically generated make config: don't edit" >> $CONFIG
  203. echo "#" >> $CONFIG
  204.  
  205. echo "/*" > $CONFIG_H
  206. echo " * Automatically generated C config: don't edit" >> $CONFIG_H
  207. echo " */" >> $CONFIG_H
  208.  
  209. stack=''
  210. branch='t'
  211.  
  212. while IFS='@' read raw_input_line
  213. do
  214.     # Slimy hack to get bash to rescan a line.
  215.     #read cmd rest <<-END_OF_COMMAND
  216.     #    $raw_input_line
  217.     #END_OF_COMMAND
  218.     split "$raw_input_line"
  219.  
  220.     if [ "$cmd" = "*" ]; then
  221.         if [ "$branch" = "t" ]; then
  222.             echo "$raw_input_line"
  223.             echo "# $rest" >>$CONFIG
  224.             if [ "$prevcmd" != "*" ]; then
  225.                 echo >>$CONFIG_H
  226.                 echo "/* $rest" >>$CONFIG_H
  227.             else
  228.                 echo " * $rest" >>$CONFIG_H
  229.             fi
  230.             prevcmd="*"
  231.         fi
  232.     else
  233.         [ "$prevcmd" = "*" ] && echo " */" >>$CONFIG_H
  234.         prevcmd=""
  235.         case "$cmd" in
  236.         :)    [ "$branch" = "t" ] && echo "$raw_input_line" ;;
  237.         int)    [ "$branch" = "t" ] && int "$rest" ;;
  238.         bool)    [ "$branch" = "t" ] && bool "$rest" ;;
  239.         exec)    [ "$branch" = "t" ] && ( sh -c "$rest" ) ;;
  240.         "if")   stack="$branch $stack"
  241.             if [ "$branch" = "t" ] && eval "$rest"; then
  242.                 branch=t
  243.             else
  244.                 branch=f
  245.             fi ;;
  246.         "else") if [ "$branch" = "t" ]; then
  247.                 branch=f
  248.             else
  249.                 #read branch rest <<-END_OF_STACK
  250.                 #    $stack
  251.                 #END_OF_STACK
  252.                 getstack rest
  253.             fi ;;
  254.         "fi")   [ -z "$stack" ] && echo "Error!  Extra fi." 1>&2
  255.             #read branch stack <<-END_OF_STACK
  256.             #    $stack
  257.             #END_OF_STACK
  258.             getstack stack
  259.             ;;
  260.         esac
  261.     fi
  262.     echo "$raw_input_line" >>config.new
  263. done
  264. [ "$prevcmd" = "*" ] && echo " */" >>$CONFIG_H
  265.  
  266. [ -z "$stack" ] || echo "Error!  Unterminated if." 1>&2
  267.  
  268. mv config.in config.old
  269. mv config.new config.in
  270.  
  271. echo
  272. echo "The linux kernel is now hopefully configured for your setup."
  273. echo "Check the top-level Makefile for additional configuration,"
  274. echo "and do a 'make dep ; make clean' if you want to be sure all"
  275. echo "the files are correctly re-made"
  276. echo
  277.  
  278. exit 0
  279.