.HTML "Maintaining Files on Plan 9 with Mk .TL Maintaining Files on Plan 9 with Mk .AU Andrew G. Hume andrew@research.att.com Bob Flandrena bobf@plan9.bell-labs.com .AB .PP .CW Mk is a tool for describing and maintaining dependencies between files. It is similar to the UNIX program .CW make , but provides several extensions. .CW Mk\fR'\fPs flexible rule specifications, implied dependency derivation, and parallel execution of maintenance actions are well-suited to the Plan 9 environment. Almost all Plan 9 maintenance procedures are automated using .CW mk . .AE .NH 1 Introduction .PP This document describes how .CW mk , a program functionally similar to .CW make [Feld79], is used to maintain dependencies between files in Plan 9. .CW Mk provides several extensions to the capabilities of its predecessor that work well in Plan 9's distributed, multi-architecture environment. It exploits the power of multiprocessors by executing maintenance actions in parallel and interacts with the Plan 9 command interpreter .CW rc to provide a powerful set of maintenance tools. It accepts pattern-based dependency specifications that are not limited to describing rules for program construction. The result is a tool that is flexible enough to perform many maintenance tasks including database maintenance, hardware design, and document production. .PP This document begins by discussing the syntax of the control file, the pattern matching capabilities, and the special rules for maintaining archives. A brief description of .CW mk\fR'\fPs algorithm for deriving dependencies is followed by a discussion of the conventions used to resolve ambiguous specifications. The final sections describe parallel execution and special features. .PP An earlier paper [Hume87] provides a detailed discussion of .CW mk\fR'\fPs design and an appendix summarizes the differences between .CW mk and .CW make . .NH 1 The \f(CWMkfile\fP .PP .CW Mk reads a file describing relationships among files and executes commands to bring the files up to date. The specification file, called a .CW mkfile , contains three types of statements: assignments, includes, and rules. Assignment and include statements are similar to those in C. Rules specify dependencies between a .I target and its .I prerequisites . When the target and prerequisites are files, their modification times determine if they are out of date. Rules often contain a .I recipe , an .I rc (1) script that produces the target from the prerequisites. .PP This simple .CW mkfile produces an executable from a C source file: .P1 CC=pcc f1: f1.c $CC -o f1 f1.c .P2 The first line assigns the name of the portable ANSI/POSIX compiler to the .CW mk variable .CW CC ; subsequent references of the form .CW $CC select this compiler. The only rule specifies a dependence between the target file .CW f1 and the prerequisite file .CW f1.c . If the target does not exist or if the prerequisite has been modified more recently than the target, .CW mk passes the recipe to .CW rc for execution. Here, .CW f1.c is compiled and loaded to produce .CW f1 . .PP The native Plan 9 environment requires executables for all architectures, not only the current one. The Plan 9 version of the same .CW mkfile looks like: .P1 $target .P2 produces the message .P1 .CW "mk: pic mk.ms | ... : exit status=rc 685: deleting 'pic.out'" .P2 if any program in the recipe exits with an error status. .NH 1 Unspecified dependencies .PP The .CW -w command line flag forces the files following the flag to be treated as if they were just modified. We can use this flag with a command that selects files to force a build based on the selection criterion. For example, if the declaration of a global variable named .I var is changed in a header file, all source files that reference it can be rebuilt with the command .P1 $ mk -w`{grep -l \fIvar\fP *.[cyl]} .P2 .NH 1 Conclusion .PP There are many programs related to .CW make , each choosing a different balance between specialization and generality. .CW Mk emphasizes generality but allows customization through its pattern specifications and include facilities. .PP Plan 9 presents a difficult maintenance environment with its heterogeneous architectures and languages. .CW Mk\fR'\fPs flexible specification language and simple interaction with .CW rc work well in this environment. As a result, Plan 9 relies on .CW mk to automate almost all maintenance. Tasks as diverse as updating the network data base, producing the manual, or building a release are expressed as .CW mk procedures. .NH 1 References .LP [Cmel86] R. F. Cmelik, ``Concurrent Make: A Distributed Program in Concurrent C'', AT&T Bell Laboratories Technical Report, 1986. .LP [Feld79] S. I. Feldman, ``Make \(em a program for maintaining computer programs'', .I Software Practice & Experience , .R 1979 Vol 9 #4, pp. 255-266. .LP [Flan95] Bob Flandrena, ``Plan 9 Mkfiles'', this volume. .LP [Hume87] A. G. Hume, ``Mk: A Successor to Make'', .I USENIX Summer Conf. Proc., .R Phoenix, Az. .NH 1 Appendix: Differences between .CW make and .CW mk .PP The differences between .CW mk and .CW make are: .IP \(bu 3n .CW Make builds targets when it needs them, allowing systematic use of side effects. .CW Mk constructs the entire dependency graph before building any target. .IP \(bu .CW Make supports suffix rules and .CW % metarules. .CW Mk supports .CW % and regular expression metarules. (Older versions of .CW make support only suffix rules.) .IP \(bu .CW Mk performs transitive closure on metarules, .CW make does not. .IP \(bu .CW Make supports cyclic dependencies, .CW mk does not. .IP \(bu .CW Make evaluates recipes one line at a time, replacing variables by their values and executing some commands internally. .CW Mk passes the entire recipe to the shell without interpretation or internal execution. .IP \(bu .CW Make supports parallel execution of single-line recipes when building the prerequisites for specified targets. .CW Mk supports parallel execution of all recipes. (Older versions of .CW make did not support parallel execution.) .IP \(bu .CW Make uses special targets (beginning with a period) to indicate special processing. .CW Mk uses attributes to modify rule evaluation. .IP \(bu .CW Mk supports virtual targets that are independent of the file system. .IP \(bu .CW Mk allows non-standard out-of-date determination, .CW make does not. .PP It is usually easy to convert a .CW makefile to or from an equivalent .CW mkfile .