Linux 2.4.0-test10pre1
[davej-history.git] / scripts / Menuconfig
blob5a76152e734cc925a1712cacb566bb7321a94821
1 #! /bin/sh
3 # This script is used to configure the linux kernel.
5 # It was inspired by a desire to not have to hit <enter> 9 million times
6 # or startup the X server just to change a single kernel parameter.
8 # This script attempts to parse the configuration files, which are
9 # scattered throughout the kernel source tree, and creates a temporary
10 # set of mini scripts which are in turn used to create nested menus and
11 # radiolists.
13 # It uses a very modified/mutilated version of the "dialog" utility
14 # written by Savio Lam (lam836@cs.cuhk.hk). Savio is not responsible
15 # for this script or the version of dialog used by this script.
16 # Please do not contact him with questions. The official version of
17 # dialog is available at sunsite.unc.edu or a sunsite mirror.
19 # Portions of this script were borrowed from the original Configure
20 # script.
22 # William Roadcap was the original author of Menuconfig.
23 # Michael Elizabeth Chastain (mec@shout.net) is the current maintainer.
25 # 070497 Bernhard Kaindl (bkaindl@netway.at) - get default values for
26 # new bool, tristate and dep_tristate parameters from the defconfig file.
27 # new configuration parameters are marked with '(NEW)' as in make config.
29 # 180697 Bernhard Kaindl (bkaindl@netway.at) - added the needed support
30 # for string options. They are handled like the int and hex options.
32 # 081297 Pavel Machek (pavel@atrey.karlin.mff.cuni.cz) - better error
33 # handling
35 # 131197 Michael Chastain (mec@shout.net) - output all lines for a
36 # choice list, not just the selected one. This makes the output
37 # the same as Configure output, which is important for smart config
38 # dependencies.
40 # 101297 Michael Chastain (mec@shout.net) - remove sound driver cruft.
42 # 221297 Michael Chastain (mec@shout.net) - make define_bool actually
43 # define its arguments so that later tests on them work right.
45 # 160198 Michael Chastain (mec@shout.net) - fix bug with 'c' command
46 # (complement existing value) when used on virgin uninitialized variables.
48 # 090398 Axel Boldt (boldt@math.ucsb.edu) - allow for empty lines in help
49 # texts.
51 # 12 Dec 1998, Michael Elizabeth Chastain (mec@shout.net)
52 # Remove a /tmp security hole in get_def (also makes it faster).
53 # Give uninitialized variables canonical values rather than null value.
54 # Change a lot of places to call set_x_info uniformly.
55 # Take out message about preparing version (old sound driver cruft).
57 # 13 Dec 1998, Riley H Williams <rhw@memalpha.cx>
58 # When an error occurs, actually display the error message as well as
59 # our comments thereon.
61 # 31 Dec 1998, Michael Elizabeth Chastain (mec@shout.net)
62 # Fix mod_bool to honor $CONFIG_MODULES.
63 # Fix dep_tristate to call define_bool when dependency is "n".
65 # 02 January 1999, Michael Elizabeth Chastain (mec@shout.net)
66 # Blow away lxdialog.scrltmp on entry to activate_menu. This protects
67 # against people who use commands like ' ' to select menus.
69 # 24 January 1999, Michael Elizabeth Chastain, <mec@shout.net>
70 # - Improve the exit message (Jeff Ronne).
72 # 06 July 1999, Andrzej M. Krzysztofowicz, <ankry@mif.pg.gda.pl>
73 # - Support for multiple conditions in dep_tristate().
74 # - Implemented new functions: define_tristate(), define_int(), define_hex(),
75 # define_string(), dep_bool().
80 # Change this to TRUE if you prefer all kernel options listed
81 # in a single menu rather than the standard menu hierarchy.
83 single_menu_mode=
86 # Make sure we're really running bash.
88 [ -z "$BASH" ] && { echo "Menuconfig requires bash" 1>&2; exit 1; }
91 # Cache function definitions, turn off posix compliance
93 set -h +o posix
97 # Given a configuration variable, set the global variable $x to its value,
98 # and the global variable $info to the string " (NEW)" if this is a new
99 # variable.
101 # This function looks for: (1) the current value, or (2) the default value
102 # from the arch-dependent defconfig file, or (3) a default passed by the caller.
104 function set_x_info () {
105 eval x=\$$1
106 if [ -z "$x" ]; then
107 eval `sed -n -e 's/# \(.*\) is not set.*/\1=n/' -e "/^$1=/p" arch/$ARCH/defconfig`
108 eval x=\${$1:-"$2"}
109 eval $1=$x
110 eval INFO_$1="' (NEW)'"
112 eval info="\$INFO_$1"
116 # Load the functions used by the config.in files.
118 # I do this because these functions must be redefined depending
119 # on whether they are being called for interactive use or for
120 # saving a configuration to a file.
122 # Thank the heavens bash supports nesting function definitions.
124 load_functions () {
127 # Additional comments
129 function comment () {
130 comment_ctr=$[ comment_ctr + 1 ]
131 echo -ne "': $comment_ctr' '--- $1' " >>MCmenu
135 # Define a boolean to a specific value.
137 function define_bool () {
138 eval $1=$2
141 function define_tristate () {
142 eval $1=$2
145 function define_hex () {
146 eval $1=$2
149 function define_int () {
150 eval $1=$2
153 function define_string () {
154 eval $1="$2"
158 # Create a boolean (Yes/No) function for our current menu
159 # which calls our local bool function.
161 function bool () {
162 set_x_info "$2" "n"
164 case $x in
165 y|m) flag="*" ;;
166 n) flag=" " ;;
167 esac
169 echo -ne "'$2' '[$flag] $1$info' " >>MCmenu
171 echo -e "function $2 () { l_bool '$2' \"\$1\" ;}\n" >>MCradiolists
175 # Create a tristate (Yes/No/Module) radiolist function
176 # which calls our local tristate function.
178 # Collapses to a boolean (Yes/No) if module support is disabled.
180 function tristate () {
181 if [ "$CONFIG_MODULES" != "y" ]
182 then
183 bool "$1" "$2"
184 else
185 set_x_info "$2" "n"
187 case $x in
188 y) flag="*" ;;
189 m) flag="M" ;;
190 *) flag=" " ;;
191 esac
193 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
195 echo -e "
196 function $2 () { l_tristate '$2' \"\$1\" ;}" >>MCradiolists
201 # Create a tristate radiolist function which is dependent on
202 # another kernel configuration option.
204 # Quote from the original configure script:
206 # If the option we depend upon is a module,
207 # then the only allowable options are M or N. If Y, then
208 # this is a normal tristate. This is used in cases where modules
209 # are nested, and one module requires the presence of something
210 # else in the kernel.
212 function dep_tristate () {
213 ques="$1"
214 var="$2"
215 dep=y
216 shift 2
217 while [ $# -gt 0 ]; do
218 if [ "$1" = y ]; then
219 shift
220 elif [ "$1" = m ]; then
221 dep=m
222 shift
223 else
224 dep=n
225 shift $#
227 done
228 if [ "$dep" = y ]; then
229 tristate "$ques" "$var"
230 elif [ "$dep" = m ]; then
231 mod_bool "$ques" "$var"
232 else
233 define_tristate "$var" n
238 # Same as above, but now only Y and N are allowed as dependency
239 # (i.e. third and next arguments).
241 function dep_bool () {
242 ques="$1"
243 var="$2"
244 dep=y
245 shift 2
246 while [ $# -gt 0 ]; do
247 if [ "$1" = y ]; then
248 shift
249 else
250 dep=n
251 shift $#
253 done
254 if [ "$dep" = y ]; then
255 bool "$ques" "$var"
256 else
257 define_bool "$var" n
261 function dep_mbool () {
262 ques="$1"
263 var="$2"
264 dep=y
265 shift 2
266 while [ $# -gt 0 ]; do
267 if [ "$1" = y -o "$1" = m ]; then
268 shift
269 else
270 dep=n
271 shift $#
273 done
274 if [ "$dep" = y ]; then
275 bool "$ques" "$var"
276 else
277 define_bool "$var" n
282 # Add a menu item which will call our local int function.
284 function int () {
285 set_x_info "$2" "$3"
287 echo -ne "'$2' '($x) $1$info' " >>MCmenu
289 echo -e "function $2 () { l_int '$1' '$2' '$3' '$x' ;}" >>MCradiolists
293 # Add a menu item which will call our local hex function.
295 function hex () {
296 set_x_info "$2" "$3"
297 x=${x##*[x,X]}
299 echo -ne "'$2' '($x) $1$info' " >>MCmenu
301 echo -e "function $2 () { l_hex '$1' '$2' '$3' '$x' ;}" >>MCradiolists
305 # Add a menu item which will call our local string function.
307 function string () {
308 set_x_info "$2" "$3"
310 echo -ne "'$2' ' $1: \"$x\"$info' " >>MCmenu
312 echo -e "function $2 () { l_string '$1' '$2' '$3' '$x' ;}" >>MCradiolists
316 # Add a menu item which will call our local One-of-Many choice list.
318 function choice () {
320 # Need to remember params cause they're gonna get reset.
322 title=$1
323 choices=$2
324 default=$3
325 current=
328 # Find out if one of the choices is already set.
329 # If it's not then make it the default.
331 set -- $choices
332 firstchoice=$2
334 while [ -n "$2" ]
336 if eval [ "_\$$2" = "_y" ]
337 then
338 current=$1
339 break
341 shift ; shift
342 done
344 : ${current:=$default}
346 echo -ne "'$firstchoice' '($current) $title' " >>MCmenu
348 echo -e "
349 function $firstchoice () \
350 { l_choice '$title' \"$choices\" $current ;}" >>MCradiolists
353 } # END load_functions()
360 # Extract available help for an option from Configure.help
361 # and send it to standard output.
363 # Most of this function was borrowed from the original kernel
364 # Configure script.
366 function extract_help () {
367 if [ -f Documentation/Configure.help ]
368 then
369 #first escape regexp special characters in the argument:
370 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
371 #now pick out the right help text:
372 text=$(sed -n "/^$var[ ]*\$/,\${
373 /^$var[ ]*\$/c\\
374 ${var}:\\
376 /^#/b
377 /^[^ ]/q
378 s/^ //
380 }" Documentation/Configure.help)
382 if [ -z "$text" ]
383 then
384 echo "There is no help available for this kernel option."
385 return 1
386 else
387 echo "$text"
389 else
390 echo "There is no help available for this kernel option."
391 return 1
396 # Activate a help dialog.
398 function help () {
399 if extract_help $1 >help.out
400 then
401 $DIALOG --backtitle "$backtitle" --title "$2"\
402 --textbox help.out $ROWS $COLS
403 else
404 $DIALOG --backtitle "$backtitle" \
405 --textbox help.out $ROWS $COLS
407 rm -f help.out
411 # Show the README file.
413 function show_readme () {
414 $DIALOG --backtitle "$backtitle" \
415 --textbox scripts/README.Menuconfig $ROWS $COLS
419 # Begin building the dialog menu command and Initialize the
420 # Radiolist function file.
422 function menu_name () {
423 echo -ne "$DIALOG --title '$1'\
424 --backtitle '$backtitle' \
425 --menu '$menu_instructions' \
426 $ROWS $COLS $((ROWS-10)) \
427 '$default' " >MCmenu
428 >MCradiolists
432 # Add a submenu option to the menu currently under construction.
434 function submenu () {
435 echo -ne "'activate_menu $2' '$1 --->' " >>MCmenu
439 # Handle a boolean (Yes/No) option.
441 function l_bool () {
442 if [ -n "$2" ]
443 then
444 case "$2" in
445 y|m) eval $1=y ;;
446 c) eval x=\$$1
447 case $x in
448 y) eval $1=n ;;
449 n) eval $1=y ;;
450 *) eval $1=y ;;
451 esac ;;
452 *) eval $1=n ;;
453 esac
454 else
455 echo -ne "\007"
460 # Same as bool() except options are (Module/No)
462 function mod_bool () {
463 if [ "$CONFIG_MODULES" != "y" ]; then
464 define_bool "$2" "n"
465 else
466 set_x_info "$2" "n"
468 case $x in
469 y|m) flag='M' ;;
470 *) flag=' ' ;;
471 esac
473 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
475 echo -e "function $2 () { l_mod_bool '$2' \"\$1\" ;}" >>MCradiolists
480 # Same as l_bool() except options are (Module/No)
482 function l_mod_bool() {
483 if [ -n "$2" ]
484 then
485 case "$2" in
486 y) echo -en "\007"
487 ${DIALOG} --backtitle "$backtitle" \
488 --infobox "\
489 This feature depends on another which has been configured as a module. \
490 As a result, this feature will be built as a module." 4 70
491 sleep 5
492 eval $1=m ;;
493 m) eval $1=m ;;
494 c) eval x=\$$1
495 case $x in
496 m) eval $1=n ;;
497 n) eval $1=m ;;
498 *) eval $1=m ;;
499 esac ;;
500 *) eval $1=n ;;
501 esac
502 else
503 echo -ne "\007"
508 # Handle a tristate (Yes/No/Module) option.
510 function l_tristate () {
511 if [ -n "$2" ]
512 then
513 eval x=\$$1
515 case "$2" in
516 y) eval $1=y ;;
517 m) eval $1=m ;;
518 c) eval x=\$$1
519 case $x in
520 y) eval $1=n ;;
521 n) eval $1=m ;;
522 m) eval $1=y ;;
523 *) eval $1=y ;;
524 esac ;;
525 *) eval $1=n ;;
526 esac
527 else
528 echo -ne "\007"
533 # Create a dialog for entering an integer into a kernel option.
535 function l_int () {
536 while true
538 if $DIALOG --title "$1" \
539 --backtitle "$backtitle" \
540 --inputbox "$inputbox_instructions_int" \
541 10 75 "$4" 2>MCdialog.out
542 then
543 answer="`cat MCdialog.out`"
544 answer="${answer:-$3}"
546 # Semantics of + and ? in GNU expr changed, so
547 # we avoid them:
548 if expr "$answer" : '0$' '|' "$answer" : '[1-9][0-9]*$' '|' "$answer" : '-[1-9][0-9]*$' >/dev/null
549 then
550 eval $2="$answer"
551 else
552 eval $2="$3"
553 echo -en "\007"
554 ${DIALOG} --backtitle "$backtitle" \
555 --infobox "You have made an invalid entry." 3 43
556 sleep 2
559 break
562 help "$2" "$1"
563 done
567 # Create a dialog for entering a hexadecimal into a kernel option.
569 function l_hex () {
570 while true
572 if $DIALOG --title "$1" \
573 --backtitle "$backtitle" \
574 --inputbox "$inputbox_instructions_hex" \
575 10 75 "$4" 2>MCdialog.out
576 then
577 answer="`cat MCdialog.out`"
578 answer="${answer:-$3}"
579 answer="${answer##*[x,X]}"
581 if expr "$answer" : '[0-9a-fA-F][0-9a-fA-F]*$' >/dev/null
582 then
583 eval $2="$answer"
584 else
585 eval $2="$3"
586 echo -en "\007"
587 ${DIALOG} --backtitle "$backtitle" \
588 --infobox "You have made an invalid entry." 3 43
589 sleep 2
592 break
595 help "$2" "$1"
596 done
600 # Create a dialog for entering a string into a kernel option.
602 function l_string () {
603 while true
605 if $DIALOG --title "$1" \
606 --backtitle "$backtitle" \
607 --inputbox "$inputbox_instructions_string" \
608 10 75 "$4" 2>MCdialog.out
609 then
610 answer="`cat MCdialog.out`"
611 answer="${answer:-$3}"
614 # Someone may add a nice check for the entered
615 # string here...
617 eval $2=\"$answer\"
619 break
622 help "$2" "$1"
623 done
628 # Handle a one-of-many choice list.
630 function l_choice () {
632 # Need to remember params cause they're gonna get reset.
634 title="$1"
635 choices="$2"
636 current="$3"
637 chosen=
640 # Scan current value of choices and set radiolist switches.
642 list=
643 set -- $choices
644 firstchoice=$2
645 while [ -n "$2" ]
647 case "$1" in
648 "$current"*) if [ -z "$chosen" ]; then
649 list="$list $2 $1 ON "
650 chosen=1
651 else
652 list="$list $2 $1 OFF "
653 fi ;;
654 *) list="$list $2 $1 OFF " ;;
655 esac
657 shift ; shift
658 done
660 while true
662 if $DIALOG --title "$title" \
663 --backtitle "$backtitle" \
664 --radiolist "$radiolist_instructions" \
665 15 70 6 $list 2>MCdialog.out
666 then
667 choice=`cat MCdialog.out`
668 break
671 help "$firstchoice" "$title"
672 done
675 # Now set the boolean value of each option based on
676 # the selection made from the radiolist.
678 set -- $choices
679 while [ -n "$2" ]
681 if [ "$2" = "$choice" ]
682 then
683 eval $2="y"
684 else
685 eval $2="n"
688 shift ; shift
689 done
693 # Call awk, and watch for error codes, etc.
695 function callawk () {
696 awk "$1" || echo "Awk died with error code $?. Giving up." || exit 1
700 # A faster awk based recursive parser. (I hope)
702 function parser1 () {
703 callawk '
704 BEGIN {
705 menu_no = 0
706 comment_is_option = 0
707 parser("'$CONFIG_IN'","MCmenu0")
710 function parser(ifile,menu) {
712 while (getline <ifile) {
713 if ($1 == "mainmenu_option") {
714 comment_is_option = "1"
716 else if ($1 == "comment" && comment_is_option == "1") {
717 comment_is_option= "0"
718 sub($1,"",$0)
719 ++menu_no
721 printf("submenu %s MCmenu%s\n", $0, menu_no) >>menu
723 newmenu = sprintf("MCmenu%d", menu_no);
724 printf( "function MCmenu%s () {\n"\
725 "default=$1\n"\
726 "menu_name %s\n",\
727 menu_no, $0) >newmenu
729 parser(ifile, newmenu)
731 else if ($0 ~ /^#|\$MAKE|mainmenu_name/) {
732 printf("") >>menu
734 else if ($1 ~ "endmenu") {
735 printf("}\n") >>menu
736 return
738 else if ($1 == "source") {
739 parser($2,menu)
741 else {
742 print >>menu
749 # Secondary parser for single menu mode.
751 function parser2 () {
752 callawk '
753 BEGIN {
754 parser("'$CONFIG_IN'","MCmenu0")
757 function parser(ifile,menu) {
759 while (getline <ifile) {
760 if ($0 ~ /^#|$MAKE|mainmenu_name/) {
761 printf("") >>menu
763 else if ($1 ~ /mainmenu_option|endmenu/) {
764 printf("") >>menu
766 else if ($1 == "source") {
767 parser($2,menu)
769 else {
770 print >>menu
777 # Parse all the config.in files into mini scripts.
779 function parse_config_files () {
780 rm -f MCmenu*
782 echo "function MCmenu0 () {" >MCmenu0
783 echo 'default=$1' >>MCmenu0
784 echo "menu_name 'Main Menu'" >>MCmenu0
786 if [ "_$single_menu_mode" = "_TRUE" ]
787 then
788 parser2
789 else
790 parser1
793 echo "comment ''" >>MCmenu0
794 echo "g_alt_config" >>MCmenu0
795 echo "s_alt_config" >>MCmenu0
797 echo "}" >>MCmenu0
800 # These mini scripts must be sourced into the current
801 # environment in order for all of this to work. Leaving
802 # them on the disk as executables screws up the recursion
803 # in activate_menu(), among other things. Once they are
804 # sourced we can discard them.
806 for i in MCmenu*
808 echo -n "."
809 source ./$i
810 done
811 rm -f MCmenu*
815 # This is the menu tree's bootstrap.
817 # Executes the parsed menus on demand and creates a set of functions,
818 # one per configuration option. These functions will in turn execute
819 # dialog commands or recursively call other menus.
821 function activate_menu () {
822 rm -f lxdialog.scrltmp
823 while true
825 comment_ctr=0 #So comment lines get unique tags
827 $1 "$default" 2> MCerror #Create the lxdialog menu & functions
829 if [ "$?" != "0" ]
830 then
831 clear
832 cat <<EOM
834 Menuconfig has encountered a possible error in one of the kernel's
835 configuration files and is unable to continue. Here is the error
836 report:
839 sed 's/^/ Q> /' MCerror
840 cat <<EOM
842 Please report this to the maintainer <mec@shout.net>. You may also
843 send a problem report to <linux-kernel@vger.kernel.org>.
845 Please indicate the kernel version you are trying to configure and
846 which menu you were trying to enter when this error occurred.
849 cleanup
850 exit 1
852 rm -f MCerror
854 . ./MCradiolists #Source the menu's functions
856 . ./MCmenu 2>MCdialog.out #Activate the lxdialog menu
857 ret=$?
859 read selection <MCdialog.out
861 case "$ret" in
862 0|3|4|5|6)
863 defaults="$selection\x12$defaults" #pseudo stack
864 case "$ret" in
865 0) eval $selection ;;
866 3) eval $selection y ;;
867 4) eval $selection n ;;
868 5) eval $selection m ;;
869 6) eval $selection c ;;
870 esac
871 default="${defaults%%\x12*}" defaults="${defaults#*\x12}"
874 default="${selection%%\ *}"
876 case "$selection" in
877 *"-->"*|*"alt_config"*)
878 show_readme ;;
880 eval help $selection ;;
881 esac
883 255|1)
884 break
886 139)
887 stty sane
888 clear
889 cat <<EOM
891 There seems to be a problem with the lxdialog companion utility which is
892 built prior to running Menuconfig. Usually this is an indicator that you
893 have upgraded/downgraded your ncurses libraries and did not remove the
894 old ncurses header file(s) in /usr/include or /usr/include/ncurses.
896 It is VERY important that you have only one set of ncurses header files
897 and that those files are properly version matched to the ncurses libraries
898 installed on your machine.
900 You may also need to rebuild lxdialog. This can be done by moving to
901 the /usr/src/linux/scripts/lxdialog directory and issuing the
902 "make clean all" command.
904 If you have verified that your ncurses install is correct, you may email
905 the maintainer <mec@shout.net> or post a message to
906 <linux-kernel@vger.kernel.org> for additional assistance.
909 cleanup
910 exit 139
912 esac
913 done
917 # Create a menu item to load an alternate configuration file.
919 g_alt_config () {
920 echo -n "get_alt_config 'Load an Alternate Configuration File' "\
921 >>MCmenu
925 # Get alternate config file name and load the
926 # configuration from it.
928 get_alt_config () {
929 set -f ## Switch file expansion OFF
931 while true
933 ALT_CONFIG="${ALT_CONFIG:-$DEFAULTS}"
935 $DIALOG --backtitle "$backtitle" \
936 --inputbox "\
937 Enter the name of the configuration file you wish to load. \
938 Accept the name shown to restore the configuration you \
939 last retrieved. Leave blank to abort."\
940 11 55 "$ALT_CONFIG" 2>MCdialog.out
942 if [ "$?" = "0" ]
943 then
944 ALT_CONFIG=`cat MCdialog.out`
946 [ "_" = "_$ALT_CONFIG" ] && break
948 if eval [ -r "$ALT_CONFIG" ]
949 then
950 eval load_config_file "$ALT_CONFIG"
951 break
952 else
953 echo -ne "\007"
954 $DIALOG --backtitle "$backtitle" \
955 --infobox "File does not exist!" 3 38
956 sleep 2
958 else
959 cat <<EOM >help.out
961 For various reasons, one may wish to keep several different kernel
962 configurations available on a single machine.
964 If you have saved a previous configuration in a file other than the
965 kernel's default, entering the name of the file here will allow you
966 to modify that configuration.
968 If you are uncertain, then you have probably never used alternate
969 configuration files. You should therefor leave this blank to abort.
972 $DIALOG --backtitle "$backtitle"\
973 --title "Load Alternate Configuration"\
974 --textbox help.out $ROWS $COLS
976 done
978 set +f ## Switch file expansion ON
979 rm -f help.out MCdialog.out
983 # Create a menu item to store an alternate config file.
985 s_alt_config () {
986 echo -n "save_alt_config 'Save Configuration to an Alternate File' "\
987 >>MCmenu
991 # Get an alternate config file name and save the current
992 # configuration to it.
994 save_alt_config () {
995 set -f ## Switch file expansion OFF
997 while true
999 $DIALOG --backtitle "$backtitle" \
1000 --inputbox "\
1001 Enter a filename to which this configuration should be saved \
1002 as an alternate. Leave blank to abort."\
1003 10 55 "$ALT_CONFIG" 2>MCdialog.out
1005 if [ "$?" = "0" ]
1006 then
1007 ALT_CONFIG=`cat MCdialog.out`
1009 [ "_" = "_$ALT_CONFIG" ] && break
1011 if eval touch $ALT_CONFIG 2>/dev/null
1012 then
1013 eval save_configuration $ALT_CONFIG
1014 load_functions ## RELOAD
1015 break
1016 else
1017 echo -ne "\007"
1018 $DIALOG --backtitle "$backtitle" \
1019 --infobox "Can't create file! Probably a nonexistent directory." 3 60
1020 sleep 2
1022 else
1023 cat <<EOM >help.out
1025 For various reasons, one may wish to keep different kernel
1026 configurations available on a single machine.
1028 Entering a file name here will allow you to later retrieve, modify
1029 and use the current configuration as an alternate to whatever
1030 configuration options you have selected at that time.
1032 If you are uncertain what all this means then you should probably
1033 leave this blank.
1035 $DIALOG --backtitle "$backtitle"\
1036 --title "Save Alternate Configuration"\
1037 --textbox help.out $ROWS $COLS
1039 done
1041 set +f ## Switch file expansion ON
1042 rm -f help.out MCdialog.out
1046 # Load config options from a file.
1047 # Converts all "# OPTION is not set" lines to "OPTION=n" lines
1049 function load_config_file () {
1050 awk '
1051 /# .* is not set.*/ { printf("%s=n\n", $2) }
1052 ! /# .* is not set.*/ { print }
1053 ' $1 >.tmpconfig
1055 source ./.tmpconfig
1056 rm -f .tmpconfig
1060 # Just what it says.
1062 save_configuration () {
1063 echo
1064 echo -n "Saving your kernel configuration."
1067 # Now, let's redefine the configuration functions for final
1068 # output to the config files.
1070 # Nested function definitions, YIPEE!
1072 function bool () {
1073 set_x_info "$2" "n"
1074 eval define_bool "$2" "$x"
1077 function tristate () {
1078 set_x_info "$2" "n"
1079 eval define_tristate "$2" "$x"
1082 function dep_tristate () {
1083 set_x_info "$2" "n"
1084 var="$2"
1085 shift 2
1086 while [ $# -gt 0 ]; do
1087 if [ "$1" = y ]; then
1088 shift
1089 elif [ "$1" = m -a "$x" != n ]; then
1090 x=m; shift
1091 else
1092 x=n; shift $#
1094 done
1095 define_tristate "$var" "$x"
1098 function dep_bool () {
1099 set_x_info "$2" "n"
1100 var="$2"
1101 shift 2
1102 while [ $# -gt 0 ]; do
1103 if [ "$1" = y ]; then
1104 shift
1105 else
1106 x=n; shift $#
1108 done
1109 define_bool "$var" "$x"
1112 function dep_mbool () {
1113 set_x_info "$2" "n"
1114 var="$2"
1115 shift 2
1116 while [ $# -gt 0 ]; do
1117 if [ "$1" = y -o "$1" = m ]; then
1118 shift
1119 else
1120 x=n; shift $#
1122 done
1123 define_bool "$var" "$x"
1126 function int () {
1127 set_x_info "$2" "$3"
1128 echo "$2=$x" >>$CONFIG
1129 echo "#define $2 ($x)" >>$CONFIG_H
1132 function hex () {
1133 set_x_info "$2" "$3"
1134 echo "$2=$x" >>$CONFIG
1135 echo "#define $2 0x${x##*[x,X]}" >>$CONFIG_H
1138 function string () {
1139 set_x_info "$2" "$3"
1140 echo "$2=\"$x\"" >>$CONFIG
1141 echo "#define $2 \"$x\"" >>$CONFIG_H
1144 function define_hex () {
1145 eval $1="$2"
1146 echo "$1=$2" >>$CONFIG
1147 echo "#define $1 0x${2##*[x,X]}" >>$CONFIG_H
1150 function define_int () {
1151 eval $1="$2"
1152 echo "$1=$2" >>$CONFIG
1153 echo "#define $1 ($2)" >>$CONFIG_H
1156 function define_string () {
1157 eval $1="$2"
1158 echo "$1=\"$2\"" >>$CONFIG
1159 echo "#define $1 \"$2\"" >>$CONFIG_H
1162 function define_bool () {
1163 define_tristate "$1" "$2"
1166 function define_tristate () {
1167 eval $1="$2"
1169 case "$2" in
1171 echo "$1=y" >>$CONFIG
1172 echo "#define $1 1" >>$CONFIG_H
1176 if [ "$CONFIG_MODULES" = "y" ]
1177 then
1178 echo "$1=m" >>$CONFIG
1179 echo "#undef $1" >>$CONFIG_H
1180 echo "#define $1_MODULE 1" >>$CONFIG_H
1181 else
1182 echo "$1=y" >>$CONFIG
1183 echo "#define $1 1" >>$CONFIG_H
1188 echo "# $1 is not set" >>$CONFIG
1189 echo "#undef $1" >>$CONFIG_H
1191 esac
1194 function choice () {
1196 # Find the first choice that's already set to 'y'
1198 choices="$2"
1199 default="$3"
1200 current=
1201 chosen=
1203 set -- $choices
1204 while [ -n "$2" ]
1206 if eval [ "_\$$2" = "_y" ]
1207 then
1208 current=$1
1209 break
1211 shift ; shift
1212 done
1215 # Use the default if none were set.
1217 : ${current:=$default}
1220 # Output all choices (to be compatible with other configs).
1222 set -- $choices
1223 while [ -n "$2" ]
1225 case "$1" in
1226 "$current"*) if [ -z "$chosen" ]; then
1227 define_bool "$2" "y"
1228 chosen=1
1229 else
1230 define_bool "$2" "n"
1231 fi ;;
1232 *) define_bool "$2" "n" ;;
1233 esac
1234 shift ; shift
1235 done
1238 function mainmenu_name () {
1242 function mainmenu_option () {
1243 comment_is_option=TRUE
1246 function endmenu () {
1250 function comment () {
1251 if [ "$comment_is_option" ]
1252 then
1253 comment_is_option=
1254 echo >>$CONFIG
1255 echo "#" >>$CONFIG
1256 echo "# $1" >>$CONFIG
1257 echo "#" >>$CONFIG
1259 echo >>$CONFIG_H
1260 echo "/*" >>$CONFIG_H
1261 echo " * $1" >>$CONFIG_H
1262 echo " */" >>$CONFIG_H
1266 echo -n "."
1268 DEF_CONFIG="${1:-.config}"
1269 DEF_CONFIG_H="include/linux/autoconf.h"
1271 CONFIG=.tmpconfig
1272 CONFIG_H=.tmpconfig.h
1274 echo "#" >$CONFIG
1275 echo "# Automatically generated by make menuconfig: don't edit" >>$CONFIG
1276 echo "#" >>$CONFIG
1278 echo "/*" >$CONFIG_H
1279 echo " * Automatically generated by make menuconfig: don't edit" >>$CONFIG_H
1280 echo " */" >>$CONFIG_H
1281 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
1283 echo -n "."
1284 if . $CONFIG_IN >>.menuconfig.log 2>&1
1285 then
1286 if [ "$DEF_CONFIG" = ".config" ]
1287 then
1288 mv $CONFIG_H $DEF_CONFIG_H
1291 if [ -f "$DEF_CONFIG" ]
1292 then
1293 rm -f ${DEF_CONFIG}.old
1294 mv $DEF_CONFIG ${DEF_CONFIG}.old
1297 mv $CONFIG $DEF_CONFIG
1299 return 0
1300 else
1301 return 1
1306 # Remove temporary files
1308 cleanup () {
1309 cleanup1
1310 cleanup2
1313 cleanup1 () {
1314 rm -f MCmenu* MCradiolists MCdialog.out help.out
1317 cleanup2 () {
1318 rm -f .tmpconfig .tmpconfig.h
1321 set_geometry () {
1322 # Some distributions export these with incorrect values
1323 # which can really screw up some ncurses programs.
1324 LINES= COLUMNS=
1326 ROWS=${1:-24} COLS=${2:-80}
1328 # Just in case the nasty rlogin bug returns.
1330 [ $ROWS = 0 ] && ROWS=24
1331 [ $COLS = 0 ] && COLS=80
1333 if [ $ROWS -lt 19 -o $COLS -lt 80 ]
1334 then
1335 echo -e "\n\007Your display is too small to run Menuconfig!"
1336 echo "It must be at least 19 lines by 80 columns."
1337 exit 0
1340 ROWS=$((ROWS-4)) COLS=$((COLS-5))
1344 set_geometry `stty size 2>/dev/null`
1346 menu_instructions="\
1347 Arrow keys navigate the menu. \
1348 <Enter> selects submenus --->. \
1349 Highlighted letters are hotkeys. \
1350 Pressing <Y> includes, <N> excludes, <M> modularizes features. \
1351 Press <Esc><Esc> to exit, <?> for Help. \
1352 Legend: [*] built-in [ ] excluded <M> module < > module capable"
1354 radiolist_instructions="\
1355 Use the arrow keys to navigate this window or \
1356 press the hotkey of the item you wish to select \
1357 followed by the <SPACE BAR>.
1358 Press <?> for additional information about this option."
1360 inputbox_instructions_int="\
1361 Please enter a decimal value. \
1362 Fractions will not be accepted. \
1363 Use the <TAB> key to move from the input field to the buttons below it."
1365 inputbox_instructions_hex="\
1366 Please enter a hexadecimal value. \
1367 Use the <TAB> key to move from the input field to the buttons below it."
1369 inputbox_instructions_string="\
1370 Please enter a string value. \
1371 Use the <TAB> key to move from the input field to the buttons below it."
1373 DIALOG="./scripts/lxdialog/lxdialog"
1375 kernel_version="${VERSION}.${PATCHLEVEL}.${SUBLEVEL}${EXTRAVERSION}"
1377 backtitle="Linux Kernel v$kernel_version Configuration"
1379 trap "cleanup ; exit 1" 1 2 15
1383 # Locate default files.
1385 CONFIG_IN=./config.in
1386 if [ "$1" != "" ] ; then
1387 CONFIG_IN=$1
1390 DEFAULTS=arch/$ARCH/defconfig
1391 if [ -f .config ]; then
1392 DEFAULTS=.config
1395 if [ -f $DEFAULTS ]
1396 then
1397 echo "Using defaults found in" $DEFAULTS
1398 load_config_file $DEFAULTS
1399 else
1400 echo "No defaults found"
1404 # Fresh new log.
1405 >.menuconfig.log
1407 # Load the functions used by the config.in files.
1408 echo -n "Preparing scripts: functions"
1409 load_functions
1411 if [ ! -e $CONFIG_IN ]
1412 then
1413 echo "Your main config.in file ($CONFIG_IN) does not exist"
1414 exit 1
1417 if [ ! -x $DIALOG ]
1418 then
1419 echo "Your lxdialog utility does not exist"
1420 exit 1
1424 # Read config.in files and parse them into one shell function per menu.
1426 echo -n ", parsing"
1427 parse_config_files $CONFIG_IN
1429 echo "done."
1431 # Start the ball rolling from the top.
1433 activate_menu MCmenu0
1436 # All done!
1438 cleanup1
1441 # Confirm and Save
1443 if $DIALOG --backtitle "$backtitle" \
1444 --yesno "Do you wish to save your new kernel configuration?" 5 60
1445 then
1446 save_configuration
1447 echo
1448 echo
1449 echo "*** End of Linux kernel configuration."
1450 echo "*** Check the top-level Makefile for additional configuration."
1451 if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then
1452 echo "*** Next, you must run 'make dep'."
1453 else
1454 echo "*** Next, you may run 'make bzImage', 'make bzdisk', or 'make install'."
1456 echo
1457 else
1458 echo
1459 echo
1460 echo Your kernel configuration changes were NOT saved.
1461 echo
1464 # Remove log if empty.
1465 if [ ! -s .menuconfig.log ] ; then
1466 rm -f .menuconfig.log
1469 exit 0