This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: libstdc++ configure time


On Tue, Mar 20, 2001 at 02:21:10AM -0300, Alexandre Oliva wrote:
>
> But you have to transform \s in @s first, but you can't use echo to
> do this.  Of course, if the string is a literal, you can get m4 to
> do the transformation for you, but sometimes you don't have a string
> literal.

Putting \ in variables substituted into AC_DEFINE_UNQUOTED is going to
have to be a "don't do that, then", unless you have a Clever Plan.
There are too many AC_DEFINE_UNQUOTEDs in libstdc++v3/configure to
give up and go back to here documents.

Here's what I got - it is hopefully a bit easier to comprehend, and it
handles leading -n.  I'm coming to agree with rth about M4.  These
quoting rules, oy vey.

zw

changequote([,])divert(-1)
# Escape characters that cannot appear in shell single and double
# quoted strings, respectively.
#
define(ACQS, [patsubst([$1], ['], ['\\''])])
define(ACQD, [patsubst([$1],[["\]], [\\\&])])

# Protect various sorts of strings from echo.
# _0? - no special protection needed
# _1? - only needs backslash escaped
# _2? - only needs a leading dash escaped
# _3? - needs both, or needs one of them but contains at signs
#
# Mode 3 uses this map:
#	@	@0
#	\	@1
#	-	@2
#
# The _?i macros set up the quoting scheme.
#
define(_AC_GEN_FILE_0i, [_AC_GEN_FILE_0o([$1],$3[]indir([$4],[$2])$3)])
define(_AC_GEN_FILE_1i,
	[_AC_GEN_FILE_1o([$1],$3[]indir([$4],translit([$2], \, @))$3)])
define(_AC_GEN_FILE_2i,
	[_AC_GEN_FILE_2o([$1],$3[]indir([$4],translit([$2], -, @))$3)])
define(_AC_GEN_FILE_3i,
	[_AC_GEN_FILE_3o([$1],$3[]indir([$4],
	patsubst(patsubst(patsubst([$2], @, @0), \\, @1), -, @2))$3)])

# The _?o macros undo the quoting when the shell script is run.
#
define(_AC_GEN_FILE_0o, [echo $2 $1])
define(_AC_GEN_FILE_1o, [echo $2 | tr @ \\\\ $1])
define(_AC_GEN_FILE_2o, [echo $2 | tr @ - $1])
define(_AC_GEN_FILE_3o,
	[echo $2 | sed -e 's/@2/-/g' -e 's/@1/\\/g' -e 's/@0/@/g' $1])

# _AC_GEN_FILE(target-file, text, quote, quote-fn)
# forwards to the appropriate echo-protection macro.
#
# The changecom calls work around an m4 bug: substr's return is not
# properly quoted, so if it returns '#', that will be treated as a
# comment introducer and m4 will get totally lost.
#
define(_AC_GEN_FILE,
[changecom()_AC_GEN_FILE_DISPATCH(
ifelse(substr([$2], 0, 1), -, y, n)[]dnl
ifelse(index([$2], \), -1, n, y)[]dnl
ifelse(index([$2], @), -1, n, y),
		$@)[]changecom([#])])
define(_AC_GEN_FILE_DISPATCH,
[ifelse($1, nnn,	[_AC_GEN_FILE_0i(shift($@))],
	$1, nny,	[_AC_GEN_FILE_0i(shift($@))],
	$1, nyn,	[_AC_GEN_FILE_1i(shift($@))],
	$1, ynn,	[_AC_GEN_FILE_2i(shift($@))],
			[_AC_GEN_FILE_3i(shift($@))])])

# Macros for user consumption.
#
define(AC_CREATE_FILE,   [_AC_GEN_FILE([>$1],  [$2], ["], [ACQD])])
define(AC_CREATE_FILE_Q, [_AC_GEN_FILE([>$1],  [$2], ['], [ACQS])])
define(AC_APPEND_FILE,   [_AC_GEN_FILE([>>$1], [$2], ["], [ACQD])])
define(AC_APPEND_FILE_Q, [_AC_GEN_FILE([>>$1], [$2], ['], [ACQS])])

# and a specific use
define(AC_DEFINE,
[AC_APPEND_FILE_Q(confdefs.h,
	[ifelse(eval([$# >= 2]), 1, [#define $1 $2], [#define $1 1])])])

dnl debugmode(+V)
divert(0)dnl
AC_DEFINE(CASE_A, hi)
AC_DEFINE(CASE_B, "\n")
AC_DEFINE(CASE_C, "@home\n")
AC_DEFINE(CASE_D, '\'')
AC_APPEND_FILE_Q(confdefs.h, -n)
AC_APPEND_FILE_Q(confdefs.h, -n "@home\n")


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]