0

次のメイクファイル コードがあります。

NAME := test

target1: $(addsuffix .bar,$(NAME))
target2: $(addsuffix .dar,$(NAME))

%.bar: $(INPUT)
    touch $@

%.dar: %.bar
    touch $@

このメイクファイルを GNU Make v3.81 で次のように実行します。

user@node1:/data/user/Tests/oldfile3$ rm test.*
removed `test.bar'
removed `test.txt'
user@node1:/data/user/Tests/oldfile3$ touch test.txt
user@node1:/data/user/Tests/oldfile3$ make target2
touch test.bar
touch test.dar
user@node1:/data/user/Tests/oldfile3$ make target2
make: Nothing to be done for `target2'.
user@node1:/data/user/Tests/oldfile3$ rm test.bar
removed `test.bar'
user@node1:/data/user/Tests/oldfile3$ make target2
make: Nothing to be done for `target2'.
user@node1:/data/user/Tests/oldfile3$ 

予想どおり、中間ファイル test.bar は、削除しても再構築されません。これは、test.dar がまだ最新であるためです。しかし、GNU Make v3.82 を使用すると:

user@node1:/data/user/Tests/oldfile3$ rm test.*
removed `test.dar'
removed `test.txt'
user@node1:/data/user/Tests/oldfile3$ touch test.txt
user@node1:/data/user/Tests/oldfile3$ mk82 target2
touch test.bar
touch test.dar
user@node1:/data/user/Tests/oldfile3$ mk82 target2
make: Nothing to be done for `target2'.
user@node1:/data/user/Tests/oldfile3$ rm test.bar
removed `test.bar'
user@node1:/data/user/Tests/oldfile3$ mk82 target2
touch test.bar
touch test.dar
user@node1:/data/user/Tests/oldfile3$ 

test.bar を削除して make を呼び出すと、test.bar が再構築され、次に test.dar が再構築されます。test.txt はまだ test.dar よりも古いのに、なぜ test.txt に依存する test.bar を作り直すのですか? 次のように target1 を削除すると、これは発生しません。

NAME := test

target2: $(addsuffix .dar,$(NAME))

%.bar: $(INPUT)
    touch $@

%.dar: %.bar
    touch $@

どこにも指定しないのに target1 をビルドするのはなぜですか?

ありがとう、

マーティン

4

1 に答える 1

1

test.barの前提条件として明示的に言及されているため、中間ファイルではありませんtarget1。make がビルドを決定する一連のターゲットと前提条件でのみ明示的に言及する必要はありません。makefile のどこかで明示的に言及するだけで済みます。

結局のところ、target1次にビルドを要求してから make を再ビルドする必要があるかもtest.barしれませんが、削除されていなければ再ビルドする必要はありません。

ETA: GNU make 3.81 の動作はバグだと思います。

于 2013-10-15T14:42:13.480 に答える