1#! /bin/sh 2# 3# This script is used to configure the linux kernel. 4# 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. 7# 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. 12# 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. 18# 19# Portions of this script were borrowed from the original Configure 20# script. 21# 22# William Roadcap was the original author of Menuconfig. 23# Michael Elizabeth Chastain (mec@shout.net) is the current maintainer. 24# 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. 28# 29# 180697 Bernhard Kaindl (bkaindl@netway.at) - added the needed support 30# for string options. They are handled like the int and hex options. 31# 32# 081297 Pavel Machek (pavel@atrey.karlin.mff.cuni.cz) - better error 33# handling 34# 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. 39# 40# 101297 Michael Chastain (mec@shout.net) - remove sound driver cruft. 41# 42# 221297 Michael Chastain (mec@shout.net) - make define_bool actually 43# define its arguments so that later tests on them work right. 44# 45# 160198 Michael Chastain (mec@shout.net) - fix bug with 'c' command 46# (complement existing value) when used on virgin uninitialized variables. 47# 48# 090398 Axel Boldt (boldt@math.ucsb.edu) - allow for empty lines in help 49# texts. 50# 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). 56# 57# 13 Dec 1998, Riley H Williams <Riley@Williams.Name> 58# When an error occurs, actually display the error message as well as 59# our comments thereon. 60# 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". 64# 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. 68# 69# 24 January 1999, Michael Elizabeth Chastain, <mec@shout.net> 70# - Improve the exit message (Jeff Ronne). 71# 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(). 76# 77 78 79# 80# Change this to TRUE if you prefer all kernel options listed 81# in a single menu rather than the standard menu hierarchy. 82# 83single_menu_mode= 84 85# 86# Make sure we're really running bash. 87# 88[ -z "$BASH" ] && { echo "Menuconfig requires bash" 1>&2; exit 1; } 89 90# 91# Cache function definitions, turn off posix compliance 92# 93set -h +o posix 94 95 96 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. 100# 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. 103 104function 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)'" 111 fi 112 eval info="\$INFO_$1" 113} 114 115# 116# Load the functions used by the config.in files. 117# 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. 121# 122# Thank the heavens bash supports nesting function definitions. 123# 124load_functions () { 125 126# 127# Additional comments 128# 129function comment () { 130 comment_ctr=$[ comment_ctr + 1 ] 131 echo -ne "': $comment_ctr' '--- $1' " >>MCmenu 132} 133 134# 135# Define a boolean to a specific value. 136# 137function define_bool () { 138 eval $1=$2 139} 140 141function define_tristate () { 142 eval $1=$2 143} 144 145function define_hex () { 146 eval $1=$2 147} 148 149function define_int () { 150 eval $1=$2 151} 152 153function define_string () { 154 eval $1="$2" 155} 156 157# 158# Create a boolean (Yes/No) function for our current menu 159# which calls our local bool function. 160# 161function bool () { 162 set_x_info "$2" "n" 163 164 case $x in 165 y|m) flag="*" ;; 166 n) flag=" " ;; 167 esac 168 169 echo -ne "'$2' '[$flag] $1$info' " >>MCmenu 170 171 echo -e "function $2 () { l_bool '$2' \"\$1\" ;}\n" >>MCradiolists 172} 173 174# 175# Create a tristate (Yes/No/Module) radiolist function 176# which calls our local tristate function. 177# 178# Collapses to a boolean (Yes/No) if module support is disabled. 179# 180function tristate () { 181 if [ "$CONFIG_MODULES" != "y" ] 182 then 183 bool "$1" "$2" 184 else 185 set_x_info "$2" "n" 186 187 case $x in 188 y) flag="*" ;; 189 m) flag="M" ;; 190 *) flag=" " ;; 191 esac 192 193 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu 194 195 echo -e " 196 function $2 () { l_tristate '$2' \"\$1\" ;}" >>MCradiolists 197 fi 198} 199 200# 201# Create a tristate radiolist function which is dependent on 202# another kernel configuration option. 203# 204# Quote from the original configure script: 205# 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. 211# 212function 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 $# 226 fi 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 234 fi 235} 236 237# 238# Same as above, but now only Y and N are allowed as dependency 239# (i.e. third and next arguments). 240# 241function 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 $# 252 fi 253 done 254 if [ "$dep" = y ]; then 255 bool "$ques" "$var" 256 else 257 define_bool "$var" n 258 fi 259} 260 261function dep_mbool () { 262 ques="$1" 263 var="$2" 264 dep=y 265 shift 2 266 while [ $# -gt 0 ]; do 267 if [ "$1" = y -o "$1" = m ]; then 268 shift 269 else 270 dep=n 271 shift $# 272 fi 273 done 274 if [ "$dep" = y ]; then 275 bool "$ques" "$var" 276 else 277 define_bool "$var" n 278 fi 279} 280 281# 282# Add a menu item which will call our local int function. 283# 284function int () { 285 set_x_info "$2" "$3" 286 287 echo -ne "'$2' '($x) $1$info' " >>MCmenu 288 289 echo -e "function $2 () { l_int '$1' '$2' '$3' '$x' ;}" >>MCradiolists 290} 291 292# 293# Add a menu item which will call our local hex function. 294# 295function hex () { 296 set_x_info "$2" "$3" 297 x=${x##*[x,X]} 298 299 echo -ne "'$2' '($x) $1$info' " >>MCmenu 300 301 echo -e "function $2 () { l_hex '$1' '$2' '$3' '$x' ;}" >>MCradiolists 302} 303 304# 305# Add a menu item which will call our local string function. 306# 307function string () { 308 set_x_info "$2" "$3" 309 310 echo -ne "'$2' ' $1: \"$x\"$info' " >>MCmenu 311 312 echo -e "function $2 () { l_string '$1' '$2' '$3' '$x' ;}" >>MCradiolists 313} 314 315# 316# Add a menu item which will call our local One-of-Many choice list. 317# 318function choice () { 319 # 320 # Need to remember params cause they're gonna get reset. 321 # 322 title=$1 323 choices=$2 324 default=$3 325 current= 326 327 # 328 # Find out if one of the choices is already set. 329 # If it's not then make it the default. 330 # 331 set -- $choices 332 firstchoice=$2 333 334 while [ -n "$2" ] 335 do 336 if eval [ "_\$$2" = "_y" ] 337 then 338 current=$1 339 break 340 fi 341 shift ; shift 342 done 343 344 : ${current:=$default} 345 346 echo -ne "'$firstchoice' '($current) $title' " >>MCmenu 347 348 echo -e " 349 function $firstchoice () \ 350 { l_choice '$title' \"$choices\" $current ;}" >>MCradiolists 351} 352 353} # END load_functions() 354 355 356 357 358 359# 360# Extract available help for an option from Configure.help 361# and send it to standard output. 362# 363# Most of this function was borrowed from the original kernel 364# Configure script. 365# 366function extract_help () { 367 if [ -f Documentation/Configure.help ] 368 then 369 #first escape regexp special characters in the argument: 370 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g') 371 #now pick out the right help text: 372 text=$(sed -n "/^$var[ ]*\$/,\${ 373 /^$var[ ]*\$/c\\ 374${var}:\\ 375 376 /^#/b 377 /^[^ ]/q 378 s/^ // 379 p 380 }" Documentation/Configure.help) 381 382 if [ -z "$text" ] 383 then 384 echo "There is no help available for this kernel option." 385 return 1 386 else 387 echo "$text" 388 fi 389 else 390 echo "There is no help available for this kernel option." 391 return 1 392 fi 393} 394 395# 396# Activate a help dialog. 397# 398function help () { 399 if extract_help $1 >help.out 400 then 401 $DIALOG --backtitle "$backtitle" --title "$2"\ 402 --textbox help.out $ROWS $COLS 403 else 404 $DIALOG --backtitle "$backtitle" \ 405 --textbox help.out $ROWS $COLS 406 fi 407 rm help.out 408} 409 410# 411# Show the README file. 412# 413function show_readme () { 414 $DIALOG --backtitle "$backtitle" \ 415 --textbox scripts/README.Menuconfig $ROWS $COLS 416} 417 418# 419# Begin building the dialog menu command and Initialize the 420# Radiolist function file. 421# 422function menu_name () { 423 echo -ne "$DIALOG --title '$1'\ 424 --backtitle '$backtitle' \ 425 --menu '$menu_instructions' \ 426 $ROWS $COLS $((ROWS-10)) \ 427 '$default' " >MCmenu 428 echo "#!/bin/sh" >MCradiolists 429} 430 431# 432# Add a submenu option to the menu currently under construction. 433# 434function submenu () { 435 echo -ne "'activate_menu $2' '$1 --->' " >>MCmenu 436} 437 438# 439# Handle a boolean (Yes/No) option. 440# 441function l_bool () { 442 if [ -n "$2" ] 443 then 444 case "$2" in 445 y|m) eval $1=y ;; 446 c) eval x=\$$1 447 case $x in 448 y) eval $1=n ;; 449 n) eval $1=y ;; 450 *) eval $1=y ;; 451 esac ;; 452 *) eval $1=n ;; 453 esac 454 else 455 echo -ne "\007" 456 fi 457} 458 459# 460# Same as bool() except options are (Module/No) 461# 462function mod_bool () { 463 if [ "$CONFIG_MODULES" != "y" ]; then 464 define_bool "$2" "n" 465 else 466 set_x_info "$2" "n" 467 468 case $x in 469 y|m) flag='M' ;; 470 *) flag=' ' ;; 471 esac 472 473 echo -ne "'$2' '<$flag> $1$info' " >>MCmenu 474 475 echo -e "function $2 () { l_mod_bool '$2' \"\$1\" ;}" >>MCradiolists 476 fi 477} 478 479# 480# Same as l_bool() except options are (Module/No) 481# 482function l_mod_bool() { 483 if [ -n "$2" ] 484 then 485 case "$2" in 486 y) echo -en "\007" 487 ${DIALOG} --backtitle "$backtitle" \ 488 --infobox "\ 489This feature depends on another which has been configured as a module. \ 490As a result, this feature will be built as a module." 4 70 491 sleep 5 492 eval $1=m ;; 493 m) eval $1=m ;; 494 c) eval x=\$$1 495 case $x in 496 m) eval $1=n ;; 497 n) eval $1=m ;; 498 *) eval $1=m ;; 499 esac ;; 500 *) eval $1=n ;; 501 esac 502 else 503 echo -ne "\007" 504 fi 505} 506 507# 508# Handle a tristate (Yes/No/Module) option. 509# 510function l_tristate () { 511 if [ -n "$2" ] 512 then 513 eval x=\$$1 514 515 case "$2" in 516 y) eval $1=y ;; 517 m) eval $1=m ;; 518 c) eval x=\$$1 519 case $x in 520 y) eval $1=n ;; 521 n) eval $1=m ;; 522 m) eval $1=y ;; 523 *) eval $1=y ;; 524 esac ;; 525 *) eval $1=n ;; 526 esac 527 else 528 echo -ne "\007" 529 fi 530} 531 532# 533# Create a dialog for entering an integer into a kernel option. 534# 535function l_int () { 536 while true 537 do 538 if $DIALOG --title "$1" \ 539 --backtitle "$backtitle" \ 540 --inputbox "$inputbox_instructions_int" \ 541 10 75 "$4" 2>MCdialog.out 542 then 543 answer="`cat MCdialog.out`" 544 answer="${answer:-$3}" 545 546 # Semantics of + and ? in GNU expr changed, so 547 # we avoid them: 548 if expr "$answer" : '0$\|-[1-9][0-9]*$\|[1-9][0-9]*$' >/dev/null 549 then 550 eval $2="$answer" 551 else 552 eval $2="$3" 553 echo -en "\007" 554 ${DIALOG} --backtitle "$backtitle" \ 555 --infobox "You have made an invalid entry." 3 43 556 sleep 2 557 fi 558 559 break 560 fi 561 562 help "$2" "$1" 563 done 564} 565 566# 567# Create a dialog for entering a hexadecimal into a kernel option. 568# 569function l_hex () { 570 while true 571 do 572 if $DIALOG --title "$1" \ 573 --backtitle "$backtitle" \ 574 --inputbox "$inputbox_instructions_hex" \ 575 10 75 "$4" 2>MCdialog.out 576 then 577 answer="`cat MCdialog.out`" 578 answer="${answer:-$3}" 579 answer="${answer##*[x,X]}" 580 581 if expr "$answer" : '[0-9a-fA-F][0-9a-fA-F]*$' >/dev/null 582 then 583 eval $2="$answer" 584 else 585 eval $2="$3" 586 echo -en "\007" 587 ${DIALOG} --backtitle "$backtitle" \ 588 --infobox "You have made an invalid entry." 3 43 589 sleep 2 590 fi 591 592 break 593 fi 594 595 help "$2" "$1" 596 done 597} 598 599# 600# Create a dialog for entering a string into a kernel option. 601# 602function l_string () { 603 while true 604 do 605 if $DIALOG --title "$1" \ 606 --backtitle "$backtitle" \ 607 --inputbox "$inputbox_instructions_string" \ 608 10 75 "$4" 2>MCdialog.out 609 then 610 answer="`cat MCdialog.out`" 611 answer="${answer:-$3}" 612 613 # 614 # Someone may add a nice check for the entered 615 # string here... 616 # 617 eval $2=\"$answer\" 618 619 break 620 fi 621 622 help "$2" "$1" 623 done 624} 625 626 627# 628# Handle a one-of-many choice list. 629# 630function l_choice () { 631 # 632 # Need to remember params cause they're gonna get reset. 633 # 634 title="$1" 635 choices="$2" 636 current="$3" 637 638 # 639 # Scan current value of choices and set radiolist switches. 640 # 641 list= 642 set -- $choices 643 firstchoice=$2 644 while [ -n "$2" ] 645 do 646 case "$1" in 647 "$current") list="$list $2 $1 ON " ;; 648 *) list="$list $2 $1 OFF " ;; 649 esac 650 651 shift ; shift 652 done 653 654 while true 655 do 656 if $DIALOG --title "$title" \ 657 --backtitle "$backtitle" \ 658 --radiolist "$radiolist_instructions" \ 659 15 70 6 $list 2>MCdialog.out 660 then 661 choice=`cat MCdialog.out` 662 break 663 fi 664 665 help "$firstchoice" "$title" 666 done 667 668 # 669 # Now set the boolean value of each option based on 670 # the selection made from the radiolist. 671 # 672 set -- $choices 673 while [ -n "$2" ] 674 do 675 if [ "$2" = "$choice" ] 676 then 677 eval $2="y" 678 else 679 eval $2="n" 680 fi 681 682 shift ; shift 683 done 684} 685 686# 687# Call awk, and watch for error codes, etc. 688# 689function callawk () { 690awk "$1" || echo "Awk died with error code $?. Giving up." || exit 1 691} 692 693# 694# A faster awk based recursive parser. (I hope) 695# 696function parser1 () { 697callawk ' 698BEGIN { 699 menu_no = 0 700 comment_is_option = 0 701 parser("'$CONFIG_IN'","MCmenu0") 702} 703 704function parser(ifile,menu) { 705 706 while (getline <ifile) { 707 if ($1 == "mainmenu_option") { 708 comment_is_option = "1" 709 } 710 else if ($1 == "comment" && comment_is_option == "1") { 711 comment_is_option= "0" 712 sub($1,"",$0) 713 ++menu_no 714 715 printf("submenu %s MCmenu%s\n", $0, menu_no) >>menu 716 printf( "#!/bin/sh\n"\ 717 "function MCmenu%s () {\n"\ 718 "default=$1\n"\ 719 "menu_name %s\n",\ 720 menu_no, $0) >>"MCmenu"menu_no 721 722 parser(ifile, "MCmenu"menu_no) 723 } 724 else if ($1 ~ "endmenu") { 725 printf("}\n") >>menu 726 return 727 } 728 else if ($0 ~ /^#|\$MAKE|mainmenu_name/) { 729 printf("") >>menu 730 } 731 else if ($1 == "source") { 732 parser($2,menu) 733 } 734 else { 735 print >>menu 736 } 737 } 738}' 739} 740 741# 742# Secondary parser for single menu mode. 743# 744function parser2 () { 745callawk ' 746BEGIN { 747 parser("'$CONFIG_IN'","MCmenu0") 748} 749 750function parser(ifile,menu) { 751 752 while (getline <ifile) { 753 if ($1 ~ /mainmenu_option|endmenu/) { 754 printf("") >>menu 755 } 756 else if ($0 ~ /^#|$MAKE|mainmenu_name/) { 757 printf("") >>menu 758 } 759 else if ($1 == "source") { 760 parser($2,menu) 761 } 762 else { 763 print >>menu 764 } 765 } 766}' 767} 768 769# 770# Parse all the config.in files into mini scripts. 771# 772function parse_config_files () { 773 rm -f MCmenu* 774 775 echo "#!/bin/sh" > MCmenu0 776 echo "function MCmenu0 () {" >>MCmenu0 777 echo 'default=$1' >>MCmenu0 778 echo "menu_name 'Main Menu'" >>MCmenu0 779 780 if [ "_$single_menu_mode" = "_TRUE" ] 781 then 782 parser2 783 else 784 parser1 785 fi 786 787 echo "comment ''" >>MCmenu0 788 echo "g_alt_config" >>MCmenu0 789 echo "s_alt_config" >>MCmenu0 790 791 echo "}" >>MCmenu0 792 793 # 794 # These mini scripts must be sourced into the current 795 # environment in order for all of this to work. Leaving 796 # them on the disk as executables screws up the recursion 797 # in activate_menu(), among other things. Once they are 798 # sourced we can discard them. 799 # 800 for i in MCmenu* 801 do 802 echo -n "." 803 source ./$i 804 done 805 rm -f MCmenu* 806} 807 808# 809# This is the menu tree's bootstrap. 810# 811# Executes the parsed menus on demand and creates a set of functions, 812# one per configuration option. These functions will in turn execute 813# dialog commands or recursively call other menus. 814# 815function activate_menu () { 816 rm -f lxdialog.scrltmp 817 while true 818 do 819 comment_ctr=0 #So comment lines get unique tags 820 821 $1 "$default" 2> MCerror #Create the lxdialog menu & functions 822 823 if [ "$?" != "0" ] 824 then 825 clear 826 cat <<EOM 827 828Menuconfig has encountered a possible error in one of the kernel's 829configuration files and is unable to continue. Here is the error 830report: 831 832EOM 833 sed 's/^/ Q> /' MCerror 834 cat <<EOM 835 836Please report this to the maintainer <mec@shout.net>. You may also 837send a problem report to <linux-kernel@vger.kernel.org>. 838 839Please indicate the kernel version you are trying to configure and 840which menu you were trying to enter when this error occurred. 841 842EOM 843 cleanup 844 exit 1 845 fi 846 rm -f MCerror 847 848 . ./MCradiolists #Source the menu's functions 849 850 . ./MCmenu 2>MCdialog.out #Activate the lxdialog menu 851 ret=$? 852 853 read selection <MCdialog.out 854 855 case "$ret" in 856 0|3|4|5|6) 857 defaults="$selection$defaults" #pseudo stack 858 case "$ret" in 859 0) eval $selection ;; 860 3) eval $selection y ;; 861 4) eval $selection n ;; 862 5) eval $selection m ;; 863 6) eval $selection c ;; 864 esac 865 default="${defaults%%*}" defaults="${defaults#*}" 866 ;; 867 2) 868 default="${selection%%\ *}" 869 870 case "$selection" in 871 *"-->"*|*"alt_config"*) 872 show_readme ;; 873 *) 874 eval help $selection ;; 875 esac 876 ;; 877 255|1) 878 break 879 ;; 880 139) 881 stty sane 882 clear 883 cat <<EOM 884 885There seems to be a problem with the lxdialog companion utility which is 886built prior to running Menuconfig. Usually this is an indicator that you 887have upgraded/downgraded your ncurses libraries and did not remove the 888old ncurses header file(s) in /usr/include or /usr/include/ncurses. 889 890It is VERY important that you have only one set of ncurses header files 891and that those files are properly version matched to the ncurses libraries 892installed on your machine. 893 894You may also need to rebuild lxdialog. This can be done by moving to 895the /usr/src/linux/scripts/lxdialog directory and issuing the 896"make clean all" command. 897 898If you have verified that your ncurses install is correct, you may email 899the maintainer <mec@shout.net> or post a message to 900<linux-kernel@vger.kernel.org> for additional assistance. 901 902EOM 903 cleanup 904 exit 139 905 ;; 906 esac 907 done 908} 909 910# 911# Create a menu item to load an alternate configuration file. 912# 913g_alt_config () { 914 echo -n "get_alt_config 'Load an Alternate Configuration File' "\ 915 >>MCmenu 916} 917 918# 919# Get alternate config file name and load the 920# configuration from it. 921# 922get_alt_config () { 923 set -f ## Switch file expansion OFF 924 925 while true 926 do 927 ALT_CONFIG="${ALT_CONFIG:-$DEFAULTS}" 928 929 $DIALOG --backtitle "$backtitle" \ 930 --inputbox "\ 931Enter the name of the configuration file you wish to load. \ 932Accept the name shown to restore the configuration you \ 933last retrieved. Leave blank to abort."\ 934 11 55 "$ALT_CONFIG" 2>MCdialog.out 935 936 if [ "$?" = "0" ] 937 then 938 ALT_CONFIG=`cat MCdialog.out` 939 940 [ "_" = "_$ALT_CONFIG" ] && break 941 942 if eval [ -r "$ALT_CONFIG" ] 943 then 944 eval load_config_file "$ALT_CONFIG" 945 break 946 else 947 echo -ne "\007" 948 $DIALOG --backtitle "$backtitle" \ 949 --infobox "File does not exist!" 3 38 950 sleep 2 951 fi 952 else 953 cat <<EOM >help.out 954 955For various reasons, one may wish to keep several different kernel 956configurations available on a single machine. 957 958If you have saved a previous configuration in a file other than the 959kernel's default, entering the name of the file here will allow you 960to modify that configuration. 961 962If you are uncertain, then you have probably never used alternate 963configuration files. You should therefor leave this blank to abort. 964 965EOM 966 $DIALOG --backtitle "$backtitle"\ 967 --title "Load Alternate Configuration"\ 968 --textbox help.out $ROWS $COLS 969 fi 970 done 971 972 set +f ## Switch file expansion ON 973 rm -f help.out MCdialog.out 974} 975 976# 977# Create a menu item to store an alternate config file. 978# 979s_alt_config () { 980 echo -n "save_alt_config 'Save Configuration to an Alternate File' "\ 981 >>MCmenu 982} 983 984# 985# Get an alternate config file name and save the current 986# configuration to it. 987# 988save_alt_config () { 989 set -f ## Switch file expansion OFF 990 991 while true 992 do 993 $DIALOG --backtitle "$backtitle" \ 994 --inputbox "\ 995Enter a filename to which this configuration should be saved \ 996as an alternate. Leave blank to abort."\ 997 10 55 "$ALT_CONFIG" 2>MCdialog.out 998 999 if [ "$?" = "0" ] 1000 then
1001 ALT_CONFIG=`cat MCdialog.out` 1002 1003 [ "_" = "_$ALT_CONFIG" ] && break 1004 1005 if eval touch $ALT_CONFIG 2>/dev/null 1006 then 1007 eval save_configuration $ALT_CONFIG 1008 load_functions ## RELOAD 1009 break 1010 else 1011 echo -ne "\007" 1012 $DIALOG --backtitle "$backtitle" \ 1013 --infobox "Can't create file! Probably a nonexistent directory." 3 60 1014 sleep 2 1015 fi 1016 else 1017 cat <<EOM >help.out 1018 1019For various reasons, one may wish to keep different kernel 1020configurations available on a single machine. 1021 1022Entering a file name here will allow you to later retrieve, modify 1023and use the current configuration as an alternate to whatever 1024configuration options you have selected at that time. 1025 1026If you are uncertain what all this means then you should probably 1027leave this blank. 1028EOM 1029 $DIALOG --backtitle "$backtitle"\ 1030 --title "Save Alternate Configuration"\ 1031 --textbox help.out $ROWS $COLS 1032 fi 1033 done 1034 1035 set +f ## Switch file expansion ON 1036 rm -f help.out MCdialog.out 1037} 1038 1039# 1040# Load config options from a file. 1041# Converts all "# OPTION is not set" lines to "OPTION=n" lines 1042# 1043function load_config_file () { 1044 awk ' 1045 /# .* is not set.*/ { printf("%s=n\n", $2) } 1046 ! /# .* is not set.*/ { print } 1047 ' $1 >.tmpconfig 1048 1049 source ./.tmpconfig 1050 rm -f .tmpconfig 1051} 1052 1053# 1054# Just what it says. 1055# 1056save_configuration () { 1057 echo 1058 echo -n "Saving your kernel configuration." 1059 1060 # 1061 # Now, let's redefine the configuration functions for final 1062 # output to the config files. 1063 # 1064 # Nested function definitions, YIPEE! 1065 # 1066 function bool () { 1067 set_x_info "$2" "n" 1068 eval define_bool "$2" "$x" 1069 } 1070 1071 function tristate () { 1072 set_x_info "$2" "n" 1073 eval define_tristate "$2" "$x" 1074 } 1075 1076 function dep_tristate () { 1077 set_x_info "$2" "n" 1078 var="$2" 1079 shift 2 1080 while [ $# -gt 0 ]; do 1081 if [ "$1" = y ]; then 1082 shift 1083 elif [ "$1" = m -a "$x" != n ]; then 1084 x=m; shift 1085 else 1086 x=n; shift $# 1087 fi 1088 done 1089 define_tristate "$var" "$x" 1090 } 1091 1092 function dep_bool () { 1093 set_x_info "$2" "n" 1094 var="$2" 1095 shift 2 1096 while [ $# -gt 0 ]; do 1097 if [ "$1" = y ]; then 1098 shift 1099 else 1100 x=n; shift $# 1101 fi 1102 done 1103 define_bool "$var" "$x" 1104 } 1105 1106 function dep_mbool () { 1107 set_x_info "$2" "n" 1108 var="$2" 1109 shift 2 1110 while [ $# -gt 0 ]; do 1111 if [ "$1" = y -o "$1" = m ]; then 1112 shift 1113 else 1114 x=n; shift $# 1115 fi 1116 done 1117 define_bool "$var" "$x" 1118 } 1119 1120 function int () { 1121 set_x_info "$2" "$3" 1122 echo "$2=$x" >>$CONFIG 1123 echo "#define $2 ($x)" >>$CONFIG_H 1124 } 1125 1126 function hex () { 1127 set_x_info "$2" "$3" 1128 echo "$2=$x" >>$CONFIG 1129 echo "#define $2 0x${x##*[x,X]}" >>$CONFIG_H 1130 } 1131 1132 function string () { 1133 set_x_info "$2" "$3" 1134 echo "$2=\"$x\"" >>$CONFIG 1135 echo "#define $2 \"$x\"" >>$CONFIG_H 1136 } 1137 1138 function define_hex () { 1139 eval $1="$2" 1140 echo "$1=$2" >>$CONFIG 1141 echo "#define $1 0x${2##*[x,X]}" >>$CONFIG_H 1142 } 1143 1144 function define_int () { 1145 eval $1="$2" 1146 echo "$1=$2" >>$CONFIG 1147 echo "#define $1 ($2)" >>$CONFIG_H 1148 } 1149 1150 function define_string () { 1151 eval $1="$2" 1152 echo "$1=\"$2\"" >>$CONFIG 1153 echo "#define $1 \"$2\"" >>$CONFIG_H 1154 } 1155 1156 function define_bool () { 1157 define_tristate "$1" "$2" 1158 } 1159 1160 function define_tristate () { 1161 eval $1="$2" 1162 1163 case "$2" in 1164 y) 1165 echo "$1=y" >>$CONFIG 1166 echo "#define $1 1" >>$CONFIG_H 1167 ;; 1168 1169 m) 1170 if [ "$CONFIG_MODULES" = "y" ] 1171 then 1172 echo "$1=m" >>$CONFIG 1173 echo "#undef $1" >>$CONFIG_H 1174 echo "#define $1_MODULE 1" >>$CONFIG_H 1175 else 1176 echo "$1=y" >>$CONFIG 1177 echo "#define $1 1" >>$CONFIG_H 1178 fi 1179 ;; 1180 1181 n) 1182 echo "# $1 is not set" >>$CONFIG 1183 echo "#undef $1" >>$CONFIG_H 1184 ;; 1185 esac 1186 } 1187 1188 function choice () { 1189 # 1190 # Find the first choice that's already set to 'y' 1191 # 1192 choices="$2" 1193 default="$3" 1194 current= 1195 1196 set -- $choices 1197 while [ -n "$2" ] 1198 do 1199 if eval [ "_\$$2" = "_y" ] 1200 then 1201 current=$1 1202 break 1203 fi 1204 shift ; shift 1205 done 1206 1207 # 1208 # Use the default if none were set. 1209 # 1210 : ${current:=$default} 1211 1212 # 1213 # Output all choices (to be compatible with other configs). 1214 # 1215 set -- $choices 1216 while [ -n "$2" ] 1217 do 1218 if eval [ "$1" = "$current" ] 1219 then 1220 define_bool "$2" "y" 1221 else 1222 define_bool "$2" "n" 1223 fi 1224 shift ; shift 1225 done 1226 } 1227 1228 function mainmenu_name () { 1229 : 1230 } 1231 1232 function mainmenu_option () { 1233 comment_is_option=TRUE 1234 } 1235 1236 function endmenu () { 1237 : 1238 } 1239 1240 function comment () { 1241 if [ "$comment_is_option" ] 1242 then 1243 comment_is_option= 1244 echo >>$CONFIG 1245 echo "#" >>$CONFIG 1246 echo "# $1" >>$CONFIG 1247 echo "#" >>$CONFIG 1248 1249 echo >>$CONFIG_H 1250 echo "/*" >>$CONFIG_H 1251 echo " * $1" >>$CONFIG_H 1252 echo " */" >>$CONFIG_H 1253 fi 1254 } 1255 1256 echo -n "." 1257 1258 DEF_CONFIG="${1:-.config}" 1259 DEF_CONFIG_H="include/linux/autoconf.h" 1260 1261 CONFIG=.tmpconfig 1262 CONFIG_H=.tmpconfig.h 1263 1264 echo "#" >$CONFIG 1265 echo "# Automatically generated by make menuconfig: don't edit" >>$CONFIG 1266 echo "#" >>$CONFIG 1267 1268 echo "/*" >$CONFIG_H 1269 echo " * Automatically generated by make menuconfig: don't edit" >>$CONFIG_H 1270 echo " */" >>$CONFIG_H 1271 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H 1272 1273 echo -n "." 1274 if . $CONFIG_IN >>.menuconfig.log 2>&1 1275 then 1276 if [ "$DEF_CONFIG" = ".config" ] 1277 then 1278 mv $CONFIG_H $DEF_CONFIG_H 1279 fi 1280 1281 if [ -f "$DEF_CONFIG" ] 1282 then 1283 rm -f ${DEF_CONFIG}.old 1284 mv $DEF_CONFIG ${DEF_CONFIG}.old 1285 fi 1286 1287 mv $CONFIG $DEF_CONFIG 1288 1289 return 0 1290 else 1291 return 1 1292 fi 1293} 1294 1295# 1296# Remove temporary files 1297# 1298cleanup () { 1299 cleanup1 1300 cleanup2 1301} 1302 1303cleanup1 () { 1304 rm -f MCmenu* MCradiolists MCdialog.out help.out 1305} 1306 1307cleanup2 () { 1308 rm -f .tmpconfig .tmpconfig.h 1309} 1310 1311set_geometry () { 1312 # Some distributions export these with incorrect values 1313 # which can really screw up some ncurses programs. 1314 LINES= COLUMNS= 1315 1316 ROWS=${1:-24} COLS=${2:-80} 1317 1318 # Just in case the nasty rlogin bug returns. 1319 # 1320 [ $ROWS = 0 ] && ROWS=24 1321 [ $COLS = 0 ] && COLS=80 1322 1323 if [ $ROWS -lt 19 -o $COLS -lt 80 ] 1324 then 1325 echo -e "\n\007Your display is too small to run Menuconfig!" 1326 echo "It must be at least 19 lines by 80 columns." 1327 exit 0 1328 fi 1329 1330 ROWS=$((ROWS-4)) COLS=$((COLS-5)) 1331} 1332 1333 1334set_geometry `stty size 2>/dev/null` 1335 1336menu_instructions="\ 1337Arrow keys navigate the menu. \ 1338<Enter> selects submenus --->. \ 1339Highlighted letters are hotkeys. \ 1340Pressing <Y> includes, <N> excludes, <M> modularizes features. \ 1341Press <Esc><Esc> to exit, <?> for Help. \ 1342Legend: [*] built-in [ ] excluded <M> module < > module capable" 1343 1344radiolist_instructions="\ 1345Use the arrow keys to navigate this window or \ 1346press the hotkey of the item you wish to select \ 1347followed by the <SPACE BAR>. 1348Press <?> for additional information about this option." 1349 1350inputbox_instructions_int="\ 1351Please enter a decimal value. \ 1352Fractions will not be accepted. \ 1353Use the <TAB> key to move from the input field to the buttons below it." 1354 1355inputbox_instructions_hex="\ 1356Please enter a hexadecimal value. \ 1357Use the <TAB> key to move from the input field to the buttons below it." 1358 1359inputbox_instructions_string="\ 1360Please enter a string value. \ 1361Use the <TAB> key to move from the input field to the buttons below it." 1362 1363DIALOG="./scripts/lxdialog/lxdialog" 1364 1365kernel_version="${VERSION}.${PATCHLEVEL}.${SUBLEVEL}${EXTRAVERSION}" 1366 1367backtitle="Linux Kernel v$kernel_version Configuration" 1368 1369trap "cleanup ; exit 1" 1 2 15 1370 1371 1372# 1373# Locate default files. 1374# 1375CONFIG_IN=./config.in 1376if [ "$1" != "" ] ; then 1377 CONFIG_IN=$1 1378fi 1379 1380DEFAULTS=arch/$ARCH/defconfig 1381if [ -f .config ]; then 1382 DEFAULTS=.config 1383fi 1384 1385if [ -f $DEFAULTS ] 1386then 1387 echo "Using defaults found in" $DEFAULTS 1388 load_config_file $DEFAULTS 1389else 1390 echo "No defaults found" 1391fi 1392 1393 1394# Fresh new log. 1395>.menuconfig.log 1396 1397# Load the functions used by the config.in files. 1398echo -n "Preparing scripts: functions" 1399load_functions 1400 1401if [ ! -e $CONFIG_IN ] 1402then 1403 echo "Your main config.in file ($CONFIG_IN) does not exist" 1404 exit 1 1405fi 1406 1407if [ ! -x $DIALOG ] 1408then 1409 echo "Your lxdialog utility does not exist" 1410 exit 1 1411fi 1412 1413# 1414# Read config.in files and parse them into one shell function per menu. 1415# 1416echo -n ", parsing" 1417parse_config_files $CONFIG_IN 1418 1419echo "done." 1420# 1421# Start the ball rolling from the top. 1422# 1423activate_menu MCmenu0 1424 1425# 1426# All done! 1427# 1428cleanup1 1429 1430# 1431# Confirm and Save 1432# 1433if $DIALOG --backtitle "$backtitle" \ 1434 --yesno "Do you wish to save your new kernel configuration?" 5 60 1435then 1436 save_configuration 1437 echo 1438 echo 1439 echo "*** End of Linux kernel configuration." 1440 echo "*** Check the top-level Makefile for additional configuration." 1441 if [ ! -f .hdepend -o "$CONFIG_MODVERSIONS" = "y" ] ; then 1442 echo "*** Next, you must run 'make dep'." 1443 else 1444 echo "*** Next, you may run 'make zImage', 'make zdisk', or 'make zlilo.'" 1445 fi 1446 echo 1447else 1448 echo 1449 echo 1450 echo Your kernel configuration changes were NOT saved. 1451 echo 1452fi 1453exit 0 1454

