next up previous
Next: Special macros Up: A sample makefile and Previous: Dependency rules

Special dependencies

The first dependency is magic. When you execute make, it expects you to give it the name of a target to update on the command line, ie. gmake usepix. If you don't give a target, it simply updates the first target it comes to. In the sample, it's just usepix, but in a larger project, there might be several test programs, libraries, and so on. It's common to have a first target called `all' which depends on the files you want to update most frequently. No file named `all' ever really exists because it is a pseudo-target...

Pseudo-targets are really useful. A pseudo-target is a file which never really exists. It has a dependency section in the makefile, and if you tell make to update the target, it will do its normal stuff and update all the dependencies. However, pseudo-targets don't have to have commands that update them, and make doesn't mind a bit. Here's an example:

testsuite: test1 test2

test1: test1.o libtapestry.a
   ->   ...
test2: test2.o libtapestry.a
   ->   ...

Issuing the command gmake testsuite causes make to update test1 and test2.

Another way to use them is to have a target which has no dependencies but has a few commands listed under it. In the sample makefile, `clean' is just such as pseudo-target:

clean:
   ->   rm -f $(OBJ)

Targets which have no dependencies are always considered out of date and any commands listed under them are always executed. If you were to issue the command gmake clean using the sample makefile, make would remove all those .o files from the current directory.

Having a `cleanup' target or two is quite useful: You're not likely to mistype gmake clean, but notice how easy it is to mistype rm -f *.o (remove all your .o files) as rm -f *>o (remove everything and re-direct any output into a file called `o').

Here are some sample pseudo-targets that are useful for lots of different things. Note that some macros are used that you'll have to define for yourself elsewhere:

all: usepix testpix toast pancake

clean:
   ->   rm -f $(OBJ)

# More about this one in the section on makedepend...
depend:
   ->   makedepend $(CXXFLAGS) -Y $(SRC)

# This is a neat way to make a compressed archive file for
# saving or submitting your project.
# Note that several commands go with this target; all will be
# executed if you run gmake archive.
archive:
   ->   rm -rf project project.tar.gz
   ->   mkdir project
   ->   cp $(SUBMISSIONS) project
   ->   tar -cf project.tar project
   ->   gzip project.tar

# This next one makes a printout of all your source code.
# The $? means all dependencies newer than the target.
# See the section on special macros

PRINTCMD = enscript -2rG -pprintout.ps

print: $(SOURCE) $(HEADERS)
   ->   echo spooling $? to printer using $(PRINTCMD)
   ->   $(PRINTCMD) $?
   ->   print printout.ps
   ->   rm printout.ps


next up previous
Next: Special macros Up: A sample makefile and Previous: Dependency rules

Garrett
Fri Jan 24 17:04:25 EST 1997