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

Re: [Xen-devel] Automatic dependencies are out of sync



>>> On 06.09.18 at 10:27, <jgross@xxxxxxxx> wrote:
> On 06/09/18 10:10, Jan Beulich wrote:
>>>>> On 06.09.18 at 09:34, <jgross@xxxxxxxx> wrote:
>>> I've setup a little example Makefile solving the problem (just to show
>>> the correct dependencies, needs to be adapted for naming the .d and .d2
>>> files and how to build the .d2):
>>>
>>> -->8 snip here 8<--
>>>
>>> DEPS := tst.d2
>>>
>>> all: tst $(DEPS)
>> 
>> -include $(DEPS) already ought to have the effect of such a dependency,
>> since all makefiles are checked for rules of how to re-make them.
> 
> Obviously this isn't the case. Otherwise there would be .d2 files more
> common after doing a make.

Well, be this (mis?)behavior is what needs explaining first.

>>> %.o %.d: %.c
>>>         gcc -MMD -o $(patsubst %.c,%.o,$<) -c $<
>> 
>> Doesn't this result in gcc to be invoked twice, perhaps resulting in
>> corrupt .o and/or .d? I think %.d wants to depend on %.o, without
>> a command.
> 
> No, that's perfectly fine. make will invoke the command only once, its
> just not clear for which target (that's the reason I need to use the
> $(patsubst %.c,%.o,$<) instead of $@, which might be the .o _or_ the .d
> file).
> 
> From the make docs:
> 
>   Pattern rules may have more than one target. Unlike normal rules, this
>   does not act as many different rules with the same prerequisites and
>   recipe. If a pattern rule has multiple targets, make knows that the
>   rule’s recipe is responsible for making all of the targets. The recipe
>   is executed only once to make all the targets.

Oh, right. But then there's no need to play games - just use $*.

>>> %: %.o
>>>         gcc $< -o $@
>>>
>>> -include $(DEPS)
>>>
>>> -->8 snip here 8<--
>>>
>>> So the basic ideas are:
>>>
>>> - add a rule for constructing the .d files
>>> - let the build depend on the .d2 files
>> 
>> IOW I wonder whether this really is any different from what we
>> do now (minus bugs/quirks in make itself, of course). And from this
>> as well as your original mail I still don't understand what's actually
>> broken with the current approach.
> 
> The main problem is that the .d2 files used for determining which object
> files need to be (re-)built are based on the build before the last one.
> I'm not sure this is always the case, but at least when starting with a
> clean tree I need two invocations of "make" to get all .d2 files built.

But that's correct: They're not needed _until_ a rebuild happens.
And by way of make's rebuilding of makefiles (if there are suitable
rules) they should appear _before_ any .o gets rebuilt, and even
before make evaluates which ones need rebuilding.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.