help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to rebuild on recipe change?


From: Philip Guenther
Subject: Re: How to rebuild on recipe change?
Date: Mon, 15 Feb 2010 18:52:00 -0800

On Mon, Feb 15, 2010 at 9:57 AM, Kirill Smelkov <address@hidden> wrote:
> I'm trying to do reliable incremental build system, and this means that
> those and only those parts which depend on changed environment have to
> be remade.
>
> However changed environment could be not only file changes, but also
> changes to CFLAGS (global or target specific), or command recipe for
> .cpp -> .o rule and the like.
...
> So the question is:
>
>    How to do it? How to properly rebuild on recipe change without
>    sacrificing clearness and performance?

So, the file foo.o should be built if any of its input files (foo.c,
whatever foo.c #includes, etc) changes or if the command line used to
build it change.  So, how about if you save the command line in a file
and make that file a dependency of foo.o.  If the rule to build the
command file only updates the file if the command actually changed,
then you'll get the desired behavior, no?

I.e., something like:
--------
# delete the normal rule, so that ours is preferred
%.o: %.c

# provide ours that expects %.o_c to contain the command for building
the .o file
%.o: %.o_c %.c
        $(shell cat $(filter %.o_c,$^)) $(OUTPUT_OPTION) $(filter %.c,$^)

# generate or update the file containing the command.  The FORCE is because
# we need this to be rebuilt each time, but we can't declare it .PHONY (as then
# the %.o would always be rebuilt too, even if the %.o_c didn't change)
%.o_c: FORCE
        @+new='$(COMPILE.c)'; \
        printf '%s\n' "$$new" | cmp -s - $@ || printf '%s\n' "$$new" >$@

# Don't want these to be deleted...
.SECONDARY: %.o_c

# for the FORCE
.PHONY: FORCE
--------

That's pretty crude, but maybe it'll give you ideas on where to go.


Philip Guenther




reply via email to

[Prev in Thread] Current Thread [Next in Thread]