helloworld: helloworld.ccc helloworld.c -o helloworld # NOTE: Line starts with TAB, not with 8 spaces!
Interprete the Makefile this way:
There is only one target, called helloworld.
(A Makefile normally has several targets.)
The "target" is simply the name of the file we want to create.
In this case, we want to create the executable "helloworld".
We could have called the target whatever we want to, but to take advantage of make's ability to detect timestamp changes, we should. If there has been no changes in the required source code file(s) (in this case "helloworld.c"), make will detect that the executable's timestamp is newer than the source code's. Thus, there is need to recompile
There is one prerequisite for the target helloworld, called helloworld.c
(Each target in a Makefile may have zero or more prerequisites.)
That is, the file helloworld.c must exist if we want to build the target helloworld.
On a separate line (always starting with TAB!), the command to be executed is listed: cc helloworld.c -o helloworld
(Each target may have one or more lines with commands.)
In this case, we only specify one command: how to compile helloworld.c
If no target is specified, make looks for the first target in the Makefile.
In this case, the first (and only) target is helloworld, so we can omit the target:
make
You should see an output similar to this one:
cc helloworld.c -o helloworld # NOTE: Line starts with TAB, not with 8 spaces!
Repeat:
make
You should now see an output similar to this one:
make: `helloworld' is up to date.
Exercises:
"Fool" make to think recompile is needed by changing the executable's timestamp.
Tip: to change the timestamp:
touch -t 01010000 helloworld
Using MSYS on MS Windows:
touch -t 01010000 helloworld.exe
Now type make. Is the target up to date?
Change the target's name from "helloworld" to "hi_there", then type make.
Why do you *never* see this message?