autoconf
[Top][All Lists]
Advanced

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

m4_map and AC_REQUIRE hoisting


From: Nick Bowler
Subject: m4_map and AC_REQUIRE hoisting
Date: Wed, 24 Jan 2018 01:32:09 -0500
User-agent: NeoMutt/20171215

Hello Autoconfers,

I hit a weird (to me) issue involving m4_map(all) and AC_REQUIRE, and I
would appreciate some help understanding what's going on here!

So normally when expanding a macro defined with AC_DEFUN and a nested
AC_REQUIRE causes a macro to be expanded, that expansion gets "hoisted"
outside of the topmost macro expansion.  Example:

  AC_INIT([test], [0])
  
  AC_DEFUN([DEF0], [echo def0])
  AC_DEFUN([REQ0], [AC_REQUIRE([DEF0])])
  
  AC_DEFUN([TEST0], [m4_newline([echo hello])[]m4_newline([REQ0])])
  TEST0

When I run this, I see:

  def0
  hello

which is as expected.

But when my macro is using m4_map or m4_mapall, this mechanism seems to
break down.  Example:

  AC_INIT([test], [0])

  AC_DEFUN([DEF1], [echo def1])
  AC_DEFUN([REQ1], [AC_REQUIRE([DEF1])])

  AC_DEFUN([TEST1], [m4_mapall([m4_newline], [[echo hello], [REQ1]])])
  TEST1

When I run that, I get:

  hello
  def1

with the order reversed from my expectation...

But if I implement my own version of mapall in a straightforward way,
it seems to work out just fine:

  AC_INIT([test], [0])
  
  AC_DEFUN([DEF2], [echo def2])
  AC_DEFUN([REQ2], [AC_REQUIRE([DEF2])])
  
  m4_define([my_mapall], [m4_ifval([$2],
    [m4_indir([$1], m4_car($2))[]my_mapall([$1], m4_cdr($2))])])
  AC_DEFUN([TEST2], [my_mapall([m4_newline], [[echo hello], [REQ2]])])
  TEST2

Running this gives:

  def2
  hello

as expected.

I really have no idea why TEST1 results in a different expansion from
the other two examples.  What exactly is different about m4_mapall?

Thanks,
  Nick



reply via email to

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