Import 2.2.8pre4
[davej-history.git] / scripts / Menuconfig
bloba2572275607695c75867a684eae47cc94d110664
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).
74 # Change this to TRUE if you prefer all kernel options listed
75 # in a single menu rather than the standard menu hierarchy.
77 single_menu_mode=
80 # Make sure we're really running bash.
82 [ -z "$BASH" ] && { echo "Menuconfig requires bash" 1>&2; exit 1; }
85 # Cache function definitions, turn off posix compliance
87 set -h +o posix
91 # Given a configuration variable, set the global variable $x to its value,
92 # and the global variable $info to the string " (NEW)" if this is a new
93 # variable.
95 # This function looks for: (1) the current value, or (2) the default value
96 # from the arch-dependent defconfig file, or (3) a default passed by the caller.
98 function set_x_info () {
99 eval x=\$$1
100 if [ -z "$x" ]; then
101 eval `sed -n -e 's/# \(.*\) is not set.*/\1=n/' -e "/^$1=/p" arch/$ARCH/defconfig`
102 eval x=\${$1:-"$2"}
103 eval $1=$x
104 eval INFO_$1="' (NEW)'"
106 eval info="\$INFO_$1"
110 # Load the functions used by the config.in files.
112 # I do this because these functions must be redefined depending
113 # on whether they are being called for interactive use or for
114 # saving a configuration to a file.
116 # Thank the heavens bash supports nesting function definitions.
118 load_functions () {
121 # Additional comments
123 function comment () {
124 comment_ctr=$[ comment_ctr + 1 ]
125 echo -ne "': $comment_ctr' '--- $1' " >>MCmenu
129 # Define a boolean to a specific value.
131 function define_bool () {
132 eval $1=$2
136 # Create a boolean (Yes/No) function for our current menu
137 # which calls our local bool function.
139 function bool () {
140 set_x_info "$2" "n"
142 case $x in
143 y|m) flag="*" ;;
144 n) flag=" " ;;
145 esac
147 echo -ne "'$2' '[$flag] $1$info' " >>MCmenu
149 echo -e "function $2 () { l_bool '$2' \"\$1\" ;}\n" >>MCradiolists
153 # Create a tristate (Yes/No/Module) radiolist function
154 # which calls our local tristate function.
156 # Collapses to a boolean (Yes/No) if module support is disabled.
158 function tristate () {
159 if [ "$CONFIG_MODULES" != "y" ]
160 then
161 bool "$1" "$2"
162 else
163 set_x_info "$2" "n"
165 case $x in
166 y) flag="*" ;;
167 m) flag="M" ;;
168 *) flag=" " ;;
169 esac
171 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
173 echo -e "
174 function $2 () { l_tristate '$2' \"\$1\" ;}" >>MCradiolists
179 # Create a tristate radiolist function which is dependent on
180 # another kernel configuration option.
182 # Quote from the original configure script:
184 # If the option we depend upon is a module,
185 # then the only allowable options are M or N. If Y, then
186 # this is a normal tristate. This is used in cases where modules
187 # are nested, and one module requires the presence of something
188 # else in the kernel.
190 function dep_tristate () {
191 if [ "$3" = "y" ]; then
192 tristate "$1" "$2"
193 else if [ "$3" = "m" ]; then
194 mod_bool "$1" "$2"
195 else
196 define_bool "$2" n
197 fi; fi
201 # Add a menu item which will call our local int function.
203 function int () {
204 set_x_info "$2" "$3"
206 echo -ne "'$2' '($x) $1$info' " >>MCmenu
208 echo -e "function $2 () { l_int '$1' '$2' '$3' '$x' ;}" >>MCradiolists
212 # Add a menu item which will call our local hex function.
214 function hex () {
215 set_x_info "$2" "$3"
216 x=${x##*[x,X]}
218 echo -ne "'$2' '($x) $1$info' " >>MCmenu
220 echo -e "function $2 () { l_hex '$1' '$2' '$3' '$x' ;}" >>MCradiolists
224 # Add a menu item which will call our local string function.
226 function string () {
227 set_x_info "$2" "$3"
229 echo -ne "'$2' ' $1: \"$x\"$info' " >>MCmenu
231 echo -e "function $2 () { l_string '$1' '$2' '$3' '$x' ;}" >>MCradiolists
235 # Add a menu item which will call our local One-of-Many choice list.
237 function choice () {
239 # Need to remember params cause they're gonna get reset.
241 title=$1
242 choices=$2
243 default=$3
244 current=
247 # Find out if one of the choices is already set.
248 # If it's not then make it the default.
250 set -- $choices
251 firstchoice=$2
253 while [ -n "$2" ]
255 if eval [ "_\$$2" = "_y" ]
256 then
257 current=$1
258 break
260 shift ; shift
261 done
263 : ${current:=$default}
265 echo -ne "'$firstchoice' '($current) $title' " >>MCmenu
267 echo -e "
268 function $firstchoice () \
269 { l_choice '$title' \"$choices\" $current ;}" >>MCradiolists
272 } # END load_functions()
279 # Extract available help for an option from Configure.help
280 # and send it to standard output.
282 # Most of this function was borrowed from the original kernel
283 # Configure script.
285 function extract_help () {
286 if [ -f Documentation/Configure.help ]
287 then
288 #first escape regexp special characters in the argument:
289 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
290 #now pick out the right help text:
291 text=$(sed -n "/^$var[ ]*\$/,\${
292 /^$var[ ]*\$/c\\
293 ${var}:\\
295 /^#/b
296 /^[^ ]/q
297 s/^ //
299 }" Documentation/Configure.help)
301 if [ -z "$text" ]
302 then
303 echo "There is no help available for this kernel option."
304 return 1
305 else
306 echo "$text"
308 else
309 echo "There is no help available for this kernel option."
310 return 1
315 # Activate a help dialog.
317 function help () {
318 if extract_help $1 >help.out
319 then
320 $DIALOG --backtitle "$backtitle" --title "$2"\
321 --textbox help.out $ROWS $COLS
322 else
323 $DIALOG --backtitle "$backtitle" \
324 --textbox help.out $ROWS $COLS
326 rm help.out
330 # Show the README file.
332 function show_readme () {
333 $DIALOG --backtitle "$backtitle" \
334 --textbox scripts/README.Menuconfig $ROWS $COLS
338 # Begin building the dialog menu command and Initialize the
339 # Radiolist function file.
341 function menu_name () {
342 echo -ne "$DIALOG --title '$1'\
343 --backtitle '$backtitle' \
344 --menu '$menu_instructions' \
345 $ROWS $COLS $((ROWS-10)) \
346 '$default' " >MCmenu
347 >MCradiolists
351 # Add a submenu option to the menu currently under construction.
353 function submenu () {
354 echo -ne "'activate_menu $2' '$1 --->' " >>MCmenu
358 # Handle a boolean (Yes/No) option.
360 function l_bool () {
361 if [ -n "$2" ]
362 then
363 case "$2" in
364 y|m) eval $1=y ;;
365 c) eval x=\$$1
366 case $x in
367 y) eval $1=n ;;
368 n) eval $1=y ;;
369 *) eval $1=y ;;
370 esac ;;
371 *) eval $1=n ;;
372 esac
373 else
374 echo -ne "\007"
379 # Same as bool() except options are (Module/No)
381 function mod_bool () {
382 if [ "$CONFIG_MODULES" != "y" ]; then
383 define_bool "$2" "n"
384 else
385 set_x_info "$2" "n"
387 case $x in
388 y|m) flag='M' ;;
389 *) flag=' ' ;;
390 esac
392 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
394 echo -e "function $2 () { l_mod_bool '$2' \"\$1\" ;}" >>MCradiolists
399 # Same as l_bool() except options are (Module/No)
401 function l_mod_bool() {
402 if [ -n "$2" ]
403 then
404 case "$2" in
405 y) echo -en "\007"
406 ${DIALOG} --backtitle "$backtitle" \
407 --infobox "\
408 This feature depends on another which has been configured as a module. \
409 As a result, this feature will be built as a module." 4 70
410 sleep 5
411 eval $1=m ;;
412 m) eval $1=m ;;
413 c) eval x=\$$1
414 case $x in
415 m) eval $1=n ;;
416 n) eval $1=m ;;
417 *) eval $1=m ;;
418 esac ;;
419 *) eval $1=n ;;
420 esac
421 else
422 echo -ne "\007"
427 # Handle a tristate (Yes/No/Module) option.
429 function l_tristate () {
430 if [ -n "$2" ]
431 then
432 eval x=\$$1
434 case "$2" in
435 y) eval $1=y ;;
436 m) eval $1=m ;;
437 c) eval x=\$$1
438 case $x in
439 y) eval $1=n ;;
440 n) eval $1=m ;;
441 m) eval $1=y ;;
442 *) eval $1=y ;;
443 esac ;;
444 *) eval $1=n ;;
445 esac
446 else
447 echo -ne "\007"
452 # Create a dialog for entering an integer into a kernel option.
454 function l_int () {
455 while true
457 if $DIALOG --title "$1" \
458 --backtitle "$backtitle" \
459 --inputbox "$inputbox_instructions_int" \
460 10 75 "$4" 2>MCdialog.out
461 then
462 answer="`cat MCdialog.out`"
463 answer="${answer:-$3}"
465 # Semantics of + and ? in GNU expr changed, so
466 # we avoid them:
467 if expr "$answer" : '0$\|-[1-9][0-9]*$\|[1-9][0-9]*$' >/dev/null
468 then
469 eval $2="$answer"
470 else
471 eval $2="$3"
472 echo -en "\007"
473 ${DIALOG} --backtitle "$backtitle" \
474 --infobox "You have made an invalid entry." 3 43
475 sleep 2
478 break
481 help "$2" "$1"
482 done
486 # Create a dialog for entering a hexadecimal into a kernel option.
488 function l_hex () {
489 while true
491 if $DIALOG --title "$1" \
492 --backtitle "$backtitle" \
493 --inputbox "$inputbox_instructions_hex" \
494 10 75 "$4" 2>MCdialog.out
495 then
496 answer="`cat MCdialog.out`"
497 answer="${answer:-$3}"
498 answer="${answer##*[x,X]}"
500 if expr "$answer" : '[0-9a-fA-F][0-9a-fA-F]*$' >/dev/null
501 then
502 eval $2="$answer"
503 else
504 eval $2="$3"
505 echo -en "\007"
506 ${DIALOG} --backtitle "$backtitle" \
507 --infobox "You have made an invalid entry." 3 43
508 sleep 2
511 break
514 help "$2" "$1"
515 done
519 # Create a dialog for entering a string into a kernel option.
521 function l_string () {
522 while true
524 if $DIALOG --title "$1" \
525 --backtitle "$backtitle" \
526 --inputbox "$inputbox_instructions_string" \
527 10 75 "$4" 2>MCdialog.out
528 then
529 answer="`cat MCdialog.out`"
530 answer="${answer:-$3}"
533 # Someone may add a nice check for the entered
534 # string here...
536 eval $2=\"$answer\"
538 break
541 help "$2" "$1"
542 done
547 # Handle a one-of-many choice list.
549 function l_choice () {
551 # Need to remember params cause they're gonna get reset.
553 title="$1"
554 choices="$2"
555 current="$3"
558 # Scan current value of choices and set radiolist switches.
560 list=
561 set -- $choices
562 firstchoice=$2
563 while [ -n "$2" ]
565 case "$1" in
566 "$current") list="$list $2 $1 ON " ;;
567 *) list="$list $2 $1 OFF " ;;
568 esac
570 shift ; shift
571 done
573 while true
575 if $DIALOG --title "$title" \
576 --backtitle "$backtitle" \
577 --radiolist "$radiolist_instructions" \
578 15 70 6 $list 2>MCdialog.out
579 then
580 choice=`cat MCdialog.out`
581 break
584 help "$firstchoice" "$title"
585 done
588 # Now set the boolean value of each option based on
589 # the selection made from the radiolist.
591 set -- $choices
592 while [ -n "$2" ]
594 if [ "$2" = "$choice" ]
595 then
596 eval $2="y"
597 else
598 eval $2="n"
601 shift ; shift
602 done
606 # Call awk, and watch for error codes, etc.
608 function callawk () {
609 awk "$1" || echo "Awk died with error code $?. Giving up." || exit 1
613 # A faster awk based recursive parser. (I hope)
615 function parser1 () {
616 callawk '
617 BEGIN {
618 menu_no = 0
619 comment_is_option = 0
620 parser("'$CONFIG_IN'","MCmenu0")
623 function parser(ifile,menu) {
625 while (getline <ifile) {
626 if ($1 == "mainmenu_option") {
627 comment_is_option = "1"
629 else if ($1 == "comment" && comment_is_option == "1") {
630 comment_is_option= "0"
631 sub($1,"",$0)
632 ++menu_no
634 printf("submenu %s MCmenu%s\n", $0, menu_no) >>menu
636 printf( "function MCmenu%s () {\n"\
637 "default=$1\n"\
638 "menu_name %s\n",\
639 menu_no, $0) >"MCmenu"menu_no
641 parser(ifile, "MCmenu"menu_no)
643 else if ($1 ~ "endmenu") {
644 printf("}\n") >>menu
645 return
647 else if ($0 ~ /^#|\$MAKE|mainmenu_name/) {
648 printf("") >>menu
650 else if ($1 == "source") {
651 parser($2,menu)
653 else {
654 print >>menu
661 # Secondary parser for single menu mode.
663 function parser2 () {
664 callawk '
665 BEGIN {
666 parser("'$CONFIG_IN'","MCmenu0")
669 function parser(ifile,menu) {
671 while (getline <ifile) {
672 if ($1 ~ /mainmenu_option|endmenu/) {
673 printf("") >>menu
675 else if ($0 ~ /^#|$MAKE|mainmenu_name/) {
676 printf("") >>menu
678 else if ($1 == "source") {
679 parser($2,menu)
681 else {
682 print >>menu
689 # Parse all the config.in files into mini scripts.
691 function parse_config_files () {
692 rm -f MCmenu*
694 echo "function MCmenu0 () {" >MCmenu0
695 echo 'default=$1' >>MCmenu0
696 echo "menu_name 'Main Menu'" >>MCmenu0
698 if [ "_$single_menu_mode" = "_TRUE" ]
699 then
700 parser2
701 else
702 parser1
705 echo "comment ''" >>MCmenu0
706 echo "g_alt_config" >>MCmenu0
707 echo "s_alt_config" >>MCmenu0
709 echo "}" >>MCmenu0
712 # These mini scripts must be sourced into the current
713 # environment in order for all of this to work. Leaving
714 # them on the disk as executables screws up the recursion
715 # in activate_menu(), among other things. Once they are
716 # sourced we can discard them.
718 for i in MCmenu*
720 echo -n "."
721 source ./$i
722 done
723 rm -f MCmenu*
727 # This is the menu tree's bootstrap.
729 # Executes the parsed menus on demand and creates a set of functions,
730 # one per configuration option. These functions will in turn execute
731 # dialog commands or recursively call other menus.
733 function activate_menu () {
734 rm -f lxdialog.scrltmp
735 while true
737 comment_ctr=0 #So comment lines get unique tags
739 $1 "$default" 2> MCerror #Create the lxdialog menu & functions
741 if [ "$?" != "0" ]
742 then
743 clear
744 cat <<EOM
746 Menuconfig has encountered a possible error in one of the kernel's
747 configuration files and is unable to continue. Here is the error
748 report:
751 sed 's/^/ Q> /' MCerror
752 cat <<EOM
754 Please report this to the maintainer <mec@shout.net>. You may also
755 send a problem report to <linux-kernel@vger.rutgers.edu>.
757 Please indicate the kernel version you are trying to configure and
758 which menu you were trying to enter when this error occurred.
761 cleanup
762 exit 1
764 rm -f MCerror
766 . ./MCradiolists #Source the menu's functions
768 . ./MCmenu 2>MCdialog.out #Activate the lxdialog menu
769 ret=$?
771 read selection <MCdialog.out
773 case "$ret" in
774 0|3|4|5|6)
775 defaults="$selection\x12$defaults" #pseudo stack
776 case "$ret" in
777 0) eval $selection ;;
778 3) eval $selection y ;;
779 4) eval $selection n ;;
780 5) eval $selection m ;;
781 6) eval $selection c ;;
782 esac
783 default="${defaults%%\x12*}" defaults="${defaults#*\x12}"
786 default="${selection%%\ *}"
788 case "$selection" in
789 *"-->"*|*"alt_config"*)
790 show_readme ;;
792 eval help $selection ;;
793 esac
795 255|1)
796 break
798 139)
799 stty sane
800 clear
801 cat <<EOM
803 There seems to be a problem with the lxdialog companion utility which is
804 built prior to running Menuconfig. Usually this is an indicator that you
805 have upgraded/downgraded your ncurses libraries and did not remove the
806 old ncurses header file(s) in /usr/include or /usr/include/ncurses.
808 It is VERY important that you have only one set of ncurses header files
809 and that those files are properly version matched to the ncurses libraries
810 installed on your machine.
812 You may also need to rebuild lxdialog. This can be done by moving to
813 the /usr/src/linux/scripts/lxdialog directory and issuing the
814 "make clean all" command.
816 If you have verified that your ncurses install is correct, you may email
817 the maintainer <mec@shout.net> or post a message to
818 <linux-kernel@vger.rutgers.edu> for additional assistance.
821 cleanup
822 exit 139
824 esac
825 done
829 # Create a menu item to load an alternate configuration file.
831 g_alt_config () {
832 echo -n "get_alt_config 'Load an Alternate Configuration File' "\
833 >>MCmenu
837 # Get alternate config file name and load the
838 # configuration from it.
840 get_alt_config () {
841 set -f ## Switch file expansion OFF
843 while true
845 ALT_CONFIG="${ALT_CONFIG:-$DEFAULTS}"
847 $DIALOG --backtitle "$backtitle" \
848 --inputbox "\
849 Enter the name of the configuration file you wish to load. \
850 Accept the name shown to restore the configuration you \
851 last retrieved. Leave blank to abort."\
852 11 55 "$ALT_CONFIG" 2>MCdialog.out
854 if [ "$?" = "0" ]
855 then
856 ALT_CONFIG=`cat MCdialog.out`
858 [ "_" = "_$ALT_CONFIG" ] && break
860 if eval [ -r "$ALT_CONFIG" ]
861 then
862 eval load_config_file "$ALT_CONFIG"
863 break
864 else
865 echo -ne "\007"
866 $DIALOG --backtitle "$backtitle" \
867 --infobox "File does not exist!" 3 38
868 sleep 2
870 else
871 cat <<EOM >help.out
873 For various reasons, one may wish to keep several different kernel
874 configurations available on a single machine.
876 If you have saved a previous configuration in a file other than the
877 kernel's default, entering the name of the file here will allow you
878 to modify that configuration.
880 If you are uncertain, then you have probably never used alternate
881 configuration files. You should therefor leave this blank to abort.
884 $DIALOG --backtitle "$backtitle"\
885 --title "Load Alternate Configuration"\
886 --textbox help.out $ROWS $COLS
888 done
890 set +f ## Switch file expansion ON
891 rm -f help.out MCdialog.out
895 # Create a menu item to store an alternate config file.
897 s_alt_config () {
898 echo -n "save_alt_config 'Save Configuration to an Alternate File' "\
899 >>MCmenu
903 # Get an alternate config file name and save the current
904 # configuration to it.
906 save_alt_config () {
907 set -f ## Switch file expansion OFF
909 while true
911 $DIALOG --backtitle "$backtitle" \
912 --inputbox "\
913 Enter a filename to which this configuration should be saved \
914 as an alternate. Leave blank to abort."\
915 10 55 "$ALT_CONFIG" 2>MCdialog.out
917 if [ "$?" = "0" ]
918 then
919 ALT_CONFIG=`cat MCdialog.out`
921 [ "_" = "_$ALT_CONFIG" ] && break
923 if eval touch $ALT_CONFIG 2>/dev/null
924 then
925 eval save_configuration $ALT_CONFIG
926 load_functions ## RELOAD
927 break
928 else
929 echo -ne "\007"
930 $DIALOG --backtitle "$backtitle" \
931 --infobox "Can't create file! Probably a nonexistent directory." 3 60
932 sleep 2
934 else
935 cat <<EOM >help.out
937 For various reasons, one may wish to keep different kernel
938 configurations available on a single machine.
940 Entering a file name here will allow you to later retrieve, modify
941 and use the current configuration as an alternate to whatever
942 configuration options you have selected at that time.
944 If you are uncertain what all this means then you should probably
945 leave this blank.
947 $DIALOG --backtitle "$backtitle"\
948 --title "Save Alternate Configuration"\
949 --textbox help.out $ROWS $COLS
951 done
953 set +f ## Switch file expansion ON
954 rm -f help.out MCdialog.out
958 # Load config options from a file.
959 # Converts all "# OPTION is not set" lines to "OPTION=n" lines
961 function load_config_file () {
962 awk '
963 /# .* is not set.*/ { printf("%s=n\n", $2) }
964 ! /# .* is not set.*/ { print }
965 ' $1 >.tmpconfig
967 source ./.tmpconfig
968 rm -f .tmpconfig
972 # Just what it says.
974 save_configuration () {
975 echo
976 echo -n "Saving your kernel configuration."
979 # Now, let's redefine the configuration functions for final
980 # output to the config files.
982 # Nested function definitions, YIPEE!
984 function bool () {
985 set_x_info "$2" "n"
986 eval define_bool "$2" "$x"
989 function tristate () {
990 set_x_info "$2" "n"
991 eval define_bool "$2" "$x"
994 function dep_tristate () {
995 set_x_info "$2" "n"
996 if [ "$3" = "m" -a "$x" = "y" ]; then x="m"; fi
997 define_bool "$2" "$x"
1000 function int () {
1001 set_x_info "$2" "$3"
1002 echo "$2=$x" >>$CONFIG
1003 echo "#define $2 ($x)" >>$CONFIG_H
1006 function hex () {
1007 set_x_info "$2" "$3"
1008 echo "$2=$x" >>$CONFIG
1009 echo "#define $2 0x${x##*[x,X]}" >>$CONFIG_H
1012 function string () {
1013 set_x_info "$2" "$3"
1014 echo "$2=\"$x\"" >>$CONFIG
1015 echo "#define $2 \"$x\"" >>$CONFIG_H
1018 function define_bool () {
1019 eval $1="$2"
1021 case "$2" in
1023 echo "$1=y" >>$CONFIG
1024 echo "#define $1 1" >>$CONFIG_H
1028 if [ "$CONFIG_MODULES" = "y" ]
1029 then
1030 echo "$1=m" >>$CONFIG
1031 echo "#undef $1" >>$CONFIG_H
1032 echo "#define $1_MODULE 1" >>$CONFIG_H
1033 else
1034 echo "$1=y" >>$CONFIG
1035 echo "#define $1 1" >>$CONFIG_H
1040 echo "# $1 is not set" >>$CONFIG
1041 echo "#undef $1" >>$CONFIG_H
1043 esac
1046 function choice () {
1048 # Find the first choice that's already set to 'y'
1050 choices="$2"
1051 default="$3"
1052 current=
1054 set -- $choices
1055 while [ -n "$2" ]
1057 if eval [ "_\$$2" = "_y" ]
1058 then
1059 current=$1
1060 break
1062 shift ; shift
1063 done
1066 # Use the default if none were set.
1068 : ${current:=$default}
1071 # Output all choices (to be compatible with other configs).
1073 set -- $choices
1074 while [ -n "$2" ]
1076 if eval [ "$1" = "$current" ]
1077 then
1078 define_bool "$2" "y"
1079 else
1080 define_bool "$2" "n"
1082 shift ; shift
1083 done
1086 function mainmenu_name () {
1090 function mainmenu_option () {
1091 comment_is_option=TRUE
1094 function endmenu () {
1098 function comment () {
1099 if [ "$comment_is_option" ]
1100 then
1101 comment_is_option=
1102 echo >>$CONFIG
1103 echo "#" >>$CONFIG
1104 echo "# $1" >>$CONFIG
1105 echo "#" >>$CONFIG
1107 echo >>$CONFIG_H
1108 echo "/*" >>$CONFIG_H
1109 echo " * $1" >>$CONFIG_H
1110 echo " */" >>$CONFIG_H
1114 echo -n "."
1116 DEF_CONFIG="${1:-.config}"
1117 DEF_CONFIG_H="include/linux/autoconf.h"
1119 CONFIG=.tmpconfig
1120 CONFIG_H=.tmpconfig.h
1122 echo "#" >$CONFIG
1123 echo "# Automatically generated by make menuconfig: don't edit" >>$CONFIG
1124 echo "#" >>$CONFIG
1126 echo "/*" >$CONFIG_H
1127 echo " * Automatically generated by make menuconfig: don't edit" >>$CONFIG_H
1128 echo " */" >>$CONFIG_H
1129 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
1131 echo -n "."
1132 if . $CONFIG_IN >>.menuconfig.log 2>&1
1133 then
1134 if [ "$DEF_CONFIG" = ".config" ]
1135 then
1136 mv $CONFIG_H $DEF_CONFIG_H
1139 if [ -f "$DEF_CONFIG" ]
1140 then
1141 rm -f ${DEF_CONFIG}.old
1142 mv $DEF_CONFIG ${DEF_CONFIG}.old
1145 mv $CONFIG $DEF_CONFIG
1147 return 0
1148 else
1149 return 1
1154 # Remove temporary files
1156 cleanup () {
1157 cleanup1
1158 cleanup2
1161 cleanup1 () {
1162 rm -f MCmenu* MCradiolists MCdialog.out help.out
1165 cleanup2 () {
1166 rm -f .tmpconfig .tmpconfig.h
1169 set_geometry () {
1170 # Some distributions export these with incorrect values
1171 # which can really screw up some ncurses programs.
1172 LINES= COLUMNS=
1174 ROWS=${1:-24} COLS=${2:-80}
1176 # Just in case the nasty rlogin bug returns.
1178 [ $ROWS = 0 ] && ROWS=24
1179 [ $COLS = 0 ] && COLS=80
1181 if [ $ROWS -lt 19 -o $COLS -lt 80 ]
1182 then
1183 echo -e "\n\007Your display is too small to run Menuconfig!"
1184 echo "It must be at least 19 lines by 80 columns."
1185 exit 0
1188 ROWS=$((ROWS-4)) COLS=$((COLS-5))
1192 set_geometry `stty size 2>/dev/null`
1194 menu_instructions="\
1195 Arrow keys navigate the menu. \
1196 <Enter> selects submenus --->. \
1197 Highlighted letters are hotkeys. \
1198 Pressing <Y> includes, <N> excludes, <M> modularizes features. \
1199 Press <Esc><Esc> to exit, <?> for Help. \
1200 Legend: [*] built-in [ ] excluded <M> module < > module capable"
1202 radiolist_instructions="\
1203 Use the arrow keys to navigate this window or \
1204 press the hotkey of the item you wish to select \
1205 followed by the <SPACE BAR>.
1206 Press <?> for additional information about this option."
1208 inputbox_instructions_int="\
1209 Please enter a decimal value. \
1210 Fractions will not be accepted. \
1211 Use the <TAB> key to move from the input field to the buttons below it."
1213 inputbox_instructions_hex="\
1214 Please enter a hexadecimal value. \
1215 Use the <TAB> key to move from the input field to the buttons below it."
1217 inputbox_instructions_string="\
1218 Please enter a string value. \
1219 Use the <TAB> key to move from the input field to the buttons below it."
1221 DIALOG="./scripts/lxdialog/lxdialog"
1223 kernel_version="${VERSION}.${PATCHLEVEL}.${SUBLEVEL}"
1225 backtitle="Linux Kernel v$kernel_version Configuration"
1227 trap "cleanup ; exit 1" 1 2 15
1231 # Locate default files.
1233 CONFIG_IN=./config.in
1234 if [ "$1" != "" ] ; then
1235 CONFIG_IN=$1
1238 DEFAULTS=arch/$ARCH/defconfig
1239 if [ -f .config ]; then
1240 DEFAULTS=.config
1243 if [ -f $DEFAULTS ]
1244 then
1245 echo "Using defaults found in" $DEFAULTS
1246 load_config_file $DEFAULTS
1247 else
1248 echo "No defaults found"
1252 # Fresh new log.
1253 >.menuconfig.log
1255 # Load the functions used by the config.in files.
1256 echo -n "Preparing scripts: functions"
1257 load_functions
1259 if [ ! -e $CONFIG_IN ]
1260 then
1261 echo "Your main config.in file ($CONFIG_IN) does not exist"
1262 exit 1
1265 if [ ! -x $DIALOG ]
1266 then
1267 echo "Your lxdialog utility does not exist"
1268 exit 1
1272 # Read config.in files and parse them into one shell function per menu.
1274 echo -n ", parsing"
1275 parse_config_files $CONFIG_IN
1277 echo "done."
1279 # Start the ball rolling from the top.
1281 activate_menu MCmenu0
1284 # All done!
1286 cleanup1
1289 # Confirm and Save
1291 if $DIALOG --backtitle "$backtitle" \
1292 --yesno "Do you wish to save your new kernel configuration?" 5 60
1293 then
1294 save_configuration
1295 echo
1296 echo
1297 echo "*** End of Linux kernel configuration."
1298 echo "*** Check the top-level Makefile for additional configuration."
1299 if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then
1300 echo "*** Next, you must run 'make dep'."
1301 else
1302 echo "*** Next, you may run 'make zImage', 'make zdisk', or 'make zlilo.'"
1304 echo
1305 else
1306 echo
1307 echo
1308 echo Your kernel configuration changes were NOT saved.
1309 echo
1311 exit 0