Annotation of dmsdos/src/Configure, revision 1.1.1.2

1.1       root        1: #! /bin/sh
                      2: #
                      3: # This script is used to configure dmsdos compile-time options.
                      4: # It has been shamelessly stolen from the linux kernel. For a list
                      5: # of credits see there (linux/scripts/Configure).
                      6: #
                      7: 
                      8: #
                      9: # Make sure we're really running bash.
                     10: #
                     11: # I would really have preferred to write this script in a language with
                     12: # better string handling, but alas, bash is the only scripting language
                     13: # that I can be reasonable sure everybody has on their linux machine.
                     14: #
                     15: [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
                     16: 
                     17: # Disable filename globbing once and for all.
                     18: # Enable function cacheing.
                     19: set -f -h
                     20: 
                     21: #
                     22: # Dummy functions for use with a config.in modified for menuconf
                     23: #
                     24: function mainmenu_option () {
                     25:        :
                     26: }
                     27: function mainmenu_name () {
                     28:        :
                     29: }
                     30: function endmenu () {
                     31:        :
                     32: }
                     33: 
                     34: #
                     35: # help prints the corresponding help text from Configure.help to stdout
                     36: #
                     37: #       help variable
                     38: #
                     39: function help () {
                     40:   if [ -f Configure.help ]
                     41:   then
                     42:      #first escape regexp special characters in the argument:
                     43:      var=$(echo "$1"|sed 's/[][\/.^$*]/\\&/g')
                     44:      #now pick out the right help text:
                     45:      text=$(sed -n "/^$var[    ]*\$/,\${
                     46:                        /^$var[         ]*\$/b
                     47:                        /^#.*/b
                     48:                        /^[     ]*\$/q
                     49:                        p
                     50:                    }" Configure.help)
                     51:      if [ -z "$text" ]
                     52:      then
                     53:          echo; echo "  Sorry, no help available for this option yet.";echo
                     54:      else
                     55:          (echo; echo "$text"; echo) | ${PAGER:-more}
                     56:      fi
                     57:   else
                     58:      echo;
                     59:      echo "  Can't access the file Configure.help which"
                     60:      echo "  should contain the help texts."
                     61:      echo
                     62:   fi
                     63: }
                     64: 
                     65: 
                     66: #
                     67: # readln reads a line into $ans.
                     68: #
                     69: #      readln prompt default oldval
                     70: #
                     71: function readln () {
                     72:        if [ "$DEFAULT" = "-d" -a -n "$3" ]; then
                     73:                echo "$1"
                     74:                ans=$2
                     75:        else
                     76:                echo -n "$1"
                     77:                [ -z "$3" ] && echo -n "(NEW) "
                     78:                IFS='@' read ans </dev/tty || exit 1
                     79:                [ -z "$ans" ] && ans=$2
                     80:        fi
                     81: }
                     82: 
                     83: #
                     84: # comment does some pretty-printing
                     85: #
                     86: #      comment 'xxx'
                     87: # 
                     88: function comment () {
                     89:        echo "*"; echo "* $1" ; echo "*"
                     90:        (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
                     91:        (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
                     92: }
                     93: 
                     94: #
                     95: # define_bool sets the value of a boolean argument
                     96: #
                     97: #      define_bool define value
                     98: #
                     99: function define_bool () {
                    100:        case "$2" in
                    101:         "y")
                    102:                echo "$1=y" >>$CONFIG
                    103:                echo "#define $1 1" >>$CONFIG_H
                    104:                ;;
                    105: 
                    106:         "m")
                    107:                echo "$1=m" >>$CONFIG
                    108:                echo "#undef  $1" >>$CONFIG_H
                    109:                echo "#define $1_MODULE 1" >>$CONFIG_H
                    110:                ;;
                    111: 
                    112:         "n")
                    113:                echo "# $1 is not set" >>$CONFIG
                    114:                echo "#undef  $1" >>$CONFIG_H
                    115:                ;;
                    116:        esac
                    117:        eval "$1=$2"
                    118: }
                    119: 
                    120: #
                    121: # bool processes a boolean argument
                    122: #
                    123: #      bool question define
                    124: #
                    125: function bool () {
                    126:        old=$(eval echo "\${$2}")
                    127:        def=${old:-'n'}
                    128:        case "$def" in
                    129:         "y" | "m") defprompt="Y/n/?"
                    130:              def="y"
                    131:              ;;
                    132:         "n") defprompt="N/y/?"
                    133:              ;;
                    134:        esac
                    135:        while :; do
                    136:          readln "$1 ($2) [$defprompt] " "$def" "$old"
                    137:          case "$ans" in
                    138:            [yY] | [yY]es ) define_bool "$2" "y"
                    139:                            break;;
                    140:            [nN] | [nN]o )  define_bool "$2" "n"
                    141:                            break;;
                    142:            * )             help "$2"
                    143:                            ;;
                    144:          esac
                    145:        done
                    146: }
                    147: 
                    148: #
                    149: # tristate processes a tristate argument
                    150: #
                    151: #      tristate question define
                    152: #
                    153: function tristate () {
                    154:        if [ "$CONFIG_MODULES" != "y" ]; then
                    155:          bool "$1" "$2"
                    156:        else 
                    157:          old=$(eval echo "\${$2}")
                    158:          def=${old:-'n'}
                    159:          case "$def" in
                    160:           "y") defprompt="Y/m/n/?"
                    161:                ;;
                    162:           "m") defprompt="M/n/y/?"
                    163:                ;;
                    164:           "n") defprompt="N/y/m/?"
                    165:                ;;
                    166:          esac
                    167:          while :; do
                    168:            readln "$1 ($2) [$defprompt] " "$def" "$old"
                    169:            case "$ans" in
                    170:              [yY] | [yY]es ) define_bool "$2" "y"
                    171:                              break ;;
                    172:              [nN] | [nN]o )  define_bool "$2" "n"
                    173:                              break ;;
                    174:              [mM] )          define_bool "$2" "m"
                    175:                              break ;;
                    176:              * )             help "$2"
                    177:                              ;;
                    178:            esac
                    179:          done
                    180:        fi
                    181: }
                    182: 
                    183: #
                    184: # dep_tristate processes a tristate argument that depends upon
                    185: # another option.  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: #      tristate question define default
                    192: #
                    193: function dep_tristate () {
                    194:        old=$(eval echo "\${$2}")
                    195:        def=${old:-'n'}
                    196:        if [ "$3" = "n" ]; then
                    197:                define_bool "$2" "n"
                    198:        elif [ "$3" = "y" ]; then
                    199:                tristate "$1" "$2"
                    200:        else
                    201:           if [ "$CONFIG_MODULES" = "y" ]; then
                    202:                case "$def" in
                    203:                 "y" | "m") defprompt="M/n/?"
                    204:                      def="m"
                    205:                      ;;
                    206:                 "n") defprompt="N/m/?"
                    207:                      ;;
                    208:                esac
                    209:                while :; do
                    210:                  readln "$1 ($2) [$defprompt] " "$def" "$old"
                    211:                  case "$ans" in
                    212:                      [nN] | [nN]o )  define_bool "$2" "n"
                    213:                                      break ;;
                    214:                      [mM] )          define_bool "$2" "m"
                    215:                                      break ;;
                    216:                      [yY] | [yY]es ) echo 
                    217:    echo "  This answer is not allowed, because it is not consistent with"
                    218:    echo "  your other choices."
                    219:    echo "  This driver depends on another one which you chose to compile"
                    220:    echo "  as a module. This means that you can either compile this one"
                    221:    echo "  as a module as well (with M) or leave it out altogether (N)."
                    222:                                      echo
                    223:                                      ;;
                    224:                      * )             help "$2"
                    225:                                      ;;
                    226:                  esac
                    227:                done
                    228:           fi
                    229:        fi
                    230: }
                    231: 
                    232: #
                    233: # define_int sets the value of a integer argument
                    234: #
                    235: #      define_int define value
                    236: #
                    237: function define_int () {
                    238:        echo "$1=$2" >>$CONFIG
                    239:        echo "#define $1 ($2)" >>$CONFIG_H
                    240:        eval "$1=$2"
                    241: }
                    242: 
                    243: #
                    244: # int processes an integer argument
                    245: #
                    246: #      int question define default
                    247: # GNU expr changed handling of ?.  In older versions you need ?,
                    248: # in newer you need \?
                    249: OLD_EXPR=`expr "0" : '0\?'`
                    250: if [ $OLD_EXPR -eq 1 ]; then
                    251:     INT_EXPR='0$\|-\?[1-9][0-9]*$'
                    252: else
                    253:     INT_EXPR='0$\|-?[1-9][0-9]*$'
                    254: fi
                    255: function int () {
                    256:        old=$(eval echo "\${$2}")
                    257:        def=${old:-$3}
                    258:        while :; do
                    259:          readln "$1 ($2) [$def] " "$def" "$old"
                    260:          if expr "$ans" : $INT_EXPR > /dev/null; then
                    261:            define_int "$2" "$ans"
                    262:            break
                    263:          else
                    264:            help "$2"
                    265:          fi
                    266:        done
                    267: }
                    268: #
                    269: # define_hex sets the value of a hexadecimal argument
                    270: #
                    271: #      define_hex define value
                    272: #
                    273: function define_hex () {
                    274:        echo "$1=$2" >>$CONFIG
                    275:        echo "#define $1 0x${2#*[x,X]}" >>$CONFIG_H
                    276:        eval "$1=$2"
                    277: }
                    278: 
                    279: #
                    280: # hex processes an hexadecimal argument
                    281: #
                    282: #      hex question define default
                    283: #
                    284: function hex () {
                    285:        old=$(eval echo "\${$2}")
                    286:        def=${old:-$3}
                    287:        def=${def#*[x,X]}
                    288:        while :; do
                    289:          readln "$1 ($2) [$def] " "$def" "$old"
                    290:          ans=${ans#*[x,X]}
                    291:          if expr "$ans" : '[0-9a-fA-F][0-9a-fA-F]*$' > /dev/null; then
                    292:            define_hex "$2" "$ans"
                    293:            break
                    294:          else
                    295:            help "$2"
                    296:          fi
                    297:        done
                    298: }
                    299: 
                    300: #
                    301: # choice processes a choice list (1-out-of-n)
                    302: #
                    303: #      choice question choice-list default
                    304: #
                    305: # The choice list has a syntax of:
                    306: #      NAME WHITESPACE VALUE { WHITESPACE NAME WHITESPACE VALUE }
                    307: # The user may enter any unique prefix of one of the NAMEs and
                    308: # choice will define VALUE as if it were a boolean option.
                    309: # VALUE must be in all uppercase.  Normally, VALUE is of the
                    310: # form CONFIG_<something>.  Thus, if the user selects <something>,
                    311: # the CPP symbol CONFIG_<something> will be defined and the
                    312: # shell variable CONFIG_<something> will be set to "y".
                    313: #
                    314: function choice () {
                    315:        question="$1"
                    316:        choices="$2"
                    317:        old=
                    318:        def=$3
                    319: 
                    320:        # determine default answer:
                    321:        names=""
                    322:        set -- $choices
                    323:        firstvar=$2
                    324:        while [ -n "$2" ]; do
                    325:                if [ -n "$names" ]; then
                    326:                        names="$names, $1"
                    327:                else
                    328:                        names="$1"
                    329:                fi
                    330:                if [ "$(eval echo \"\${$2}\")" = "y" ]; then
                    331:                        old=$1
                    332:                        def=$1
                    333:                fi
                    334:                shift; shift
                    335:        done
                    336: 
                    337:        val=""
                    338:        while [ -z "$val" ]; do
                    339:                ambg=n
                    340:                readln "$question ($names) [$def] " "$def" "$old"
                    341:                ans=$(echo $ans | tr a-z A-Z)
                    342:                set -- $choices
                    343:                while [ -n "$1" ]; do
                    344:                        name=$(echo $1 | tr a-z A-Z)
                    345:                        case "$name" in
                    346:                                "$ans"* )
                    347:                                        if [ "$name" = "$ans" ]; then
                    348:                                                val="$2"
                    349:                                                break   # stop on exact match
                    350:                                        fi
                    351:                                        if [ -n "$val" ]; then
                    352:                                                echo;echo \
                    353:                "  Sorry, \"$ans\" is ambiguous; please enter a longer string."
                    354:                                                echo
                    355:                                                val=""
                    356:                                                ambg=y
                    357:                                                break
                    358:                                        else
                    359:                                                val="$2"
                    360:                                        fi;;
                    361:                        esac
                    362:                        shift; shift
                    363:                done
                    364:                if [ "$val" = "" -a "$ambg" = "n" ]; then
                    365:                        help "$firstvar"
                    366:                fi
                    367:        done
                    368:        set -- $choices
                    369:        while [ -n "$2" ]; do
                    370:                if [ "$2" = "$val" ]; then
                    371:                        echo "  defined $val"
                    372:                        define_bool "$2" "y"
                    373:                else
                    374:                        define_bool "$2" "n"
                    375:                fi
                    376:                shift; shift
                    377:        done
                    378: }
                    379: 
                    380: CONFIG=.tmpconfig
                    381: CONFIG_H=.tmpconfig.h
                    382: trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
                    383: 
                    384: #
                    385: # Make sure we start out with a clean slate.
                    386: #
                    387: echo "#" > $CONFIG
                    388: echo "# Automatically generated make config: don't edit" >> $CONFIG
                    389: echo "#" >> $CONFIG
                    390: 
                    391: echo "/*" > $CONFIG_H
                    392: echo " * Automatically generated C config: don't edit" >> $CONFIG_H
                    393: echo " * Run Configure instead" >> $CONFIG_H
                    394: echo " */" >> $CONFIG_H
                    395: 
                    396: DEFAULT=""
                    397: if [ "$1" = "-d" ] ; then
                    398:        DEFAULT="-d"
                    399:        shift
                    400: fi
                    401: 
1.1.1.2 ! root      402: CONFIG_IN=./Config.in
1.1       root      403: if [ "$1" != "" ] ; then
                    404:        CONFIG_IN=$1
                    405: fi
                    406: 
                    407: DEFAULTS=dmsdos-config.default
                    408: if [ -f .config ]; then
                    409:   DEFAULTS=.config
                    410: fi
                    411: 
                    412: if [ -f $DEFAULTS ]; then
                    413:   echo "#"
                    414:   echo "# Using defaults found in" $DEFAULTS
                    415:   echo "#"
                    416:   . $DEFAULTS
                    417:   sed -e 's/# \(.*\) is not.*/\1=n/' < $DEFAULTS > /tmp/conf.$$
                    418:   . /tmp/conf.$$
                    419:   rm /tmp/conf.$$
                    420: else
                    421:   echo "#"
                    422:   echo "# No defaults found"
                    423:   echo "#"
                    424: fi
                    425: 
                    426: . $CONFIG_IN
                    427: 
                    428: rm -f .config.old
                    429: if [ -f .config ]; then
                    430:        mv .config .config.old
                    431: fi
                    432: mv .tmpconfig .config
                    433: mv .tmpconfig.h dmsdos-config.h
                    434: 
                    435: echo
                    436: echo "Dmsdos is now configured. Do a 'make clean; make' to (re)compile."
                    437: 
                    438: exit 0

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.