Hi Dmitry,

Thanks for the quick reply.

On Friday 04 July 2025 at 20:38:25 -0400, Dmitry Goncharov wrote:
> You should not mark included makefiles as phony. i don't think marking
> included files as phony was ever intended.

But it did work for a long time. :-)

> On Fri, Jul 4, 2025 at 12:46 PM Mike Crowe via Bug reports and
> discussion for GNU make <bug-make@gnu.org> wrote:
> > what is the preferred way to ensure
> > that generated files are built in a separate step before Make considers
> > which targets are out of date during the main build?
> 
> Make reads all makefiles and generates missing or out-of-date
> makefiles and then if any makefile was updated, make re-executes
> itself and does all that again. This time there should be no outdated
> makefiles and make will proceed to build the intended targets.
> So, as long as you avoid marking included makefiles as phony, make
> will build generated files and re-execute and proceed to the main
> build.
> 
> It is not clear what you want to achieve with marking included
> makefiles as phony.
> If you want to have the dependency files to be generated and included,
> have a look at
> https://make.mad-scientist.net/papers/advanced-auto-dependency-generation.
> and
> https://github.com/dgoncharov/efficient-autodeps-with-gmake

The Makefiles that I ran into this problem with were written based on
articles much like the first link - perhaps even that exact one. The
dependencies are generated and included in the way explained right at the
top.

The example I posted was being used to generate headers before any
compilation took place:

 .PHONY: /dev/null .early-generation
 /dev/null: .early-generation
 include /dev/null

 .early-generation : generated_header1.h
 generated_header1.h : some-input-file Makefile
         some-stuff-to-make-the-header < $< > $@

This means that it's not necessary to be explicit about which source files
(or worse header files) depend on those generated headers. I'm not really
including anything - which is why I was including /dev/null - I'm just
using include as a trick to ensure that the headers were generated during
the first invocation of make so that they could be used during the
re-invocation after the dependencies of the included file had been
satisfied. I also rely on the second invocation looking at the generated
header timestamps to determine whether the header actually changed when the
rule was executed because sometimes the header doesn't change even though
the rule runs.

My attempt to do this by making all the object files depend on the
generated headers too caused more stuff to be rebuilt than I wanted when a
header changes.

It looks like I can continue to do this just using a file that doesn't
exist rather than /dev/null and ensuring that I don't mark that file as
.PHONY.

Thanks.

Mike.

PS Apologies for sending my original message to the bug list rather than
   the user list. When I started writing the message it really was a bug
   report!

Reply via email to