| 1 | .TH MAKE 1 |
| 2 | .SH NAME |
| 3 | make \- maintain program groups |
| 4 | .SH SYNOPSIS |
| 5 | .B make |
| 6 | [ |
| 7 | .B \-f |
| 8 | makefile ] [ option ] ... |
| 9 | file ... |
| 10 | .SH DESCRIPTION |
| 11 | .I Make |
| 12 | executes commands in |
| 13 | .I makefile |
| 14 | to update |
| 15 | one or more target |
| 16 | .IR names . |
| 17 | .I Name |
| 18 | is typically a program. |
| 19 | If no |
| 20 | .B \-f |
| 21 | option is present, `makefile' and `Makefile' are |
| 22 | tried in order. |
| 23 | If |
| 24 | .I makefile |
| 25 | is `\-', the standard input is taken. |
| 26 | More than one |
| 27 | .B \-f |
| 28 | option may appear |
| 29 | .PP |
| 30 | .I Make |
| 31 | updates a target if it depends on prerequisite files |
| 32 | that have been modified since the target was last modified, |
| 33 | or if the target does not exist. |
| 34 | .PP |
| 35 | .I Makefile |
| 36 | contains a sequence of entries that specify dependencies. |
| 37 | The first line of an entry is a |
| 38 | blank-separated list of targets, then a colon, |
| 39 | then a list of prerequisite files. |
| 40 | Text following a semicolon, and all following lines |
| 41 | that begin with a tab, are shell commands |
| 42 | to be executed to update the target. |
| 43 | .PP |
| 44 | Sharp and newline surround comments. |
| 45 | .PP |
| 46 | The following makefile says that `pgm' depends on two |
| 47 | files `a.o' and `b.o', and that they in turn depend on |
| 48 | `.c' files and a common file `incl'. |
| 49 | .RS |
| 50 | .HP |
| 51 | .PD 0 |
| 52 | .nf |
| 53 | pgm: a.o b.o |
| 54 | cc a.o b.o \-lm \-o pgm |
| 55 | .HP |
| 56 | a.o: incl a.c |
| 57 | cc \-c a.c |
| 58 | .HP |
| 59 | b.o: incl b.c |
| 60 | cc \-c b.c |
| 61 | .fi |
| 62 | .RE |
| 63 | .PD |
| 64 | .PP |
| 65 | .I Makefile |
| 66 | entries of the form |
| 67 | .PP |
| 68 | .IP |
| 69 | string1 = string2 |
| 70 | .PP |
| 71 | are macro definitions. |
| 72 | Subsequent appearances of |
| 73 | .I $(string1) |
| 74 | are replaced by |
| 75 | .IR string2 . |
| 76 | If |
| 77 | .I string1 |
| 78 | is a single character, the parentheses are optional. |
| 79 | .PP |
| 80 | .I Make |
| 81 | infers prerequisites for files for which |
| 82 | .I makefile |
| 83 | gives no construction commands. |
| 84 | For example, a |
| 85 | `.c' file may be inferred as prerequisite for a `.o' file |
| 86 | and be compiled to produce the `.o' file. |
| 87 | Thus the preceding example can be done more briefly: |
| 88 | .RS |
| 89 | .HP |
| 90 | .PD 0 |
| 91 | .nf |
| 92 | pgm: a.o b.o |
| 93 | cc a.o b.o \-lm \-o pgm |
| 94 | .HP |
| 95 | a.o b.o: incl |
| 96 | .fi |
| 97 | .RE |
| 98 | .PD |
| 99 | .PP |
| 100 | Prerequisites are inferred according to selected suffixes |
| 101 | listed as the `prerequisites' for the special name `.SUFFIXES'; |
| 102 | multiple lists accumulate; |
| 103 | an empty list clears what came before. |
| 104 | Order is significant; the first possible name for which both |
| 105 | a file and a rule as described in the next paragraph exist |
| 106 | is inferred. |
| 107 | The default list is |
| 108 | .IP |
| 109 | \&.SUFFIXES: .out .o .c .e .r .f .y .l .s |
| 110 | .PP |
| 111 | The rule to create a file with suffix |
| 112 | .I s2 |
| 113 | that depends on a similarly named file with suffix |
| 114 | .I s1 |
| 115 | is specified as an entry |
| 116 | for the `target' |
| 117 | .IR s1s2 . |
| 118 | In such an entry, the special macro $* stands for |
| 119 | the target name with suffix deleted, $@ for the full target name, |
| 120 | $< for the complete list of prerequisites, |
| 121 | and |
| 122 | $? for the list of prerequisites that are out of date. |
| 123 | For example, a rule for making |
| 124 | optimized `.o' files from `.c' files is |
| 125 | .IP |
| 126 | \&.c.o: ; cc \-c \-O \-o $@ $*.c |
| 127 | .PP |
| 128 | Certain macros are used by the default inference rules |
| 129 | to communicate optional arguments to |
| 130 | any resulting compilations. |
| 131 | In particular, `CFLAGS' is used for |
| 132 | .I cc |
| 133 | and |
| 134 | .IR f77 (1) |
| 135 | options, `LFLAGS' and `YFLAGS' for |
| 136 | .I lex |
| 137 | and |
| 138 | .IR yacc (1) |
| 139 | options. |
| 140 | .PP |
| 141 | Command lines are executed one at a time, each by its |
| 142 | own shell. |
| 143 | A line is printed when it is executed unless |
| 144 | the special target `.SILENT' |
| 145 | is in |
| 146 | .I makefile, |
| 147 | or the first character of the command is `@'. |
| 148 | .PP |
| 149 | Commands returning nonzero status (see |
| 150 | .IR intro (1)) |
| 151 | cause |
| 152 | .I make |
| 153 | to terminate unless |
| 154 | the special target `.IGNORE' is in |
| 155 | .I makefile |
| 156 | or the command begins with |
| 157 | <tab><hyphen>. |
| 158 | .PP |
| 159 | Interrupt and quit cause the target to be deleted |
| 160 | unless the target depends on the special name `.PRECIOUS'. |
| 161 | .PP |
| 162 | Other options: |
| 163 | .TP |
| 164 | .B \-i |
| 165 | Equivalent to the special entry `.IGNORE:'. |
| 166 | .TP |
| 167 | .B \-k |
| 168 | When a command returns nonzero status, |
| 169 | abandon work on the current entry, but |
| 170 | continue on branches that do not depend on the current entry. |
| 171 | .TP |
| 172 | .B \-n |
| 173 | Trace and print, but do not execute the commands |
| 174 | needed to update the targets. |
| 175 | .TP |
| 176 | .B \-t |
| 177 | Touch, i.e. update the modified date of targets, without |
| 178 | executing any commands. |
| 179 | .TP |
| 180 | .B \-r |
| 181 | Equivalent to an initial special entry `.SUFFIXES:' |
| 182 | with no list. |
| 183 | .TP |
| 184 | .B \-s |
| 185 | Equivalent to the special entry |
| 186 | `.SILENT:'. |
| 187 | .SH FILES |
| 188 | makefile, Makefile |
| 189 | .br |
| 190 | .SH "SEE ALSO" |
| 191 | sh(1), touch(1) |
| 192 | .br |
| 193 | S. I. Feldman |
| 194 | .I |
| 195 | Make \- A Program for Maintaining Computer Programs |
| 196 | .SH BUGS |
| 197 | Some commands return nonzero status inappropriately. |
| 198 | Use |
| 199 | .B \-i |
| 200 | to overcome the difficulty. |
| 201 | .br |
| 202 | Commands that are directly executed by the shell, |
| 203 | notably |
| 204 | .IR cd (1), |
| 205 | are ineffectual across newlines in |
| 206 | .I make. |