3 # This script is used to configure an Aversive project. It is mainly
4 # coming from the Linux Kernel Menuconfig script. Thanks to the authors.
8 # Change this to TRUE if you prefer all kernel options listed
9 # in a single menu rather than the standard menu hierarchy.
14 # Make sure we're really running bash.
16 [ -z "$BASH" ] && { echo "Menuconfig requires bash" 1>&2; exit 1; }
19 # Cache function definitions, turn off posix compliance
25 # Given a configuration variable, set the global variable $x to its value,
26 # and the global variable $info to the string " (NEW)" if this is a new
29 # This function looks for: (1) the current value, or (2) the default value
30 # from the arch-dependent defconfig file, or (3) a default passed by the caller.
32 function set_x_info () {
35 eval `sed -n -e 's/# \(.*\) is not set.*/\1=n/' -e "/^$1=/p" arch/$ARCH/defconfig`
38 eval INFO_$1="' (NEW)'"
44 # Load the functions used by the config.in files.
46 # I do this because these functions must be redefined depending
47 # on whether they are being called for interactive use or for
48 # saving a configuration to a file.
50 # Thank the heavens bash supports nesting function definitions.
58 comment_ctr=$[ comment_ctr + 1 ]
59 echo -ne "': $comment_ctr' '--- $1' " >>MCmenu
63 # Define a boolean to a specific value.
65 function define_bool () {
69 function define_hex () {
73 function define_int () {
77 function define_string () {
82 # Create a boolean (Yes/No) function for our current menu
83 # which calls our local bool function.
93 echo -ne "'$2' '[$flag] $1$info' " >>MCmenu
95 echo -e "function $2 () { l_bool '$2' \"\$1\" ;}\n" >>MCradiolists
99 # Same as above, but now only Y and N are allowed as dependency
100 # (i.e. third and next arguments).
102 function dep_bool () {
107 while [ $# -gt 0 ]; do
108 if [ "$1" = y ]; then
115 if [ "$dep" = y ]; then
123 # Add a menu item which will call our local int function.
128 echo -ne "'$2' '($x) $1$info' " >>MCmenu
130 echo -e "function $2 () { l_int '$1' '$2' '$3' '$x' ;}" >>MCradiolists
134 # Add a menu item which will call our local hex function.
140 echo -ne "'$2' '($x) $1$info' " >>MCmenu
142 echo -e "function $2 () { l_hex '$1' '$2' '$3' '$x' ;}" >>MCradiolists
146 # Add a menu item which will call our local string function.
151 echo -ne "'$2' ' $1: \"$x\"$info' " >>MCmenu
153 echo -e "function $2 () { l_string '$1' '$2' '$3' '$x' ;}" >>MCradiolists
157 # Add a menu item which will call our local One-of-Many choice list.
161 # Need to remember params cause they're gonna get reset.
169 # Find out if one of the choices is already set.
170 # If it's not then make it the default.
177 if eval [ "_\$$2" = "_y" ]
185 : ${current:=$default}
187 echo -ne "'$firstchoice' '($current) $title' " >>MCmenu
190 function $firstchoice () \
191 { l_choice '$title' \"$choices\" $current ;}" >>MCradiolists
194 } # END load_functions()
198 #################################################################
201 # Extract available help for an option from Configure.help
202 # and send it to standard output.
204 # Most of this function was borrowed from the original kernel
207 function extract_help () {
208 if [ -f ${HELP_FILE} ]
210 #first escape regexp special characters in the argument:
211 var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
212 #now pick out the right help text:
213 text=$(sed -n "/^$var[ ]*\$/,\${
225 echo "There is no help available for this Aversive option."
231 echo "There is no help available for this Aversive option."
237 # Activate a help dialog.
240 if extract_help $1 >help.out
242 $DIALOG --backtitle "$backtitle" --title "$2"\
243 --textbox help.out $ROWS $COLS
245 $DIALOG --backtitle "$backtitle" \
246 --textbox help.out $ROWS $COLS
252 # Show the README file.
254 function show_readme () {
255 $DIALOG --backtitle "$backtitle" \
256 --textbox scripts/README.Menuconfig $ROWS $COLS
260 # Begin building the dialog menu command and Initialize the
261 # Radiolist function file.
263 function menu_name () {
264 echo -ne "$DIALOG --title '$1'\
265 --backtitle '$backtitle' \
266 --menu '$menu_instructions' \
267 $ROWS $COLS $((ROWS-10)) \
273 # Add a submenu option to the menu currently under construction.
275 function submenu () {
276 echo -ne "'activate_menu $2' '$1 --->' " >>MCmenu
280 # Handle a boolean (Yes/No) option.
301 # Create a dialog for entering an integer into a kernel option.
306 if $DIALOG --title "$1" \
307 --backtitle "$backtitle" \
308 --inputbox "$inputbox_instructions_int" \
309 10 75 "$4" 2>MCdialog.out
311 answer="`cat MCdialog.out`"
312 answer="${answer:-$3}"
314 # Semantics of + and ? in GNU expr changed, so
316 if expr "$answer" : '0$' '|' "$answer" : '[1-9][0-9]*$' '|' "$answer" : '-[1-9][0-9]*$' >/dev/null
322 ${DIALOG} --backtitle "$backtitle" \
323 --infobox "You have made an invalid entry." 3 43
335 # Create a dialog for entering a hexadecimal into a kernel option.
340 if $DIALOG --title "$1" \
341 --backtitle "$backtitle" \
342 --inputbox "$inputbox_instructions_hex" \
343 10 75 "$4" 2>MCdialog.out
345 answer="`cat MCdialog.out`"
346 answer="${answer:-$3}"
347 answer="${answer##*[x,X]}"
349 if expr "$answer" : '[0-9a-fA-F][0-9a-fA-F]*$' >/dev/null
355 ${DIALOG} --backtitle "$backtitle" \
356 --infobox "You have made an invalid entry." 3 43
368 # Create a dialog for entering a string into a kernel option.
370 function l_string () {
373 if $DIALOG --title "$1" \
374 --backtitle "$backtitle" \
375 --inputbox "$inputbox_instructions_string" \
376 10 75 "$4" 2>MCdialog.out
378 answer="`cat MCdialog.out`"
379 answer="${answer:-$3}"
382 # Someone may add a nice check for the entered
396 # Handle a one-of-many choice list.
398 function l_choice () {
400 # Need to remember params cause they're gonna get reset.
408 # Scan current value of choices and set radiolist switches.
416 "$current"*) if [ -z "$chosen" ]; then
417 list="$list $2 $1 ON "
420 list="$list $2 $1 OFF "
422 *) list="$list $2 $1 OFF " ;;
430 if $DIALOG --title "$title" \
431 --backtitle "$backtitle" \
432 --radiolist "$radiolist_instructions" \
433 15 70 6 $list 2>MCdialog.out
435 choice=`cat MCdialog.out`
439 help "$firstchoice" "$title"
443 # Now set the boolean value of each option based on
444 # the selection made from the radiolist.
449 if [ "$2" = "$choice" ]
461 # Call awk, and watch for error codes, etc.
463 function callawk () {
464 awk "$1" || echo "Awk died with error code $?. Giving up." || exit 1
468 # A faster awk based recursive parser. (I hope)
470 function parser1 () {
474 comment_is_option = 0
475 parser("'$CONFIG_IN'","MCmenu0")
478 function parser(ifile,menu) {
480 while (getline <ifile) {
481 if ($1 == "mainmenu_option") {
482 comment_is_option = "1"
484 else if ($1 == "comment" && comment_is_option == "1") {
485 comment_is_option= "0"
489 printf("submenu %s MCmenu%s\n", $0, menu_no) >>menu
491 newmenu = sprintf("MCmenu%d", menu_no);
492 printf( "function MCmenu%s () {\n"\
495 menu_no, $0) >newmenu
497 parser(ifile, newmenu)
499 else if ($0 ~ /^#|\$MAKE|mainmenu_name/) {
502 else if ($1 ~ "endmenu") {
506 else if ($1 == "source") {
517 # Secondary parser for single menu mode.
519 function parser2 () {
522 parser("'$CONFIG_IN'","MCmenu0")
525 function parser(ifile,menu) {
527 while (getline <ifile) {
528 if ($0 ~ /^#|$MAKE|mainmenu_name/) {
531 else if ($1 ~ /mainmenu_option|endmenu/) {
534 else if ($1 == "source") {
545 # Parse all the config.in files into mini scripts.
547 function parse_config_files () {
550 echo "function MCmenu0 () {" >MCmenu0
551 echo 'default=$1' >>MCmenu0
552 echo "menu_name 'Main Menu'" >>MCmenu0
554 if [ "_$single_menu_mode" = "_TRUE" ]
561 echo "comment ''" >>MCmenu0
562 echo "g_alt_config" >>MCmenu0
563 echo "s_alt_config" >>MCmenu0
568 # These mini scripts must be sourced into the current
569 # environment in order for all of this to work. Leaving
570 # them on the disk as executables screws up the recursion
571 # in activate_menu(), among other things. Once they are
572 # sourced we can discard them.
583 # This is the menu tree's bootstrap.
585 # Executes the parsed menus on demand and creates a set of functions,
586 # one per configuration option. These functions will in turn execute
587 # dialog commands or recursively call other menus.
589 function activate_menu () {
590 rm -f lxdialog.scrltmp
593 comment_ctr=0 #So comment lines get unique tags
595 $1 "$default" 2> MCerror #Create the lxdialog menu & functions
602 Menuconfig has encountered a possible error in one of the
603 configuration files and is unable to continue. Here is the error
607 sed 's/^/ Q> /' MCerror
610 Please report this to <zer0@droids-corp.org>.
618 . ./MCradiolists #Source the menu's functions
620 . ./MCmenu 2>MCdialog.out #Activate the lxdialog menu
623 read selection <MCdialog.out
627 defaults="$selection
\12$defaults" #pseudo stack
629 0) eval $selection ;;
630 3) eval $selection y ;;
631 4) eval $selection n ;;
632 5) eval $selection m ;;
633 6) eval $selection c ;;
635 default="${defaults%%
\12*}" defaults="${defaults#*
\12}"
638 default="${selection%%\ *}"
641 *"-->"*|*"alt_config"*)
644 eval help $selection ;;
655 There seems to be a problem with the lxdialog companion utility which is
656 built prior to running Menuconfig. Usually this is an indicator that you
657 have upgraded/downgraded your ncurses libraries and did not remove the
658 old ncurses header file(s) in /usr/include or /usr/include/ncurses.
660 It is VERY important that you have only one set of ncurses header files
661 and that those files are properly version matched to the ncurses libraries
662 installed on your machine.
664 You may also need to rebuild lxdialog. This can be done by moving to
665 the /usr/src/linux/scripts/lxdialog directory and issuing the
666 "make clean all" command.
668 If you have verified that your ncurses install is correct, you may email
669 <zer0@droids-corp.org>
680 # Create a menu item to load an alternate configuration file.
683 echo -n "get_alt_config 'Load an Alternate Configuration File' "\
688 # Get alternate config file name and load the
689 # configuration from it.
692 set -f ## Switch file expansion OFF
696 ALT_CONFIG="${ALT_CONFIG:-$DEFAULTS}"
698 $DIALOG --backtitle "$backtitle" \
700 Enter the name of the configuration file you wish to load. \
701 Accept the name shown to restore the configuration you \
702 last retrieved. Leave blank to abort."\
703 11 55 "$ALT_CONFIG" 2>MCdialog.out
707 ALT_CONFIG=`cat MCdialog.out`
709 [ "_" = "_$ALT_CONFIG" ] && break
711 if eval [ -r "$ALT_CONFIG" ]
713 eval load_config_file "$ALT_CONFIG"
717 $DIALOG --backtitle "$backtitle" \
718 --infobox "File does not exist!" 3 38
724 For various reasons, one may wish to keep several different Aversive
725 configurations available on a single machine.
727 If you have saved a previous configuration in a file other than the
728 Aversive's default, entering the name of the file here will allow you
729 to modify that configuration.
731 If you are uncertain, then you have probably never used alternate
732 configuration files. You should therefor leave this blank to abort.
735 $DIALOG --backtitle "$backtitle"\
736 --title "Load Alternate Configuration"\
737 --textbox help.out $ROWS $COLS
741 set +f ## Switch file expansion ON
742 rm -f help.out MCdialog.out
746 # Create a menu item to store an alternate config file.
749 echo -n "save_alt_config 'Save Configuration to an Alternate File' "\
754 # Get an alternate config file name and save the current
755 # configuration to it.
758 set -f ## Switch file expansion OFF
762 $DIALOG --backtitle "$backtitle" \
764 Enter a filename to which this configuration should be saved \
765 as an alternate. Leave blank to abort."\
766 10 55 "$ALT_CONFIG" 2>MCdialog.out
770 ALT_CONFIG=`cat MCdialog.out`
772 [ "_" = "_$ALT_CONFIG" ] && break
774 if eval touch $ALT_CONFIG 2>/dev/null
776 eval save_configuration $ALT_CONFIG
777 load_functions ## RELOAD
781 $DIALOG --backtitle "$backtitle" \
782 --infobox "Can't create file! Probably a nonexistent directory." 3 60
788 For various reasons, one may wish to keep different kernel
789 configurations available on a single machine.
791 Entering a file name here will allow you to later retrieve, modify
792 and use the current configuration as an alternate to whatever
793 configuration options you have selected at that time.
795 If you are uncertain what all this means then you should probably
798 $DIALOG --backtitle "$backtitle"\
799 --title "Save Alternate Configuration"\
800 --textbox help.out $ROWS $COLS
804 set +f ## Switch file expansion ON
805 rm -f help.out MCdialog.out
809 # Load config options from a file.
810 # Converts all "# OPTION is not set" lines to "OPTION=n" lines
812 function load_config_file () {
814 /# .* is not set.*/ { printf("%s=n\n", $2) }
815 ! /# .* is not set.*/ { print }
825 save_configuration () {
827 echo -n "Saving your Aversive configuration."
830 # Now, let's redefine the configuration functions for final
831 # output to the config files.
833 # Nested function definitions, YIPEE!
837 eval define_bool "$2" "$x"
840 function dep_bool () {
844 while [ $# -gt 0 ]; do
845 if [ "$1" = y ]; then
851 define_bool "$var" "$x"
854 function dep_mbool () {
858 while [ $# -gt 0 ]; do
859 if [ "$1" = y -o "$1" = m ]; then
865 define_bool "$var" "$x"
870 echo "$2=$x" >>$CONFIG
871 echo "#define $2 ($x)" >>$CONFIG_H
876 echo "$2=$x" >>$CONFIG
877 echo "#define $2 0x${x##*[x,X]}" >>$CONFIG_H
882 echo "$2=\"$x\"" >>$CONFIG
883 echo "#define $2 \"$x\"" >>$CONFIG_H
886 function define_hex () {
888 echo "$1=$2" >>$CONFIG
889 echo "#define $1 0x${2##*[x,X]}" >>$CONFIG_H
892 function define_int () {
894 echo "$1=$2" >>$CONFIG
895 echo "#define $1 ($2)" >>$CONFIG_H
898 function define_string () {
900 echo "$1=\"$2\"" >>$CONFIG
901 echo "#define $1 \"$2\"" >>$CONFIG_H
904 function define_bool () {
909 echo "$1=y" >>$CONFIG
910 echo "#define $1 1" >>$CONFIG_H
914 echo "# $1 is not set" >>$CONFIG
915 echo "#undef $1" >>$CONFIG_H
922 # Find the first choice that's already set to 'y'
932 if eval [ "_\$$2" = "_y" ]
941 # Use the default if none were set.
943 : ${current:=$default}
946 # Output all choices (to be compatible with other configs).
952 "$current"*) if [ -z "$chosen" ]; then
958 *) define_bool "$2" "n" ;;
964 function mainmenu_name () {
968 function mainmenu_option () {
969 comment_is_option=TRUE
972 function endmenu () {
976 function comment () {
977 if [ "$comment_is_option" ]
982 echo "# $1" >>$CONFIG
986 echo "/*" >>$CONFIG_H
987 echo " * $1" >>$CONFIG_H
988 echo " */" >>$CONFIG_H
994 DEF_CONFIG="${1:-.config}"
995 #DEF_CONFIG_H="include/linux/autoconf.h"
996 DEF_CONFIG_H="autoconf.h"
999 CONFIG_H=.tmpconfig.h
1002 echo "# Automatically generated by make menuconfig: don't edit" >>$CONFIG
1005 echo "/*" >$CONFIG_H
1006 echo " * Automatically generated by make menuconfig: don't edit" >>$CONFIG_H
1007 echo " */" >>$CONFIG_H
1008 echo "#define AUTOCONF_INCLUDED" >> $CONFIG_H
1011 if . $CONFIG_IN >>.menuconfig.log 2>&1
1013 if [ "$DEF_CONFIG" = ".config" -a -d `dirname $DEF_CONFIG_H` ]
1015 mv $CONFIG_H $DEF_CONFIG_H
1018 if [ -f "$DEF_CONFIG" ]
1020 rm -f ${DEF_CONFIG}.old
1021 mv $DEF_CONFIG ${DEF_CONFIG}.old
1024 mv $CONFIG $DEF_CONFIG
1033 # Remove temporary files
1041 rm -f MCmenu* MCradiolists MCdialog.out help.out
1045 rm -f .tmpconfig .tmpconfig.h
1049 # Some distributions export these with incorrect values
1050 # which can really screw up some ncurses programs.
1053 ROWS=${1:-24} COLS=${2:-80}
1055 # Just in case the nasty rlogin bug returns.
1057 [ $ROWS = 0 ] && ROWS=24
1058 [ $COLS = 0 ] && COLS=80
1060 if [ $ROWS -lt 19 -o $COLS -lt 80 ]
1062 echo -e "\n\007Your display is too small to run Menuconfig!"
1063 echo "It must be at least 19 lines by 80 columns."
1067 ROWS=$((ROWS-4)) COLS=$((COLS-5))
1071 set_geometry `stty size 2>/dev/null`
1073 menu_instructions="\
1074 Arrow keys navigate the menu. \
1075 <Enter> selects submenus --->. \
1076 Highlighted letters are hotkeys. \
1077 Pressing <Y> includes, <N> excludes. \
1078 Press <Esc><Esc> to exit, <?> for Help. \
1079 Legend: [*] built-in [ ] excluded "
1081 radiolist_instructions="\
1082 Use the arrow keys to navigate this window or \
1083 press the hotkey of the item you wish to select \
1084 followed by the <SPACE BAR>.
1085 Press <?> for additional information about this option."
1087 inputbox_instructions_int="\
1088 Please enter a decimal value. \
1089 Fractions will not be accepted. \
1090 Use the <TAB> key to move from the input field to the buttons below it."
1092 inputbox_instructions_hex="\
1093 Please enter a hexadecimal value. \
1094 Use the <TAB> key to move from the input field to the buttons below it."
1096 inputbox_instructions_string="\
1097 Please enter a string value. \
1098 Use the <TAB> key to move from the input field to the buttons below it."
1100 DIALOG="$AVERSIVE_DIR/config/scripts/lxdialog/lxdialog"
1102 kernel_version="${VERSIONPKG}"
1104 backtitle="Aversive Configuration"
1106 trap "cleanup ; exit 1" 1 2 15
1110 # Locate default files.
1112 CONFIG_IN=./config.in
1113 if [ "$1" != "" ] ; then
1117 DEFAULTS=$AVERSIVE_DIR/config/.config
1118 if [ -f .config ]; then
1124 echo "Using defaults found in" $DEFAULTS
1125 load_config_file $DEFAULTS
1127 echo "No defaults found"
1130 if [ -z "$HELP_FILE" ]
1132 HELP_FILE="Documentation/Configure.help"
1138 # Load the functions used by the config.in files.
1139 echo -n "Preparing scripts: functions"
1142 if [ ! -e $CONFIG_IN ]
1144 echo "Your main config.in file ($CONFIG_IN) does not exist"
1150 echo "Your lxdialog utility does not exist"
1155 # Read config.in files and parse them into one shell function per menu.
1158 parse_config_files $CONFIG_IN
1162 # Start the ball rolling from the top.
1164 activate_menu MCmenu0
1174 if $DIALOG --backtitle "$backtitle" \
1175 --yesno "Do you wish to save your new configuration?" 5 60
1178 $AVERSIVE_DIR/config/generate_aversive_config .config .aversive_conf
1181 echo "*** End of Aversive configuration."
1182 echo "*** Next, you should run 'make clean', then 'make'"
1187 echo Your configuration changes were NOT saved.
1192 # Remove log if empty.
1193 if [ ! -s .menuconfig.log ] ; then
1194 rm -f .menuconfig.log