On 9 March 2015 at 15:06, Marc Wäckerlin <m...@waeckerlin.org> wrote: > According to the official documentation(*): > ------------------------------------------ > Here is an example of how to define a conditional config file: > AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue]) > AM_COND_IF([SHELL_WRAPPER], > [AC_CONFIG_FILES([wrapper:wrapper.in])]) > ------------------------------------------ > > I try to generically find out, whether examples/makefile.am exists in a > project and to automatically use it, if it exists: > ------------------------------------------ > AM_CONDITIONAL([HAVE_EXAMPLES_DIR], [test -f examples/makefile.am]) > AM_COND_IF([HAVE_EXAMPLES_DIR], [AC_CONFIG_FILES([examples/makefile])]) > ------------------------------------------ > > But automake fails: > ------------------------------------------ > configure.ac:27: error: required file 'examples/makefile.in' not found > ------------------------------------------ > > So, what's the problem? > > It's nearly the same code as in the example ... >
As you found automake gets information from configure.ac. It does this using a macro "tracing" feature of autoconf. If you run "automake --verbose" you will see the macros it is tracing, including AC_CONFIG_FILES. With a setup like yours, $autoconf --trace=AC_CONFIG_FILES:\$f:\$l::\$d::\$n::\${::}% gives the output configure.ac:6::1::AC_CONFIG_FILES::examples/makefile:examples/makefile.in configure.ac:12::1::AC_CONFIG_FILES::Makefile automake doesn't know or care that one of these uses of AC_CONFIG_FILES was conditional. It is looking for the input files to automake (like "Makefile.am"), which it will derive from the arguments to AC_CONFIG_FILES. It wouldn't be possible for these input files to be defined conditionally in the configure script, because logically automake runs before the configure script. The automake manual says that automake won't recognize an argument to AC_CONFIG_FILES if its value is given indirectly through a shell variable (see "Requirements" node), so maybe you could try that.