Reputation: 9587
Assume a trivial configure.ac
:
AC_INIT([foobar], 1.0)
m4_define([foobar_m4], [foobar.m4])
m4_include(foobar_m4)
with a trivial foobar.m4
:
AS_ECHO(["foobar.m4 was included"])
Running autoreconf
produces:
aclocal: error: configure.ac:10: file 'foobar_m4' does not exist
autoreconf-2.69: aclocal failed with exit status: 1
How to include m4-expanded filenames in a configure.ac
?
Upvotes: 1
Views: 879
Reputation: 9587
The culprit is the aclocal
utility, not m4
. The m4
expansion works just fine, but before m4
is invoked, aclocal
scans configure.ac
for dependencies, and it blindly handles the m4_include
macro as if it were always called with a literal file argument.
There are two workarounds:
Use the built-in macro include
:
m4_builtin([include], foobar_m4)
This will completely circumvent the autoconf-provided m4_include
macro, which protects against repeated inclusions of the same file.
Define your own macro that invokes m4_include
:
m4_define([my_include], [m4_include][([$1])])dnl
my_include(foobar_m4)
Why the weird quoting? We have to quote m4_include
in the above definition so that it is not expanded during the definition of my_include
, but quoting the whole m4_include([$1])
invocation would still trip aclocal
in the same way as in the question.
As far as I know, there is no built-in way to prevent aclocal
from specially treating the m4_include
macro. This behavior of aclocal
is essential for dependency tracking, so including files in this way is likely to fail due to undefined macros used in included files (this is also explained here).
Upvotes: 3