Autoreconf stops with "non-POSIX variable name"

autoreconf, makefile, posix

Solution

As it says, the problem is you're using a GNUism in your `Makefile.am`, when it's only meant to contain portable Makefile code.

Either rewrite your code so it's portable (you should use `AM_CPPFLAGS` because you're passing flags to the preprocessor, not the compiler):

AM_CPPFLAGS = -I$(EXTRAS_INCLUDE_DIR) -I$(top_srcdir) -DMY_REVISION=`cat $(top_srcdir)/$(MY_REVISION_FILE)`

If you don't want to invoke `cat` on every compile, you could find the value in `configure.ac` and either `AC_SUBST` it into `Makefile` or `AC_DEFINE` it so it goes into `config.h`.

Or if you want to be non-portable (ಠ_ಠ), you can take `-Werror` out of your `AM_INIT_AUTOMAKE` or `AUTOMAKE_OPTIONS`, or add `-Wno-portability`.

Problem

I created a Makefile.in where I read the content out of a file and pass it to CFLAGS. Calling ./configure ... the Makefile will be generated an all works well. ``` Makefile.in: ... MY_REVISION_FILE=my-revision.txt MY_REVISION=$(shell cat $(top_srcdir)/$(MY_REVISION_FILE)) AM_CFLAGS = -I$(EXTRAS_INCLUDE_DIR) -I$(top_srcdir) -DMY_REVISION=$(MY_REVISION) ... ``` The problem arises once I moved the Makefile.in code into Makefile.am to allow the auto generation of Makefile.in. There calling autoreconf -i --force stops with the following error: ``` server/Makefile.am:9: cat $(top_srcdir: non-POSIX variable name server/Makefile.am:9: (probably a GNU make extension) autoreconf: automake failed with exit status: 1 ``` This problem hunts me now since quite some time. I searched everywhere but did not find anything that could help me finding a solution for that. In short, the only thing I need is a way to get an uninterpreted text such as "$(shell cat $(top_srcdir)/$(MY_REVISION_FILE))" copied from Makefile.am to Makefile.in Any idea? Thanks, Oliver

Original source