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

