1 /* $NetBSD: make.h,v 1.263 2021/06/21 10:33:11 rillig Exp $ */ 2 3 /* 4 * Copyright (c) 1988, 1989, 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * from: @(#)make.h 8.3 (Berkeley) 6/13/95 35 */ 36 37 /* 38 * Copyright (c) 1989 by Berkeley Softworks 39 * All rights reserved. 40 * 41 * This code is derived from software contributed to Berkeley by 42 * Adam de Boor. 43 * 44 * Redistribution and use in source and binary forms, with or without 45 * modification, are permitted provided that the following conditions 46 * are met: 47 * 1. Redistributions of source code must retain the above copyright 48 * notice, this list of conditions and the following disclaimer. 49 * 2. Redistributions in binary form must reproduce the above copyright 50 * notice, this list of conditions and the following disclaimer in the 51 * documentation and/or other materials provided with the distribution. 52 * 3. All advertising materials mentioning features or use of this software 53 * must display the following acknowledgement: 54 * This product includes software developed by the University of 55 * California, Berkeley and its contributors. 56 * 4. Neither the name of the University nor the names of its contributors 57 * may be used to endorse or promote products derived from this software 58 * without specific prior written permission. 59 * 60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 63 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 70 * SUCH DAMAGE. 71 * 72 * from: @(#)make.h 8.3 (Berkeley) 6/13/95 73 */ 74 75 /* 76 * make.h -- 77 * The global definitions for pmake 78 */ 79 80 #ifndef MAKE_MAKE_H 81 #define MAKE_MAKE_H 82 83 #ifdef HAVE_CONFIG_H 84 # include "config.h" 85 #endif 86 87 #include <sys/types.h> 88 #include <sys/param.h> 89 #include <sys/stat.h> 90 91 #include <assert.h> 92 #include <ctype.h> 93 #include <fcntl.h> 94 #include <stdarg.h> 95 #include <stdio.h> 96 #include <stdlib.h> 97 #ifdef HAVE_STRING_H 98 #include <string.h> 99 #else 100 #include <strings.h> 101 #endif 102 #include <unistd.h> 103 #include <sys/cdefs.h> 104 105 #ifndef FD_CLOEXEC 106 #define FD_CLOEXEC 1 107 #endif 108 109 #if defined(__GNUC__) 110 #define MAKE_GNUC_PREREQ(x, y) \ 111 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 112 (__GNUC__ > (x))) 113 #else /* defined(__GNUC__) */ 114 #define MAKE_GNUC_PREREQ(x, y) 0 115 #endif /* defined(__GNUC__) */ 116 117 #if MAKE_GNUC_PREREQ(2, 7) 118 #define MAKE_ATTR_UNUSED __attribute__((__unused__)) 119 #else 120 #define MAKE_ATTR_UNUSED /* delete */ 121 #endif 122 123 #if MAKE_GNUC_PREREQ(2, 5) 124 #define MAKE_ATTR_DEAD __attribute__((__noreturn__)) 125 #elif defined(__GNUC__) 126 #define MAKE_ATTR_DEAD __volatile 127 #else 128 #define MAKE_ATTR_DEAD /* delete */ 129 #endif 130 131 #if MAKE_GNUC_PREREQ(2, 7) 132 #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) \ 133 __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 134 #else 135 #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) /* delete */ 136 #endif 137 138 #define MAKE_INLINE static inline MAKE_ATTR_UNUSED 139 #define MAKE_STATIC static MAKE_ATTR_UNUSED 140 141 #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN) 142 #include <stdbool.h> 143 #else 144 #ifndef bool 145 typedef unsigned int Boolean; 146 #define bool Boolean 147 #endif 148 #ifndef true 149 #define true 1 150 #endif 151 #ifndef false 152 #define false 0 153 #endif 154 #endif 155 156 #include "lst.h" 157 #include "enum.h" 158 #include "make_malloc.h" 159 #include "str.h" 160 #include "hash.h" 161 #include "make-conf.h" 162 #include "buf.h" 163 164 /* 165 * some vendors don't have this --sjg 166 */ 167 #if defined(S_IFDIR) && !defined(S_ISDIR) 168 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 169 #endif 170 171 #if defined(sun) && (defined(__svr4__) || defined(__SVR4)) 172 # define POSIX_SIGNALS 173 #endif 174 175 /* 176 * The typical flow of states is: 177 * 178 * The direct successful path: 179 * UNMADE -> BEINGMADE -> MADE. 180 * 181 * The direct error path: 182 * UNMADE -> BEINGMADE -> ERROR. 183 * 184 * The successful path when dependencies need to be made first: 185 * UNMADE -> DEFERRED -> REQUESTED -> BEINGMADE -> MADE. 186 * 187 * A node that has dependencies, and one of the dependencies cannot be made: 188 * UNMADE -> DEFERRED -> ABORTED. 189 * 190 * A node that turns out to be up-to-date: 191 * UNMADE -> BEINGMADE -> UPTODATE. 192 */ 193 typedef enum GNodeMade { 194 /* Not examined yet. */ 195 UNMADE, 196 /* The node has been examined but is not yet ready since its 197 * dependencies have to be made first. */ 198 DEFERRED, 199 200 /* The node is on the toBeMade list. */ 201 REQUESTED, 202 203 /* The node is already being made. Trying to build a node in this 204 * state indicates a cycle in the graph. */ 205 BEINGMADE, 206 207 /* Was out-of-date and has been made. */ 208 MADE, 209 /* Was already up-to-date, does not need to be made. */ 210 UPTODATE, 211 /* An error occurred while it was being made. 212 * Used only in compat mode. */ 213 ERROR, 214 /* The target was aborted due to an error making a dependency. 215 * Used only in compat mode. */ 216 ABORTED 217 } GNodeMade; 218 219 /* 220 * The OP_ constants are used when parsing a dependency line as a way of 221 * communicating to other parts of the program the way in which a target 222 * should be made. 223 * 224 * Some of the OP_ constants can be combined, others cannot. 225 * 226 * See the tests depsrc-*.mk and deptgt-*.mk. 227 */ 228 typedef enum GNodeType { 229 OP_NONE = 0, 230 231 /* The dependency operator ':' is the most common one. The commands 232 * of this node are executed if any child is out-of-date. */ 233 OP_DEPENDS = 1 << 0, 234 /* The dependency operator '!' always executes its commands, even if 235 * its children are up-to-date. */ 236 OP_FORCE = 1 << 1, 237 /* The dependency operator '::' behaves like ':', except that it 238 * allows multiple dependency groups to be defined. Each of these 239 * groups is executed on its own, independently from the others. 240 * Each individual dependency group is called a cohort. */ 241 OP_DOUBLEDEP = 1 << 2, 242 243 /* Matches the dependency operators ':', '!' and '::'. */ 244 OP_OPMASK = OP_DEPENDS | OP_FORCE | OP_DOUBLEDEP, 245 246 /* Don't care if the target doesn't exist and can't be created. */ 247 OP_OPTIONAL = 1 << 3, 248 /* Use associated commands for parents. */ 249 OP_USE = 1 << 4, 250 /* Target is never out of date, but always execute commands anyway. 251 * Its time doesn't matter, so it has none...sort of. */ 252 OP_EXEC = 1 << 5, 253 /* Ignore non-zero exit status from shell commands when creating the 254 * node. */ 255 OP_IGNORE = 1 << 6, 256 /* Don't remove the target when interrupted. */ 257 OP_PRECIOUS = 1 << 7, 258 /* Don't echo commands when executed. */ 259 OP_SILENT = 1 << 8, 260 /* Target is a recursive make so its commands should always be 261 * executed when it is out of date, regardless of the state of the 262 * -n or -t flags. */ 263 OP_MAKE = 1 << 9, 264 /* Target is out-of-date only if any of its children was out-of-date. */ 265 OP_JOIN = 1 << 10, 266 /* Assume the children of the node have been already made. */ 267 OP_MADE = 1 << 11, 268 /* Special .BEGIN, .END or .INTERRUPT. */ 269 OP_SPECIAL = 1 << 12, 270 /* Like .USE, only prepend commands. */ 271 OP_USEBEFORE = 1 << 13, 272 /* The node is invisible to its parents. I.e. it doesn't show up in 273 * the parents' local variables (.IMPSRC, .ALLSRC). */ 274 OP_INVISIBLE = 1 << 14, 275 /* The node does not become the main target, even if it is the first 276 * target in the first makefile. */ 277 OP_NOTMAIN = 1 << 15, 278 /* Not a file target; run always. */ 279 OP_PHONY = 1 << 16, 280 /* Don't search for the file in the path. */ 281 OP_NOPATH = 1 << 17, 282 /* In a dependency line "target: source1 .WAIT source2", source1 is 283 * made first, including its children. Once that is finished, 284 * source2 is made, including its children. The .WAIT keyword may 285 * appear more than once in a single dependency declaration. */ 286 OP_WAIT = 1 << 18, 287 /* .NOMETA do not create a .meta file */ 288 OP_NOMETA = 1 << 19, 289 /* .META we _do_ want a .meta file */ 290 OP_META = 1 << 20, 291 /* Do not compare commands in .meta file */ 292 OP_NOMETA_CMP = 1 << 21, 293 /* Possibly a submake node */ 294 OP_SUBMAKE = 1 << 22, 295 296 /* Attributes applied by PMake */ 297 298 /* The node is a transformation rule, such as ".c.o". */ 299 OP_TRANSFORM = 1 << 30, 300 /* Target is a member of an archive */ 301 /* XXX: How does this differ from OP_ARCHV? */ 302 OP_MEMBER = 1 << 29, 303 /* The node is a library, 304 * its name has the form "-l<libname>" */ 305 OP_LIB = 1 << 28, 306 /* The node is an archive member, 307 * its name has the form "archive(member)" */ 308 /* XXX: How does this differ from OP_MEMBER? */ 309 OP_ARCHV = 1 << 27, 310 /* Target has all the commands it should. Used when parsing to catch 311 * multiple command groups for a target. Only applies to the 312 * dependency operators ':' and '!', but not to '::'. */ 313 OP_HAS_COMMANDS = 1 << 26, 314 /* The special command "..." has been seen. All further commands from 315 * this node will be saved on the .END node instead, to be executed at 316 * the very end. */ 317 OP_SAVE_CMDS = 1 << 25, 318 /* Already processed by Suff_FindDeps, to find dependencies from 319 * suffix transformation rules. */ 320 OP_DEPS_FOUND = 1 << 24, 321 /* Node found while expanding .ALLSRC */ 322 OP_MARK = 1 << 23, 323 324 OP_NOTARGET = OP_NOTMAIN | OP_USE | OP_EXEC | OP_TRANSFORM 325 } GNodeType; 326 327 typedef enum GNodeFlags { 328 GNF_NONE = 0, 329 /* this target needs to be (re)made */ 330 REMAKE = 1 << 0, 331 /* children of this target were made */ 332 CHILDMADE = 1 << 1, 333 /* children don't exist, and we pretend made */ 334 FORCE = 1 << 2, 335 /* Set by Make_ProcessWait() */ 336 DONE_WAIT = 1 << 3, 337 /* Build requested by .ORDER processing */ 338 DONE_ORDER = 1 << 4, 339 /* Node created from .depend */ 340 FROM_DEPEND = 1 << 5, 341 /* We do it once only */ 342 DONE_ALLSRC = 1 << 6, 343 /* Used by MakePrintStatus */ 344 CYCLE = 1 << 12, 345 /* Used by MakePrintStatus */ 346 DONECYCLE = 1 << 13 347 } GNodeFlags; 348 349 typedef struct List StringList; 350 typedef struct ListNode StringListNode; 351 352 typedef struct List GNodeList; 353 typedef struct ListNode GNodeListNode; 354 355 typedef struct SearchPath { 356 List /* of CachedDir */ dirs; 357 } SearchPath; 358 359 /* 360 * A graph node represents a target that can possibly be made, including its 361 * relation to other targets and a lot of other details. 362 */ 363 typedef struct GNode { 364 /* The target's name, such as "clean" or "make.c" */ 365 char *name; 366 /* The unexpanded name of a .USE node */ 367 char *uname; 368 /* The full pathname of the file belonging to the target. 369 * XXX: What about .PHONY targets? These don't have an associated 370 * path. */ 371 char *path; 372 373 /* The type of operator used to define the sources (see the OP flags 374 * below). 375 * XXX: This looks like a wild mixture of type and flags. */ 376 GNodeType type; 377 GNodeFlags flags; 378 379 /* The state of processing on this node */ 380 GNodeMade made; 381 /* The number of unmade children */ 382 int unmade; 383 384 /* The modification time; 0 means the node does not have a 385 * corresponding file; see GNode_IsOODate. */ 386 time_t mtime; 387 struct GNode *youngestChild; 388 389 /* The GNodes for which this node is an implied source. May be empty. 390 * For example, when there is an inference rule for .c.o, the node for 391 * file.c has the node for file.o in this list. */ 392 GNodeList implicitParents; 393 394 /* The nodes that depend on this one, or in other words, the nodes for 395 * which this is a source. */ 396 GNodeList parents; 397 /* The nodes on which this one depends. */ 398 GNodeList children; 399 400 /* .ORDER nodes we need made. The nodes that must be made (if they're 401 * made) before this node can be made, but that do not enter into the 402 * datedness of this node. */ 403 GNodeList order_pred; 404 /* .ORDER nodes who need us. The nodes that must be made (if they're 405 * made at all) after this node is made, but that do not depend on 406 * this node, in the normal sense. */ 407 GNodeList order_succ; 408 409 /* 410 * Other nodes of the same name, for targets that were defined using 411 * the '::' dependency operator (OP_DOUBLEDEP). 412 */ 413 GNodeList cohorts; 414 /* The "#n" suffix for this cohort, or "" for other nodes */ 415 char cohort_num[8]; 416 /* The number of unmade instances on the cohorts list */ 417 int unmade_cohorts; 418 /* Pointer to the first instance of a '::' node; only set when on a 419 * cohorts list */ 420 struct GNode *centurion; 421 422 /* Last time (sequence number) we tried to make this node */ 423 unsigned int checked_seqno; 424 425 /* 426 * The "local" variables that are specific to this target and this 427 * target only, such as $@, $<, $?. 428 * 429 * Also used for the global variable scopes SCOPE_GLOBAL, 430 * SCOPE_CMDLINE, SCOPE_INTERNAL, which contain variables with 431 * arbitrary names. 432 */ 433 HashTable /* of Var pointer */ vars; 434 435 /* The commands to be given to a shell to create this target. */ 436 StringList commands; 437 438 /* Suffix for the node (determined by Suff_FindDeps and opaque to 439 * everyone but the Suff module) */ 440 struct Suffix *suffix; 441 442 /* Filename where the GNode got defined */ 443 /* XXX: What is the lifetime of this string? */ 444 const char *fname; 445 /* Line number where the GNode got defined */ 446 int lineno; 447 } GNode; 448 449 /* Error levels for diagnostics during parsing. */ 450 typedef enum ParseErrorLevel { 451 /* Exit when the current top-level makefile has been parsed 452 * completely. */ 453 PARSE_FATAL = 1, 454 /* Print "warning"; may be upgraded to fatal by the -w option. */ 455 PARSE_WARNING, 456 /* Informational, mainly used during development of makefiles. */ 457 PARSE_INFO 458 } ParseErrorLevel; 459 460 /* 461 * Values returned by Cond_EvalLine and Cond_EvalCondition. 462 */ 463 typedef enum CondEvalResult { 464 COND_PARSE, /* Parse the next lines */ 465 COND_SKIP, /* Skip the next lines */ 466 COND_INVALID /* Not a conditional statement */ 467 } CondEvalResult; 468 469 /* Names of the variables that are "local" to a specific target. */ 470 #define TARGET "@" /* Target of dependency */ 471 #define OODATE "?" /* All out-of-date sources */ 472 #define ALLSRC ">" /* All sources */ 473 #define IMPSRC "<" /* Source implied by transformation */ 474 #define PREFIX "*" /* Common prefix */ 475 #define ARCHIVE "!" /* Archive in "archive(member)" syntax */ 476 #define MEMBER "%" /* Member in "archive(member)" syntax */ 477 478 /* 479 * Global Variables 480 */ 481 482 /* True if every target is precious */ 483 extern bool allPrecious; 484 /* True if failed targets should be deleted */ 485 extern bool deleteOnError; 486 /* true while processing .depend */ 487 extern bool doing_depend; 488 /* .DEFAULT rule */ 489 extern GNode *defaultNode; 490 491 /* 492 * Variables defined internally by make which should not override those set 493 * by makefiles. 494 */ 495 extern GNode *SCOPE_INTERNAL; 496 /* Variables defined in a global scope, e.g in the makefile itself. */ 497 extern GNode *SCOPE_GLOBAL; 498 /* Variables defined on the command line. */ 499 extern GNode *SCOPE_CMDLINE; 500 501 /* 502 * Value returned by Var_Parse when an error is encountered. It actually 503 * points to an empty string, so naive callers needn't worry about it. 504 */ 505 extern char var_Error[]; 506 507 /* The time at the start of this whole process */ 508 extern time_t now; 509 510 /* 511 * The list of directories to search when looking for targets (set by the 512 * special target .PATH). 513 */ 514 extern SearchPath dirSearchPath; 515 /* Used for .include "...". */ 516 extern SearchPath *parseIncPath; 517 /* 518 * Used for .include <...>, for the built-in sys.mk and for makefiles from 519 * the command line arguments. 520 */ 521 extern SearchPath *sysIncPath; 522 /* The default for sysIncPath. */ 523 extern SearchPath *defSysIncPath; 524 525 /* Startup directory */ 526 extern char curdir[]; 527 /* The basename of the program name, suffixed with [n] for sub-makes. */ 528 extern const char *progname; 529 extern int makelevel; 530 /* Name of the .depend makefile */ 531 extern char *makeDependfile; 532 /* If we replaced environ, this will be non-NULL. */ 533 extern char **savedEnv; 534 535 extern pid_t myPid; 536 537 #define MAKEFLAGS ".MAKEFLAGS" 538 #define MAKEOVERRIDES ".MAKEOVERRIDES" 539 /* prefix when printing the target of a job */ 540 #define MAKE_JOB_PREFIX ".MAKE.JOB.PREFIX" 541 #define MAKE_EXPORTED ".MAKE.EXPORTED" /* exported variables */ 542 #define MAKE_MAKEFILES ".MAKE.MAKEFILES" /* all loaded makefiles */ 543 #define MAKE_LEVEL ".MAKE.LEVEL" /* recursion level */ 544 #define MAKE_MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE" 545 #define MAKE_DEPENDFILE ".MAKE.DEPENDFILE" /* .depend */ 546 #define MAKE_MODE ".MAKE.MODE" 547 #ifndef MAKE_LEVEL_ENV 548 # define MAKE_LEVEL_ENV "MAKELEVEL" 549 #endif 550 551 typedef enum DebugFlags { 552 DEBUG_NONE = 0, 553 DEBUG_ARCH = 1 << 0, 554 DEBUG_COND = 1 << 1, 555 DEBUG_CWD = 1 << 2, 556 DEBUG_DIR = 1 << 3, 557 DEBUG_ERROR = 1 << 4, 558 DEBUG_FOR = 1 << 5, 559 DEBUG_GRAPH1 = 1 << 6, 560 DEBUG_GRAPH2 = 1 << 7, 561 DEBUG_GRAPH3 = 1 << 8, 562 DEBUG_HASH = 1 << 9, 563 DEBUG_JOB = 1 << 10, 564 DEBUG_LOUD = 1 << 11, 565 DEBUG_MAKE = 1 << 12, 566 DEBUG_META = 1 << 13, 567 DEBUG_PARSE = 1 << 14, 568 DEBUG_SCRIPT = 1 << 15, 569 DEBUG_SHELL = 1 << 16, 570 DEBUG_SUFF = 1 << 17, 571 DEBUG_TARG = 1 << 18, 572 DEBUG_VAR = 1 << 19, 573 DEBUG_ALL = (1 << 20) - 1 574 } DebugFlags; 575 576 #define CONCAT(a, b) a##b 577 578 #define DEBUG(module) ((opts.debug & CONCAT(DEBUG_, module)) != 0) 579 580 void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2); 581 582 #define DEBUG_IMPL(module, args) \ 583 do { \ 584 if (DEBUG(module)) \ 585 debug_printf args; \ 586 } while (/*CONSTCOND*/false) 587 588 #define DEBUG0(module, text) \ 589 DEBUG_IMPL(module, ("%s", text)) 590 #define DEBUG1(module, fmt, arg1) \ 591 DEBUG_IMPL(module, (fmt, arg1)) 592 #define DEBUG2(module, fmt, arg1, arg2) \ 593 DEBUG_IMPL(module, (fmt, arg1, arg2)) 594 #define DEBUG3(module, fmt, arg1, arg2, arg3) \ 595 DEBUG_IMPL(module, (fmt, arg1, arg2, arg3)) 596 #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \ 597 DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4)) 598 #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \ 599 DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5)) 600 601 typedef enum PrintVarsMode { 602 PVM_NONE, 603 PVM_UNEXPANDED, 604 PVM_EXPANDED 605 } PrintVarsMode; 606 607 /* Command line options */ 608 typedef struct CmdOpts { 609 /* -B: whether we are make compatible */ 610 bool compatMake; 611 612 /* -d: debug control: There is one bit per module. It is up to the 613 * module what debug information to print. */ 614 DebugFlags debug; 615 616 /* -df: debug output is written here - default stderr */ 617 FILE *debug_file; 618 619 /* -dL: lint mode 620 * 621 * Runs make in strict mode, with additional checks and better error 622 * handling. */ 623 bool strict; 624 625 /* -dV: for the -V option, print unexpanded variable values */ 626 bool debugVflag; 627 628 /* -e: check environment variables before global variables */ 629 bool checkEnvFirst; 630 631 /* -f: the makefiles to read */ 632 StringList makefiles; 633 634 /* -i: if true, ignore all errors from shell commands */ 635 bool ignoreErrors; 636 637 /* -j: the maximum number of jobs that can run in parallel; 638 * this is coordinated with the submakes */ 639 int maxJobs; 640 641 /* -k: if true and an error occurs while making a node, continue 642 * making nodes that do not depend on the erroneous node */ 643 bool keepgoing; 644 645 /* -N: execute no commands from the targets */ 646 bool noRecursiveExecute; 647 648 /* -n: execute almost no commands from the targets */ 649 bool noExecute; 650 651 /* 652 * -q: if true, do not really make anything, just see if the targets 653 * are out-of-date 654 */ 655 bool queryFlag; 656 657 /* -r: raw mode, do not load the builtin rules. */ 658 bool noBuiltins; 659 660 /* -s: don't echo the shell commands before executing them */ 661 bool beSilent; 662 663 /* -t: touch the targets if they are out-of-date, but don't actually 664 * make them */ 665 bool touchFlag; 666 667 /* -[Vv]: print expanded or unexpanded selected variables */ 668 PrintVarsMode printVars; 669 /* -[Vv]: the variables to print */ 670 StringList variables; 671 672 /* -W: if true, makefile parsing warnings are treated as errors */ 673 bool parseWarnFatal; 674 675 /* -w: print 'Entering' and 'Leaving' for submakes */ 676 bool enterFlag; 677 678 /* -X: if true, do not export variables set on the command line to the 679 * environment. */ 680 bool varNoExportEnv; 681 682 /* The target names specified on the command line. 683 * Used to resolve .if make(...) statements. */ 684 StringList create; 685 686 } CmdOpts; 687 688 extern CmdOpts opts; 689 690 #include "nonints.h" 691 692 void GNode_UpdateYoungestChild(GNode *, GNode *); 693 bool GNode_IsOODate(GNode *); 694 void Make_ExpandUse(GNodeList *); 695 time_t Make_Recheck(GNode *); 696 void Make_HandleUse(GNode *, GNode *); 697 void Make_Update(GNode *); 698 void GNode_SetLocalVars(GNode *); 699 bool Make_Run(GNodeList *); 700 bool shouldDieQuietly(GNode *, int); 701 void PrintOnError(GNode *, const char *); 702 void Main_ExportMAKEFLAGS(bool); 703 bool Main_SetObjdir(bool, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3); 704 int mkTempFile(const char *, char *, size_t); 705 int str2Lst_Append(StringList *, char *); 706 void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *); 707 bool GNode_ShouldExecute(GNode *gn); 708 709 /* See if the node was seen on the left-hand side of a dependency operator. */ 710 MAKE_INLINE bool 711 GNode_IsTarget(const GNode *gn) 712 { 713 return (gn->type & OP_OPMASK) != 0; 714 } 715 716 MAKE_INLINE const char * 717 GNode_Path(const GNode *gn) 718 { 719 return gn->path != NULL ? gn->path : gn->name; 720 } 721 722 MAKE_INLINE bool 723 GNode_IsWaitingFor(const GNode *gn) 724 { 725 return (gn->flags & REMAKE) && gn->made <= REQUESTED; 726 } 727 728 MAKE_INLINE bool 729 GNode_IsReady(const GNode *gn) 730 { 731 return gn->made > DEFERRED; 732 } 733 734 MAKE_INLINE bool 735 GNode_IsDone(const GNode *gn) 736 { 737 return gn->made >= MADE; 738 } 739 740 MAKE_INLINE bool 741 GNode_IsError(const GNode *gn) 742 { 743 return gn->made == ERROR || gn->made == ABORTED; 744 } 745 746 MAKE_INLINE const char * 747 GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); } 748 MAKE_INLINE const char * 749 GNode_VarOodate(GNode *gn) { return GNode_ValueDirect(gn, OODATE); } 750 MAKE_INLINE const char * 751 GNode_VarAllsrc(GNode *gn) { return GNode_ValueDirect(gn, ALLSRC); } 752 MAKE_INLINE const char * 753 GNode_VarImpsrc(GNode *gn) { return GNode_ValueDirect(gn, IMPSRC); } 754 MAKE_INLINE const char * 755 GNode_VarPrefix(GNode *gn) { return GNode_ValueDirect(gn, PREFIX); } 756 MAKE_INLINE const char * 757 GNode_VarArchive(GNode *gn) { return GNode_ValueDirect(gn, ARCHIVE); } 758 MAKE_INLINE const char * 759 GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); } 760 761 #if defined(__GNUC__) && __STDC_VERSION__ >= 199901L 762 #define UNCONST(ptr) ({ \ 763 union __unconst { \ 764 const void *__cp; \ 765 void *__p; \ 766 } __d; \ 767 __d.__cp = ptr, __d.__p; }) 768 #else 769 #define UNCONST(ptr) (void *)(ptr) 770 #endif 771 772 /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */ 773 #ifdef HAVE_LIMITS_H 774 #include <limits.h> 775 #endif 776 #ifndef MAXPATHLEN 777 #define MAXPATHLEN BMAKE_PATH_MAX 778 #endif 779 #ifndef PATH_MAX 780 #define PATH_MAX MAXPATHLEN 781 #endif 782 783 #if defined(SYSV) 784 #define KILLPG(pid, sig) kill(-(pid), (sig)) 785 #else 786 #define KILLPG(pid, sig) killpg((pid), (sig)) 787 #endif 788 789 MAKE_INLINE bool 790 ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; } 791 MAKE_INLINE bool 792 ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; } 793 MAKE_INLINE bool 794 ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; } 795 MAKE_INLINE bool 796 ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; } 797 MAKE_INLINE bool 798 ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; } 799 MAKE_INLINE char 800 ch_tolower(char ch) { return (char)tolower((unsigned char)ch); } 801 MAKE_INLINE char 802 ch_toupper(char ch) { return (char)toupper((unsigned char)ch); } 803 804 MAKE_INLINE void 805 cpp_skip_whitespace(const char **pp) 806 { 807 while (ch_isspace(**pp)) 808 (*pp)++; 809 } 810 811 MAKE_INLINE void 812 cpp_skip_hspace(const char **pp) 813 { 814 while (**pp == ' ' || **pp == '\t') 815 (*pp)++; 816 } 817 818 MAKE_INLINE void 819 pp_skip_whitespace(char **pp) 820 { 821 while (ch_isspace(**pp)) 822 (*pp)++; 823 } 824 825 MAKE_INLINE void 826 pp_skip_hspace(char **pp) 827 { 828 while (**pp == ' ' || **pp == '\t') 829 (*pp)++; 830 } 831 832 #if defined(lint) 833 # define MAKE_RCSID(id) extern void do_not_define_rcsid(void) 834 #elif defined(MAKE_NATIVE) 835 # include <sys/cdefs.h> 836 # define MAKE_RCSID(id) __RCSID(id) 837 #elif defined(MAKE_ALL_IN_ONE) && defined(__COUNTER__) 838 # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y) 839 # define MAKE_RCSID(id) static volatile char \ 840 MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id 841 #elif defined(MAKE_ALL_IN_ONE) 842 # define MAKE_RCSID(id) extern void do_not_define_rcsid(void) 843 #else 844 # define MAKE_RCSID(id) static volatile char rcsid[] = id 845 #endif 846 847 #endif /* MAKE_MAKE_H */ 848