autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: m4_divert_text


From: Eric Blake
Subject: Re: m4_divert_text
Date: Wed, 14 Sep 2016 08:16:30 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 09/14/2016 07:26 AM, Russell Shaw wrote:
> Hi,
> 
> In binutils/configure.ac there is:
> 
> m4_divert_text([PARSE_ARGS],
> [case $srcdir in
>   *" "*)
> m4_pushdef([AS_MESSAGE_LOG_FD], [])dnl
>     AC_MSG_ERROR([path to source, $srcdir, contains spaces])
> m4_popdef([AS_MESSAGE_LOG_FD])dnl
>     ;;
> esac
> ac_subdirs_all=`cd $srcdir && echo */configure | sed 's,/configure,,g'`
> ])
> 
> 
> I can't find where it's used, and was wondering how one would use this
> definition.

AS_MESSAGE_LOG_FD is documented;
https://www.gnu.org/software/autoconf/manual/autoconf.html#AS_005fMESSAGE_005fLOG_005fFD.

But let's look at what happens here.  AC_MSG_ERROR is a synonym for
AS_ERROR, and the definition of AS_ERROR is:

m4_defun_init([AS_ERROR],
[m4_append_uniq([_AS_CLEANUP],
  [m4_divert_text([M4SH-INIT-FN], [_AS_ERROR_PREPARE[]])])],
[as_fn_error m4_default([$2], [$?])
"_AS_QUOTE([$1])"m4_ifval(AS_MESSAGE_LOG_FD,
  [ "$LINENO" AS_MESSAGE_LOG_FD])])

That is, the result of invoking AC_MSG_ERROR is a shell-script call to
the function as_fun_error, with either 2 arguments (the error code and
message) or 4 arguments (the error code, message, current line number,
and log fd), based on whether the current macro definition of
AS_MESSAGE_LOG_FD is blank.  Looking at that shell function, it behaves
differently according to whether the third and fourth arguments are
present, by additionally logging to the log fd.

So what binutils is doing is writing a low-level macro where they DON'T
want the message logged to config.log, so they temporarily redefine
AS_MESSAGE_LOG_FD to the empty string around the duration of the
expansion of AC_MSG_ERROR, in order to change how that macro is expanded.


> 
> Doesn't the pushdef/popdef pair make it useless?

No, the pushdef/popdef pair is what makes it so that the temporary
non-logging nature of AC_MSG_ERROR() lasts only for the duration of the
expansion of this snippet, rather than the rest of configure.ac.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]