start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

11.11. Even More Uses for make

Thinking about make will pay off in many ways. One way to get ideas about how to use it is to look at other Makefiles.

One of my favorites is the Makefile for NIS (Section 1.21) (formerly called YP, or "Yellow Pages"). I like this Makefile because it does something that you'd never think of doing (even though it suits make perfectly): updating a distributed database.

The Makefile is fairly complicated, so I don't want to get into a line-by-line explication; but I will give you a sketch of how it works. Here's the problem: a system administrator updates one or more files (we'll say the passwd file) and wants to get her changes into the NIS database. So you need to check whether the new password file is more recent than the database. Unfortunately, the database isn't represented by a single file, so there's nothing to "check" against. The NIS Makefile handles this situation by creating empty files that serve as timestamps. There's a separate timestamp file for every database that NIS serves. When you type make, make checks every master file against the corresponding timestamp. If a master file is newer than the timestamp, make knows that it has to rebuild part of the database. After rebuilding the database, the Makefile "touches" the timestamp, so that it reflects the time at which the database was built.

The Makefile looks something like this:

passwd: passwd.time
passwd.time:  /etc/master/passwd
         @ lots of commands that rebuild the database
         @ touch passwd.time
         @ more commands to distribute the new database

hosts: hosts.time
hosts.time:  similar stuff

You may never need to write a Makefile this complicated, but you should look for situations in which you can use make profitably. It isn't just for programming.

-- ML



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.