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