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