开发者

makefile unexpectedly removes target

A minimal example:

%.txt: foo.log
    # pass

%.log:
    # pass

Run:

$ 开发者_如何学运维make a.txt --dry-run
# pass
# pass
rm foo.log

Why is the last action rm foo.log? How can I get rid of it?


By default, GNU make removes intermediate files. Since %.txt depends on %.log, make wants to remove the .log file. To prevent that behavior you mark them as precious with .PRECIOUS or .SECONDARY.

.PRECIOUS: foo.log

Also, you can make it so that no intermediate files are ever removed by using .SECONDARY with no dependencies.

.SECONDARY:

See this section of the GNU make manual.


You are making a.txt by means of a chain of implicit rules (in this case implicit rules which you defined yourself). So Make considers foo.log an intermediate file, and deletes it when it has served its purpose. You can override this behavior by declaring foo.log a SECONDARY target:

.SECONDARY: foo.log
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜