L5. make
Learn / L5
Goal: stop typing nas and ld. Describe how
upcase is built once, and let make do the rest.
What you need
L3: the upcase source. The directory on
the disk, /usr/src/examples/UPCASE, already holds the Makefile beside
it, and the session copies both.
The file
Each rule is a target, a colon, the files it is made from, and then the commands
that make it, each indented by a tab. The first rule is what a bare
make builds.
examples/upcase/Makefile — on the disk as /usr/src/examples/UPCASE/Makefile# make finds nas, ld and rm on PATH, as `sh -c` would (they live in /bin).
upcase: upcase.o
ld -o upcase upcase.o -L /usr/lib -l a
upcase.o: upcase.s
nas -o upcase.o upcase.s
clean:
rm -f upcase upcase.o
The session
make -n prints the commands without running them.
$ mkdir /tmp/l5 $ cd /tmp/l5 $ cp /usr/src/examples/UPCASE/* . $ ls Makefile upcase.s $ make -n nas -o upcase.o upcase.s ld -o upcase upcase.o -L /usr/lib -l a $ make nas -o upcase.o upcase.s nas: 36 bytes -> upcase.o ld -o upcase upcase.o -L /usr/lib -l a $ make $ make -n $ ./upcase < /usr/src/examples/HELLOSH/hello #!/BIN/SH ECHO HELLO, WORLD $ make clean rm -f upcase upcase.o $ ls Makefile upcase.s $ make -n nas -o upcase.o upcase.s ld -o upcase upcase.o -L /usr/lib -l a
What just happened
make read the first rule and saw that upcase needs
upcase.o, which needs upcase.s. The source exists and the
object does not, so it ran the commands from the bottom up and printed each one as
it ran it. A command that exits non-zero stops the whole thing. The second
make printed nothing at all: no file was newer than the target made
from it, so there was nothing to do. (Some makes say so; this one is silent,
and so is make -n at that point.) make clean is an ordinary
rule that no file depends on; you ask for it by name.
How does it decide a target is out of date? It compares the modification times
ProDOS keeps for the two files. ProDOS stamps files to the minute, not the second,
so maux's make has a one-minute rule: a target rebuilt within a minute
of its source's last change compares equal to it and is judged up to date. If you
edit upcase.s, run make, edit again and run make
within the same minute, the second build can be skipped. The BUGS section of the
manual page names -t and touch as the way out, and says
there is no -B to force a rebuild. The gate that produced the session above runs with the clock
card off, so every stamp is the same; it cannot show the rule, and this page does not
pretend to.
Because no shell sits between make and the command, a recipe line is
split at blanks and run directly. There is no pipe, no redirection and no globbing in
a recipe; a rule that needs one runs a script. L7
does exactly that.
Try next
Add a rule test: upcase whose one command runs
upcase on a file you choose. What does make test print the
first time, and the second?