|
Home > Archive > Unix Programming > August 2006 > M4/Autotools question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
M4/Autotools question
|
|
| Alan Woodland 2006-08-16, 1:25 pm |
| Hi, I'm not sure if this is OT here. I can't find anything more
relevant, and google groups showed a few previous posts about
automake/m4 to this group.
I'm trying to copy the value of some variables out of a file (another
makefile as it happens in this case)
Using grep/awk this would be easy enough normally, but when I try to use
it in my configure.ac/autoconf functions it's making a substitution.
The line as I have it right now read:
DEFINES=$([eval grep -E "^DEFINES" Makefile | awk 'BEGIN {FS= "=" } {
print $2 }' ])
but I've been trying quite a few different permutations on
quoting/escaping for this. The problem is that $2 is being subsituted
for an empty string (seeing as how it's undefined at this point), but I
need to find a way of stopping it. Oddly though if I swap $2 for $FOO
the output in the configure script is literally $FOO, with no
substituions taking place.
It all works exactly as I expected in a plain shell script, and from
viewing the the configure script as produced it looks like autoconf/m4
are trying to do something to this.
Can anyone shed some light on this one for me please?
Thanks,
Alan
| |
| William Ahern 2006-08-16, 7:21 pm |
| On Wed, 16 Aug 2006 17:43:14 +0100, Alan Woodland wrote:
<snip>
> Using grep/awk this would be easy enough normally, but when I try to use
> it in my configure.ac/autoconf functions it's making a substitution.
>
> The line as I have it right now read:
>
> DEFINES=$([eval grep -E "^DEFINES" Makefile | awk 'BEGIN {FS= "=" } {
> print $2 }' ])
>
> but I've been trying quite a few different permutations on
> quoting/escaping for this. The problem is that $2 is being subsituted
> for an empty string (seeing as how it's undefined at this point), but I
> need to find a way of stopping it. Oddly though if I swap $2 for $FOO
> the output in the configure script is literally $FOO, with no
> substituions taking place.
>
Try quoting it: [$2]. If that doesn't work, try [[$2]]. M4 evaluates text
like crazy, and sometimes it can be hard to figure out at what level of
evaluation you're at.
In M4 $1, $2, et al expand to the value of that argument position in the
function call. Autoconf redefines the quoting characters to be '[' and ']'.
| |
| Alan Woodland 2006-08-17, 7:35 am |
| William Ahern wrote:
> On Wed, 16 Aug 2006 17:43:14 +0100, Alan Woodland wrote:
> <snip>
>
> Try quoting it: [$2]. If that doesn't work, try [[$2]]. M4 evaluates text
> like crazy, and sometimes it can be hard to figure out at what level of
> evaluation you're at.
>
> In M4 $1, $2, et al expand to the value of that argument position in the
> function call. Autoconf redefines the quoting characters to be '[' and ']'.
For reference I've changed it to read:
DEFINES=$(eval grep -E "^DEFINES" Makefile | awk 'BEGIN {FS= "=" } {
print [$]2 }')
Which seems to work.
Thanks,
Alan
|
|
|
|
|