Hello Peter, sorry for the delay.
* Peter Breitenlohner wrote on Wed, Mar 18, 2009 at 10:35:51AM CET: > Let me be somewhat more explicit and give you an (idealized) Makefile.am > (fragment): > > if COND > bin_PROGRAMS = prog > endif COND > > prog_SOURCES = foo.c foo.h > nodist_prog_SOURCES = bar.h > > bar.h: tool bar.orig > .tool $(srcdir)/bar.orig > > =============== > > This fails (if COND is true) because, in our case, foo.c includes bar.h, but > that is only known to Make once foo.c has been compiled (as least with > depmode=gcc3). > > What we really would need is a dependency > > foo.o: bar.h > > but then this ought to be foo.$(OBJEXT) or maybe prog-foo.$(OBJEXT) and, > more important, would prevent Automake from generating a rule for this > compilation. Here's a suggestion: # In the following, we rely on an undocumented limitation of Automake, # namely that for target overrides, it does not look through variable # expansions. Further, we rely on the specific naming of the object # {foo,prog-foo}.$(OBJEXT), which is also an Automake-internal detail. foo_object = foo.$(OBJEXT) $(foo_object): bar.h You can stick the above into a conditional if you need. > I have tried adding > > BUILT_SOURCES = bar.h > > but then tool will run even if COND is false > > $(prog_SOURCES): bar.h > > is somewhat better until I run 'make dist'. Yep. The statement is wrong: it's not prog_SOURCES that depend on bar.h but the object file generated from those sources. > I could use > > if COND > BUILT_SOURCES = bar.h > endif COND > > or > > if COND > $(prog_SOURCES): bar.h > endif COND > > and these two almost do what I need, unless: > > COND is false but prog nevertheless needs to be built because it appears as > dependency of something else, or I might have second thoughts and say > > make prog > > This will then fail. Yep. > What I really would need is a way to tell Automake: 'before you can compile > foo.c you must first create bar.h', and I have found no way to do that > (other than writing a compilation rule as Automake would do). See above. Hope that helps. Cheers, Ralf