ff9df950781ce131095ffa1c6399eae8419be273
[ircu2.10.12-pk.git] / config / Configure.in
1 # @configure_input@
2 #
3 # This script is used to configure the Undernet Daemon.
4 # It was copied from the linux kernel distribution and only slightly
5 # changed.
6 #
7 # 170897 (carlo@runaway.xs4all.nl) -
8 # Changed the default configuration file to be defconfig.
9 # Changed the location of autoconf.h to be 'include/'.
10 # Changed the final text printed at the end.
11 # Changed replacement to only match 'is not set' (and not 'is not').
12 # Added function string() and define_string().
13 # Added function define_macro()
14 #
15 # 180897 (carlo@runaway.xs4all.nl) -
16 # Changed bool() so it can take a default argument.
17 # Introduced hard link ../.config, to inherit config files over new
18 # distributions.
19 # Got rid of 'is not set' and using '=n' instead.
20 # Changed configuration help file to be doc/Configure.help.
21 # Changed DEFAULT into USE_DEFAULT, which is asked for in config.in.
22 #
23 # 210897 (carlo@runaway.xs4all.nl) -
24 # Changed the location of autoconf.h and .config to be 'configure/'.
25 # Fixed the script to work with a general 'sh' and not only with bash.
26 #       (removing 'function', using `` instead of $(), using \\$ inside
27 #        that instead of \$, using 'eval set -- $choices' rather then
28 #        'set -- $choices', introduction of function 'expr' instead of
29 #        using external executable 'expr', using set -fh rather then
30 #        set -f -h, using "" around reg.exp rather then '' and removing
31 #        unnecessary backslashes from it).
32 # Removed tristate and hex functions.
33 # Making the hardlink to ../.config only when configure/.config doesn't exist.
34 #
35 # 280897 (carlo@runaway.xs4all.nl) -
36 # Added CONFIG_NEW: Ask if one wants to use this configuration as main
37 #       configuration.
38 # Changed /bin/rm into $RM, so now this environment variable must be set!
39 #
40 # 290897 (carlo@runaway.xs4all.nl) -
41 # Added support for the solaris Born shell.
42 # Changed the directory configure/ to config/ in order not to collide with
43 # GNU autoconf in the future.
44 #
45 # 020997 (carlo@runaway.xs4all.nl) -
46 # The future is here... renamed 'config.in' to 'config-sh', reserving
47 # 'file.in' for input files of autoconfs' 'configure' script.
48 # 'autoconf.h' has been renamed to 'config.h', because it would be confusing
49 # otherwise with autoconf.
50 # Changed Configure to be run from within config/.
51 #
52 # 050997 (carlo@runaway.xs4all.nl) -
53 # Don't use 'def={$old:-$3}' but instead the equivalent ': ${def=$3}' because
54 # some sh don't understand the first expression.
55 # Pressing a 'c' at any question continues in 'batch' mode.
56 #
57 # 220199 (carlo@runaway.xs4all.nl) -
58 # Put MACRO name at front, making it easier to find it when scanning
59 # through the defaults to change just one.
60 # Make pressing 'c' stop at every paragraph, and pressing 'C' finish the
61 # whole script.
62 #
63 # -----------------------------------------------------------------------------
64 #
65 # This script is used to configure the linux kernel.
66 #
67 # It was inspired by the challenge in the original Configure script
68 # to ``do something better'', combined with the actual need to ``do
69 # something better'' because the old configure script wasn't flexible
70 # enough.
71 #
72 # Please send comments / questions / bug fixes to raymondc@microsoft.com.
73 #
74 #              ***** IMPORTANT COMPATIBILITY NOTE ****
75 # If configuration changes are made which might adversely effect 
76 # Menuconfig or xconfig, please notify the respective authors so that 
77 # those utilities can be updated in parallel.
78 #
79 # Menuconfig:  <roadcapw@cfw.com>
80 # xconfig:     <apenwarr@foxnet.net>  <eric@aib.com>
81 #              ****************************************
82 #
83 # Each line in the config file is a command.
84 #
85 # 050793 - use IFS='@' to get around a bug in a pre-version of bash-1.13
86 # with an empty IFS.
87 #
88 # 030995 (storner@osiris.ping.dk) - added support for tri-state answers,
89 # for selecting modules to compile.
90 #
91 # 180995 Bernhard Kaindl (bkaindl@ping.at) - added dummy functions for
92 # use with a config.in modified for make menuconfig.
93 #
94 # 301195 (boldt@math.ucsb.edu) - added help text support
95 #
96 # 281295 Paul Gortmaker - make tri_state functions collapse to boolean
97 # if module support is not enabled.
98 #
99 # 010296 Aaron Ucko (ucko@vax1.rockhurst.edu) - fix int and hex to accept
100 # arbitrary ranges
101 #
102 # 150296 Dick Streefland (dicks@tasking.nl) - report new configuration
103 # items and ask for a value even when doing a "make oldconfig"
104 #
105 # 200396 Tom Dyas (tdyas@eden.rutgers.edu) - when the module option is
106 # chosen for an item, define the macro <option_name>_MODULE
107 #
108 # 090397 Axel Boldt (boldt@math.ucsb.edu) - avoid ? and + in regular 
109 # expressions for GNU expr since version 1.15 and up use \? and \+.
110
111 #### Start of system configuration section. ####
112
113 SHELL=@SHPROG@
114 RM=@RMPROG@
115 LN_S="@LN_S@"
116 unet_cv_sys_set_h=@unet_cv_sys_set_h@
117
118 #### End of system configuration section. ####
119
120 # Disable filename globbing
121 set -f
122
123 if test $unet_cv_sys_set_h = yes; then
124         set -h
125 fi
126
127 # Figure out how to do 'echo' without newline:
128 c=''
129 n=''
130 if [ "`eval echo -n 'a'`" = "-n a" ] ; then
131         c='\c'
132 else
133         n='-n'
134 fi
135
136 # Check if ${VAR:-def} works
137 DUMMY_VAR=""
138 DUMMY_VAR2="some value"
139 DUMMY_VAR=${DUMMY_VAR:-test}
140 DUMMY_VAR2=${DUMMY_VAR2:-test}
141 if [ "$DUMMY_VAR" != "test" -o "$DUMMY_VAR2" != "some value" ]; then
142   echo "You /bin/sh doesn't understand '\${VAR:-default}'"
143   exit 1
144 fi
145
146 #
147 # Dummy functions for use with a config.in modified for menuconf
148 #
149 mainmenu_option () {
150         :
151 }
152 mainmenu_name () {
153         :
154 }
155 endmenu () {
156         :
157 }
158
159 #
160 # help prints the corresponding help text from Configure.help to stdout
161 #
162 #       help variable
163 #
164 help () {
165   if [ -f ../doc/Configure.help ]
166   then
167     #first escape regexp special characters in the argument:
168     var=`echo "$1"|sed 's/[][\/.^$*]/\\&/g'`
169     #now pick out the right help text:
170     text=`sed -n "/^$var[       ]*\\$/,\\${
171         /^$var[         ]*\\$/b
172         /^#.*/b
173         /^[     ]*\\$/q
174         p
175     }" ../doc/Configure.help`
176     if [ -z "$text" ]
177     then
178       echo; echo "  Sorry, no help available for this option yet.";echo
179     else
180       (echo; echo "$text"; echo) | ${PAGER:-more}
181     fi
182   else
183     echo;
184     echo "  Can't access the file doc/Configure.help which"
185     echo "  should contain the help texts."
186     echo
187   fi
188 }
189
190
191 #
192 # readln reads a line into $ans.
193 #
194 #       readln macro prompt default oldval
195 #
196 readln () {
197   echo $1 | awk '{ printf("%-20.20s: ", $1); }'
198   if [ "$USE_DEFAULT" != "n" -a -n "$4" ]; then
199     echo $2
200     ans=$3
201   else
202     echo $n "$2$c"
203     [ -z "$4" ] && echo $n "(NEW) $c"
204     IFS='@' read ans </dev/tty || exit 1
205     [ -z "$ans" ] && ans=$3
206     if [ "$ans" = "c" -o "$ans" = "C" ]; then
207       USE_DEFAULT=$ans
208       ans=$3
209     fi
210   fi
211 }
212
213 #
214 # comment does some pretty-printing
215 #
216 #       comment 'xxx'
217
218 comment () {
219   echo ""
220   echo "*-----------------------------------------------------------------------------";
221   echo "* $1" ;
222   echo "*"
223   (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
224   (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
225   if [ "$USE_DEFAULT" = "c" ]; then
226     USE_DEFAULT=n
227   fi
228 }
229
230 #
231 # define_bool sets the value of a boolean argument
232 #
233 #       define_bool define value
234 #
235 define_bool () {
236   case "$2" in
237     "y")
238       echo "$1=y" >>$CONFIG
239       echo "#define $1" >>$CONFIG_H
240       ;;
241
242     "n")
243       echo "$1=n" >>$CONFIG
244       echo "#undef  $1" >>$CONFIG_H
245       ;;
246   esac
247   eval "$1=$2"
248 }
249
250 #
251 # expr determines if string matches a regular expression
252 #
253 #       expr string reg_exp
254 #
255 expr () {
256   MATCH=`echo $1 | egrep -e $2`
257   if [ -z "$MATCH" ]; then
258     return 1
259   else
260     return 0
261   fi
262 }
263
264 #
265 # bool processes a boolean argument
266 #
267 #       bool question define
268 #
269 bool () {
270   old=`eval echo "\\${$2}"`
271   if [ -z "$old" -a -n "$3" ]; then
272     def=$3
273   else
274     def=${old:-n}
275   fi
276   case "$def" in
277     "y")
278       defprompt="Y/n/?"
279       def="y"
280       ;;
281
282     "n")
283       defprompt="N/y/?"
284       ;;
285   esac
286   while :; do
287     readln $2 "$1 [$defprompt] " "$def" "$old"
288     case "$ans" in
289       [yY] | [yY]es )
290         define_bool "$2" "y"
291         break
292         ;;
293
294       [nN] | [nN]o )
295         define_bool "$2" "n"
296         break
297         ;;
298
299       * )
300         help "$2"
301         ;;
302     esac
303   done
304 }
305
306 #
307 # define_int sets the value of a integer argument
308 #
309 #       define_int define value
310 #
311 define_int () {
312   echo "$1=$2" >>$CONFIG
313   echo "#define $1 ($2)" >>$CONFIG_H
314   eval "$1=$2"
315 }
316
317 #
318 # int processes an integer argument
319 #
320 #       int question define default
321 #
322 int () {
323   old=`eval echo "\\${$2}"`
324   def=${old:-$3}
325   while :; do
326     readln $2 "$1 [$def] " "$def" "$old"
327     if expr "$ans" "^0$|^(-[1-9]|[1-9])[0-9]*$"; then
328       define_int "$2" "$ans"
329       break
330     else
331       help "$2"
332     fi
333   done
334 }
335
336 #
337 # choice processes a choice list (1-out-of-n)
338 #
339 #       choice question choice-list default
340 #
341 # The choice list has a syntax of:
342 #       NAME WHITESPACE VALUE { WHITESPACE NAME WHITESPACE VALUE }
343 # The user may enter any unique prefix of one of the NAMEs and
344 # choice will define VALUE as if it were a boolean option.
345 # VALUE must be in all uppercase.  Normally, VALUE is of the
346 # form CONFIG_<something>.  Thus, if the user selects <something>,
347 # the CPP symbol CONFIG_<something> will be defined and the
348 # shell variable CONFIG_<something> will be set to "y".
349 #
350 choice () {
351   question="$1"
352   choices="$2"
353   old=
354   def=$3
355
356   # determine default answer:
357   names=""
358   eval set -- $choices
359   firstvar=$2
360   while [ -n "$2" ]; do
361     if [ -n "$names" ]; then
362       names="$names, $1"
363     else
364       names="$1"
365     fi
366     if [ "`eval echo "\\${$2}"`" = "y" ]; then
367       old=$1
368       def=$1
369     fi
370     shift; shift
371   done
372
373   val=""
374   while [ -z "$val" ]; do
375     ambg=n
376     readln $names "$question [$def] " "$def" "$old"
377     ans=`echo $ans | tr a-z A-Z`
378     eval set -- $choices
379     while [ -n "$1" ]; do
380       name=`echo $1 | tr a-z A-Z`
381       case "$name" in
382         "$ans"* )
383           if [ "$name" = "$ans" ]; then
384             val="$2"
385             break       # stop on exact match
386           fi
387           if [ -n "$val" ]; then
388             echo;
389             echo \
390                 "  Sorry, \"$ans\" is ambiguous; please enter a longer string."
391             echo
392             val=""
393             ambg=y
394             break
395           else
396             val="$2"
397           fi
398           ;;
399       esac
400       shift; shift
401     done
402     if [ "$val" = "" -a "$ambg" = "n" ]; then
403       help "$firstvar"
404     fi
405   done
406   eval set -- $choices
407   while [ -n "$2" ]; do
408     if [ "$2" = "$val" ]; then
409       echo "  defined $val"
410       define_bool "$2" "y"
411     else
412       define_bool "$2" "n"
413     fi
414     shift; shift
415   done
416 }
417
418 #
419 # define_macro sets the value of a macro argument
420 #
421 #       define_macro define value
422 #
423 define_macro () {
424   if [ -n "$2" ]; then
425     echo "$1=\"$2\"" >>$CONFIG
426     echo "#define $1 $2" >>$CONFIG_H
427   fi
428   eval "$1=\"$2\""
429 }
430
431 #
432 # define_string sets the value of a string argument
433 #
434 #       define_string define value
435 #
436 define_string () {
437   if [ -n "$2" ]; then
438     echo "$1=\"$2\"" >>$CONFIG
439     echo "#define $1 \"$2\"" >>$CONFIG_H
440   fi
441   eval "$1=\"$2\""
442 }
443
444 #
445 # string processes a string argument
446 #
447 #       string question define default
448 #
449 string () {
450   old=`eval echo "\\${$2}"`
451   def=${old:-$3}
452   while :; do
453     readln $2 "$1 [$def] " "$def" "$old"
454     if expr "$ans" "^[^\"].*[^\"]$"; then
455       define_string "$2" "$ans"
456       break
457     else
458       help "$2"
459     fi
460   done
461 }
462
463 CONFIG=.tmpconfig
464 CONFIG_H=.tmpconfig.h
465 trap "$RM -f $CONFIG $CONFIG_H ; exit 1" 1 2 15
466
467 #
468 # Make sure we start out with a clean slate.
469 #
470 echo "#" > $CONFIG
471 echo "# Configuration default generated for:" > $CONFIG
472 echo '# `pwd`' > $CONFIG
473 echo "#" > $CONFIG
474 echo "# Automatically generated by 'make config': don't edit" >> $CONFIG
475 echo "#" >> $CONFIG
476
477 echo "/*" > $CONFIG_H
478 echo " * Automatically generated C config: don't edit" >> $CONFIG_H
479 echo " */" >> $CONFIG_H
480 echo "#ifndef INCLUDED_config_h" >> $CONFIG_H
481 echo "#define INCLUDED_config_h" >> $CONFIG_H
482 echo "#ifndef INCLUDED_setup_h" >> $CONFIG_H
483 echo "#include \"setup.h\"">> $CONFIG_H
484 echo "#endif" >> $CONFIG_H
485 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
486
487 CONFIG_IN=./config-sh
488 if [ "$1" != "" ] ; then
489   CONFIG_IN=$1
490 fi
491
492 DEFAULTS=none
493 if [ -r .config ]; then
494   DEFAULTS=./.config
495 else
496   if [ -r ../../.config ]; then
497     echo "*"
498     echo "* WARNING: Inheriting .config from previous version!"
499     DEFAULTS=../../.config
500   fi
501 fi
502
503 if [ -r $DEFAULTS ]; then
504   echo "*"
505   echo "* Using defaults found in" $DEFAULTS
506   echo "* If you type a 'C' the script will finish using all defaults."
507   echo "* If you type a 'c' the script will skip to the next paragraph."
508   echo "*"
509   . $DEFAULTS
510 else
511   echo "*"
512   echo "* No defaults found"
513   echo "*"
514 fi
515
516 . $CONFIG_IN
517
518 echo "#endif /* INCLUDED_config_h */" >> $CONFIG_H
519
520 mv $CONFIG_H config.h
521 $RM -f .config.old
522 if [ -f .config ]; then
523   # Keep the inode of .config (hardlink to ../../.config) intact:
524   cp .config .config.old
525   cat $CONFIG > .config
526   $RM -f $CONFIG
527 fi
528 if test ! -f .config -o ! -r ../../.config; then
529   if [ "$CONFIG_BATCH" = "y" ]; then
530     CONFIG_NEW=n
531   else
532     CONFIG_NEW=y
533     USE_DEFAULT=n
534     echo "*"
535     echo "*"
536     echo "*"
537     bool 'Use .config of THIS source tree as your upgrade default' CONFIG_NEW
538   fi
539   if [ ! -f .config ]; then
540     mv $CONFIG .config
541   fi
542   if [ "$CONFIG_NEW" = "y" ]; then
543     CONFIG_CURDIR=`pwd`
544     cd ../..
545     $RM -f .config .config.cache
546     ln $CONFIG_CURDIR/.config .config
547     ln $CONFIG_CURDIR/config.cache .config.cache
548     echo
549     echo "NOTE: Linking ../.config to THIS source tree's configuration !"
550     echo "(The configuration of this source tree will be used as default when you upgrade)"
551   fi
552 fi
553
554 echo
555
556 exit 0