Menuconfig
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:30k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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