Discussion:
Why is this "quadrigraph" necessary?
Bruce Korb
2014-11-23 21:38:54 UTC
Permalink
AC_DEFUN([INVOKE_AG_MACROS_LAST],[
[if test X${INVOKE_AG_MACROS_LAST_done} != Xyes ; then]
GUILE_FLAGS
[ag_gv=$( exec 2>/dev/tty ; set -x
gdir=$(pkg-config --cflags-only-I guile-${GUILE_EFFECTIVE_VERSION})
gdir=$(echo ${gdir#-I})
gdir=$(awk '/SCM_MICRO_VERSION/{ print @S|@3 }' ${gdir}/libguile/version.h)
printf '%u%02u%03u' ${GUILE_EFFECTIVE_VERSION%\.*} ${GUILE_EFFECTIVE_VERSION#*\.} ${gdir}
)]

If I change that "@S|@" thingy to "$" it and the following "3" disappear. Why?
(And, yes, this fragment only works on recent POSIX shells.)
Bert Wesarg
2014-11-24 07:16:24 UTC
Permalink
Hi,
Post by Bruce Korb
AC_DEFUN([INVOKE_AG_MACROS_LAST],[
[if test X${INVOKE_AG_MACROS_LAST_done} != Xyes ; then]
GUILE_FLAGS
[ag_gv=$( exec 2>/dev/tty ; set -x
gdir=$(pkg-config --cflags-only-I guile-${GUILE_EFFECTIVE_VERSION})
gdir=$(echo ${gdir#-I})
${gdir}/libguile/version.h)
printf '%u%02u%03u' ${GUILE_EFFECTIVE_VERSION%\.*}
${GUILE_EFFECTIVE_VERSION#*\.} ${gdir}
)]
Why?
Because '$3' will be recognize by M4 as a parameter. It will be
replaced by the third argument to INVOKE_AG_MACROS_LAST. Thus it needs
quoting, be it by "@S|@" or "$[]3"
does not matter though.

Bert
Post by Bruce Korb
(And, yes, this fragment only works on recent POSIX shells.)
Bruce Korb
2014-11-24 14:56:37 UTC
Permalink
Hi Gary,

Thanks. Good to hear from you.

It was just so non-obvious to someone who doesn't live & breath m4. :)
It took too long to figure out.

The genesis of that fragment is that guile.m4 does not reveal the
"micro version",
so you have to extract it from the version header file, so I used awk to
pull the number from the header. It all breaks if "--cflags-only-I" were
ever to return anything other than a single "-I".
Post by Bert Wesarg
Because '$3' will be recognize by M4 as a parameter. It will be
replaced by the third argument to INVOKE_AG_MACROS_LAST. Thus it needs
does not matter though.
Actually, since it is enclosed in quotes, I think you might need "$][3" to
close and then re-open the quotation. A good doc enhancement might be
to recommend the quadrigraphic thingys when you need $numbers in the
shell script result. Maybe you did and I missed it, but I don't think it was as
clear as the discussion about subscripts in C code.

Thank you both!

Cheers - Bruce
Post by Bert Wesarg
Hi Bruce,
Post by Bruce Korb
AC_DEFUN([INVOKE_AG_MACROS_LAST],[
[if test X${INVOKE_AG_MACROS_LAST_done} != Xyes ; then]
GUILE_FLAGS
[ag_gv=$( exec 2>/dev/tty ; set -x
gdir=$(pkg-config --cflags-only-I guile-${GUILE_EFFECTIVE_VERSION})
gdir=$(echo ${gdir#-I})
printf '%u%02u%03u' ${GUILE_EFFECTIVE_VERSION%\.*} ${GUILE_EFFECTIVE_VERSION#*\.} ${gdir}
)]
(And, yes, this fragment only works on recent POSIX shells.)
I haven't tried very hard to understand the working of this particular definition, and
my apologies if I am merely stating the obvious... without the quadrigraph, M4 will
replace the literal $3 with the third argument to the unexpanded macro call at
autoconf time (quite likely the empty string if the macro was not designed to work
with a three or more arguments). Otherwise, as quoted above, the $3 will make it
through to the Autoconf expanded script, where it is interpreted by the AWK command
it is part of.
HTH,
--
Gary V. Vaughan (gary AT gnu DOT org)
Eric Blake
2014-11-24 20:21:35 UTC
Permalink
Post by Bert Wesarg
Because '$3' will be recognize by M4 as a parameter. It will be
replaced by the third argument to INVOKE_AG_MACROS_LAST. Thus it needs
does not matter though.
Or even ${3} (the {} hides the 3 from m4).

Or, since it is awk, '$ 3', since awk (unlike shell or m4) ignores space
between $ and the number.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Loading...