I don't understand that once the target file - $(TEST_LOG) has been generated, both make check_tests and make eval_test will skip the prerequisite but execute the recipe. Can someone give some guidance and help me to understand it?
Let's say, $(TEST_LOG) was generated one day ago, comparing with current timestamp, it is out-dated. Then user do make eval_test now, it should remake test.log within current timestamp. But in this case, the target $(TEST_LOG) is skipped. But it do execute the rule. In my opinion, if make skip the prerequisite, it will skip to execute recipe as well. Why does make act in this way in this case?
TEST_LOG = test.log
check_tests: $(TEST_LOG) eval_test
$(TEST_LOG):
@echo "-- ERROR --" |& tee -a $@
eval_test: $(TEST_LOG)
@if [ `grep -cs "ERROR" $(TEST_LOG)` -eq 0 ]; then exit 0; else exit 1 ; fi
Thanks, TM
If you want Make to rebuild
test.logevery time you callmake test.logormake eval_test, you can add one line to the makefile:This tells Make that
test.logis not to be considered a file name, and therefore that if it is called for (as a prerequisite) the rule must be executed, regardless of what files exist.(The
PHONYline can be almost anywhere in the makefile, as long as it is after the definition ofTEST_LOG, and not in a rule.)