* better
[mascara-docs.git] / i386 / linux-2.3.21 / scripts / Menuconfig
blobf7e3ef11851efb0e2392dcec24ce9ab000f5f407
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@bigfoot.com)
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
262 # Add a menu item which will call our local int function.
264 function int () {
265 set_x_info "$2" "$3"
267 echo -ne "'$2' '($x) $1$info' " >>MCmenu
269 echo -e "function $2 () { l_int '$1' '$2' '$3' '$x' ;}" >>MCradiolists
273 # Add a menu item which will call our local hex function.
275 function hex () {
276 set_x_info "$2" "$3"
277 x=${x##*[x,X]}
279 echo -ne "'$2' '($x) $1$info' " >>MCmenu
281 echo -e "function $2 () { l_hex '$1' '$2' '$3' '$x' ;}" >>MCradiolists
285 # Add a menu item which will call our local string function.
287 function string () {
288 set_x_info "$2" "$3"
290 echo -ne "'$2' ' $1: \"$x\"$info' " >>MCmenu
292 echo -e "function $2 () { l_string '$1' '$2' '$3' '$x' ;}" >>MCradiolists
296 # Add a menu item which will call our local One-of-Many choice list.
298 function choice () {
300 # Need to remember params cause they're gonna get reset.
302 title=$1
303 choices=$2
304 default=$3
305 current=
308 # Find out if one of the choices is already set.
309 # If it's not then make it the default.
311 set -- $choices
312 firstchoice=$2
314 while [ -n "$2" ]
316 if eval [ "_\$$2" = "_y" ]
317 then
318 current=$1
319 break
321 shift ; shift
322 done
324 : ${current:=$default}
326 echo -ne "'$firstchoice' '($current) $title' " >>MCmenu
328 echo -e "
329 function $firstchoice () \
330 { l_choice '$title' \"$choices\" $current ;}" >>MCradiolists
333 } # END load_functions()
340 # Extract available help for an option from Configure.help
341 # and send it to standard output.
343 # Most of this function was borrowed from the original kernel
344 # Configure script.
346 function extract_help () {
347 if [ -f Documentation/Configure.help ]
348 then
349 #first escape regexp special characters in the argument:
350 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
351 #now pick out the right help text:
352 text=$(sed -n "/^$var[ ]*\$/,\${
353 /^$var[ ]*\$/c\\
354 ${var}:\\
356 /^#/b
357 /^[^ ]/q
358 s/^ //
360 }" Documentation/Configure.help)
362 if [ -z "$text" ]
363 then
364 echo "There is no help available for this kernel option."
365 return 1
366 else
367 echo "$text"
369 else
370 echo "There is no help available for this kernel option."
371 return 1
376 # Activate a help dialog.
378 function help () {
379 if extract_help $1 >help.out
380 then
381 $DIALOG --backtitle "$backtitle" --title "$2"\
382 --textbox help.out $ROWS $COLS
383 else
384 $DIALOG --backtitle "$backtitle" \
385 --textbox help.out $ROWS $COLS
387 rm help.out
391 # Show the README file.
393 function show_readme () {
394 $DIALOG --backtitle "$backtitle" \
395 --textbox scripts/README.Menuconfig $ROWS $COLS
399 # Begin building the dialog menu command and Initialize the
400 # Radiolist function file.
402 function menu_name () {
403 echo -ne "$DIALOG --title '$1'\
404 --backtitle '$backtitle' \
405 --menu '$menu_instructions' \
406 $ROWS $COLS $((ROWS-10)) \
407 '$default' " >MCmenu
408 >MCradiolists
412 # Add a submenu option to the menu currently under construction.
414 function submenu () {
415 echo -ne "'activate_menu $2' '$1 --->' " >>MCmenu
419 # Handle a boolean (Yes/No) option.
421 function l_bool () {
422 if [ -n "$2" ]
423 then
424 case "$2" in
425 y|m) eval $1=y ;;
426 c) eval x=\$$1
427 case $x in
428 y) eval $1=n ;;
429 n) eval $1=y ;;
430 *) eval $1=y ;;
431 esac ;;
432 *) eval $1=n ;;
433 esac
434 else
435 echo -ne "\007"
440 # Same as bool() except options are (Module/No)
442 function mod_bool () {
443 if [ "$CONFIG_MODULES" != "y" ]; then
444 define_bool "$2" "n"
445 else
446 set_x_info "$2" "n"
448 case $x in
449 y|m) flag='M' ;;
450 *) flag=' ' ;;
451 esac
453 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
455 echo -e "function $2 () { l_mod_bool '$2' \"\$1\" ;}" >>MCradiolists
460 # Same as l_bool() except options are (Module/No)
462 function l_mod_bool() {
463 if [ -n "$2" ]
464 then
465 case "$2" in
466 y) echo -en "\007"
467 ${DIALOG} --backtitle "$backtitle" \
468 --infobox "\
469 This feature depends on another which has been configured as a module. \
470 As a result, this feature will be built as a module." 4 70
471 sleep 5
472 eval $1=m ;;
473 m) eval $1=m ;;
474 c) eval x=\$$1
475 case $x in
476 m) eval $1=n ;;
477 n) eval $1=m ;;
478 *) eval $1=m ;;
479 esac ;;
480 *) eval $1=n ;;
481 esac
482 else
483 echo -ne "\007"
488 # Handle a tristate (Yes/No/Module) option.
490 function l_tristate () {
491 if [ -n "$2" ]
492 then
493 eval x=\$$1
495 case "$2" in
496 y) eval $1=y ;;
497 m) eval $1=m ;;
498 c) eval x=\$$1
499 case $x in
500 y) eval $1=n ;;
501 n) eval $1=m ;;
502 m) eval $1=y ;;
503 *) eval $1=y ;;
504 esac ;;
505 *) eval $1=n ;;
506 esac
507 else
508 echo -ne "\007"
513 # Create a dialog for entering an integer into a kernel option.
515 function l_int () {
516 while true
518 if $DIALOG --title "$1" \
519 --backtitle "$backtitle" \
520 --inputbox "$inputbox_instructions_int" \
521 10 75 "$4" 2>MCdialog.out
522 then
523 answer="`cat MCdialog.out`"
524 answer="${answer:-$3}"
526 # Semantics of + and ? in GNU expr changed, so
527 # we avoid them:
528 if expr "$answer" : '0$\|-[1-9][0-9]*$\|[1-9][0-9]*$' >/dev/null
529 then
530 eval $2="$answer"
531 else
532 eval $2="$3"
533 echo -en "\007"
534 ${DIALOG} --backtitle "$backtitle" \
535 --infobox "You have made an invalid entry." 3 43
536 sleep 2
539 break
542 help "$2" "$1"
543 done
547 # Create a dialog for entering a hexadecimal into a kernel option.
549 function l_hex () {
550 while true
552 if $DIALOG --title "$1" \
553 --backtitle "$backtitle" \
554 --inputbox "$inputbox_instructions_hex" \
555 10 75 "$4" 2>MCdialog.out
556 then
557 answer="`cat MCdialog.out`"
558 answer="${answer:-$3}"
559 answer="${answer##*[x,X]}"
561 if expr "$answer" : '[0-9a-fA-F][0-9a-fA-F]*$' >/dev/null
562 then
563 eval $2="$answer"
564 else
565 eval $2="$3"
566 echo -en "\007"
567 ${DIALOG} --backtitle "$backtitle" \
568 --infobox "You have made an invalid entry." 3 43
569 sleep 2
572 break
575 help "$2" "$1"
576 done
580 # Create a dialog for entering a string into a kernel option.
582 function l_string () {
583 while true
585 if $DIALOG --title "$1" \
586 --backtitle "$backtitle" \
587 --inputbox "$inputbox_instructions_string" \
588 10 75 "$4" 2>MCdialog.out
589 then
590 answer="`cat MCdialog.out`"
591 answer="${answer:-$3}"
594 # Someone may add a nice check for the entered
595 # string here...
597 eval $2=\"$answer\"
599 break
602 help "$2" "$1"
603 done
608 # Handle a one-of-many choice list.
610 function l_choice () {
612 # Need to remember params cause they're gonna get reset.
614 title="$1"
615 choices="$2"
616 current="$3"
619 # Scan current value of choices and set radiolist switches.
621 list=
622 set -- $choices
623 firstchoice=$2
624 while [ -n "$2" ]
626 case "$1" in
627 "$current") list="$list $2 $1 ON " ;;
628 *) list="$list $2 $1 OFF " ;;
629 esac
631 shift ; shift
632 done
634 while true
636 if $DIALOG --title "$title" \
637 --backtitle "$backtitle" \
638 --radiolist "$radiolist_instructions" \
639 15 70 6 $list 2>MCdialog.out
640 then
641 choice=`cat MCdialog.out`
642 break
645 help "$firstchoice" "$title"
646 done
649 # Now set the boolean value of each option based on
650 # the selection made from the radiolist.
652 set -- $choices
653 while [ -n "$2" ]
655 if [ "$2" = "$choice" ]
656 then
657 eval $2="y"
658 else
659 eval $2="n"
662 shift ; shift
663 done
667 # Call awk, and watch for error codes, etc.
669 function callawk () {
670 awk "$1" || echo "Awk died with error code $?. Giving up." || exit 1
674 # A faster awk based recursive parser. (I hope)
676 function parser1 () {
677 callawk '
678 BEGIN {
679 menu_no = 0
680 comment_is_option = 0
681 parser("'$CONFIG_IN'","MCmenu0")
684 function parser(ifile,menu) {
686 while (getline <ifile) {
687 if ($1 == "mainmenu_option") {
688 comment_is_option = "1"
690 else if ($1 == "comment" && comment_is_option == "1") {
691 comment_is_option= "0"
692 sub($1,"",$0)
693 ++menu_no
695 printf("submenu %s MCmenu%s\n", $0, menu_no) >>menu
697 newmenu = sprintf("MCmenu%d", menu_no);
698 printf( "function MCmenu%s () {\n"\
699 "default=$1\n"\
700 "menu_name %s\n",\
701 menu_no, $0) >newmenu
703 parser(ifile, newmenu)
705 else if ($1 ~ "endmenu") {
706 printf("}\n") >>menu
707 return
709 else if ($0 ~ /^#|\$MAKE|mainmenu_name/) {
710 printf("") >>menu
712 else if ($1 == "source") {
713 parser($2,menu)
715 else {
716 print >>menu
723 # Secondary parser for single menu mode.
725 function parser2 () {
726 callawk '
727 BEGIN {
728 parser("'$CONFIG_IN'","MCmenu0")
731 function parser(ifile,menu) {
733 while (getline <ifile) {
734 if ($1 ~ /mainmenu_option|endmenu/) {
735 printf("") >>menu
737 else if ($0 ~ /^#|$MAKE|mainmenu_name/) {
738 printf("") >>menu
740 else if ($1 == "source") {
741 parser($2,menu)
743 else {
744 print >>menu
751 # Parse all the config.in files into mini scripts.
753 function parse_config_files () {
754 rm -f MCmenu*
756 echo "function MCmenu0 () {" >MCmenu0
757 echo 'default=$1' >>MCmenu0
758 echo "menu_name 'Main Menu'" >>MCmenu0
760 if [ "_$single_menu_mode" = "_TRUE" ]
761 then
762 parser2
763 else
764 parser1
767 echo "comment ''" >>MCmenu0
768 echo "g_alt_config" >>MCmenu0
769 echo "s_alt_config" >>MCmenu0
771 echo "}" >>MCmenu0
774 # These mini scripts must be sourced into the current
775 # environment in order for all of this to work. Leaving
776 # them on the disk as executables screws up the recursion
777 # in activate_menu(), among other things. Once they are
778 # sourced we can discard them.
780 for i in MCmenu*
782 echo -n "."
783 source ./$i
784 done
785 rm -f MCmenu*
789 # This is the menu tree's bootstrap.
791 # Executes the parsed menus on demand and creates a set of functions,
792 # one per configuration option. These functions will in turn execute
793 # dialog commands or recursively call other menus.
795 function activate_menu () {
796 rm -f lxdialog.scrltmp
797 while true
799 comment_ctr=0 #So comment lines get unique tags
801 $1 "$default" 2> MCerror #Create the lxdialog menu & functions
803 if [ "$?" != "0" ]
804 then
805 clear
806 cat <<EOM
808 Menuconfig has encountered a possible error in one of the kernel's
809 configuration files and is unable to continue. Here is the error
810 report:
813 sed 's/^/ Q> /' MCerror
814 cat <<EOM
816 Please report this to the maintainer <mec@shout.net>. You may also
817 send a problem report to <linux-kernel@vger.rutgers.edu>.
819 Please indicate the kernel version you are trying to configure and
820 which menu you were trying to enter when this error occurred.
823 cleanup
824 exit 1
826 rm -f MCerror
828 . ./MCradiolists #Source the menu's functions
830 . ./MCmenu 2>MCdialog.out #Activate the lxdialog menu
831 ret=$?
833 read selection <MCdialog.out
835 case "$ret" in
836 0|3|4|5|6)
837 defaults="$selection\x12$defaults" #pseudo stack
838 case "$ret" in
839 0) eval $selection ;;
840 3) eval $selection y ;;
841 4) eval $selection n ;;
842 5) eval $selection m ;;
843 6) eval $selection c ;;
844 esac
845 default="${defaults%%\x12*}" defaults="${defaults#*\x12}"
848 default="${selection%%\ *}"
850 case "$selection" in
851 *"-->"*|*"alt_config"*)
852 show_readme ;;
854 eval help $selection ;;
855 esac
857 255|1)
858 break
860 139)
861 stty sane
862 clear
863 cat <<EOM
865 There seems to be a problem with the lxdialog companion utility which is
866 built prior to running Menuconfig. Usually this is an indicator that you
867 have upgraded/downgraded your ncurses libraries and did not remove the
868 old ncurses header file(s) in /usr/include or /usr/include/ncurses.
870 It is VERY important that you have only one set of ncurses header files
871 and that those files are properly version matched to the ncurses libraries
872 installed on your machine.
874 You may also need to rebuild lxdialog. This can be done by moving to
875 the /usr/src/linux/scripts/lxdialog directory and issuing the
876 "make clean all" command.
878 If you have verified that your ncurses install is correct, you may email
879 the maintainer <mec@shout.net> or post a message to
880 <linux-kernel@vger.rutgers.edu> for additional assistance.
883 cleanup
884 exit 139
886 esac
887 done
891 # Create a menu item to load an alternate configuration file.
893 g_alt_config () {
894 echo -n "get_alt_config 'Load an Alternate Configuration File' "\
895 >>MCmenu
899 # Get alternate config file name and load the
900 # configuration from it.
902 get_alt_config () {
903 set -f ## Switch file expansion OFF
905 while true
907 ALT_CONFIG="${ALT_CONFIG:-$DEFAULTS}"
909 $DIALOG --backtitle "$backtitle" \
910 --inputbox "\
911 Enter the name of the configuration file you wish to load. \
912 Accept the name shown to restore the configuration you \
913 last retrieved. Leave blank to abort."\
914 11 55 "$ALT_CONFIG" 2>MCdialog.out
916 if [ "$?" = "0" ]
917 then
918 ALT_CONFIG=`cat MCdialog.out`
920 [ "_" = "_$ALT_CONFIG" ] && break
922 if eval [ -r "$ALT_CONFIG" ]
923 then
924 eval load_config_file "$ALT_CONFIG"
925 break
926 else
927 echo -ne "\007"
928 $DIALOG --backtitle "$backtitle" \
929 --infobox "File does not exist!" 3 38
930 sleep 2
932 else
933 cat <<EOM >help.out
935 For various reasons, one may wish to keep several different kernel
936 configurations available on a single machine.
938 If you have saved a previous configuration in a file other than the
939 kernel's default, entering the name of the file here will allow you
940 to modify that configuration.
942 If you are uncertain, then you have probably never used alternate
943 configuration files. You should therefor leave this blank to abort.
946 $DIALOG --backtitle "$backtitle"\
947 --title "Load Alternate Configuration"\
948 --textbox help.out $ROWS $COLS
950 done
952 set +f ## Switch file expansion ON
953 rm -f help.out MCdialog.out
957 # Create a menu item to store an alternate config file.
959 s_alt_config () {
960 echo -n "save_alt_config 'Save Configuration to an Alternate File' "\
961 >>MCmenu
965 # Get an alternate config file name and save the current
966 # configuration to it.
968 save_alt_config () {
969 set -f ## Switch file expansion OFF
971 while true
973 $DIALOG --backtitle "$backtitle" \
974 --inputbox "\
975 Enter a filename to which this configuration should be saved \
976 as an alternate. Leave blank to abort."\
977 10 55 "$ALT_CONFIG" 2>MCdialog.out
979 if [ "$?" = "0" ]
980 then
981 ALT_CONFIG=`cat MCdialog.out`
983 [ "_" = "_$ALT_CONFIG" ] && break
985 if eval touch $ALT_CONFIG 2>/dev/null
986 then
987 eval save_configuration $ALT_CONFIG
988 load_functions ## RELOAD
989 break
990 else
991 echo -ne "\007"
992 $DIALOG --backtitle "$backtitle" \
993 --infobox "Can't create file! Probably a nonexistent directory." 3 60
994 sleep 2
996 else
997 cat <<EOM >help.out
999 For various reasons, one may wish to keep different kernel
1000 configurations available on a single machine.
1002 Entering a file name here will allow you to later retrieve, modify
1003 and use the current configuration as an alternate to whatever
1004 configuration options you have selected at that time.
1006 If you are uncertain what all this means then you should probably
1007 leave this blank.
1009 $DIALOG --backtitle "$backtitle"\
1010 --title "Save Alternate Configuration"\
1011 --textbox help.out $ROWS $COLS
1013 done
1015 set +f ## Switch file expansion ON
1016 rm -f help.out MCdialog.out
1020 # Load config options from a file.
1021 # Converts all "# OPTION is not set" lines to "OPTION=n" lines
1023 function load_config_file () {
1024 awk '
1025 /# .* is not set.*/ { printf("%s=n\n", $2) }
1026 ! /# .* is not set.*/ { print }
1027 ' $1 >.tmpconfig
1029 source ./.tmpconfig
1030 rm -f .tmpconfig
1034 # Just what it says.
1036 save_configuration () {
1037 echo
1038 echo -n "Saving your kernel configuration."
1041 # Now, let's redefine the configuration functions for final
1042 # output to the config files.
1044 # Nested function definitions, YIPEE!
1046 function bool () {
1047 set_x_info "$2" "n"
1048 eval define_bool "$2" "$x"
1051 function tristate () {
1052 set_x_info "$2" "n"
1053 eval define_tristate "$2" "$x"
1056 function dep_tristate () {
1057 set_x_info "$2" "n"
1058 var="$2"
1059 shift 2
1060 while [ $# -gt 0 ]; do
1061 if [ "$1" = y ]; then
1062 shift
1063 elif [ "$1" = m -a "$x" != n ]; then
1064 x=m; shift
1065 else
1066 x=n; shift $#
1068 done
1069 define_tristate "$var" "$x"
1072 function dep_bool () {
1073 set_x_info "$2" "n"
1074 var="$2"
1075 shift 2
1076 while [ $# -gt 0 ]; do
1077 if [ "$1" = y ]; then
1078 shift
1079 else
1080 x=n; shift $#
1082 done
1083 define_bool "$var" "$x"
1086 function int () {
1087 set_x_info "$2" "$3"
1088 echo "$2=$x" >>$CONFIG
1089 echo "#define $2 ($x)" >>$CONFIG_H
1092 function hex () {
1093 set_x_info "$2" "$3"
1094 echo "$2=$x" >>$CONFIG
1095 echo "#define $2 0x${x##*[x,X]}" >>$CONFIG_H
1098 function string () {
1099 set_x_info "$2" "$3"
1100 echo "$2=\"$x\"" >>$CONFIG
1101 echo "#define $2 \"$x\"" >>$CONFIG_H
1104 function define_hex () {
1105 eval $1="$2"
1106 echo "$1=$2" >>$CONFIG
1107 echo "#define $1 0x${2##*[x,X]}" >>$CONFIG_H
1110 function define_int () {
1111 eval $1="$2"
1112 echo "$1=$2" >>$CONFIG
1113 echo "#define $1 ($2)" >>$CONFIG_H
1116 function define_string () {
1117 eval $1="$2"
1118 echo "$1=\"$2\"" >>$CONFIG
1119 echo "#define $1 \"$2\"" >>$CONFIG_H
1122 function define_bool () {
1123 define_tristate "$1" "$2"
1126 function define_tristate () {
1127 eval $1="$2"
1129 case "$2" in
1131 echo "$1=y" >>$CONFIG
1132 echo "#define $1 1" >>$CONFIG_H
1136 if [ "$CONFIG_MODULES" = "y" ]
1137 then
1138 echo "$1=m" >>$CONFIG
1139 echo "#undef $1" >>$CONFIG_H
1140 echo "#define $1_MODULE 1" >>$CONFIG_H
1141 else
1142 echo "$1=y" >>$CONFIG
1143 echo "#define $1 1" >>$CONFIG_H
1148 echo "# $1 is not set" >>$CONFIG
1149 echo "#undef $1" >>$CONFIG_H
1151 esac
1154 function choice () {
1156 # Find the first choice that's already set to 'y'
1158 choices="$2"
1159 default="$3"
1160 current=
1162 set -- $choices
1163 while [ -n "$2" ]
1165 if eval [ "_\$$2" = "_y" ]
1166 then
1167 current=$1
1168 break
1170 shift ; shift
1171 done
1174 # Use the default if none were set.
1176 : ${current:=$default}
1179 # Output all choices (to be compatible with other configs).
1181 set -- $choices
1182 while [ -n "$2" ]
1184 if eval [ "$1" = "$current" ]
1185 then
1186 define_bool "$2" "y"
1187 else
1188 define_bool "$2" "n"
1190 shift ; shift
1191 done
1194 function mainmenu_name () {
1198 function mainmenu_option () {
1199 comment_is_option=TRUE
1202 function endmenu () {
1206 function comment () {
1207 if [ "$comment_is_option" ]
1208 then
1209 comment_is_option=
1210 echo >>$CONFIG
1211 echo "#" >>$CONFIG
1212 echo "# $1" >>$CONFIG
1213 echo "#" >>$CONFIG
1215 echo >>$CONFIG_H
1216 echo "/*" >>$CONFIG_H
1217 echo " * $1" >>$CONFIG_H
1218 echo " */" >>$CONFIG_H
1222 echo -n "."
1224 DEF_CONFIG="${1:-.config}"
1225 DEF_CONFIG_H="include/linux/autoconf.h"
1227 CONFIG=.tmpconfig
1228 CONFIG_H=.tmpconfig.h
1230 echo "#" >$CONFIG
1231 echo "# Automatically generated by make menuconfig: don't edit" >>$CONFIG
1232 echo "#" >>$CONFIG
1234 echo "/*" >$CONFIG_H
1235 echo " * Automatically generated by make menuconfig: don't edit" >>$CONFIG_H
1236 echo " */" >>$CONFIG_H
1237 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
1239 echo -n "."
1240 if . $CONFIG_IN >>.menuconfig.log 2>&1
1241 then
1242 if [ "$DEF_CONFIG" = ".config" ]
1243 then
1244 mv $CONFIG_H $DEF_CONFIG_H
1247 if [ -f "$DEF_CONFIG" ]
1248 then
1249 rm -f ${DEF_CONFIG}.old
1250 mv $DEF_CONFIG ${DEF_CONFIG}.old
1253 mv $CONFIG $DEF_CONFIG
1255 return 0
1256 else
1257 return 1
1262 # Remove temporary files
1264 cleanup () {
1265 cleanup1
1266 cleanup2
1269 cleanup1 () {
1270 rm -f MCmenu* MCradiolists MCdialog.out help.out
1273 cleanup2 () {
1274 rm -f .tmpconfig .tmpconfig.h
1277 set_geometry () {
1278 # Some distributions export these with incorrect values
1279 # which can really screw up some ncurses programs.
1280 LINES= COLUMNS=
1282 ROWS=${1:-24} COLS=${2:-80}
1284 # Just in case the nasty rlogin bug returns.
1286 [ $ROWS = 0 ] && ROWS=24
1287 [ $COLS = 0 ] && COLS=80
1289 if [ $ROWS -lt 19 -o $COLS -lt 80 ]
1290 then
1291 echo -e "\n\007Your display is too small to run Menuconfig!"
1292 echo "It must be at least 19 lines by 80 columns."
1293 exit 0
1296 ROWS=$((ROWS-4)) COLS=$((COLS-5))
1300 set_geometry `stty size 2>/dev/null`
1302 menu_instructions="\
1303 Arrow keys navigate the menu. \
1304 <Enter> selects submenus --->. \
1305 Highlighted letters are hotkeys. \
1306 Pressing <Y> includes, <N> excludes, <M> modularizes features. \
1307 Press <Esc><Esc> to exit, <?> for Help. \
1308 Legend: [*] built-in [ ] excluded <M> module < > module capable"
1310 radiolist_instructions="\
1311 Use the arrow keys to navigate this window or \
1312 press the hotkey of the item you wish to select \
1313 followed by the <SPACE BAR>.
1314 Press <?> for additional information about this option."
1316 inputbox_instructions_int="\
1317 Please enter a decimal value. \
1318 Fractions will not be accepted. \
1319 Use the <TAB> key to move from the input field to the buttons below it."
1321 inputbox_instructions_hex="\
1322 Please enter a hexadecimal value. \
1323 Use the <TAB> key to move from the input field to the buttons below it."
1325 inputbox_instructions_string="\
1326 Please enter a string value. \
1327 Use the <TAB> key to move from the input field to the buttons below it."
1329 DIALOG="./scripts/lxdialog/lxdialog"
1331 kernel_version="${VERSION}.${PATCHLEVEL}.${SUBLEVEL}"
1333 backtitle="Linux Kernel v$kernel_version Configuration"
1335 trap "cleanup ; exit 1" 1 2 15
1339 # Locate default files.
1341 CONFIG_IN=./config.in
1342 if [ "$1" != "" ] ; then
1343 CONFIG_IN=$1
1346 DEFAULTS=arch/$ARCH/defconfig
1347 if [ -f .config ]; then
1348 DEFAULTS=.config
1351 if [ -f $DEFAULTS ]
1352 then
1353 echo "Using defaults found in" $DEFAULTS
1354 load_config_file $DEFAULTS
1355 else
1356 echo "No defaults found"
1360 # Fresh new log.
1361 >.menuconfig.log
1363 # Load the functions used by the config.in files.
1364 echo -n "Preparing scripts: functions"
1365 load_functions
1367 if [ ! -e $CONFIG_IN ]
1368 then
1369 echo "Your main config.in file ($CONFIG_IN) does not exist"
1370 exit 1
1373 if [ ! -x $DIALOG ]
1374 then
1375 echo "Your lxdialog utility does not exist"
1376 exit 1
1380 # Read config.in files and parse them into one shell function per menu.
1382 echo -n ", parsing"
1383 parse_config_files $CONFIG_IN
1385 echo "done."
1387 # Start the ball rolling from the top.
1389 activate_menu MCmenu0
1392 # All done!
1394 cleanup1
1397 # Confirm and Save
1399 if $DIALOG --backtitle "$backtitle" \
1400 --yesno "Do you wish to save your new kernel configuration?" 5 60
1401 then
1402 save_configuration
1403 echo
1404 echo
1405 echo "*** End of Linux kernel configuration."
1406 echo "*** Check the top-level Makefile for additional configuration."
1407 if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then
1408 echo "*** Next, you must run 'make dep'."
1409 else
1410 echo "*** Next, you may run 'make zImage', 'make zdisk', or 'make zlilo.'"
1412 echo
1413 else
1414 echo
1415 echo
1416 echo Your kernel configuration changes were NOT saved.
1417 echo
1419 exit 0