Import 2.1.81
[davej-history.git] / scripts / Menuconfig
blob4dd37ab52a61398835f16befc9036bbfdcaedee0
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 # Please send comments / questions / bug fixes to roadcapw@cfw.com
24 # 070497 Bernhard Kaindl (bkaindl@netway.at) - get default values for
25 # new bool, tristate and dep_tristate parameters from the defconfig file.
26 # new configuration parameters are marked with '(NEW)' as in make config.
28 # 180697 Bernhard Kaindl (bkaindl@netway.at) - added the needed support
29 # for string options. They are handled like the int and hex options.
31 # 081297 Pavel Machek (pavel@atrey.karlin.mff.cuni.cz) - better error
32 # handling
34 # 131197 Michael Chastain (mec@shout.net) - output all lines for a
35 # choice list, not just the selected one. This makes the output
36 # the same as Configure output, which is important for smart config
37 # dependencies.
39 # 101297 Michael Chastain (mec@shout.net) - remove sound driver cruft.
41 # 221297 Michael Chastain (mec@shout.net) - make define_bool actually
42 # define its arguments so that later tests on them work right.
44 # 160198 Michael Chastain (mec@shout.net) - fix bug with 'c' command
45 # (complement existing value) when used on virgin uninitialized variables.
46 #----------------------------------------------------------------------------
50 # Change this to TRUE if you prefer all kernel options listed
51 # in a single menu rather than the standard menu hierarchy.
53 single_menu_mode=
56 # Make sure we're really running bash.
58 [ -z "$BASH" ] && { echo "Menuconfig requires bash" 1>&2; exit 1; }
61 # Cache function definitions, turn off posix compliance
63 set -h +o posix
66 # Converts "# xxx is not..." to xxx=n
68 parse_config () {
69 sed -e 's/# \(.*\) is not.*/\1=n/'
73 # Parses the defconfig file to set the default for a new parameter.
75 function get_def () {
76 parse_config < arch/$ARCH/defconfig | grep "^$1=" > /tmp/conf.$$
77 . /tmp/conf.$$
78 rm /tmp/conf.$$
82 # Load the functions used by the config.in files.
84 # I do this because these functions must be redefined depending
85 # on whether they are being called for interactive use or for
86 # saving a configuration to a file.
88 # Thank the heavens bash supports nesting function definitions.
90 load_functions () {
93 # Macro for setting the x and info varibles. get's default from defconfig
94 # file if it's a new parameter.
96 function set_x () {
97 eval x=\$$1
98 if [ -z "$x" ]; then
99 get_def "$1"
100 eval x=\${$1:-'n'} INFO_$1="' (NEW)'"
102 eval info="\$INFO_$1"
106 # Additional comments
108 function comment () {
109 comment_ctr=$[ comment_ctr + 1 ]
110 echo -ne "': $comment_ctr' '--- $1' " >>MCmenu
114 # Define a boolean to a specific value.
116 function define_bool () {
117 eval $1=$2
121 # Create a boolean (Yes/No) function for our current menu
122 # which calls our local bool function.
124 function bool () {
125 set_x "$2"
127 case $x in
128 y|m) flag="*" ;;
129 n) flag=" " ;;
130 esac
132 echo -ne "'$2' '[$flag] $1$info' " >>MCmenu
134 echo -e "function $2 () { l_bool '$2' \"\$1\" ;}\n" >>MCradiolists
138 # Create a tristate (Yes/No/Module) radiolist function
139 # which calls our local tristate function.
141 # Collapses to a boolean (Yes/No) if module support is disabled.
143 function tristate () {
144 if [ "$CONFIG_MODULES" != "y" ]
145 then
146 bool "$1" "$2"
147 else
148 set_x "$2"
150 case $x in
151 y) flag="*" ;;
152 m) flag="M" ;;
153 *) flag=" " ;;
154 esac
156 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
158 echo -e "
159 function $2 () { l_tristate '$2' \"\$1\" ;}" >>MCradiolists
164 # Create a tristate radiolist function which is dependent on
165 # another kernel configuration option.
167 # Quote from the original configure script:
169 # If the option we depend upon is a module,
170 # then the only allowable options are M or N. If Y, then
171 # this is a normal tristate. This is used in cases where modules
172 # are nested, and one module requires the presence of something
173 # else in the kernel.
175 function dep_tristate () {
176 if [ "$CONFIG_MODULES" != "y" ]
177 then
178 bool "$1" "$2"
179 else
180 if eval [ "_$3" != "_m" ]
181 then
182 tristate "$1" "$2" $3
183 else
184 mod_bool "$1" "$2"
190 # Add a menu item which will call our local int function.
192 function int () {
193 eval $2=\${$2:-"$3"} x=\$$2
195 echo -ne "'$2' '($x) $1' " >>MCmenu
197 echo -e "function $2 () { l_int '$1' '$2' '$3' '$x' ;}" >>MCradiolists
201 # Add a menu item which will call our local hex function.
203 function hex () {
204 eval $2=\${$2:-"$3"} x=\${$2##*[x,X]}
206 echo -ne "'$2' '($x) $1' " >>MCmenu
208 echo -e "function $2 () { l_hex '$1' '$2' '$3' '$x' ;}" >>MCradiolists
212 # Add a menu item which will call our local string function.
214 function string () {
215 eval $2=\${$2:-"$3"} x=\$$2
217 echo -ne "'$2' ' $1: \"$x\"' " >>MCmenu
219 echo -e "function $2 () { l_string '$1' '$2' '$3' '$x' ;}" >>MCradiolists
223 # Add a menu item which will call our local One-of-Many choice list.
225 function choice () {
227 # Need to remember params cause they're gonna get reset.
229 title=$1
230 choices=$2
231 default=$3
232 current=
235 # Find out if one of the choices is already set.
236 # If it's not then make it the default.
238 set -- $choices
239 firstchoice=$2
241 while [ -n "$2" ]
243 if eval [ "_\$$2" = "_y" ]
244 then
245 current=$1
246 break
248 shift ; shift
249 done
251 : ${current:=$default}
253 echo -ne "'$firstchoice' '($current) $title' " >>MCmenu
255 echo -e "
256 function $firstchoice () \
257 { l_choice '$title' \"$choices\" $current ;}" >>MCradiolists
260 } # END load_functions()
267 # Extract available help for an option from Configure.help
268 # and send it to standard output.
270 # Most of this function was borrowed from the original kernel
271 # Configure script.
273 function extract_help () {
274 if [ -f Documentation/Configure.help ]
275 then
276 #first escape regexp special characters in the argument:
277 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
278 #now pick out the right help text:
279 text=$(sed -n "/^$var[ ]*\$/,\${
280 /^$var[ ]*\$/d
281 /^#.*/d
282 /^[ ]*\$/q
283 s/^ //
285 }" Documentation/Configure.help)
287 if [ -z "$text" ]
288 then
289 echo "There is no help available for this kernel option."
290 return 1
291 else
292 echo "$text"
294 else
295 echo "There is no help available for this kernel option."
296 return 1
301 # Activate a help dialog.
303 function help () {
304 if extract_help $1 >help.out
305 then
306 $DIALOG --backtitle "$backtitle" --title "$2"\
307 --textbox help.out $ROWS $COLS
308 else
309 $DIALOG --backtitle "$backtitle" \
310 --textbox help.out $ROWS $COLS
312 rm help.out
316 # Show the README file.
318 function show_readme () {
319 $DIALOG --backtitle "$backtitle" \
320 --textbox scripts/README.Menuconfig $ROWS $COLS
324 # Begin building the dialog menu command and Initialize the
325 # Radiolist function file.
327 function menu_name () {
328 echo -ne "$DIALOG --title '$1'\
329 --backtitle '$backtitle' \
330 --menu '$menu_instructions' \
331 $ROWS $COLS $((ROWS-10)) \
332 '$default' " >MCmenu
333 >MCradiolists
337 # Add a submenu option to the menu currently under construction.
339 function submenu () {
340 echo -ne "'activate_menu $2' '$1 --->' " >>MCmenu
344 # Handle a boolean (Yes/No) option.
346 function l_bool () {
347 if [ -n "$2" ]
348 then
349 case "$2" in
350 y|m) eval $1=y ;;
351 c) eval x=\$$1
352 case $x in
353 y) eval $1=n ;;
354 n) eval $1=y ;;
355 *) eval $1=y ;;
356 esac ;;
357 *) eval $1=n ;;
358 esac
359 else
360 echo -ne "\007"
365 # Same as bool() except options are (Module/No)
367 function mod_bool () {
368 set_x "$2"
370 case $x in
371 y|m) flag='M' ;;
372 *) flag=' ' ;;
373 esac
375 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
377 echo -e "function $2 () { l_mod_bool '$2' \"\$1\" ;}" >>MCradiolists
381 # Same as l_bool() except options are (Module/No)
383 function l_mod_bool() {
384 if [ -n "$2" ]
385 then
386 case "$2" in
387 y) echo -en "\007"
388 ${DIALOG} --backtitle "$backtitle" \
389 --infobox "\
390 This feature depends on another which has been configured as a module. \
391 As a result, this feature will be built as a module." 4 70
392 sleep 5
393 eval $1=m ;;
394 m) eval $1=m ;;
395 c) eval x=\$$1
396 case $x in
397 m) eval $1=n ;;
398 n) eval $1=m ;;
399 *) eval $1=m ;;
400 esac ;;
401 *) eval $1=n ;;
402 esac
403 else
404 echo -ne "\007"
409 # Handle a tristate (Yes/No/Module) option.
411 function l_tristate () {
412 if [ -n "$2" ]
413 then
414 eval x=\$$1
416 case "$2" in
417 y) eval $1=y ;;
418 m) eval $1=m ;;
419 c) eval x=\$$1
420 case $x in
421 y) eval $1=n ;;
422 n) eval $1=m ;;
423 m) eval $1=y ;;
424 *) eval $1=y ;;
425 esac ;;
426 *) eval $1=n ;;
427 esac
428 else
429 echo -ne "\007"
434 # Create a dialog for entering an integer into a kernel option.
436 function l_int () {
437 while true
439 if $DIALOG --title "$1" \
440 --backtitle "$backtitle" \
441 --inputbox "$inputbox_instructions_int" \
442 10 75 "$4" 2>MCdialog.out
443 then
444 answer="`cat MCdialog.out`"
445 answer="${answer:-$3}"
447 # Semantics of + and ? in GNU expr changed, so
448 # we avoid them:
449 if expr "$answer" : '0$\|-[1-9][0-9]*$\|[1-9][0-9]*$' >/dev/null
450 then
451 eval $2="$answer"
452 else
453 eval $2="$3"
454 echo -en "\007"
455 ${DIALOG} --backtitle "$backtitle" \
456 --infobox "You have made an invalid entry." 3 43
457 sleep 2
460 break
463 help "$2" "$1"
464 done
468 # Create a dialog for entering a hexadecimal into a kernel option.
470 function l_hex () {
471 while true
473 if $DIALOG --title "$1" \
474 --backtitle "$backtitle" \
475 --inputbox "$inputbox_instructions_hex" \
476 10 75 "$4" 2>MCdialog.out
477 then
478 answer="`cat MCdialog.out`"
479 answer="${answer:-$3}"
480 answer="${answer##*[x,X]}"
482 if expr "$answer" : '[0-9a-fA-F][0-9a-fA-F]*$' >/dev/null
483 then
484 eval $2="$answer"
485 else
486 eval $2="$3"
487 echo -en "\007"
488 ${DIALOG} --backtitle "$backtitle" \
489 --infobox "You have made an invalid entry." 3 43
490 sleep 2
493 break
496 help "$2" "$1"
497 done
501 # Create a dialog for entering a string into a kernel option.
503 function l_string () {
504 while true
506 if $DIALOG --title "$1" \
507 --backtitle "$backtitle" \
508 --inputbox "$inputbox_instructions_string" \
509 10 75 "$4" 2>MCdialog.out
510 then
511 answer="`cat MCdialog.out`"
512 answer="${answer:-$3}"
515 # Someone may add a nice check for the entered
516 # string here...
518 eval $2=\"$answer\"
520 break
523 help "$2" "$1"
524 done
529 # Handle a one-of-many choice list.
531 function l_choice () {
533 # Need to remember params cause they're gonna get reset.
535 title="$1"
536 choices="$2"
537 current="$3"
540 # Scan current value of choices and set radiolist switches.
542 list=
543 set -- $choices
544 firstchoice=$2
545 while [ -n "$2" ]
547 case "$1" in
548 "$current") list="$list $2 $1 ON " ;;
549 *) list="$list $2 $1 OFF " ;;
550 esac
552 shift ; shift
553 done
555 while true
557 if $DIALOG --title "$title" \
558 --backtitle "$backtitle" \
559 --radiolist "$radiolist_instructions" \
560 15 70 6 $list 2>MCdialog.out
561 then
562 choice=`cat MCdialog.out`
563 break
566 help "$firstchoice" "$title"
567 done
570 # Now set the boolean value of each option based on
571 # the selection made from the radiolist.
573 set -- $choices
574 while [ -n "$2" ]
576 if [ "$2" = "$choice" ]
577 then
578 eval $2="y"
579 else
580 eval $2="n"
583 shift ; shift
584 done
588 # Call awk, and watch for error codes, etc.
590 function callawk () {
591 awk "$1" || echo "Awk died with error code $?. Giving up." || exit 1
595 # A faster awk based recursive parser. (I hope)
597 function parser1 () {
598 callawk '
599 BEGIN {
600 menu_no = 0
601 comment_is_option = 0
602 parser("'$CONFIG_IN'","MCmenu0")
605 function parser(ifile,menu) {
607 while (getline <ifile) {
608 if ($1 == "mainmenu_option") {
609 comment_is_option = "1"
611 else if ($1 == "comment" && comment_is_option == "1") {
612 comment_is_option= "0"
613 sub($1,"",$0)
614 ++menu_no
616 printf("submenu %s MCmenu%s\n", $0, menu_no) >>menu
618 printf( "function MCmenu%s () {\n"\
619 "default=$1\n"\
620 "menu_name %s\n",\
621 menu_no, $0) >"MCmenu"menu_no
623 parser(ifile, "MCmenu"menu_no)
625 else if ($1 ~ "endmenu") {
626 printf("}\n") >>menu
627 return
629 else if ($0 ~ /^#|\$MAKE|mainmenu_name/) {
630 printf("") >>menu
632 else if ($1 == "source") {
633 parser($2,menu)
635 else {
636 print >>menu
643 # Secondary parser for single menu mode.
645 function parser2 () {
646 callawk '
647 BEGIN {
648 parser("'$CONFIG_IN'","MCmenu0")
651 function parser(ifile,menu) {
653 while (getline <ifile) {
654 if ($1 ~ /mainmenu_option|endmenu/) {
655 printf("") >>menu
657 else if ($0 ~ /^#|$MAKE|mainmenu_name/) {
658 printf("") >>menu
660 else if ($1 == "source") {
661 parser($2,menu)
663 else {
664 print >>menu
671 # Parse all the config.in files into mini scripts.
673 function parse_config_files () {
674 rm -f MCmenu*
676 echo "function MCmenu0 () {" >MCmenu0
677 echo 'default=$1' >>MCmenu0
678 echo "menu_name 'Main Menu'" >>MCmenu0
680 if [ "_$single_menu_mode" = "_TRUE" ]
681 then
682 parser2
683 else
684 parser1
687 echo "comment ''" >>MCmenu0
688 echo "g_alt_config" >>MCmenu0
689 echo "s_alt_config" >>MCmenu0
691 echo "}" >>MCmenu0
694 # These mini scripts must be sourced into the current
695 # environment in order for all of this to work. Leaving
696 # them on the disk as executables screws up the recursion
697 # in activate_menu(), among other things. Once they are
698 # sourced we can discard them.
700 for i in MCmenu*
702 echo -n "."
703 source ./$i
704 done
705 rm -f MCmenu*
709 # This is the menu tree's bootstrap.
711 # Executes the parsed menus on demand and creates a set of functions,
712 # one per configuration option. These functions will in turn execute
713 # dialog commands or recursively call other menus.
715 function activate_menu () {
716 while true
718 comment_ctr=0 #So comment lines get unique tags
720 $1 "$default" #Create the lxdialog menu & functions
722 if [ "$?" != "0" ]
723 then
724 clear
725 cat <<EOM
726 Menuconfig has encountered a possible error in one of the kernel's
727 configuration files and is unable to continue.
729 Please report this to the author <roadcapw@cfw.com>. You may also
730 send a problem report to linux-kernel@vger.rutgers.edu or post a
731 message to the linux.dev.kernel news group.
733 Please indicate the kernel version you are trying to configure and
734 which menu you were trying to enter when this error occurred.
737 cleanup
738 exit 1
741 . ./MCradiolists #Source the menu's functions
743 . ./MCmenu 2>MCdialog.out #Activate the lxdialog menu
744 ret=$?
746 read selection <MCdialog.out
748 case "$ret" in
749 0|3|4|5|6)
750 defaults="$selection\x12$defaults" #pseudo stack
751 case "$ret" in
752 0) eval $selection ;;
753 3) eval $selection y ;;
754 4) eval $selection n ;;
755 5) eval $selection m ;;
756 6) eval $selection c ;;
757 esac
758 default="${defaults%%\x12*}" defaults="${defaults#*\x12}"
761 default="${selection%%\ *}"
763 case "$selection" in
764 *"-->"*|*"alt_config"*)
765 show_readme ;;
767 eval help $selection ;;
768 esac
770 255|1)
771 break
773 139)
774 stty sane
775 clear
776 cat <<EOM
777 There seems to be a problem with the lxdialog companion utility which is
778 built prior to running Menuconfig. Usually this is an indicator that you
779 have upgraded/downgraded your ncurses libraries and did not remove the
780 old ncurses header file(s) in /usr/include or /usr/include/ncurses.
782 It is VERY important that you have only one set of ncurses header files
783 and that those files are properly version matched to the ncurses libraries
784 installed on your machine.
786 You may also need to rebuild lxdialog. This can be done by moving to
787 the /usr/src/linux/scripts/lxdialog directory and issuing the
788 "make clean all" command.
790 If you have verified that your ncurses install is correct, you may email
791 the author <roadcapw@cfw.com> or post a message on the linux.dev.kernel
792 news group for additional assistance.
795 cleanup
796 exit 139
798 esac
799 done
803 # Create a menu item to load an alternate configuration file.
805 g_alt_config () {
806 echo -n "get_alt_config 'Load an Alternate Configuration File' "\
807 >>MCmenu
811 # Get alternate config file name and load the
812 # configuration from it.
814 get_alt_config () {
815 set -f ## Switch file expansion OFF
817 while true
819 ALT_CONFIG="${ALT_CONFIG:-$DEFAULTS}"
821 $DIALOG --backtitle "$backtitle" \
822 --inputbox "\
823 Enter the name of the configuration file you wish to load. \
824 Accept the name shown to restore the configuration you \
825 last retrieved. Leave blank to abort."\
826 11 55 "$ALT_CONFIG" 2>MCdialog.out
828 if [ "$?" = "0" ]
829 then
830 ALT_CONFIG=`cat MCdialog.out`
832 [ "_" = "_$ALT_CONFIG" ] && break
834 if eval [ -r "$ALT_CONFIG" ]
835 then
836 eval load_config_file "$ALT_CONFIG"
837 break
838 else
839 echo -ne "\007"
840 $DIALOG --backtitle "$backtitle" \
841 --infobox "File does not exist!" 3 38
842 sleep 2
844 else
845 cat <<EOM >help.out
847 For various reasons, one may wish to keep several different kernel
848 configurations available on a single machine.
850 If you have saved a previous configuration in a file other than the
851 kernel's default, entering the name of the file here will allow you
852 to modify that configuration.
854 If you are uncertain, then you have probably never used alternate
855 configuration files. You should therefor leave this blank to abort.
858 $DIALOG --backtitle "$backtitle"\
859 --title "Load Alternate Configuration"\
860 --textbox help.out $ROWS $COLS
862 done
864 set +f ## Switch file expansion ON
865 rm -f help.out MCdialog.out
869 # Create a menu item to store an alternate config file.
871 s_alt_config () {
872 echo -n "save_alt_config 'Save Configuration to an Alternate File' "\
873 >>MCmenu
877 # Get an alternate config file name and save the current
878 # configuration to it.
880 save_alt_config () {
881 set -f ## Switch file expansion OFF
883 while true
885 $DIALOG --backtitle "$backtitle" \
886 --inputbox "\
887 Enter a filename to which this configuration should be saved \
888 as an alternate. Leave blank to abort."\
889 10 55 "$ALT_CONFIG" 2>MCdialog.out
891 if [ "$?" = "0" ]
892 then
893 ALT_CONFIG=`cat MCdialog.out`
895 [ "_" = "_$ALT_CONFIG" ] && break
897 if eval touch $ALT_CONFIG 2>/dev/null
898 then
899 eval save_configuration $ALT_CONFIG
900 load_functions ## RELOAD
901 break
902 else
903 echo -ne "\007"
904 $DIALOG --backtitle "$backtitle" \
905 --infobox "Can't create file! Probably a nonexistent directory." 3 60
906 sleep 2
908 else
909 cat <<EOM >help.out
911 For various reasons, one may wish to keep different kernel
912 configurations available on a single machine.
914 Entering a file name here will allow you to later retrieve, modify
915 and use the current configuration as an alternate to whatever
916 configuration options you have selected at that time.
918 If you are uncertain what all this means then you should probably
919 leave this blank.
921 $DIALOG --backtitle "$backtitle"\
922 --title "Save Alternate Configuration"\
923 --textbox help.out $ROWS $COLS
925 done
927 set +f ## Switch file expansion ON
928 rm -f help.out MCdialog.out
932 # Load config options from a file.
933 # Converts all "# OPTION is not set" lines to "OPTION=n" lines
935 function load_config_file () {
936 awk '
937 /# .* is not set.*/ { printf("%s=n\n", $2) }
938 ! /# .* is not set.*/ { print }
939 ' $1 >.tmpconfig
941 source ./.tmpconfig
942 rm -f .tmpconfig
946 # Just what it says.
948 save_configuration () {
949 echo
950 echo -n "Saving your kernel configuration."
953 # Macro for setting the newval varible. get's default from defconfig
954 # file if it's a new parameter and it has not been shown yet.
956 function set_newval () {
957 eval newval=\$$1
958 if [ -z "$newval" ]; then
959 get_def "$1"
960 eval newval=\${$1:-'n'}
965 # Now, let's redefine the configuration functions for final
966 # output to the config files.
968 # Nested function definitions, YIPEE!
970 function bool () {
971 set_newval "$2"
972 eval define_bool "$2" "$newval"
975 function tristate () {
976 set_newval "$2"
977 eval define_bool "$2" "$newval"
980 function dep_tristate () {
981 set_newval "$2"
983 if eval [ "_$3" = "_m" ]
984 then
985 if [ "$newval" = "y" ]
986 then
987 newval="m"
991 define_bool "$2" "$newval"
994 function int () {
995 eval x=\${$2:-"$3"}
996 echo "$2=$x" >>$CONFIG
997 echo "#define $2 ($x)" >>$CONFIG_H
1000 function hex () {
1001 eval x=\${$2:-"$3"}
1002 echo "$2=$x" >>$CONFIG
1003 echo "#define $2 0x${x##*[x,X]}" >>$CONFIG_H
1006 function string () {
1007 eval x=\${$2:-"$3"}
1008 echo "$2=\"$x\"" >>$CONFIG
1009 echo "#define $2 \"$x\"" >>$CONFIG_H
1012 function define_bool () {
1013 eval $1="$2"
1015 case "$2" in
1017 echo "$1=y" >>$CONFIG
1018 echo "#define $1 1" >>$CONFIG_H
1022 if [ "$CONFIG_MODULES" = "y" ]
1023 then
1024 echo "$1=m" >>$CONFIG
1025 echo "#undef $1" >>$CONFIG_H
1026 echo "#define $1_MODULE 1" >>$CONFIG_H
1027 else
1028 echo "$1=y" >>$CONFIG
1029 echo "#define $1 1" >>$CONFIG_H
1034 echo "# $1 is not set" >>$CONFIG
1035 echo "#undef $1" >>$CONFIG_H
1037 esac
1040 function choice () {
1042 # Find the first choice that's already set to 'y'
1044 choices="$2"
1045 default="$3"
1046 current=
1048 set -- $choices
1049 while [ -n "$2" ]
1051 if eval [ "_\$$2" = "_y" ]
1052 then
1053 current=$1
1054 break
1056 shift ; shift
1057 done
1060 # Use the default if none were set.
1062 : ${current:=$default}
1065 # Output all choices (to be compatible with other configs).
1067 set -- $choices
1068 while [ -n "$2" ]
1070 if eval [ "$1" = "$current" ]
1071 then
1072 define_bool "$2" "y"
1073 else
1074 define_bool "$2" "n"
1076 shift ; shift
1077 done
1080 function mainmenu_name () {
1084 function mainmenu_option () {
1085 comment_is_option=TRUE
1088 function endmenu () {
1092 function comment () {
1093 if [ "$comment_is_option" ]
1094 then
1095 comment_is_option=
1096 echo >>$CONFIG
1097 echo "#" >>$CONFIG
1098 echo "# $1" >>$CONFIG
1099 echo "#" >>$CONFIG
1101 echo >>$CONFIG_H
1102 echo "/*" >>$CONFIG_H
1103 echo " * $1" >>$CONFIG_H
1104 echo " */" >>$CONFIG_H
1108 echo -n "."
1110 DEF_CONFIG="${1:-.config}"
1111 DEF_CONFIG_H="include/linux/autoconf.h"
1113 CONFIG=.tmpconfig
1114 CONFIG_H=.tmpconfig.h
1116 echo "#" >$CONFIG
1117 echo "# Automatically generated by make menuconfig: don't edit" >>$CONFIG
1118 echo "#" >>$CONFIG
1120 echo "/*" >$CONFIG_H
1121 echo " * Automatically generated by make menuconfig: don't edit" >>$CONFIG_H
1122 echo " */" >>$CONFIG_H
1123 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
1125 echo -n "."
1126 if . $CONFIG_IN >>.menuconfig.log 2>&1
1127 then
1128 if [ "$DEF_CONFIG" = ".config" ]
1129 then
1130 mv $CONFIG_H $DEF_CONFIG_H
1133 if [ -f "$DEF_CONFIG" ]
1134 then
1135 rm -f ${DEF_CONFIG}.old
1136 mv $DEF_CONFIG ${DEF_CONFIG}.old
1139 mv $CONFIG $DEF_CONFIG
1141 return 0
1142 else
1143 return 1
1148 # Remove temporary files
1150 cleanup () {
1151 cleanup1
1152 cleanup2
1155 cleanup1 () {
1156 rm -f MCmenu* MCradiolists MCdialog.out help.out
1159 cleanup2 () {
1160 rm -f .tmpconfig .tmpconfig.h
1163 set_geometry () {
1164 # Some distributions export these with incorrect values
1165 # which can really screw up some ncurses programs.
1166 LINES= COLUMNS=
1168 ROWS=${1:-24} COLS=${2:-80}
1170 # Just in case the nasty rlogin bug returns.
1172 [ $ROWS = 0 ] && ROWS=24
1173 [ $COLS = 0 ] && COLS=80
1175 if [ $ROWS -lt 19 -o $COLS -lt 80 ]
1176 then
1177 echo -e "\n\007Your display is too small to run Menuconfig!"
1178 echo "It must be at least 19 lines by 80 columns."
1179 exit 0
1182 ROWS=$((ROWS-4)) COLS=$((COLS-5))
1186 set_geometry `stty size 2>/dev/null`
1188 menu_instructions="\
1189 Arrow keys navigate the menu. \
1190 <Enter> selects submenus --->. \
1191 Highlighted letters are hotkeys. \
1192 Pressing <Y> includes, <N> excludes, <M> modularizes features. \
1193 Press <Esc><Esc> to exit, <?> for Help. \
1194 Legend: [*] built-in [ ] excluded <M> module < > module capable"
1196 radiolist_instructions="\
1197 Use the arrow keys to navigate this window or \
1198 press the hotkey of the item you wish to select \
1199 followed by the <SPACE BAR>.
1200 Press <?> for additional information about this option."
1202 inputbox_instructions_int="\
1203 Please enter a decimal value. \
1204 Fractions will not be accepted. \
1205 Use the <TAB> key to move from the input field to the buttons below it."
1207 inputbox_instructions_hex="\
1208 Please enter a hexadecimal value. \
1209 Use the <TAB> key to move from the input field to the buttons below it."
1211 inputbox_instructions_string="\
1212 Please enter a string value. \
1213 Use the <TAB> key to move from the input field to the buttons below it."
1215 DIALOG="./scripts/lxdialog/lxdialog"
1217 kernel_version="${VERSION}.${PATCHLEVEL}.${SUBLEVEL}"
1219 backtitle="Linux Kernel v$kernel_version Configuration"
1221 trap "cleanup ; exit 1" 1 2 15
1225 # Locate default files.
1227 CONFIG_IN=./config.in
1228 if [ "$1" != "" ] ; then
1229 CONFIG_IN=$1
1232 DEFAULTS=arch/$ARCH/defconfig
1233 if [ -f .config ]; then
1234 DEFAULTS=.config
1237 if [ -f $DEFAULTS ]
1238 then
1239 echo "Using defaults found in" $DEFAULTS
1240 load_config_file $DEFAULTS
1241 else
1242 echo "No defaults found"
1246 # Fresh new log.
1247 >.menuconfig.log
1249 echo -n "Preparing configuration scripts: version"
1251 # Load the functions used by the config.in files.
1252 echo -n ", functions"
1253 load_functions
1255 if [ ! -e $CONFIG_IN ]
1256 then
1257 echo "Your main config.in file ($CONFIG_IN) does not exist"
1258 exit 1
1261 if [ ! -x $DIALOG ]
1262 then
1263 echo "Your lxdialog utility does not exist"
1264 exit 1
1268 # Read config.in files and parse them into one shell function per menu.
1270 echo -n ", parsing"
1271 parse_config_files $CONFIG_IN
1273 echo "done."
1275 # Start the ball rolling from the top.
1277 activate_menu MCmenu0
1280 # All done!
1282 cleanup1
1285 # Confirm and Save
1287 if $DIALOG --backtitle "$backtitle" \
1288 --yesno "Do you wish to save your new kernel configuration?" 5 60
1289 then
1290 save_configuration
1291 echo
1292 echo The linux kernel is now configured for your setup.
1293 else
1294 echo
1295 echo Your kernel configuration changes were NOT saved.
1297 exit 0