开发者

Make target run before all other rules in Makefile -- redux, GNU Make 4.4

This is an updated question an answer to a question, namely how to make sure that a certain rule in a Makefile is run before all other rules. I've been happily using Beta's answer to that question for years now.

However, recently, GNU Make 4.4 was released. And unfortunately, it looks like it broke this trick.

And example file I'm using 开发者_高级运维is this here:

all: foo

.PHONY: dummy
dummy:
    echo "Generating"

-include dummy

foo:
    echo "FOO"

With GNU Make 4.3, the output for make or make all is:

echo "Generating"
Generating
echo "FOO"
FOO

While with GNU Make 4.4, the output is:

echo "FOO"
FOO

Has somebody already figured out a way to make it work again? Or a different trick to ensure a certain rule is ran first?

Real life use-case I'm having is this: https://github.com/xoreos/xoreos-tools/blob/master/src/version/rules.mk , i.e. I'm using it read the git version information (if available). That's put into a file, but the file is only written to when there's an actual change (that's the what the `cmp is for), so that the actual code (and library, and binaries, ...) are only really rebuild when there's an actual change and not on every call to make.

What I've already tried: rewriting it to create an actual .h include file that's then included. Unfortunately, when using the generated file as a dependency, the check whether the file has been touched is done before the rule that writes to it is run. So I can't use it to rebuild the rest only when it changes.


Well, answering my own question, making that dummy target not .PHONY makes it work again in GNU Make 4.4.

Leaving the question up instead of deleting it in case someone else stumbles upon it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜