3

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?

Community
  • 1
  • 1
Ivan Dives
  • 477
  • 5
  • 9
  • 1
    Not tested at all, but try `[-I@S|@@{:@top_srcdir@:}@/include]`. https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Quadrigraphs.html#Quadrigraphs – zwol Jun 10 '14 at 18:08
  • Thank you @Zack but it gets substituted prematurely as well. – Ivan Dives Jun 11 '14 at 06:32
  • Drat. Could you post the output of `grep AM_CPPFLAGS config.status configure`, please (after running configure, of course)? – zwol Jun 11 '14 at 12:59

1 Answers1

1

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.

Diego Elio Pettenò
  • 3,152
  • 12
  • 15
  • AC_SUBSTing AM_CPPFLAGS is okay to do. Simply adding the single quotes in the invocation of AC_SUBST will also work: `AC_SUBST([AM_CPPFLAGS],['-I$(top_srcdir)/include'])` – William Pursell Jun 12 '14 at 12:07