Reputation: 4295
My Makefile.am
includes a file (with various defined variables), for example:
include make.config
...
The problem is that this file is in turn generated by a tool (i.e. config.generator.sh
) based on some input file (i.e. input.dat
). The straightforward and wrong idea would be to add a rule to generate make.config
:
make.config : input.dat
config.generator.sh input.dat > make.config
include make.config
...
Although this content is perfectly working makefile on its own without automake
, the idea is doomed with automake
. The make.config
file is included by automake
before I even have a chance to execute make
(and it fails as the file is not yet generated):
automake: cannot open < make.config: No such file or directory
Is there a way to postpone effect of include
directive until make
is run (possibly by using another directive)?
There is probably a way to simply run arbitrary commands before any makefile generation is done (i.e. AC_CONFIG_COMMANDS*
). But the question is more complicated because the config.generator.sh
is supposed to use executables which are in turn also generated during the same build process (so there is a dependency chain which logically has to be managed by makefiles from the same project). The documentation simply confirms the logic without providing alternatives.
Upvotes: 2
Views: 1248
Reputation: 147
I've come across the same annoying problem today when moving my OCaml project to Autotools. My solution is to use autoconf
's substitution to go around automake
. For the above example, I'd add a substitution to configure.ac
:
AC_SUBST([include_make_config], ["include make.config"])
and adjust Makefile.am
, replacing the include
directive with the autoconf
variable reference:
make.config : input.dat
config.generator.sh input.dat > make.config
@include_make_config@
...
automake
doesn't touch the @include_make_config@
line so it gets carried over into the generated Makefile.in
. When autoconf
takes over, it substitutes the variable with include make.config
in the final Makefile
.
Note: I use this with OCaml's ocamldep
dependency generator.
Upvotes: 2
Reputation: 4295
The solution is described in this email of Automake's mailing list.
The idea is to use include
directives inside small regular "wrapper" makefile
and include Automake-generated Makefile
into it (note the upper case M
). Because makefile
is not an Automake template, the include
works as expected triggering builds for non-existing files.
Note that:
make
utility will search for makefile
first (not for Makefile
) making this approach working seamlessly.Makefile.am
and keep the "wrapper" makefile
simple. The rules for non-existing files will naturally come from the generated Makefile
anyway.Upvotes: 2