I have a rule in my Makefile that roughly looks like this:
some_tool src_file > target_file
some_tool ... -o target_file
some_tool src_file > target_file || rm -f target_file
some_tool src_file > target_file.tmp
mv target_file.tmp target_file
You could use the special target
If .DELETE_ON_ERROR is mentioned as a target anywhere in the makefile, then make will delete the target of a rule if it has changed and its recipe exits with a nonzero exit status, just as it does when it receives a signal.
All it takes is one line:
And all rules that fail will have their target removed.