English 中文(简体)
Header dependency in automake
原标题:

I d like to create a Makefile.am file which generates one header file mentioned in a xxx.c file.

Let s say that xxx.c contains:

#include <version.h>
...

and that I have a rule to create it at the end of Makefile.am:

version.h:
       echo  #define VERSION " `hg id` "  > version.h.tmp
       cmp version.h.tmp version.h || mv version.h.tmp version.h

What do I have to change to make the xxx.c compilation depend on version.h? I tried nodist_progname_SOURCES=version.h, but that doesn t seem to do it.

最佳回答
BUILT_SOURCES = version.h

All files mentioned as BUILT_SOURCES will be built before any of the normal compilation rules run.

However, this will create a slight problem: As version.h will need to be rebuilt on every make invocation, the recompilation of every foo.c file which #includes version.h will be triggered again on every make run. We would prefer if the recompilation only happens when there is actually something that has changed.

To get around this problem, use a BUILT_SOURCES dependency on a stamp file which is "created" every time (it never is actually created, so the build rule runs every time). The build rule for that stamp file creates a new version.h file as version.h.tmp, and only copies version.h.tmp to version.h if version.h.tmp is actually different from version.h (just like your version.h rule does). So if nothing has changed in version.h, its timestamp (mtime) remains the same, and no build of objects depending on version.h is triggered:

BUILT_SOURCES = version.stamp

version.stamp:
        echo  #define VERSION " `hg id` "  > version.h.tmp
        cmp version.h.tmp version.h || mv version.h.tmp version.h

This solution will do what you are asking for.

Unfortunately though, there will be a slight problem when you are building from a dist tarball: Then hg id will give you bogus information, and there probably is no version.h in your tarball, so the build will fail or contain bogus version information.

I have solved this issue for a the xf86-video-radeonhd project which is using git. The git-version.h file generated in this solution contains some more version information than just a single version number. You can see this update-only-if-different solution of mine at the end of git_version.sh and the BUILT_SOURCES hookup (including handling of hopefully all out-of-source-tree and from-dist-tarball build cases) in RadeonHD.am if you are interested.

问题回答

暂无回答




相关问题
How to structure files / dependencies in Visual C++ project

This is more of a design question than a C++ question. I m working on a Texas Hold Em poker game in C++. So far, I have a HandChecker module written that is responsible for determining a player s ...

draw dependency graph for a java class

Heyho, I m searching for a tool like JDepend to draw a graph for a java classfile. JDepend seams to be fine, but it s not resolving the deps from the deps (maybe I m just missing some special options?)...

How to use the -MG flag in cc 4.4.1?

I ve recently upgraded my Ubuntu installation from Jaunty to Karmic. This apparently includes an update of the GNU C compiler, because code that compiled previously no longer does. Running cc 4.4.1 (...

How to manually disable/blacklist Maven repository

In my base project I use dependency of JasperReports which has non-existent repository declaration in its pom. When I run every Maven commad there is dependency looking for commons-collection in this ...

Batch Job Dependencies Using Open Source/Free Software

I run a large data warehouse plant where we have a lot of nightly jobs running concerruently however many have dependencies on a extract or data load process before they start. Currently we use an ...

热门标签