1 '\" te 2 .\" Copyright 1989 AT&T Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved 3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. 4 .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with 5 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] 6 .TH SYSV-MAKE 1 "Aug 24, 2009" 7 .SH NAME 8 sysV-make \- maintain, update, and regenerate groups of programs 9 .SH SYNOPSIS 10 .LP 11 .nf 12 \fB/usr/lib/svr4.make\fR [\fB-f\fR \fImakefile\fR] [\fB-eiknpqrst\fR] [\fInames\fR] 13 .fi 14 15 .SH DESCRIPTION 16 .LP 17 This is the \fBvanilla\fR System V version of \fBmake\fR. If the environment 18 variable \fBUSE_SVR4_MAKE\fR is set, then the command \fBmake\fR will invoke 19 this version of \fBmake\fR. (See also the \fBENVIRONMENT\fR section.) 20 .sp 21 .LP 22 \fBmake\fR allows the programmer to maintain, update, and regenerate groups of 23 computer programs. \fBmake\fR executes commands in \fImakefile\fR to update one 24 or more target \fInames\fR (\fInames\fR are typically programs). If the 25 \fB-f\fR option is not present, then \fBmakefile\fR, \fBMakefile\fR, and the 26 Source Code Control System (SCCS) files \fBs.makefile\fR and \fBs.Makefile\fR 27 are tried in order. If \fImakefile\fR is `\fB\(mi\fR\&' the standard input is 28 taken. More than one \fB-f\fR \fImakefile\fR argument pair may appear. 29 .sp 30 .LP 31 \fBmake\fR updates a target only if its dependents are newer than the target. 32 All prerequisite files of a target are added recursively to the list of 33 targets. Missing files are deemed to be outdated. 34 .sp 35 .LP 36 The following list of four directives can be included in \fImakefile\fR to 37 extend the options provided by \fBmake\fR. They are used in \fImakefile\fR as 38 if they were targets: 39 .sp 40 .ne 2 41 .na 42 \fB\fB\&.DEFAULT:\fR\fR 43 .ad 44 .RS 16n 45 If a file must be made but there are no explicit commands or relevant built-in 46 rules, the commands associated with the name \fB\&.DEFAULT\fR are used if it 47 exists. 48 .RE 49 50 .sp 51 .ne 2 52 .na 53 \fB\fB\&.IGNORE:\fR\fR 54 .ad 55 .RS 16n 56 Same effect as the \fB-i\fR option. 57 .RE 58 59 .sp 60 .ne 2 61 .na 62 \fB\fB\&.PRECIOUS:\fR\fR 63 .ad 64 .RS 16n 65 Dependents of the \fB\&.PRECIOUS\fR entry will not be removed when quit or 66 interrupt are hit. 67 .RE 68 69 .sp 70 .ne 2 71 .na 72 \fB\fB\&.SILENT:\fR\fR 73 .ad 74 .RS 16n 75 Same effect as the \fB-s\fR option. 76 .RE 77 78 .SS "Options" 79 .LP 80 The options for \fBmake\fR are listed below: 81 .sp 82 .ne 2 83 .na 84 \fB\fB-e\fR\fR 85 .ad 86 .RS 15n 87 Environment variables override assignments within makefiles. 88 .RE 89 90 .sp 91 .ne 2 92 .na 93 \fB\fB-f\fR \fImakefile\fR\fR 94 .ad 95 .RS 15n 96 Description filename (\fImakefile\fR is assumed to be the name of a description 97 file). 98 .RE 99 100 .sp 101 .ne 2 102 .na 103 \fB\fB-i\fR\fR 104 .ad 105 .RS 15n 106 Ignore error codes returned by invoked commands. 107 .RE 108 109 .sp 110 .ne 2 111 .na 112 \fB\fB-k\fR\fR 113 .ad 114 .RS 15n 115 Abandon work on the current entry if it fails, but continue on other branches 116 that do not depend on that entry. 117 .RE 118 119 .sp 120 .ne 2 121 .na 122 \fB\fB-n\fR\fR 123 .ad 124 .RS 15n 125 No execute mode. Print commands, but do not execute them. Even command lines 126 beginning with an `\fB@\fR' are printed. 127 .RE 128 129 .sp 130 .ne 2 131 .na 132 \fB\fB-p\fR\fR 133 .ad 134 .RS 15n 135 Print out the complete set of macro definitions and target descriptions. 136 .RE 137 138 .sp 139 .ne 2 140 .na 141 \fB\fB-q\fR\fR 142 .ad 143 .RS 15n 144 Question. \fBmake\fR returns a zero or non-zero status code depending on 145 whether or not the target file has been updated. 146 .RE 147 148 .sp 149 .ne 2 150 .na 151 \fB\fB-r\fR\fR 152 .ad 153 .RS 15n 154 Do not use the built-in rules. 155 .RE 156 157 .sp 158 .ne 2 159 .na 160 \fB\fB-s\fR\fR 161 .ad 162 .RS 15n 163 Silent mode. Do not print command lines before executing. 164 .RE 165 166 .sp 167 .ne 2 168 .na 169 \fB\fB-t\fR\fR 170 .ad 171 .RS 15n 172 Touch the target files (causing them to be updated) rather than issue the usual 173 commands. 174 .RE 175 176 .SS "Creating the makefile" 177 .LP 178 The makefile invoked with the \fB-f\fR option is a carefully structured file of 179 explicit instructions for updating and regenerating programs, and contains a 180 sequence of entries that specify dependencies. The first line of an entry is a 181 blank-separated, non-null list of targets, then a `\fB:\fR', then a (possibly 182 null) list of prerequisite files or dependencies. Text following a `\fB;\fR' 183 and all following lines that begin with a tab are shell commands to be executed 184 to update the target. The first non-empty line that does not begin with a tab 185 or `\fB#\fR' begins a new dependency or macro definition. Shell commands may be 186 continued across lines with a backslash-new-line (\fB\e\fR-NEWLINE) sequence. 187 Everything printed by make (except the initial TAB) is passed directly to the 188 shell as is. Thus, 189 .sp 190 .in +2 191 .nf 192 echo a\e 193 b 194 .fi 195 .in -2 196 .sp 197 198 .sp 199 .LP 200 will produce 201 .sp 202 .LP 203 \fBab\fR 204 .sp 205 .LP 206 exactly the same as the shell would. 207 .sp 208 .LP 209 Number-sign (\fB#\fR) and \fBNEWLINE\fR surround comments including contained 210 `\fB\e\fR\(miNEWLINE' sequences. 211 .sp 212 .LP 213 The following makefile says that \fBpgm\fR depends on two files \fBa.o\fR and 214 \fBb.o\fR, and that they in turn depend on their corresponding source files 215 (\fBa.c\fR and \fBb.c\fR) and a common file \fBincl.h\fR: 216 .sp 217 .in +2 218 .nf 219 pgm: a.o b.o 220 cc a.o b.o -o pgm 221 a.o: incl.h a.c 222 cc -c a.c 223 b.o: incl.h b.c 224 cc -c b.c 225 .fi 226 .in -2 227 .sp 228 229 .sp 230 .LP 231 Command lines are executed one at a time, each by its own shell. The 232 \fBSHELL\fR environment variable can be used to specify which shell \fBmake\fR 233 should use to execute commands. The default is \fB/usr/bin/sh\fR. The first one 234 or two characters in a command can be the following: `\fB@\fR', `\fB\(mi\fR\&', 235 `\fB@\(mi\fR', or `\fB\(mi@\fR\&'. If `\fB@\fR' is present, printing of the 236 command is suppressed. If `\fB\(mi\fR\&' is present, \fBmake\fR ignores an 237 error. A line is printed when it is executed unless the \fB-s\fR option is 238 present, or the entry \fB\&.SILENT:\fR is included in \fImakefile\fR, or unless 239 the initial character sequence contains a \fB@\fR. The \fB-n\fR option 240 specifies printing without execution; however, if the command line has the 241 string \fB$(MAKE)\fR in it, the line is always executed (see the discussion of 242 the \fBMAKEFLAGS\fR macro in the \fBmake\fR \fBEnvironment\fR sub-section 243 below). The \fB-t\fR (touch) option updates the modified date of a file without 244 executing any commands. 245 .sp 246 .LP 247 Commands returning non-zero status normally terminate \fBmake\fR. If the 248 \fB-i\fR option is present, if the entry \fB\&.IGNORE:\fR is included in 249 \fImakefile\fR, or if the initial character sequence of the command contains 250 `\fB\(mi\fR\&', the error is ignored. If the \fB-k\fR option is present, work 251 is abandoned on the current entry, but continues on other branches that do not 252 depend on that entry. 253 .sp 254 .LP 255 Interrupt and quit cause the target to be deleted unless the target is a 256 dependent of the directive \fB\&.PRECIOUS\fR. 257 .SS "make Environment" 258 .LP 259 The environment is read by \fBmake\fR. All variables are assumed to be macro 260 definitions and are processed as such. The environment variables are processed 261 before any makefile and after the internal rules; thus, macro assignments in a 262 makefile override environment variables. The \fB-e\fR option causes the 263 environment to override the macro assignments in a makefile. Suffixes and their 264 associated rules in the makefile will override any identical suffixes in the 265 built-in rules. 266 .sp 267 .LP 268 The \fBMAKEFLAGS\fR environment variable is processed by \fBmake\fR as 269 containing any legal input option (except \fB-f\fR and \fB-p\fR) defined for 270 the command line. Further, upon invocation, \fBmake\fR "invents" the variable 271 if it is not in the environment, puts the current options into it, and passes 272 it on to invocations of commands. Thus, \fBMAKEFLAGS\fR always contains the 273 current input options. This feature proves very useful for "super-makes". In 274 fact, as noted above, when the \fB-n\fR option is used, the command 275 \fB$(MAKE)\fR is executed anyway; hence, one can perform a \fBmake\fR \fB-n\fR 276 recursively on a whole software system to see what would have been executed. 277 This result is possible because the \fB-n\fR is put in \fBMAKEFLAGS\fR and 278 passed to further invocations of \fB$(MAKE)\fR. This usage is one way of 279 debugging all of the makefiles for a software project without actually doing 280 anything. 281 .SS "Include Files" 282 .LP 283 If the string \fIinclude\fR appears as the first seven letters of a line in a 284 \fImakefile\fR, and is followed by a blank or a tab, the rest of the line is 285 assumed to be a filename and will be read by the current invocation, after 286 substituting for any macros. 287 .SS "Macros" 288 .LP 289 Entries of the form \fIstring1\fR \fB=\fR \fIstring2\fR are macro definitions. 290 \fIstring2\fR is defined as all characters up to a comment character or an 291 unescaped NEWLINE. Subsequent appearances of 292 \fB$\fR(\fIstring1\fR[\fB:\fR\fIsubst1\fR\fB=\fR[\fIsubst2\fR]]) are replaced 293 by \fIstring2\fR. The parentheses are optional if a single-character macro name 294 is used and there is no substitute sequence. The optional 295 :\fIsubst1\fR=\fIsubst2\fR is a substitute sequence. If it is specified, all 296 non-overlapping occurrences of \fIsubst1\fR in the named macro are replaced by 297 \fIsubst2\fR. Strings (for the purposes of this type of substitution) are 298 delimited by BLANKs, TABs, NEWLINE characters, and beginnings of lines. An 299 example of the use of the substitute sequence is shown in the \fBLibraries\fR 300 sub-section below. 301 .SS "Internal Macros" 302 .LP 303 There are five internally maintained macros that are useful for writing rules 304 for building targets. 305 .sp 306 .ne 2 307 .na 308 \fB\fB$*\fR\fR 309 .ad 310 .RS 6n 311 The macro \fB$*\fR stands for the filename part of the current dependent with 312 the suffix deleted. It is evaluated only for inference rules. 313 .RE 314 315 .sp 316 .ne 2 317 .na 318 \fB\fB$@\fR\fR 319 .ad 320 .RS 6n 321 The \fB$@\fR macro stands for the full target name of the current target. It is 322 evaluated only for explicitly named dependencies. 323 .RE 324 325 .sp 326 .ne 2 327 .na 328 \fB\fB$<\fR\fR 329 .ad 330 .RS 6n 331 The \fB$<\fR macro is only evaluated for inference rules or the 332 \fB\&.DEFAULT\fR rule. It is the module that is outdated with respect to the 333 target (the "manufactured" dependent file name). Thus, in the \fB\&.c.o\fR 334 rule, the \fB$<\fR macro would evaluate to the \fB\&.c\fR file. An example for 335 making optimized \fB\&.o\fR files from \fB\&.c\fR files is: 336 .sp 337 .in +2 338 .nf 339 \&.c.o: 340 cc c O $*.c 341 .fi 342 .in -2 343 .sp 344 345 or: 346 .sp 347 .in +2 348 .nf 349 \&.c.o: 350 cc c O $< 351 .fi 352 .in -2 353 .sp 354 355 .RE 356 357 .sp 358 .ne 2 359 .na 360 \fB\fB$?\fR\fR 361 .ad 362 .RS 6n 363 The \fB$?\fR macro is evaluated when explicit rules from the makefile are 364 evaluated. It is the list of prerequisites that are outdated with respect to 365 the target, and essentially those modules that must be rebuilt. 366 .RE 367 368 .sp 369 .ne 2 370 .na 371 \fB\fB$%\fR\fR 372 .ad 373 .RS 6n 374 The \fB$%\fR macro is only evaluated when the target is an archive library 375 member of the form \fBlib(file.o)\fR. In this case, \fB$@\fR evaluates to 376 \fBlib\fR and \fB$%\fR evaluates to the library member, \fBfile.o\fR. 377 .RE 378 379 .sp 380 .LP 381 Four of the five macros can have alternative forms. When an upper case \fBD\fR 382 or \fBF\fR is appended to any of the four macros, the meaning is changed to 383 "directory part" for \fBD\fR and "file part" for \fBF\fR. Thus, \fB$(@D)\fR 384 refers to the directory part of the string \fB$@\fR. If there is no directory 385 part, \fB\&./\fR is generated. The only macro excluded from this alternative 386 form is \fB$?\fR. 387 .SS "Suffixes" 388 .LP 389 Certain names (for instance, those ending with \fB\&.o\fR) have inferable 390 prerequisites such as \fB\&.c\fR, \fB\&.s\fR, etc. If no update commands for 391 such a file appear in \fImakefile\fR, and if an inferable prerequisite exists, 392 that prerequisite is compiled to make the target. In this case, \fBmake\fR has 393 inference rules that allow building files from other files by examining the 394 suffixes and determining an appropriate inference rule to use. The current 395 default inference rules are: 396 .sp 397 398 .sp 399 .TS 400 tab( ); 401 lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) 402 lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) lw(.55i) . 403 \&.c \&.c~ \&.f \&.f~ \&.s \&.s~ \&.sh \&.sh~ \&.C \&.C~ 404 \&.c.a \&.c.o \&.c~.a \&.c~.c \&.c~.o \&.f.a \&.f.o \&.f~.a \&.f~.f \&.f~.o 405 \&.h~.h \&.l.c \&.l.o \&.l~.c \&.l~.l \&.l~.o \&.s.a \&.s.o \&.s~.a \&.s~.o 406 \&.s~.s \&.sh~.sh \&.y.c \&.y.o \&.y~.c \&.y~.o \&.y~.y \&.C.a \&.C.o \&.C~.a 407 \&.C~.C \&.C~.o \&.L.C \&.L.o \&.L~.C \&.L~.L \&.L~.o \&.Y.C \&.Y.o \&.Y~.C 408 \&.Y~.o \&.Y~.Y 409 .TE 410 411 .sp 412 .LP 413 The internal rules for \fBmake\fR are contained in the source file 414 \fBmake.rules\fR for the \fBmake\fR program. These rules can be locally 415 modified. To print out the rules compiled into the \fBmake\fR on any machine in 416 a form suitable for re-compilation, the following command is used: 417 .sp 418 .in +2 419 .nf 420 make -pf \(mi2>/dev/null < /dev/null 421 .fi 422 .in -2 423 .sp 424 425 .sp 426 .LP 427 A tilde in the above rules refers to an SCCS file (see \fBsccsfile\fR(4)). 428 Thus, the rule \fB\&.c~.o\fR would transform an SCCS C source file into an 429 object file (\fB\&.o\fR). Because the \fBs.\fR of the SCCS files is a prefix, 430 it is incompatible with the \fBmake\fR suffix point of view. Hence, the tilde 431 is a way of changing any file reference into an SCCS file reference. 432 .sp 433 .LP 434 A rule with only one suffix (for example, \fB\&.c:\fR) is the definition of how 435 to build \fIx\fR from \fIx\fR\fB\&.c\fR. In effect, the other suffix is null. 436 This feature is useful for building targets from only one source file, for 437 example, shell procedures and simple C programs. 438 .sp 439 .LP 440 Additional suffixes are given as the dependency list for \fB\&.SUFFIXES\fR. 441 Order is significant: the first possible name for which both a file and a rule 442 exist is inferred as a prerequisite. The default list is: 443 .sp 444 .LP 445 \fB\&.SUFFIXES: .o .c .c~ .y .y~ .l .l~ .s .s~ .sh .sh~ .h .h~ .f .f~\fR 446 \fB\&.C .C~ .Y .Y~ .L .L~\fR 447 .sp 448 .LP 449 Here again, the above command for printing the internal rules will display the 450 list of suffixes implemented on the current machine. Multiple suffix lists 451 accumulate; \fB\&.SUFFIXES:\fR with no dependencies clears the list of 452 suffixes. 453 .SS "Inference Rules" 454 .LP 455 The first example can be done more briefly. 456 .sp 457 .in +2 458 .nf 459 pgm: a.o b.o 460 cc a.o b.o o pgm 461 a.o b.o: incl.h 462 .fi 463 .in -2 464 .sp 465 466 .sp 467 .LP 468 This abbreviation is possible because \fBmake\fR has a set of internal rules 469 for building files. The user may add rules to this list by simply putting them 470 in the \fImakefile\fR. 471 .sp 472 .LP 473 Certain macros are used by the default inference rules to permit the inclusion 474 of optional matter in any resulting commands. Again, the previous method for 475 examining the current rules is recommended. 476 .sp 477 .LP 478 The inference of prerequisites can be controlled. The rule to create a file 479 with suffix \fB\&.o\fR from a file with suffix \fB\&.c\fR is specified as an 480 entry with \fB\&.c.o:\fR as the target and no dependents. Shell commands 481 associated with the target define the rule for making a \fB\&.o\fR file from a 482 \fB\&.c\fR file. Any target that has no slashes in it and starts with a dot is 483 identified as a rule and not a true target. 484 .SS "Libraries" 485 .LP 486 If a target or dependency name contains parentheses, it is assumed to be an 487 archive library, the string within parentheses referring to a member within the 488 library. Thus, \fBlib(file.o)\fR and \fB$(LIB)(file.o)\fR both refer to an 489 archive library that contains \fBfile.o\fR. (This example assumes the \fBLIB\fR 490 macro has been previously defined.) The expression \fB$(LIB)(file1.o 491 file2.o)\fR is not legal. Rules pertaining to archive libraries have the form 492 \fB\&.\fR\fIXX\fR\fB\&.a\fR where the \fB\fR\fIXX\fR\fB \fR is the suffix from 493 which the archive member is to be made. An unfortunate by-product of the 494 current implementation requires the \fB\fR\fIXX\fR\fB \fR to be different from 495 the suffix of the archive member. Thus, one cannot have \fBlib(file.o)\fR 496 depend upon \fBfile.o\fR explicitly. The most common use of the archive 497 interface follows. Here, we assume the source files are all C type source: 498 .sp 499 .in +2 500 .nf 501 lib: lib(file1.o) lib(file2.o) lib(file3.o) 502 @echo lib is now up-to-date 503 \&.c.a: 504 $(CC) -c $(CFLAGS) $< 505 $(AR) $(ARFLAGS) $@ $*.o 506 rm -f $*.o 507 .fi 508 .in -2 509 .sp 510 511 .sp 512 .LP 513 In fact, the \fB\&.c.a\fR rule listed above is built into \fBmake\fR and is 514 unnecessary in this example. A more interesting, but more limited example of an 515 archive library maintenance construction follows: 516 .sp 517 .in +2 518 .nf 519 lib: lib(file1.o) lib(file2.o) lib(file3.o) 520 $(CC) -c $(CFLAGS) $(?:.o=.c) 521 $(AR) $(ARFLAGS) lib $? 522 rm $? 523 @echo lib is now up-to-date 524 \&.c.a:; 525 .fi 526 .in -2 527 .sp 528 529 .sp 530 .LP 531 Here the substitution mode of the macro expansions is used. The \fB$?\fR list 532 is defined to be the set of object filenames (inside \fBlib\fR) whose C source 533 files are outdated. The substitution mode translates the \fB\&.o\fR to 534 \fB\&.c\fR. (Unfortunately, one cannot as yet transform to \fB\&.c~\fR; 535 however, this transformation may become possible in the future.) Also note the 536 disabling of the \fB\&.c.a:\fR rule, which would have created each object file, 537 one by one. This particular construct speeds up archive library maintenance 538 considerably. This type of construct becomes very cumbersome if the archive 539 library contains a mix of assembly programs and C programs. 540 .SH ENVIRONMENT VARIABLES 541 .ne 2 542 .na 543 \fB\fBUSE_SVR4_MAKE\fR\fR 544 .ad 545 .RS 17n 546 If this environment variable is set, then the \fBmake\fR command will invoke 547 this System V version of \fBmake\fR. If this variable is not set, then the 548 default version of \fBmake\fR(1S) is invoked. 549 .sp 550 \fBUSE_SVR4_MAKE\fR can be set as follows (Bourne shell): 551 .sp 552 \fB$ USE_SVR4_MAKE=``''; export USE_SVR4_MAKE\fR 553 .sp 554 or (C shell): 555 .sp 556 \fB% setenv USE_SVR4_MAKE\fR 557 .RE 558 559 .SH FILES 560 .ne 2 561 .na 562 \fB\fB[Mm]akefile\fR\fR 563 .ad 564 .br 565 .na 566 \fB\fBs.[Mm]akefile\fR\fR 567 .ad 568 .sp .6 569 .RS 4n 570 default makefiles 571 .RE 572 573 .sp 574 .ne 2 575 .na 576 \fB\fB/usr/bin/sh\fR\fR 577 .ad 578 .sp .6 579 .RS 4n 580 default shell for \fBmake\fR 581 .RE 582 583 .sp 584 .ne 2 585 .na 586 \fB\fB/usr/share/lib/make/make.rules\fR\fR 587 .ad 588 .sp .6 589 .RS 4n 590 default rules for \fBmake\fR 591 .RE 592 593 .SH SEE ALSO 594 .LP 595 \fBcd\fR(1), \fBmake\fR(1S), \fBsh\fR(1), \fBprintf\fR(3C), \fBsccsfile\fR(4), 596 \fBattributes\fR(5) 597 .SH NOTES 598 .LP 599 Some commands return non-zero status inappropriately; use \fB-i\fR or the 600 `\fB-\fR' command line prefix to overcome the difficulty. 601 .sp 602 .LP 603 Filenames containing the characters \fB=\fR, \fB:\fR, and \fB@\fR do not work. 604 Commands that are directly executed by the shell, notably \fBcd\fR(1), are 605 ineffectual across \fBNEWLINEs\fR in \fBmake\fR. The syntax \fBlib(file1.o\fR 606 \fBfile2.o\fR \fBfile3.o)\fR is illegal. You cannot build \fBlib(file.o)\fR 607 from \fBfile.o\fR.