In a makefile, I have several rules that look like this:
out.txt: foo.sh input.txt
./foo.sh -i input.txt > out.txt
If foo.sh
fails, then out.txt
will be created as a 0-sized file. If I run make again, it will mistakenly assume that the out.txt
file was created successfully, and it won't run the rule again.
What's the right way to handle this sort of scenario?
Best Answer
You can request that make delete the target file if the rule fails, by defining a special target named
.DELETE_ON_ERROR
. It doesn't need to do anything or have any dependencies, so just add this to your makefile:Then you get the following:
From Errors in Recipes: