New ask Hacker News story: Tell HN: TIL: GNU Make .DELETE_ON_ERROR
Tell HN: TIL: GNU Make .DELETE_ON_ERROR
2 by kazinator | 0 comments on Hacker News.
If you have a make recipe which creates the target file, or modifies the timestamp of the existing out-or-date target, and that recipe fails, make will not delete the target. Thus it looks up-to-date, even though the recipe failed. The manual says: "So generally the right thing to do is to delete the target file if the recipe fails after beginning to change the file. make will do this if .DELETE_ON_ERROR appears as a target. This is almost always what you want make to do, but it is not historical practice; so for compatibility, you must explicitly request it." So, hidden in the manual is the recommendation that, it's good practice to have .DELETE_ON_ERROR: somewhere in every GNU Makefile. An example where this is relevant: foo: bar generate bar > foo # redirection is used redirection will create the file or touch the timestamp of the existing one before the generate command is run. What if bar has syntax errors and generate fails? The foo file was touched and so looks updated. If you run "make foo" again, Make reports that foo is up-to-date. With .DELETE_ON_ERROR, foo will be deleted. If foo exists and its timestamp is not changed, then it's left alone. If a recipe creates or touches the target, and fails due to Make being interrupted by a signal, in that case make deletes the target without any option having to be specified.
2 by kazinator | 0 comments on Hacker News.
If you have a make recipe which creates the target file, or modifies the timestamp of the existing out-or-date target, and that recipe fails, make will not delete the target. Thus it looks up-to-date, even though the recipe failed. The manual says: "So generally the right thing to do is to delete the target file if the recipe fails after beginning to change the file. make will do this if .DELETE_ON_ERROR appears as a target. This is almost always what you want make to do, but it is not historical practice; so for compatibility, you must explicitly request it." So, hidden in the manual is the recommendation that, it's good practice to have .DELETE_ON_ERROR: somewhere in every GNU Makefile. An example where this is relevant: foo: bar generate bar > foo # redirection is used redirection will create the file or touch the timestamp of the existing one before the generate command is run. What if bar has syntax errors and generate fails? The foo file was touched and so looks updated. If you run "make foo" again, Make reports that foo is up-to-date. With .DELETE_ON_ERROR, foo will be deleted. If foo exists and its timestamp is not changed, then it's left alone. If a recipe creates or touches the target, and fails due to Make being interrupted by a signal, in that case make deletes the target without any option having to be specified.
Comments
Post a Comment