I’ve got a slightly hackish makefile for running tests:
### Run the tests tests := tests/test1 tests/test2 ... test: $(tests) $(tests): %: %.c gcc -o $@ $(testflags) $< $@
It works, but it makes Make do something I’ve never seen it do before. My test is currently broken, and causes a bus error. Make gives the following output:
gcc -o tests/test1 [flags blah blah] tests/test1.c tests/test1 make: *** [tests/test1] Bus error make: *** Deleting file `tests/test1'
I’m curious about the last line. I’ve never seen Make do that before. Why does Make delete the compiled test?
Note: I edited this example pretty heavily to make it simpler. I might have introduced some mistakes.
Because the target might not have been built correctly. The next time you
makethe project, it will attempt to rebuild the target. If the file had not been removed,makewould have no way of knowing something went wrong.makecan’t know that the failure was coming from a test rather than the process that builds the target.Whether or not this behavior is desirable in your case depends on the nature of the tests. If you plan on fixing the test so that it does not cause a
Bus error, removing the target isn’t a big deal. If you want to use the target for debugging later, you’ll need to make a change to your make process.One way to not delete targets is to use the
.PRECIOUStarget.Another might be:
Not tested, but the documentation indicates the target will not be removed:
and: