Re: Configuration improvements

Zefram (A.Main@dcs.warwick.ac.uk)
Fri, 8 Sep 1995 11:10:59 +0100 (BST)


I wrote:
>The patch included below addresses some of the problems with the kernel
>Configure script. I made this with the 1.3.24 release.

but I forgot to include the patch. :-} Here it is.

--- linux-1.3.24/Makefile Fri Sep 8 08:10:11 1995
+++ linux-1.3.24++/Makefile Fri Sep 8 08:11:23 1995
@@ -6,11 +6,9 @@

.EXPORT_ALL_VARIABLES:

-CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
- else if [ -x /bin/bash ]; then echo /bin/bash; \
- else echo sh; fi ; fi)
TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)

+CONFIG_SHELL = sh
HPATH = $(TOPDIR)/include
AS =as
LD =ld
@@ -132,6 +130,9 @@

oldconfig: symlinks
$(CONFIG_SHELL) scripts/Configure -d arch/$(ARCH)/config.in
+
+newconfig: symlinks
+ $(CONFIG_SHELL) scripts/Configure -n arch/$(ARCH)/config.in

config: symlinks
$(CONFIG_SHELL) scripts/Configure arch/$(ARCH)/config.in
--- linux-1.3.24/scripts/Configure Mon Sep 4 05:31:54 1995
+++ linux-1.3.24++/scripts/Configure Fri Sep 8 08:34:27 1995
@@ -1,4 +1,6 @@
#! /bin/sh
+# N.B. the kernel Makefile actually calls sh explicitly to run this script,
+# despite the #! line.
#
# This script is used to configure the linux kernel.
#
@@ -16,33 +18,54 @@
#
# 030995 (storner@osiris.ping.dk) - added support for tri-state answers,
# for selecting modules to compile.
+#
+# 070995 (zefram@dcs.warwick.ac.uk) - fixed to work with any sh, and
+# added support for only changing a limited set of options.
+
+# File descriptors for config output files:
+# 3 is the Makefile/shell file (.tmpconfig, .config)
+# 4 is the C header (.tmpconfig.h, include/linux/autoconf.h)
+
+# Disable filename globbing once and for all.
+set -f

#
-# Make sure we're really running bash.
+# dointeract checks if we want to ask this question interactively.
#
-# I would really have preferred to write this script in a language with
-# better string handling, but alas, bash is the only scripting language
-# that I can be reasonable sure everybody has on their linux machine.
+# dointeract defines
#
-[ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
-
-# Disable filename globbing once and for all.
-# Enable function cacheing.
-set -f -h
+dointeract () {
+ case $DONEW in
+ y) for opt do
+ eval thisopt="$"$opt
+ case "$thisopt" in
+ "") return 0 ;;
+ esac
+ done ;;
+ esac
+ for option in $CONFIG_LIST; do
+ for opt do
+ case $opt in
+ CONFIG_$option | $option) return 0 ;;
+ esac
+ done
+ done
+ return 1
+}

#
# readln reads a line into $ans.
#
-# readln prompt default
+# readln prompt defines default
#
-function readln () {
- if [ "$DEFAULT" = "-d" ]; then
- echo "$1"
- ans=$2
- else
+readln () {
+ if $DOINTERACT $2; then
echo -n "$1"
IFS='@' read ans </dev/tty || exit 1
- [ -z "$ans" ] && ans=$2
+ [ -z "$ans" ] && ans=$3
+ else
+ echo "$1"
+ ans=$3
fi
}

@@ -51,10 +74,10 @@
#
# comment 'xxx'
#
-function comment () {
+comment () {
echo "*"; echo "* $1" ; echo "*"
- (echo "" ; echo "#"; echo "# $1" ; echo "#") >>$CONFIG
- (echo "" ; echo "/*"; echo " * $1" ; echo " */") >>$CONFIG_H
+ (echo "" ; echo "#"; echo "# $1" ; echo "#") >&3
+ (echo "" ; echo "/*"; echo " * $1" ; echo " */") >&4
}

#
@@ -62,21 +85,21 @@
#
# define_bool define value
#
-function define_bool () {
+define_bool () {
case "$2" in
"y" | "Y")
- echo "$1=y" >>$CONFIG
- echo "#define $1 1" >>$CONFIG_H
+ echo "$1=y" >&3
+ echo "#define $1 1" >&4
;;

"m" | "M")
- echo "$1=m" >>$CONFIG
- echo "#undef $1" >>$CONFIG_H
+ echo "$1=m" >&3
+ echo "#undef $1" >&4
;;

"n" | "N")
- echo "# $1 is not set" >>$CONFIG
- echo "#undef $1" >>$CONFIG_H
+ echo "# $1 is not set" >&3
+ echo "#undef $1" >&4
;;
esac
eval "$1=$2"
@@ -87,17 +110,17 @@
#
# bool question define default
#
-function bool () {
+bool () {
ans=""
- def=$(eval echo "\${$2:-$3}")
+ eval def="$""{$2:-$3}"
case "$def" in
"y") defprompt="Y/n"
;;
"n") defprompt="N/y"
;;
esac
- while [ "$ans" != "y" -a "$ans" != "n" ]; do
- readln "$1 ($2) [$defprompt] " "$def"
+ while [ ."$ans" != ."y" -a ."$ans" != ."n" ]; do
+ readln "$1 ($2) [$defprompt] " "$2" "$def"
done
define_bool "$2" "$ans"
}
@@ -107,9 +130,9 @@
#
# tristate question define default
#
-function tristate () {
+tristate () {
ans=""
- def=$(eval echo "\${$2:-$3}")
+ eval def="$""{$2:-$3}"
case "$def" in
"y") defprompt="Y/m/n"
;;
@@ -118,8 +141,8 @@
"n") defprompt="N/y/m"
;;
esac
- while [ "$ans" != "y" -a "$ans" != "n" -a "$ans" != "m" ]; do
- readln "$1 ($2) [$defprompt] " "$def"
+ while [ ."$ans" != ."y" -a ."$ans" != ."n" -a ."$ans" != ."m" ]; do
+ readln "$1 ($2) [$defprompt] " "$2" "$def"
done
define_bool "$2" "$ans"
}
@@ -129,9 +152,9 @@
#
# define_int define value
#
-function define_int () {
- echo "$1=$2" >>$CONFIG
- echo "#define $1 ($2)" >>$CONFIG_H
+define_int () {
+ echo "$1=$2" >&3
+ echo "#define $1 ($2)" >&4
eval "$1=$2"
}

@@ -140,12 +163,12 @@
#
# int question define default
#
-function int () {
+int () {
# Slimier hack to get bash to rescan a line.
ans="x"
- def=$(eval echo "\${$2:-$3}")
- while [ $[$ans+0] != "$ans" ]; do
- readln "$1 ($2) [$def] " "$def"
+ eval def="$""{$2:-$3}"
+ until echo "$ans" | egrep '^[-+]?[0-9]+$' >/dev/null; do
+ readln "$1 ($2) [$def] " "$2" "$def"
done
define_int "$2" "$ans"
}
@@ -164,13 +187,13 @@
# the CPP symbol CONFIG_<something> will be defined and the
# shell variable CONFIG_<something> will be set to "y".
#
-function choice () {
+choice () {
question="$1"
choices="$2"
def="$3"

# determine default answer:
- names=""
+ names="" list=""
set -- $choices
while [ -n "$2" ]; do
if [ -n "$names" ]; then
@@ -178,23 +201,22 @@
else
names="$1"
fi
- if [ "$(eval echo \"\${$2}\")" = "y" ]; then
- def=$1
- fi
+ list="$list $1"
+ eval [ ."$"$2 = .y ] "&&" def=$1
shift; shift
done

val=""
while [ -z "$val" ]; do
- readln "$question ($names) [$def] " "$def"
- ans=$(echo $ans | tr a-z A-Z)
+ readln "$question ($names) [$def] " "$list" "$def"
+ ans=`echo $ans | tr a-z A-Z`
set -- $choices
val=""
while [ -n "$1" ]; do
- name=$(echo $1 | tr a-z A-Z)
+ name=`echo $1 | tr a-z A-Z`
case "$name" in
${ans}*)
- if [ "$name" = "$ans" ]; then
+ if [ ."$name" = ."$ans" ]; then
val="$2"
break # stop on exact match
fi
@@ -214,39 +236,56 @@
define_bool "$val" "y"
}

-CONFIG=.tmpconfig
-CONFIG_H=.tmpconfig.h
-trap "rm -f $CONFIG $CONFIG_H ; exit 1" 1 2
+trap "rm -f .tmpconfig .tmpconfig.h ; exit 1" 1 2

#
# Make sure we start out with a clean slate.
#
-echo "#" > $CONFIG
-echo "# Automatically generated make config: don't edit" >> $CONFIG
-echo "#" >> $CONFIG
-
-echo "/*" > $CONFIG_H
-echo " * Automatically generated C config: don't edit" >> $CONFIG_H
-echo " */" >> $CONFIG_H
-
-DEFAULT=""
-if [ "$1" = "-d" ] ; then
- DEFAULT="-d"
+exec 3> .tmpconfig 4> .tmpconfig.h
+
+echo >&3 "#"
+echo >&3 "# Automatically generated make config: don't edit"
+echo >&3 "#"
+
+echo >&4 "/*"
+echo >&4 " * Automatically generated C config: don't edit"
+echo >&4 " */"
+
+DOINTERACT=:
+if [ ."$1" = ."-d" ] ; then
+ DOINTERACT=false
+ shift
+fi
+
+DONEW=n
+if [ ."$1" = ."-n" ]; then
+ DOINTERACT=dointeract
+ DONEW=y
shift
fi

CONFIG_IN=./config.in
-if [ "$1" != "" ] ; then
+if [ -n "$1" -a ."$1" != ."-c" ] ; then
CONFIG_IN=$1
+ shift
+fi
+
+CONFIG_LIST=""
+if [ ."$1" = ."-c" ]; then
+ shift
+ CONFIG_LIST="`echo $* | tr a-z A-Z`"
+ DOINTERACT=dointeract
fi

if [ -f ./.config ] ; then
- . ./.config
sed -e 's/# \(.*\) is not.*/\1=n/' <./.config >/tmp/conf.$$
. /tmp/conf.$$
rm /tmp/conf.$$
fi
+
. $CONFIG_IN
+
+exec 3>&- 4>&-

if [ "$CONFIG_SOUND" = "y" ] ; then
$MAKE -C drivers/sound config || exit 1

-zefram