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
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
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
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
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.
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
66 # Converts "# xxx is not..." to xxx=n
69 sed -e 's/# \(.*\) is not.*/\1=n/'
73 # Parses the defconfig file to set the default for a new parameter.
76 parse_config
< arch
/$ARCH/defconfig |
grep "^$1=" > /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.
93 # Macro for setting the x and info varibles. get's default from defconfig
94 # file if it's a new parameter.
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
() {
121 # Create a boolean (Yes/No) function for our current menu
122 # which calls our local bool function.
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" ]
156 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu
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" ]
180 if eval [ "_$3" != "_m" ]
182 tristate
"$1" "$2" $3
190 # Add a menu item which will call our local int function.
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.
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.
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.
227 # Need to remember params cause they're gonna get reset.
235 # Find out if one of the choices is already set.
236 # If it's not then make it the default.
243 if eval [ "_\$$2" = "_y" ]
251 : ${current:=$default}
253 echo -ne "'$firstchoice' '($current) $title' " >>MCmenu
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
273 function extract_help
() {
274 if [ -f Documentation
/Configure.
help ]
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[ ]*\$/,\${
285 }" Documentation
/Configure.
help)
289 echo "There is no help available for this kernel option."
295 echo "There is no help available for this kernel option."
301 # Activate a help dialog.
304 if extract_help
$1 >help.out
306 $DIALOG --backtitle "$backtitle" --title "$2"\
307 --textbox help.out
$ROWS $COLS
309 $DIALOG --backtitle "$backtitle" \
310 --textbox help.out
$ROWS $COLS
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)) \
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.
365 # Same as bool() except options are (Module/No)
367 function mod_bool
() {
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
() {
388 ${DIALOG} --backtitle "$backtitle" \
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
409 # Handle a tristate (Yes/No/Module) option.
411 function l_tristate
() {
434 # Create a dialog for entering an integer into a kernel option.
439 if $DIALOG --title "$1" \
440 --backtitle "$backtitle" \
441 --inputbox "$inputbox_instructions_int" \
442 10 75 "$4" 2>MCdialog.out
444 answer
="`cat MCdialog.out`"
445 answer
="${answer:-$3}"
447 # Semantics of + and ? in GNU expr changed, so
449 if expr "$answer" : '0$\|-[1-9][0-9]*$\|[1-9][0-9]*$' >/dev
/null
455 ${DIALOG} --backtitle "$backtitle" \
456 --infobox "You have made an invalid entry." 3 43
468 # Create a dialog for entering a hexadecimal into a kernel option.
473 if $DIALOG --title "$1" \
474 --backtitle "$backtitle" \
475 --inputbox "$inputbox_instructions_hex" \
476 10 75 "$4" 2>MCdialog.out
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
488 ${DIALOG} --backtitle "$backtitle" \
489 --infobox "You have made an invalid entry." 3 43
501 # Create a dialog for entering a string into a kernel option.
503 function l_string
() {
506 if $DIALOG --title "$1" \
507 --backtitle "$backtitle" \
508 --inputbox "$inputbox_instructions_string" \
509 10 75 "$4" 2>MCdialog.out
511 answer
="`cat MCdialog.out`"
512 answer
="${answer:-$3}"
515 # Someone may add a nice check for the entered
529 # Handle a one-of-many choice list.
531 function l_choice
() {
533 # Need to remember params cause they're gonna get reset.
540 # Scan current value of choices and set radiolist switches.
548 "$current") list
="$list $2 $1 ON " ;;
549 *) list
="$list $2 $1 OFF " ;;
557 if $DIALOG --title "$title" \
558 --backtitle "$backtitle" \
559 --radiolist "$radiolist_instructions" \
560 15 70 6 $list 2>MCdialog.out
562 choice
=`cat MCdialog.out`
566 help "$firstchoice" "$title"
570 # Now set the boolean value of each option based on
571 # the selection made from the radiolist.
576 if [ "$2" = "$choice" ]
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
() {
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"
616 printf("submenu %s MCmenu%s\n", $0, menu_no) >>menu
618 printf( "function MCmenu%s () {\n"\
621 menu_no, $0) >"MCmenu"menu_no
623 parser(ifile, "MCmenu"menu_no)
625 else if ($1 ~ "endmenu") {
629 else if ($0 ~ /^#|\$MAKE|mainmenu_name/) {
632 else if ($1 == "source") {
643 # Secondary parser for single menu mode.
645 function parser2
() {
648 parser("'$CONFIG_IN'","MCmenu0")
651 function parser(ifile,menu) {
653 while (getline <ifile) {
654 if ($1 ~ /mainmenu_option|endmenu/) {
657 else if ($0 ~ /^#|$MAKE|mainmenu_name/) {
660 else if ($1 == "source") {
671 # Parse all the config.in files into mini scripts.
673 function parse_config_files
() {
676 echo "function MCmenu0 () {" >MCmenu0
677 echo 'default=$1' >>MCmenu0
678 echo "menu_name 'Main Menu'" >>MCmenu0
680 if [ "_$single_menu_mode" = "_TRUE" ]
687 echo "comment ''" >>MCmenu0
688 echo "g_alt_config" >>MCmenu0
689 echo "s_alt_config" >>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.
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
() {
718 comment_ctr
=0 #So comment lines get unique tags
720 $1 "$default" #Create the lxdialog menu & functions
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.
741 . .
/MCradiolists
#Source the menu's functions
743 . .
/MCmenu
2>MCdialog.out
#Activate the lxdialog menu
746 read selection
<MCdialog.out
750 defaults
="$selection\x12$defaults" #pseudo stack
752 0) eval $selection ;;
753 3) eval $selection y
;;
754 4) eval $selection n
;;
755 5) eval $selection m
;;
756 6) eval $selection c
;;
758 default
="${defaults%%\x12*}" defaults
="${defaults#*\x12}"
761 default
="${selection%%\ *}"
764 *"-->"*|
*"alt_config"*)
767 eval help $selection ;;
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.
803 # Create a menu item to load an alternate configuration file.
806 echo -n "get_alt_config 'Load an Alternate Configuration File' "\
811 # Get alternate config file name and load the
812 # configuration from it.
815 set -f ## Switch file expansion OFF
819 ALT_CONFIG
="${ALT_CONFIG:-$DEFAULTS}"
821 $DIALOG --backtitle "$backtitle" \
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
830 ALT_CONFIG
=`cat MCdialog.out`
832 [ "_" = "_$ALT_CONFIG" ] && break
834 if eval [ -r "$ALT_CONFIG" ]
836 eval load_config_file
"$ALT_CONFIG"
840 $DIALOG --backtitle "$backtitle" \
841 --infobox "File does not exist!" 3 38
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
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.
872 echo -n "save_alt_config 'Save Configuration to an Alternate File' "\
877 # Get an alternate config file name and save the current
878 # configuration to it.
881 set -f ## Switch file expansion OFF
885 $DIALOG --backtitle "$backtitle" \
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
893 ALT_CONFIG
=`cat MCdialog.out`
895 [ "_" = "_$ALT_CONFIG" ] && break
897 if eval touch $ALT_CONFIG 2>/dev
/null
899 eval save_configuration
$ALT_CONFIG
900 load_functions
## RELOAD
904 $DIALOG --backtitle "$backtitle" \
905 --infobox "Can't create file! Probably a nonexistent directory." 3 60
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
921 $DIALOG --backtitle "$backtitle"\
922 --title "Save Alternate Configuration"\
923 --textbox help.out
$ROWS $COLS
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
() {
937 /# .* is not set.*/ { printf("%s=n\n", $2) }
938 ! /# .* is not set.*/ { print }
948 save_configuration
() {
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
() {
958 if [ -z "$newval" ]; then
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!
972 eval define_bool
"$2" "$newval"
975 function tristate
() {
977 eval define_bool
"$2" "$newval"
980 function dep_tristate
() {
983 if eval [ "_$3" = "_m" ]
985 if [ "$newval" = "y" ]
991 define_bool
"$2" "$newval"
996 echo "$2=$x" >>$CONFIG
997 echo "#define $2 ($x)" >>$CONFIG_H
1002 echo "$2=$x" >>$CONFIG
1003 echo "#define $2 0x${x##*[x,X]}" >>$CONFIG_H
1006 function string
() {
1008 echo "$2=\"$x\"" >>$CONFIG
1009 echo "#define $2 \"$x\"" >>$CONFIG_H
1012 function define_bool
() {
1017 echo "$1=y" >>$CONFIG
1018 echo "#define $1 1" >>$CONFIG_H
1022 if [ "$CONFIG_MODULES" = "y" ]
1024 echo "$1=m" >>$CONFIG
1025 echo "#undef $1" >>$CONFIG_H
1026 echo "#define $1_MODULE 1" >>$CONFIG_H
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
1040 function choice
() {
1042 # Find the first choice that's already set to 'y'
1051 if eval [ "_\$$2" = "_y" ]
1060 # Use the default if none were set.
1062 : ${current:=$default}
1065 # Output all choices (to be compatible with other configs).
1070 if eval [ "$1" = "$current" ]
1072 define_bool
"$2" "y"
1074 define_bool
"$2" "n"
1080 function mainmenu_name
() {
1084 function mainmenu_option
() {
1085 comment_is_option
=TRUE
1088 function endmenu
() {
1092 function comment
() {
1093 if [ "$comment_is_option" ]
1098 echo "# $1" >>$CONFIG
1102 echo "/*" >>$CONFIG_H
1103 echo " * $1" >>$CONFIG_H
1104 echo " */" >>$CONFIG_H
1110 DEF_CONFIG
="${1:-.config}"
1111 DEF_CONFIG_H
="include/linux/autoconf.h"
1114 CONFIG_H
=.tmpconfig.h
1117 echo "# Automatically generated by make menuconfig: don't edit" >>$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
1126 if .
$CONFIG_IN >>.menuconfig.log
2>&1
1128 if [ "$DEF_CONFIG" = ".config" ]
1130 mv $CONFIG_H $DEF_CONFIG_H
1133 if [ -f "$DEF_CONFIG" ]
1135 rm -f ${DEF_CONFIG}.old
1136 mv $DEF_CONFIG ${DEF_CONFIG}.old
1139 mv $CONFIG $DEF_CONFIG
1148 # Remove temporary files
1156 rm -f MCmenu
* MCradiolists MCdialog.out
help.out
1160 rm -f .tmpconfig .tmpconfig.h
1164 # Some distributions export these with incorrect values
1165 # which can really screw up some ncurses programs.
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 ]
1177 echo -e "\n\007Your display is too small to run Menuconfig!"
1178 echo "It must be at least 19 lines by 80 columns."
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
1232 DEFAULTS
=arch
/$ARCH/defconfig
1233 if [ -f .config
]; then
1239 echo "Using defaults found in" $DEFAULTS
1240 load_config_file
$DEFAULTS
1242 echo "No defaults found"
1249 echo -n "Preparing configuration scripts: version"
1251 # Load the functions used by the config.in files.
1252 echo -n ", functions"
1255 if [ ! -e $CONFIG_IN ]
1257 echo "Your main config.in file ($CONFIG_IN) does not exist"
1263 echo "Your lxdialog utility does not exist"
1268 # Read config.in files and parse them into one shell function per menu.
1271 parse_config_files
$CONFIG_IN
1275 # Start the ball rolling from the top.
1277 activate_menu MCmenu0
1287 if $DIALOG --backtitle "$backtitle" \
1288 --yesno "Do you wish to save your new kernel configuration?" 5 60
1292 echo The linux kernel is now configured
for your setup.
1295 echo Your kernel configuration changes were NOT saved.