Alexandre wrote:
| >
| > How about:
| >
| > CONFIG_FILES=${CONFIG_FILES-$config_files}
| >
| > ?
Did you really mean a dash? As opposed to an equal.
David wrote:
|
| This proposal does work.
|
So here is my proposal. I tried to document faithfully the various
issues of assigning a default value. I tried to fix the Solaris brace
bug the libtool team faced some time ago. Alexandre, could you
confirm this is what you wanted:
/tmp % cat configure.in nostromo 18:44
AC_INIT
ac_cv_toto='${foo}'
ac_cv_tata=tata
AC_OUTPUT
/tmp % ace nostromo 18:44
/tmp % ./configure -C nostromo 18:44
creating cache config.cache
updating cache config.cache
creating ./config.status
/tmp % egrep 'toto|tata' config.cache nostromo 18:44
ac_cv_tata=${ac_cv_tata=tata}
test "${ac_cv_toto+set}" = set || ac_cv_toto='${foo}'
I'm applying the following patch, again so that David can check the
fix is effective, but modification requirements are most welcome!
Index: ChangeLog
from Akim Demaille <[EMAIL PROTECTED]>
* doc/autoconf.texi (Shell Substitutions): More on the variations
around ${foo=bar}.
(Assignments): Rewrite as a summary of the previous section.
* acgeneral.m4 (AC_CACHE_SAVE): Be protected against the Solaris'
`${foo='${bar}'}' bug.
Index: acgeneral.m4
===================================================================
RCS file: /cvs/autoconf/acgeneral.m4,v
retrieving revision 1.638
diff -u -u -r1.638 acgeneral.m4
--- acgeneral.m4 2000/11/29 16:08:43 1.638
+++ acgeneral.m4 2000/11/29 17:39:21
@@ -1974,7 +1974,7 @@
# Save the cache.
# Allow a site initialization script to override cache values.
m4_define([AC_CACHE_SAVE],
-[cat >confcache <<\EOF
+[cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
# tests run on this system so they can be shared between configure
# scripts and configure runs, see configure's option --config-cache.
@@ -1988,9 +1988,14 @@
# loading this file, other *unset* `ac_cv_foo' will be assigned the
# following values.
-EOF
+_ACEOF
+
_AC_CACHE_DUMP() |
- sed '/^ac_cv_env/!s/^\([[^=]]*\)=\(.*\)$/\1=${\1=\2}/' >>confcache
+ sed ['
+ s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+ t cleanup
+ /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+ : cleanup'] >>confcache
if cmp -s $cache_file confcache; then :; else
if test -w $cache_file; then
test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file"
Index: doc/autoconf.texi
===================================================================
RCS file: /cvs/autoconf/doc/autoconf.texi,v
retrieving revision 1.395
diff -u -u -r1.395 autoconf.texi
--- doc/autoconf.texi 2000/11/29 15:52:02 1.395
+++ doc/autoconf.texi 2000/11/29 17:39:36
@@ -5187,8 +5187,18 @@
Old @sc{bsd} shells, including the Ultrix @code{sh}, don't accept the
colon for any shell substitution, and complain and die.
-@item $@{@var{var}='@var{value}'@}
-@cindex $@{@var{var}='@var{value}'@}
+@item $@{@var{var}=@var{literal}@}
+@cindex $@{@var{var}=@var{literal}@}
+Be sure to quote:
+
+@example
+: $@{var='Some words'@}
+@end example
+
+@noindent
+otherwise some shells, such as on Digital Unix V 5.0, will die because
+of a ``bad substitution''.
+
Solaris' @command{/bin/sh} has a frightening bug in its understanding
this. Imagine you need set a variable to a string containing @samp{@}}.
This @samp{@}} character got Solaris' @command{/bin/sh} confused when
@@ -5214,6 +5224,70 @@
it is enclosed in single quotes. The problem doesn't happen using
double quotes.
+@item $@{@var{var}=@var{expanded-value}@}
+@cindex $@{@var{var}=@var{expanded-value}@}
+On Ultrix,
+running
+
+@example
+default="yu,yaa"
+: $@{var="$default"@}
+@end example
+
+@noindent
+will set @var{var} to @samp{M-yM-uM-,M-yM-aM-a}, i.e., the 8th bit of
+each char will be set. You won't observe the phenomenon using a simple
+@samp{echo $var} since apparently the shell resets the 8th bit when it
+expands $var. Here are two means to make this shell confess its sins:
+
+@example
+$ cat -v <<EOF
+$var
+EOF
+@end example
+
+@noindent
+and
+
+@example
+$ set | grep '^var=' | cat -v
+@end example
+
+One classical incarnation of this bug is:
+
+@example
+default="a b c"
+: $@{list="$default"@}
+for c in $list; do
+ echo $c
+done
+@end example
+
+@noindent
+You'll get @samp{a b c} on a single line. Why? Because there are no
+spaces in @samp{$list}: there are @samp{M- }, i.e., spaces with the 8th
+bit set, hence no IFS splitting is performed!!!
+
+A good news is that Ultrix works fine with @samp{: $@{list=$default@}},
+i.e., if you @emph{don't} quote. A bad news is then that @sc{qnx} 4.2.5
+then sets @var{list} to the @emph{last} item of @var{default}!
+
+The portable way out consists in using a double assignment, to switch
+twice the 8th bit on Ultrix:
+
+@example
+list=$@{list="$default"@}
+@end example
+
+@noindent
+but beware of the @samp{@}} bug from Solaris (see above). For safety,
+use
+
+@example
+test $@{var+set@} = set || var=@var{@{value@}}
+@end example
+
+
@item $(@var{commands})
@cindex $(@var{commands})
This construct is meant to replace @samp{`@var{commands}`}; they can be
@@ -5242,38 +5316,53 @@
@node Assignments, Special Shell Variables, Shell Substitutions, Portable Shell
@subsection Assignments
-A nonportable shell programming construct is
+When setting several variables in a row, be aware that the order of the
+evaluation is undefined. For instance @samp{foo=1 foo=2; echo $foo}
+gives @samp{1} with sh on Solaris, but @samp{2} with Bash. You must use
+@samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}.
+
+To assign default values follow this algorithm:
+
+@enumerate
+@item
+If the default value is a literal and does not contain any closing
+brace, use
+
@example
-@var{var}=$@{@var{var}:-@var{value}@}
+: $@{var='my literal'@}
@end example
-@noindent
-The intent is to set @var{var} to @var{value} only if it is not already
-set, but if @var{var} has any value, even the empty string, to leave it
-alone. Old @sc{bsd} shells, including the Ultrix @code{sh}, don't
-accept the colon for any shell substitution, and complain and die. A
-portable equivalent is
+@item
+If the default value contains no closing brace, has to be expanded and
+the variable being initialized will never be IFS split (i.e., it's not a
+list), then use:
@example
-: $@{@var{var}=@var{value}@}
+: $@{var="$default"@}
@end example
-If the value is a literal string, it should be quoted:
+@item
+If the default value contains no closing brace, has to be expanded and
+the variable being initialized will be IFS split (i.e., it's not a
+list), then use:
@example
-: $@{var='Some words'@}
+var=$@{var="$default"@}
@end example
-@noindent
-otherwise some shells, such as on Digital Unix V 5.0, will die because
-of a ``bad substitution''.
+@item
+If the default value contains a closing brace, then use
-When setting several variables in a row, be aware that the order of the
-evaluation is undefined. For instance @samp{foo=1 foo=2; echo $foo}
-gives @samp{1} with sh on Solaris, but @samp{2} with Bash. You must use
-@samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}.
+@example
+test "$@{var+set@}" = set || var='$@{indirection@}'
+@end example
+@end enumerate
+In most cases @samp{var=$@{var="$default"@}} is fine, but in case of
+doubt, just use the latter. @xref{Shell Substitutions}, items
+@samp{$@{@var{var}:-@var{value}@}} and @samp{$@{@var{var}=@var{value}@}}
+for the rationale.
@node Special Shell Variables, Limitations of Builtins, Assignments, Portable Shell