makefile unexpectedly removes target

前端 未结 2 1677
时光说笑
时光说笑 2020-12-15 05:19

A minimal example:

%.txt: foo.log
    # pass

%.log:
    # pass

Run:

$ make a.txt --dry-run
# pass
# pass
rm foo.log
         


        
2条回答
  •  甜味超标
    2020-12-15 06:00

    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
    

提交回复
热议问题