Você pode solicitar que exclua o arquivo de destino se a regra falhar, definindo um alvo especial chamado .DELETE_ON_ERROR
. Não precisa fazer nada nem ter dependências, então adicione isso ao seu makefile:
.DELETE_ON_ERROR:
Então você recebe o seguinte:
$ cat Makefile
.DELETE_ON_ERROR:
foo:
false > foo
$ make
false > foo
make: *** [foo] Error 1
make: *** Deleting file 'foo'
zsh: exit 2 make
$ stat foo
stat: cannot stat 'foo': No such file or directory
De Erros nas receitas :
Usually when a recipe line fails, if it has changed the target file at all, the file is corrupted and cannot be used—or at least it is not completely updated. Yet the file's time stamp says that it is now up to date, so the next time
make
runs, it will not try to update that file. The situation is just the same as when the shell is killed by a signal; see Interrupts. 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 wantmake
to do, but it is not historical practice; so for compatibility, you must explicitly request it.