3
votes

I'm using autotools to build my project and I'd like to globally set AM_CPPFLAGS to -I$(top_srcdir)/include.

https://stackoverflow.com/a/325436/2592351 this answer helped me and I'm doing the "include $(top_srcdir)/include" hack and it works.

However I'd like to do the "AC_SUBST" way described there as it looks cleaner. The problem is when I add this to my configure.ac:

AC_SUBST([AM_CPPFLAGS], [-I$(top_srcdir)/include])

then $(top_srcdir) is expanded too soon and I get AM_CPPFLAGS = -I/include in subdir/Makefile{,.in}.

And I don't get how to escape it.

-I@top_srcdir@/include
-I\$(top_srcdir)/include
-I$$(top_srcdir)/include

all these failed for various reasons.

Please help. How should I write the AC_SUBST so $(top_srcdir) is not escaped before it gets to Makefile{,.in}? Or maybe I should use something other than AC_SUBST?

1
Not tested at all, but try [-I@S|@@{:@top_srcdir@:}@/include]. gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/…zwol
Thank you @Zack but it gets substituted prematurely as well.Ivan Dives
Drat. Could you post the output of grep AM_CPPFLAGS config.status configure, please (after running configure, of course)?zwol

1 Answers

1
votes

Don't set AM_CPPFLAGS in your configure.ac. If you find yourself repeating the same preamble in multiple Makefile.am you should be using non-recursive automake.

But in this particular case, you should get away with it if you do

AM_CPPFLAGS='-I$(top_srcdir)/include'
AC_SUBST([AM_CPPFLAGS])

Because then the string is set quoted in the bash variable, and afterward expanded as a literal. Using AC_SUBST to set it up, it gets quoted by "" which then causes $(top_srcdir) to be shell-expanded.