[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: macros which define macros
From: |
Eric Blake |
Subject: |
Re: macros which define macros |
Date: |
Thu, 29 May 2008 18:37:28 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Sam Steingold <sds <at> gnu.org> writes:
>
> are you watching CLISP development?
Nope. Should I be? :)
> | m4_define([CL_DEFUN_CHECKER],
> | [_$0([$]1, [$]2, [$]3, [$]4, [$]5, [$]6, [$1])])
>
> interesting.
> the above version is shorter and easier for me (and, more importantly,
> those who will come after me) to understand, so I will stick with it.
Good - the first approach is certainly more idiomatic in autoconf. I merely
threw out the second approach for teaching purposes, based on the subject line;
and I'm not at all heart-broken that you aren't using it (while writing my
first reply, it took the most time and brain-effort to write the second
approach, for the very reason that it is not very idiomatic).
> | cl_program_xcheck=`cat <<\EOF
> | AC_LANG_PROGRAM([#include <sys/socket.h>
> | #include <X11/Xlib.h>
> | #include <X11/Xauth.h>],
> | [XauGetAuthByAddr(AF_INET,0,"",13,"localhost:0.0",13,"localhost:0.0");])
> | EOF`
Bug on my part (and perhaps we need to update the manual) - not all shells
behave the same when presented with incomplete here-docs:
POSIX states that this is undefined:
foo=`cat <<EOF
`
since the ` occurs unquoted within a here-document.
POSIX also requires that a here-doc end when the delimiter occurs on a line
with a newline. But various shells interpret this differently:
foo=`cat <<EOF
hi
EOF`
ash claims that EOF is not on a line by itself, thus the here-doc is not
terminated. bash claims that ` terminates the command substitution, and that a
here-doc can end on end-of-input in addition to a newline. I agree with ash's
interpretation that this is not the end of the here-doc, but that means that
behavior is undefined, which means bash's behavior is also acceptable.
On the other-hand, this should be well-defined by POSIX:
foo=$(cat <<EOF
hi
EOF)
EOF does not occur on a line by itself, so you could argue that a strict
reading of POSIX says that particular ) should not terminate the command
substitution because the contents of $() using that ) does not form a valid
script. But again, ash is the only shell that rejected that.
To be portable, you need:
foo=`cat <<EOF
hi
EOF
`
>
> this expands to
> ~ cl_clx_XauGetAuthByAddr_program=`cat <<\EOF
Looks like inadvertant macro expansion in the variable name...
> /* confdefs.h. */
> _ACEOF
> cat confdefs.h >>conftest.$ac_ext
> cat >>conftest.$ac_ext <<_ACEOF
Oh well. It looks like stashing the program in a shell variable might not work
(it certainly isn't as easy as I had thought it might be). But using an m4
macro to reduce duplication in your source should still be viable.
--
Eric Blake