### Run the tests tests := tests/test1 tests/test2 ... test: $(tests) $(tests): %: %.c gcc -o $@ $(testflags) $< $@
它的作品,但它使得做一些我以前从未见过的事情.我的测试目前被打破,导致总线错误. Make给出以下输出:
gcc -o tests/test1 [flags blah blah] tests/test1.c tests/test1 make: *** [tests/test1] Bus error make: *** Deleting file `tests/test1'
我很好奇最后一行.我从来没有见过Make为什么Make删除编译测试?
注意:我非常重视这个例子,使之更简单.我可能会出现一些错误.
解决方法
这种行为是否适合您的情况取决于测试的性质.如果您打算修复测试,这样就不会导致总线错误,那么删除目标并不是什么大不了的事情.如果以后要使用目标进行调试,则需要对make进行更改.
另一个可能是:
$(tests): %: %.c gcc -o $@ $(testflags) $< -$@
未测试,但documentation表示目标不会被删除:
When an error happens that make has not been told to ignore,it implies that the current target cannot be correctly remade,and neither can any other that depends on it either directly or indirectly. No further commands will be executed for these targets,since their preconditions have not been achieved.
和:
Usually when a command 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 command is killed by a signal; see Interrupts. So generally the right thing to do is to delete the target file if the command 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.