1MAKE(1) General Commands Manual MAKE(1)
2
3
4
6 make - maintain program groups
7
9 make [ -f makefile ] [ option ] ... file ...
10
12 Make executes commands in makefile to update one or more target names.
13 Name is typically a program. If no -f option is present, `makefile'
14 and `Makefile' are tried in order. If makefile is `-', the standard
15 input is taken. More than one -f option may appear.
16
17 Make updates a target if it depends on prerequisite files that have
18 been modified since the target was last modified, or if the target does
19 not exist.
20
21 Makefile contains a sequence of entries that specify dependencies. The
22 first line of an entry is a blank-separated list of targets, then a
23 colon, then a list of prerequisite files. Text following a semicolon,
24 and all following lines that begin with a tab, are shell commands to be
25 executed to update the target. If a name appears on the left of more
26 than one `colon' line, then it depends on all of the names on the right
27 of the colon on those lines, but only one command sequence may be spec‐
28 ified for it. If a name appears on a line with a double colon :: then
29 the command sequence following that line is performed only if the name
30 is out of date with respect to the names to the right of the double
31 colon, and is not affected by other double colon lines on which that
32 name may appear.
33
34 The special form of the name: a(b) means the file named b stored in the
35 archive named a.
36
37 Sharp and newline surround comments.
38
39 The following makefile says that `pgm' depends on two files `a.o' and
40 `b.o', and that they in turn depend on `.c' files and a common file
41 `incl'.
42
43
44 pgm: a.o b.o
45 cc a.o b.o -lm -o pgm
46 a.o: incl a.c
47 cc -c a.c
48 b.o: incl b.c
49 cc -c b.c
50
51 Makefile entries of the form
52
53 string1 = string2
54
55 are macro definitions. Subsequent appearances of $(string1) or
56 ${string1} are replaced by string2. If string1 is a single character,
57 the parentheses or braces are optional.
58
59 All environment variables are assumed to be macro definitions and pro‐
60 cessed as such. The environment variables are processed before any
61 makefile macro definitions; thus, macro assignments in a makefile over‐
62 ride environmental variables. The -e option causes the environment to
63 override the macro assignments in a makefile. Finally, command line
64 options of the form string1=string2 override both environment and make‐
65 file macro definitions.
66
67 Make infers prerequisites for files for which makefile gives no con‐
68 struction commands. For example, a `.c' file may be inferred as pre‐
69 requisite for a `.o' file and be compiled to produce the `.o' file.
70 Thus the preceding example can be done more briefly:
71
72
73 pgm: a.o b.o
74 cc a.o b.o -lm -o pgm
75 a.o b.o: incl
76
77 Prerequisites are inferred according to selected suffixes listed as the
78 `prerequisites' for the special name `.SUFFIXES'; multiple lists accu‐
79 mulate; an empty list clears what came before. Order is significant;
80 the first possible name for which both a file and a rule as described
81 in the next paragraph exist is inferred. The default list is
82
83 .SUFFIXES: .out .o .c .e .r .f .y .l .s .p
84
85 The rule to create a file with suffix s2 that depends on a similarly
86 named file with suffix s1 is specified as an entry for the `target'
87 s1s2. In such an entry, the special macro $* stands for the target
88 name with suffix deleted, $@ for the full target name, $< for the com‐
89 plete list of prerequisites, and $? for the list of prerequisites that
90 are out of date. For example, a rule for making optimized `.o' files
91 from `.c' files is
92
93 .c.o: ; cc -c -O -o $@ $*.c
94
95 Certain macros are used by the default inference rules to communicate
96 optional arguments to any resulting compilations. In particular,
97 `CFLAGS' is used for cc(1) options, `FFLAGS' for f77(1) options,
98 `PFLAGS' for pc(1) options, and `LFLAGS' and `YFLAGS' for lex and
99 yacc(1) options. In addition, the macro `MFLAGS' is filled in with the
100 initial command line options supplied to make. This simplifies main‐
101 taining a hierarchy of makefiles as one may then invoke make on make‐
102 files in subdirectories and pass along useful options such as -k.
103
104 Another special macro is `VPATH'. The `VPATH' macro should be set to a
105 list of directories separated by colons. When make searches for a file
106 as a result of a dependency relation, it will first search the current
107 directory and then each of the directories on the `VPATH' list. If the
108 file is found, the actual path to the file will be used, rather than
109 just the filename. If `VPATH' is not defined, then only the current
110 directory is searched.
111
112 One use for `VPATH' is when one has several programs that compile from
113 the same source. The source can be kept in one directory and each set
114 of object files (along with a separate makefile) would be in a separate
115 subdirectory. The `VPATH' macro would point to the source directory in
116 this case.
117
118 Command lines are executed one at a time, each by its own shell. A
119 line is printed when it is executed unless the special target `.SILENT'
120 is in makefile, or the first character of the command is `@'.
121
122 Commands returning nonzero status (see intro(1)) cause make to termi‐
123 nate unless the special target `.IGNORE' is in makefile or the command
124 begins with <tab><hyphen>.
125
126 Interrupt and quit cause the target to be deleted unless the target is
127 a directory or depends on the special name `.PRECIOUS'.
128
129 Other options:
130
131 -e Environmental variables override assignments within makefiles.
132
133 -i Equivalent to the special entry `.IGNORE:'.
134
135 -k When a command returns nonzero status, abandon work on the cur‐
136 rent entry, but continue on branches that do not depend on the
137 current entry.
138
139 -n Trace and print, but do not execute the commands needed to
140 update the targets.
141
142 -t Touch, i.e. update the modified date of targets, without execut‐
143 ing any commands.
144
145 -r Equivalent to an initial special entry `.SUFFIXES:' with no
146 list.
147
148 -s Equivalent to the special entry `.SILENT:'.
149
151 makefile, Makefile
152
154 sh(1), touch(1), f77(1), pc(1), getenv(3)
155 S. I. Feldman Make - A Program for Maintaining Computer Programs
156
158 Some commands return nonzero status inappropriately. Use -i to over‐
159 come the difficulty.
160 Commands that are directly executed by the shell, notably cd(1), are
161 ineffectual across newlines in make.
162
163 `VPATH' is intended to act like the System V `VPATH' support, but there
164 is no guarantee that it functions identically.
165
166
167
1684th Berkeley Distribution August 15, 1987 MAKE(1)