2
votes

I have a problem with depdency ordering of a source file which includes a generated file. For example, in a file called unit.cpp I have this:

 #include "generated.hpp"

Where generated.hpp is a generated file and will be produced in the output include directories. Now, this file is generated via an intermediate command, with a makefile rule such as:

 .build-generated:
     cmd.sh ... > include/generated.hpp
     touch $@

The building of the unit.o file thus requires that .build-generated is called first. If I do the following I confuse the resulting makefile:

 unit.cpp: .build-generated

Since the make will now assume that unit.cpp is a generated file and ignore the one in the source directory (only if .build-generated has to be remade). I've looked at the verbose make output and it says it is ignoring the one in the VPATH.

In a normal makefile I might make unit.o depend on the other target, but this doesn't appear to be the automake way (as it may not be portable). It actually doesn't even work, since the target may be a .lo file instead

How can I properly tell automake about this dependency?

3

3 Answers

1
votes

As per the automake manual, you are to specify it per:

BUILT_SOURCES = generated.hpp
0
votes

If you use autoconf with automake, you can depend your source file from your header:

$srcdir/unit.cpp : $builddir/include/generated.hpp

If $builddir doesn't suits you ( for example, you can use common header included in several Makefile.am ), use $top_builddir. Other useful autoconf variables can be found here.

0
votes

I think the proper solution is to have the object files depend on the generated headers:

include/generated.hpp:
     cmd.sh ... > include/generated.hpp
     touch $@
unit.o: include/generated.hpp

In case of using automake, something like

$(prog_OBJECTS): include/generated.hpp