Post by Kip WarnerPost by Quinn GrierA portable way to do this is to do the work in configure.ac and transfer
it to the Makefile with AC_SUBST. For example, with an empty
Makefile.am
      AC_INIT([Example], [1.0])
      AM_INIT_AUTOMAKE([foreign])
      m4_define([m_files_only], [a.foo b.foo c.foo])
      files_only='m_files_only'
      files_with_path='m4_map_args_w(m_files_only, [dir/], [], [ ])'
      AC_SUBST([files_only])
      AC_SUBST([files_with_path])
      AC_CONFIG_FILES([Makefile])
      AC_OUTPUT
      files_only = a.foo b.foo c.foo
      files_with_path = dir/a.foo dir/b.foo dir/c.foo
Hey Quinn. This would have worked perfectly, except automake bails when
autoreconf: running: automake --add-missing --copy --no-force
configure.ac:310: and is referred to from 'nodist_narayan_designer_SOURCES';
configure.ac:310: configure substitutions are not allowed in _SOURCES variables
autoreconf: automake failed with exit status: 1
This is likely because as the message says, I am attempting to use the
substitution within a *_SOURCES variable.
Is this a dead end or is there a workaround? Assume a reference within
a _SOURCES variable is probably necessary.
You can fix this by generating the complete macro definitions before
Automake runs and including them in Makefile.am.
One way you can do this is with a shell script that you must run before
autoreconf. For example:
files_only='a.foo b.foo c.foo'
files_path='dir/'
files_with_path=
for f in $files_only; do
files_with_path=$files_with_path\ $files_path$f
done
echo files_only = \
$files_only >files_only.am || exit 1
echo files_with_path = \
$files_with_path >files_with_path.am || exit 1
And, inside Makefile.am, you add these lines:
include files_only.am
include files_with_path.am
This is a natural fit if you're already using an autogen.sh script, as
you can put this code in there. If you're not using one, then this would
essentially force you to start using one, as you need to remember to run
this code before autoreconf.
Another idea is to generate the .am files in configure.ac at M4 time,
which should cause autoreconf to generate them before it runs Automake.
In this case, an autogen.sh script is unnecessary.
Here is an example configure.ac that does this:
AC_INIT([Example], [1.0])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CC
m4_define([m_files_only], [[a.foo b.foo c.foo]])
m4_define([m_files_path], [[[dir/]]])
m4_define([m_files_with_path],
m4_dquote(m4_map_args_w(m_files_only,
m_files_path, [], [ ])))
m4_syscmd([echo files_only = ]dnl
m_files_only[ >files_only.am])
m4_assert(m4_sysval[ == 0])
m4_syscmd([echo files_with_path = ]dnl
m_files_with_path[ >files_with_path.am])
m4_assert(m4_sysval[ == 0])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
And here is the accompanying example Makefile.am:
include files_only.am
include files_with_path.am
bin_PROGRAMS = foo
foo_SOURCES = foo.c $(files_with_path)