GNU Make includes a special target called .DELETE_ON_ERROR
. If this is included in your Makefile, Make will delete any target whose build sequence completes with a non-zero return status. This is helpful so that in subsequent invocations Make does not assume that the target has been properly built.
Here's a dummy example.
.DELETE_ON_ERROR:
out.dat: in.dat
touch out.dat
false
Because false
gives a non-zero return value, the build is considered failed and Make deletes the out.dat
target. This is the advertised and expected behavior. However, this behavior does not seem to be preserved when the target is a directory. Consider another dummy example.
.DELETE_ON_ERROR:
outdir/: in.dat
mkdir outdir/
false
In this case, the build fails again but Make does not remove the outdir
directory. Is there any way I can instruct Make to do this?
DELETE_ON_ERROR
. Would that solve the problem? – Beta