home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 28.13 make Isn't Just for Programmers! Chapter 28
Comparing Files
Next: 28.15 Show Changes in a troff File with diffmk

28.14 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 ( 1.33 ) (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 of the makefile ; 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 his changes into the yp database. So you need to check whether or not 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 .time 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
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

Previous: 28.13 make Isn't Just for Programmers! UNIX Power Tools Next: 28.15 Show Changes in a troff File with diffmk
28.13 make Isn't Just for Programmers! Book Index 28.15 Show Changes in a troff File with diffmk

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System