Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU make: “Nothing to be done for 'target'” vs. “'target' is up to date”

How does GNU make decide which of the messages to emit? The Makefile I am using causes Nothing to be done for 'target' messages to be emitted when the target is up do date. But I think 'target' is up to date would be more appropriate.

like image 782
pic11 Avatar asked Apr 20 '11 17:04

pic11


People also ask

What does target mean in makefile?

A simple makefile consists of “rules” with the following shape: target … : prerequisites … recipe … … A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ' clean ' (see Phony Targets).

What is .precious in makefile?

PRECIOUS to preserve intermediate files created by rules whose target patterns match that file's name. .INTERMEDIATE. The targets which . INTERMEDIATE depends on are treated as intermediate files. See Chains of Implicit Rules. .


1 Answers

The chief difference is in whether gmake has a rule to build the target or not. If there is no rule for the target, but the target exists, then gmake will say, "Nothing to be done", as in, "I don't know how to update this thing, but it already exists, so I guess there's nothing to be done." If there is a rule, but the target is already up-to-date, then gmake will say, "is up to date", as in, "I do have instructions for updating this thing, but it appears to already be up-to-date, so I'm not going to do anything."

Here's a concrete example:

$ echo "upToDate: older ; @echo done" > Makefile
$ touch older ; sleep 2 ; touch upToDate ; touch nothingToDo
$ ls --full-time -l older upToDate nothingToDo
-rw-r--r-- 1 ericm ericm 0 2011-04-20 11:13:04.970243002 -0700 nothingToDo
-rw-r--r-- 1 ericm ericm 0 2011-04-20 11:13:02.960243003 -0700 older
-rw-r--r-- 1 ericm ericm 0 2011-04-20 11:13:04.960243001 -0700 upToDate
$ gmake upToDate
gmake: `upToDate' is up to date.
$ gmake nothingToDo
gmake: Nothing to be done for `nothingToDo'.

Since gmake has no rule for "nothingToDo", but the file already exists, you get the "nothing to be done" message. If "nothingToDo" did not exist, you would instead get the familiar, "No rule to make" message.

In contrast, because gmake has a rule for "upToDate", and the file appears to be up-to-date, you get the "is up to date" message.

like image 179
Eric Melski Avatar answered Sep 28 '22 09:09

Eric Melski