A GNU Make Tutorial

Usage Notes

There are several additional things that can be done to increase the usability of this makefile.

As it currently stands, each test (all 40 of them for the DLX test suite!) must be run by hand, one at a time. This drudgery can be greatly reduced with a rule similar to:

test: t1.Addi t1.Jump t1.Step ...
where the target to run each of the 40-odd tests is entered as a dependency. Then the single command make test will run all the tests. Even the drudgery of maintaining this list can be eliminated by allowing make to build it at run time. This can be done with a set of built-in functions. For example,
tests = $(basename $(wildcard t1.*.out))
test: $(tests)
In this example the $(wildcard ...) function builds a list of all the files in the current directory matching the Unix regular expression 't1.*.out'. This list, separated by spaces, is the argument to the function $(basename ...) which strips the last '.' and everything after it ('.out' in this case). The resulting list is assigned to the variable tests which is then used as the dependency to the target test:. In the above rules, if diff finds a difference between the output file of dlxcpu (t1.%.tmp) and the expected output (t1.%.out) it will return an error and make quits immediately. Often only one or two out of the 40-odd tests will fail. These can be detected with by adding '-k' to the invocation of make. Make will then do all of the commands it can, even if some of them result in errors. These can be noted and the incorrect tests may be run individually while tracking the errors they reveal.
[Previous] [Tutorial Index] [GNU Make]

Copyright 1996 by Byron Weber Becker