1 /* $NetBSD: make.h,v 1.242 2021/01/10 21:20:46 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 /* 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 = 0x0001, 354 /* children of this target were made */ 355 CHILDMADE = 0x0002, 356 /* children don't exist, and we pretend made */ 357 FORCE = 0x0004, 358 /* Set by Make_ProcessWait() */ 359 DONE_WAIT = 0x0008, 360 /* Build requested by .ORDER processing */ 361 DONE_ORDER = 0x0010, 362 /* Node created from .depend */ 363 FROM_DEPEND = 0x0020, 364 /* We do it once only */ 365 DONE_ALLSRC = 0x0040, 366 /* Used by MakePrintStatus */ 367 CYCLE = 0x1000, 368 /* Used by MakePrintStatus */ 369 DONECYCLE = 0x2000, 370 /* Internal use only */ 371 INTERNAL = 0x4000 372 } GNodeFlags; 373 374 typedef struct List StringList; 375 typedef struct ListNode StringListNode; 376 377 typedef struct List GNodeList; 378 typedef struct ListNode GNodeListNode; 379 380 typedef struct List /* of CachedDir */ 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 /* Other nodes of the same name, for the '::' dependency operator. */ 433 GNodeList cohorts; 434 /* The "#n" suffix for this cohort, or "" for other nodes */ 435 char cohort_num[8]; 436 /* The number of unmade instances on the cohorts list */ 437 int unmade_cohorts; 438 /* Pointer to the first instance of a '::' node; only set when on a 439 * cohorts list */ 440 struct GNode *centurion; 441 442 /* Last time (sequence number) we tried to make this node */ 443 unsigned int checked_seqno; 444 445 /* The "local" variables that are specific to this target and this 446 * target only, such as $@, $<, $?. 447 * 448 * Also used for the global variable scopes VAR_GLOBAL, VAR_CMDLINE, 449 * VAR_INTERNAL, which contain variables with arbitrary names. */ 450 HashTable /* of Var pointer */ vars; 451 452 /* The commands to be given to a shell to create this target. */ 453 StringList commands; 454 455 /* Suffix for the node (determined by Suff_FindDeps and opaque to 456 * everyone but the Suff module) */ 457 struct Suffix *suffix; 458 459 /* Filename where the GNode got defined */ 460 /* XXX: What is the lifetime of this string? */ 461 const char *fname; 462 /* Line number where the GNode got defined */ 463 int lineno; 464 } GNode; 465 466 /* Error levels for diagnostics during parsing. */ 467 typedef enum ParseErrorLevel { 468 /* Exit when the current top-level makefile has been parsed 469 * completely. */ 470 PARSE_FATAL = 1, 471 /* Print "warning"; may be upgraded to fatal by the -w option. */ 472 PARSE_WARNING, 473 /* Informational, mainly used during development of makefiles. */ 474 PARSE_INFO 475 } ParseErrorLevel; 476 477 /* 478 * Values returned by Cond_EvalLine and Cond_EvalCondition. 479 */ 480 typedef enum CondEvalResult { 481 COND_PARSE, /* Parse the next lines */ 482 COND_SKIP, /* Skip the next lines */ 483 COND_INVALID /* Not a conditional statement */ 484 } CondEvalResult; 485 486 /* Names of the variables that are "local" to a specific target. */ 487 #define TARGET "@" /* Target of dependency */ 488 #define OODATE "?" /* All out-of-date sources */ 489 #define ALLSRC ">" /* All sources */ 490 #define IMPSRC "<" /* Source implied by transformation */ 491 #define PREFIX "*" /* Common prefix */ 492 #define ARCHIVE "!" /* Archive in "archive(member)" syntax */ 493 #define MEMBER "%" /* Member in "archive(member)" syntax */ 494 495 /* 496 * Global Variables 497 */ 498 499 /* True if every target is precious */ 500 extern Boolean allPrecious; 501 /* True if failed targets should be deleted */ 502 extern Boolean deleteOnError; 503 /* TRUE while processing .depend */ 504 extern Boolean doing_depend; 505 /* .DEFAULT rule */ 506 extern GNode *defaultNode; 507 508 /* 509 * Variables defined internally by make which should not override those set 510 * by makefiles. 511 */ 512 extern GNode *VAR_INTERNAL; 513 /* Variables defined in a global context, e.g in the Makefile itself. */ 514 extern GNode *VAR_GLOBAL; 515 /* Variables defined on the command line. */ 516 extern GNode *VAR_CMDLINE; 517 518 /* 519 * Value returned by Var_Parse when an error is encountered. It actually 520 * points to an empty string, so naive callers needn't worry about it. 521 */ 522 extern char var_Error[]; 523 524 /* The time at the start of this whole process */ 525 extern time_t now; 526 527 /* 528 * The list of directories to search when looking for targets (set by the 529 * special target .PATH). 530 */ 531 extern SearchPath dirSearchPath; 532 /* Used for .include "...". */ 533 extern SearchPath *parseIncPath; 534 /* 535 * Used for .include <...>, for the built-in sys.mk and makefiles from the 536 * command line arguments. 537 */ 538 extern SearchPath *sysIncPath; 539 /* The default for sysIncPath. */ 540 extern SearchPath *defSysIncPath; 541 542 /* Startup directory */ 543 extern char curdir[]; 544 /* The basename of the program name, suffixed with [n] for sub-makes. */ 545 extern const char *progname; 546 /* Name of the .depend makefile */ 547 extern char *makeDependfile; 548 /* If we replaced environ, this will be non-NULL. */ 549 extern char **savedEnv; 550 551 extern int makelevel; 552 553 /* 554 * We cannot vfork() in a child of vfork(). 555 * Most systems do not enforce this but some do. 556 */ 557 #define vFork() ((getpid() == myPid) ? vfork() : fork()) 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*/ 0) 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 /* -q: if true, we aren't supposed to really make anything, just see 675 * if the targets are out-of-date */ 676 Boolean queryFlag; 677 678 /* -r: raw mode, without loading the builtin rules. */ 679 Boolean noBuiltins; 680 681 /* -s: don't echo the shell commands before executing them */ 682 Boolean beSilent; 683 684 /* -t: touch the targets if they are out-of-date, but don't actually 685 * make them */ 686 Boolean touchFlag; 687 688 /* -[Vv]: print expanded or unexpanded selected variables */ 689 PrintVarsMode printVars; 690 /* -[Vv]: the variables to print */ 691 StringList variables; 692 693 /* -W: if true, makefile parsing warnings are treated as errors */ 694 Boolean parseWarnFatal; 695 696 /* -w: print Entering and Leaving for submakes */ 697 Boolean enterFlag; 698 699 /* -X: if true, do not export variables set on the command line to the 700 * environment. */ 701 Boolean varNoExportEnv; 702 703 /* The target names specified on the command line. 704 * Used to resolve .if make(...) statements. */ 705 StringList create; 706 707 } CmdOpts; 708 709 extern CmdOpts opts; 710 711 #include "nonints.h" 712 713 void GNode_UpdateYoungestChild(GNode *, GNode *); 714 Boolean GNode_IsOODate(GNode *); 715 void Make_ExpandUse(GNodeList *); 716 time_t Make_Recheck(GNode *); 717 void Make_HandleUse(GNode *, GNode *); 718 void Make_Update(GNode *); 719 void Make_DoAllVar(GNode *); 720 Boolean Make_Run(GNodeList *); 721 Boolean shouldDieQuietly(GNode *, int); 722 void PrintOnError(GNode *, const char *); 723 void Main_ExportMAKEFLAGS(Boolean); 724 Boolean Main_SetObjdir(Boolean, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3); 725 int mkTempFile(const char *, char **); 726 int str2Lst_Append(StringList *, char *); 727 void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *); 728 Boolean GNode_ShouldExecute(GNode *gn); 729 730 /* See if the node was seen on the left-hand side of a dependency operator. */ 731 MAKE_INLINE Boolean 732 GNode_IsTarget(const GNode *gn) 733 { 734 return (gn->type & OP_OPMASK) != 0; 735 } 736 737 MAKE_INLINE const char * 738 GNode_Path(const GNode *gn) 739 { 740 return gn->path != NULL ? gn->path : gn->name; 741 } 742 743 MAKE_INLINE Boolean 744 GNode_IsWaitingFor(const GNode *gn) 745 { 746 return (gn->flags & REMAKE) && gn->made <= REQUESTED; 747 } 748 749 MAKE_INLINE Boolean 750 GNode_IsReady(const GNode *gn) 751 { 752 return gn->made > DEFERRED; 753 } 754 755 MAKE_INLINE Boolean 756 GNode_IsDone(const GNode *gn) 757 { 758 return gn->made >= MADE; 759 } 760 761 MAKE_INLINE Boolean 762 GNode_IsError(const GNode *gn) 763 { 764 return gn->made == ERROR || gn->made == ABORTED; 765 } 766 767 MAKE_INLINE const char * 768 GNode_VarTarget(GNode *gn) { return Var_ValueDirect(TARGET, gn); } 769 MAKE_INLINE const char * 770 GNode_VarOodate(GNode *gn) { return Var_ValueDirect(OODATE, gn); } 771 MAKE_INLINE const char * 772 GNode_VarAllsrc(GNode *gn) { return Var_ValueDirect(ALLSRC, gn); } 773 MAKE_INLINE const char * 774 GNode_VarImpsrc(GNode *gn) { return Var_ValueDirect(IMPSRC, gn); } 775 MAKE_INLINE const char * 776 GNode_VarPrefix(GNode *gn) { return Var_ValueDirect(PREFIX, gn); } 777 MAKE_INLINE const char * 778 GNode_VarArchive(GNode *gn) { return Var_ValueDirect(ARCHIVE, gn); } 779 MAKE_INLINE const char * 780 GNode_VarMember(GNode *gn) { return Var_ValueDirect(MEMBER, gn); } 781 782 #ifdef __GNUC__ 783 #define UNCONST(ptr) ({ \ 784 union __unconst { \ 785 const void *__cp; \ 786 void *__p; \ 787 } __d; \ 788 __d.__cp = ptr, __d.__p; }) 789 #else 790 #define UNCONST(ptr) (void *)(ptr) 791 #endif 792 793 /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */ 794 #ifdef HAVE_LIMITS_H 795 #include <limits.h> 796 #endif 797 #ifndef MAXPATHLEN 798 #define MAXPATHLEN BMAKE_PATH_MAX 799 #endif 800 #ifndef PATH_MAX 801 #define PATH_MAX MAXPATHLEN 802 #endif 803 804 #if defined(SYSV) 805 #define KILLPG(pid, sig) kill(-(pid), (sig)) 806 #else 807 #define KILLPG(pid, sig) killpg((pid), (sig)) 808 #endif 809 810 MAKE_INLINE Boolean 811 ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; } 812 MAKE_INLINE Boolean 813 ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; } 814 MAKE_INLINE Boolean 815 ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; } 816 MAKE_INLINE Boolean 817 ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; } 818 MAKE_INLINE Boolean 819 ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; } 820 MAKE_INLINE char 821 ch_tolower(char ch) { return (char)tolower((unsigned char)ch); } 822 MAKE_INLINE char 823 ch_toupper(char ch) { return (char)toupper((unsigned char)ch); } 824 825 MAKE_INLINE void 826 cpp_skip_whitespace(const char **pp) 827 { 828 while (ch_isspace(**pp)) 829 (*pp)++; 830 } 831 832 MAKE_INLINE void 833 cpp_skip_hspace(const char **pp) 834 { 835 while (**pp == ' ' || **pp == '\t') 836 (*pp)++; 837 } 838 839 MAKE_INLINE void 840 pp_skip_whitespace(char **pp) 841 { 842 while (ch_isspace(**pp)) 843 (*pp)++; 844 } 845 846 MAKE_INLINE void 847 pp_skip_hspace(char **pp) 848 { 849 while (**pp == ' ' || **pp == '\t') 850 (*pp)++; 851 } 852 853 #if defined(lint) 854 # define MAKE_RCSID(id) extern void do_not_define_rcsid(void) 855 #elif defined(MAKE_NATIVE) 856 # include <sys/cdefs.h> 857 # define MAKE_RCSID(id) __RCSID(id) 858 #elif defined(MAKE_ALL_IN_ONE) && defined(__COUNTER__) 859 # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y) 860 # define MAKE_RCSID(id) static volatile char \ 861 MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id 862 #elif defined(MAKE_ALL_IN_ONE) 863 # define MAKE_RCSID(id) extern void do_not_define_rcsid(void) 864 #else 865 # define MAKE_RCSID(id) static volatile char rcsid[] = id 866 #endif 867 868 #endif /* MAKE_MAKE_H */ 869