[BACK]Return to make.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / make

Annotation of src/usr.bin/make/make.h, Revision 1.298

1.298   ! rillig      1: /*     $NetBSD: make.h,v 1.297 2022/02/04 23:22:19 rillig Exp $        */
1.6       christos    2:
1.1       cgd         3: /*
1.6       christos    4:  * Copyright (c) 1988, 1989, 1990, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
1.47      agc         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: /*
1.1       cgd        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:  *
1.11      christos   72:  *     from: @(#)make.h        8.3 (Berkeley) 6/13/95
1.1       cgd        73:  */
                     74:
1.244     rillig     75: /*
1.1       cgd        76:  * make.h --
1.290     rillig     77:  *     The global definitions for make
1.1       cgd        78:  */
                     79:
1.116     rillig     80: #ifndef MAKE_MAKE_H
                     81: #define MAKE_MAKE_H
1.1       cgd        82:
                     83: #include <sys/types.h>
1.13      christos   84: #include <sys/param.h>
1.135     rillig     85: #include <sys/stat.h>
1.44      wiz        86:
1.123     rillig     87: #include <assert.h>
1.44      wiz        88: #include <ctype.h>
1.97      christos   89: #include <fcntl.h>
1.150     rillig     90: #include <stdarg.h>
1.3       cgd        91: #include <stdio.h>
1.44      wiz        92: #include <stdlib.h>
1.1       cgd        93: #include <string.h>
1.44      wiz        94: #include <unistd.h>
1.12      christos   95:
1.19      tv         96: #ifdef BSD4_4
1.12      christos   97: # include <sys/cdefs.h>
1.4       glass      98: #endif
1.12      christos   99:
1.97      christos  100: #ifndef FD_CLOEXEC
                    101: #define FD_CLOEXEC 1
                    102: #endif
                    103:
1.259     rillig    104: #if defined(__GNUC__)
1.230     rillig    105: #define MAKE_GNUC_PREREQ(x, y)                                         \
1.52      yamt      106:        ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||                  \
                    107:         (__GNUC__ > (x)))
1.278     rillig    108: #else
1.230     rillig    109: #define MAKE_GNUC_PREREQ(x, y) 0
1.278     rillig    110: #endif
1.52      yamt      111:
1.89      joerg     112: #if MAKE_GNUC_PREREQ(2, 7)
1.230     rillig    113: #define MAKE_ATTR_UNUSED       __attribute__((__unused__))
1.51      jmc       114: #else
1.230     rillig    115: #define MAKE_ATTR_UNUSED       /* delete */
1.51      jmc       116: #endif
1.89      joerg     117:
                    118: #if MAKE_GNUC_PREREQ(2, 5)
1.230     rillig    119: #define MAKE_ATTR_DEAD         __attribute__((__noreturn__))
1.89      joerg     120: #elif defined(__GNUC__)
1.230     rillig    121: #define MAKE_ATTR_DEAD         __volatile
1.89      joerg     122: #else
1.230     rillig    123: #define MAKE_ATTR_DEAD         /* delete */
1.51      jmc       124: #endif
1.44      wiz       125:
1.89      joerg     126: #if MAKE_GNUC_PREREQ(2, 7)
                    127: #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg)      \
                    128:            __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
                    129: #else
                    130: #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg)      /* delete */
1.87      joerg     131: #endif
                    132:
1.273     rillig    133: #if MAKE_GNUC_PREREQ(4, 0)
1.278     rillig    134: #define MAKE_ATTR_USE          __attribute__((__warn_unused_result__))
1.273     rillig    135: #else
1.278     rillig    136: #define MAKE_ATTR_USE          /* delete */
1.273     rillig    137: #endif
                    138:
1.298   ! rillig    139: #if __STDC__ >= 199901L || defined(lint)
1.205     rillig    140: #define MAKE_INLINE static inline MAKE_ATTR_UNUSED
1.298   ! rillig    141: #else
        !           142: #define MAKE_INLINE static MAKE_ATTR_UNUSED
        !           143: #endif
1.264     rillig    144:
                    145: /* MAKE_STATIC marks a function that may or may not be inlined. */
                    146: #if defined(lint)
                    147: /* As of 2021-07-31, NetBSD lint ignores __attribute__((unused)). */
                    148: #define MAKE_STATIC MAKE_INLINE
                    149: #else
1.262     rillig    150: #define MAKE_STATIC static MAKE_ATTR_UNUSED
1.264     rillig    151: #endif
1.205     rillig    152:
1.257     rillig    153: #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN)
1.235     rillig    154: #include <stdbool.h>
1.265     rillig    155: #elif defined(__bool_true_false_are_defined)
                    156: /*
                    157:  * All files of make must be compiled with the same definition of bool.
                    158:  * Since one of the files includes <stdbool.h>, that means the header is
                    159:  * available on this platform.  Recompile everything with -DUSE_C99_BOOLEAN.
                    160:  */
                    161: #error "<stdbool.h> is included in pre-C99 mode"
                    162: #elif defined(bool) || defined(true) || defined(false)
                    163: /*
                    164:  * In pre-C99 mode, make does not expect that bool is already defined.
                    165:  * You need to ensure that all translation units use the same definition for
                    166:  * bool.
                    167:  */
                    168: #error "bool/true/false is defined in pre-C99 mode"
1.130     rillig    169: #else
1.265     rillig    170: typedef unsigned char bool;
1.257     rillig    171: #define true   1
                    172: #define false  0
1.140     rillig    173: #endif
1.127     rillig    174:
1.1       cgd       175: #include "lst.h"
1.261     rillig    176: #include "make_malloc.h"
                    177: #include "str.h"
1.22      mycroft   178: #include "hash.h"
1.1       cgd       179: #include "config.h"
1.3       cgd       180: #include "buf.h"
1.1       cgd       181:
1.216     rillig    182: /*
                    183:  * The typical flow of states is:
                    184:  *
                    185:  * The direct successful path:
                    186:  * UNMADE -> BEINGMADE -> MADE.
                    187:  *
                    188:  * The direct error path:
                    189:  * UNMADE -> BEINGMADE -> ERROR.
                    190:  *
                    191:  * The successful path when dependencies need to be made first:
                    192:  * UNMADE -> DEFERRED -> REQUESTED -> BEINGMADE -> MADE.
                    193:  *
                    194:  * A node that has dependencies, and one of the dependencies cannot be made:
                    195:  * UNMADE -> DEFERRED -> ABORTED.
                    196:  *
                    197:  * A node that turns out to be up-to-date:
                    198:  * UNMADE -> BEINGMADE -> UPTODATE.
                    199:  */
1.181     rillig    200: typedef enum GNodeMade {
1.219     rillig    201:        /* Not examined yet. */
                    202:        UNMADE,
1.277     rillig    203:        /*
                    204:         * The node has been examined but is not yet ready since its
                    205:         * dependencies have to be made first.
                    206:         */
1.219     rillig    207:        DEFERRED,
                    208:
                    209:        /* The node is on the toBeMade list. */
                    210:        REQUESTED,
                    211:
1.277     rillig    212:        /*
                    213:         * The node is already being made. Trying to build a node in this
                    214:         * state indicates a cycle in the graph.
                    215:         */
1.219     rillig    216:        BEINGMADE,
                    217:
                    218:        /* Was out-of-date and has been made. */
                    219:        MADE,
                    220:        /* Was already up-to-date, does not need to be made. */
                    221:        UPTODATE,
1.277     rillig    222:        /*
                    223:         * An error occurred while it was being made. Used only in compat
                    224:         * mode.
                    225:         */
1.219     rillig    226:        ERROR,
1.277     rillig    227:        /*
                    228:         * The target was aborted due to an error making a dependency. Used
                    229:         * only in compat mode.
                    230:         */
1.219     rillig    231:        ABORTED
1.119     rillig    232: } GNodeMade;
1.1       cgd       233:
1.241     rillig    234: /*
                    235:  * The OP_ constants are used when parsing a dependency line as a way of
1.120     rillig    236:  * communicating to other parts of the program the way in which a target
                    237:  * should be made.
                    238:  *
1.241     rillig    239:  * Some of the OP_ constants can be combined, others cannot.
1.263     rillig    240:  *
                    241:  * See the tests depsrc-*.mk and deptgt-*.mk.
1.241     rillig    242:  */
1.159     rillig    243: typedef enum GNodeType {
1.219     rillig    244:        OP_NONE         = 0,
1.209     rillig    245:
1.277     rillig    246:        /*
                    247:         * The dependency operator ':' is the most common one.  The commands
                    248:         * of this node are executed if any child is out-of-date.
                    249:         */
1.219     rillig    250:        OP_DEPENDS      = 1 << 0,
1.277     rillig    251:        /*
                    252:         * The dependency operator '!' always executes its commands, even if
                    253:         * its children are up-to-date.
                    254:         */
1.219     rillig    255:        OP_FORCE        = 1 << 1,
1.277     rillig    256:        /*
                    257:         * The dependency operator '::' behaves like ':', except that it
1.219     rillig    258:         * allows multiple dependency groups to be defined.  Each of these
1.277     rillig    259:         * groups is executed on its own, independently from the others. Each
                    260:         * individual dependency group is called a cohort.
                    261:         */
1.219     rillig    262:        OP_DOUBLEDEP    = 1 << 2,
                    263:
                    264:        /* Matches the dependency operators ':', '!' and '::'. */
                    265:        OP_OPMASK       = OP_DEPENDS | OP_FORCE | OP_DOUBLEDEP,
                    266:
                    267:        /* Don't care if the target doesn't exist and can't be created. */
                    268:        OP_OPTIONAL     = 1 << 3,
                    269:        /* Use associated commands for parents. */
                    270:        OP_USE          = 1 << 4,
1.277     rillig    271:        /*
                    272:         * Target is never out of date, but always execute commands anyway.
                    273:         * Its time doesn't matter, so it has none...sort of.
                    274:         */
1.219     rillig    275:        OP_EXEC         = 1 << 5,
1.277     rillig    276:        /*
                    277:         * Ignore non-zero exit status from shell commands when creating the
                    278:         * node.
                    279:         */
1.219     rillig    280:        OP_IGNORE       = 1 << 6,
                    281:        /* Don't remove the target when interrupted. */
                    282:        OP_PRECIOUS     = 1 << 7,
                    283:        /* Don't echo commands when executed. */
                    284:        OP_SILENT       = 1 << 8,
1.277     rillig    285:        /*
                    286:         * Target is a recursive make so its commands should always be
                    287:         * executed when it is out of date, regardless of the state of the -n
                    288:         * or -t flags.
                    289:         */
1.219     rillig    290:        OP_MAKE         = 1 << 9,
1.277     rillig    291:        /*
                    292:         * Target is out-of-date only if any of its children was out-of-date.
                    293:         */
1.219     rillig    294:        OP_JOIN         = 1 << 10,
                    295:        /* Assume the children of the node have been already made. */
                    296:        OP_MADE         = 1 << 11,
                    297:        /* Special .BEGIN, .END or .INTERRUPT. */
                    298:        OP_SPECIAL      = 1 << 12,
                    299:        /* Like .USE, only prepend commands. */
                    300:        OP_USEBEFORE    = 1 << 13,
1.277     rillig    301:        /*
                    302:         * The node is invisible to its parents. I.e. it doesn't show up in
                    303:         * the parents' local variables (.IMPSRC, .ALLSRC).
                    304:         */
1.219     rillig    305:        OP_INVISIBLE    = 1 << 14,
1.277     rillig    306:        /*
                    307:         * The node does not become the main target, even if it is the first
                    308:         * target in the first makefile.
                    309:         */
1.219     rillig    310:        OP_NOTMAIN      = 1 << 15,
                    311:        /* Not a file target; run always. */
                    312:        OP_PHONY        = 1 << 16,
                    313:        /* Don't search for the file in the path. */
                    314:        OP_NOPATH       = 1 << 17,
1.277     rillig    315:        /*
                    316:         * In a dependency line "target: source1 .WAIT source2", source1 is
1.219     rillig    317:         * made first, including its children.  Once that is finished,
                    318:         * source2 is made, including its children.  The .WAIT keyword may
1.277     rillig    319:         * appear more than once in a single dependency declaration.
                    320:         */
1.219     rillig    321:        OP_WAIT         = 1 << 18,
                    322:        /* .NOMETA do not create a .meta file */
                    323:        OP_NOMETA       = 1 << 19,
                    324:        /* .META we _do_ want a .meta file */
                    325:        OP_META         = 1 << 20,
                    326:        /* Do not compare commands in .meta file */
                    327:        OP_NOMETA_CMP   = 1 << 21,
                    328:        /* Possibly a submake node */
                    329:        OP_SUBMAKE      = 1 << 22,
                    330:
                    331:        /* Attributes applied by PMake */
                    332:
                    333:        /* The node is a transformation rule, such as ".c.o". */
                    334:        OP_TRANSFORM    = 1 << 30,
                    335:        /* Target is a member of an archive */
                    336:        /* XXX: How does this differ from OP_ARCHV? */
                    337:        OP_MEMBER       = 1 << 29,
1.277     rillig    338:        /*
                    339:         * The node is a library, its name has the form "-l<libname>".
                    340:         */
1.219     rillig    341:        OP_LIB          = 1 << 28,
1.277     rillig    342:        /*
                    343:         * The node is an archive member, its name has the form
                    344:         * "archive(member)".
                    345:         */
1.219     rillig    346:        /* XXX: How does this differ from OP_MEMBER? */
                    347:        OP_ARCHV        = 1 << 27,
1.277     rillig    348:        /*
                    349:         * Target has all the commands it should. Used when parsing to catch
1.219     rillig    350:         * multiple command groups for a target.  Only applies to the
1.277     rillig    351:         * dependency operators ':' and '!', but not to '::'.
                    352:         */
1.219     rillig    353:        OP_HAS_COMMANDS = 1 << 26,
1.277     rillig    354:        /*
                    355:         * The special command "..." has been seen. All further commands from
                    356:         * this node will be saved on the .END node instead, to be executed
                    357:         * at the very end.
                    358:         */
1.219     rillig    359:        OP_SAVE_CMDS    = 1 << 25,
1.277     rillig    360:        /*
                    361:         * Already processed by Suff_FindDeps, to find dependencies from
                    362:         * suffix transformation rules.
                    363:         */
1.219     rillig    364:        OP_DEPS_FOUND   = 1 << 24,
                    365:        /* Node found while expanding .ALLSRC */
1.298   ! rillig    366:        OP_MARK         = 1 << 23
1.120     rillig    367: } GNodeType;
                    368:
1.269     rillig    369: typedef struct GNodeFlags {
1.219     rillig    370:        /* this target needs to be (re)made */
1.268     rillig    371:        bool remake:1;
1.219     rillig    372:        /* children of this target were made */
1.268     rillig    373:        bool childMade:1;
1.219     rillig    374:        /* children don't exist, and we pretend made */
1.268     rillig    375:        bool force:1;
1.219     rillig    376:        /* Set by Make_ProcessWait() */
1.268     rillig    377:        bool doneWait:1;
1.219     rillig    378:        /* Build requested by .ORDER processing */
1.268     rillig    379:        bool doneOrder:1;
1.219     rillig    380:        /* Node created from .depend */
1.268     rillig    381:        bool fromDepend:1;
1.219     rillig    382:        /* We do it once only */
1.268     rillig    383:        bool doneAllsrc:1;
1.219     rillig    384:        /* Used by MakePrintStatus */
1.268     rillig    385:        bool cycle:1;
1.219     rillig    386:        /* Used by MakePrintStatus */
1.268     rillig    387:        bool doneCycle:1;
1.119     rillig    388: } GNodeFlags;
1.1       cgd       389:
1.143     rillig    390: typedef struct List StringList;
                    391: typedef struct ListNode StringListNode;
1.144     rillig    392:
1.143     rillig    393: typedef struct List GNodeList;
                    394: typedef struct ListNode GNodeListNode;
                    395:
1.246     rillig    396: typedef struct SearchPath {
                    397:        List /* of CachedDir */ dirs;
                    398: } SearchPath;
1.144     rillig    399:
1.241     rillig    400: /*
                    401:  * A graph node represents a target that can possibly be made, including its
                    402:  * relation to other targets and a lot of other details.
                    403:  */
1.119     rillig    404: typedef struct GNode {
1.219     rillig    405:        /* The target's name, such as "clean" or "make.c" */
                    406:        char *name;
                    407:        /* The unexpanded name of a .USE node */
                    408:        char *uname;
1.277     rillig    409:        /*
                    410:         * The full pathname of the file belonging to the target.
                    411:         *
1.219     rillig    412:         * XXX: What about .PHONY targets? These don't have an associated
1.277     rillig    413:         * path.
                    414:         */
1.219     rillig    415:        char *path;
                    416:
1.277     rillig    417:        /*
                    418:         * The type of operator used to define the sources (see the OP flags
1.219     rillig    419:         * below).
1.277     rillig    420:         *
                    421:         * XXX: This looks like a wild mixture of type and flags.
                    422:         */
1.219     rillig    423:        GNodeType type;
                    424:        GNodeFlags flags;
                    425:
                    426:        /* The state of processing on this node */
                    427:        GNodeMade made;
                    428:        /* The number of unmade children */
                    429:        int unmade;
                    430:
1.277     rillig    431:        /*
                    432:         * The modification time; 0 means the node does not have a
                    433:         * corresponding file; see GNode_IsOODate.
                    434:         */
1.219     rillig    435:        time_t mtime;
                    436:        struct GNode *youngestChild;
                    437:
1.277     rillig    438:        /*
                    439:         * The GNodes for which this node is an implied source. May be empty.
                    440:         * For example, when there is an inference rule for .c.o, the node
                    441:         * for file.c has the node for file.o in this list.
                    442:         */
1.225     rillig    443:        GNodeList implicitParents;
1.219     rillig    444:
1.277     rillig    445:        /*
                    446:         * The nodes that depend on this one, or in other words, the nodes
                    447:         * for which this is a source.
                    448:         */
1.222     rillig    449:        GNodeList parents;
1.219     rillig    450:        /* The nodes on which this one depends. */
1.222     rillig    451:        GNodeList children;
1.219     rillig    452:
1.277     rillig    453:        /*
                    454:         * .ORDER nodes we need made. The nodes that must be made (if they're
1.219     rillig    455:         * made) before this node can be made, but that do not enter into the
1.277     rillig    456:         * datedness of this node.
                    457:         */
1.223     rillig    458:        GNodeList order_pred;
1.277     rillig    459:        /*
                    460:         * .ORDER nodes who need us. The nodes that must be made (if they're
1.219     rillig    461:         * made at all) after this node is made, but that do not depend on
1.277     rillig    462:         * this node, in the normal sense.
                    463:         */
1.223     rillig    464:        GNodeList order_succ;
1.219     rillig    465:
1.245     rillig    466:        /*
                    467:         * Other nodes of the same name, for targets that were defined using
                    468:         * the '::' dependency operator (OP_DOUBLEDEP).
                    469:         */
1.224     rillig    470:        GNodeList cohorts;
1.219     rillig    471:        /* The "#n" suffix for this cohort, or "" for other nodes */
                    472:        char cohort_num[8];
                    473:        /* The number of unmade instances on the cohorts list */
                    474:        int unmade_cohorts;
1.277     rillig    475:        /*
                    476:         * Pointer to the first instance of a '::' node; only set when on a
                    477:         * cohorts list
                    478:         */
1.219     rillig    479:        struct GNode *centurion;
                    480:
                    481:        /* Last time (sequence number) we tried to make this node */
                    482:        unsigned int checked_seqno;
                    483:
1.252     rillig    484:        /*
                    485:         * The "local" variables that are specific to this target and this
1.219     rillig    486:         * target only, such as $@, $<, $?.
                    487:         *
1.252     rillig    488:         * Also used for the global variable scopes SCOPE_GLOBAL,
                    489:         * SCOPE_CMDLINE, SCOPE_INTERNAL, which contain variables with
                    490:         * arbitrary names.
                    491:         */
1.219     rillig    492:        HashTable /* of Var pointer */ vars;
                    493:
                    494:        /* The commands to be given to a shell to create this target. */
1.221     rillig    495:        StringList commands;
1.219     rillig    496:
1.277     rillig    497:        /*
                    498:         * Suffix for the node (determined by Suff_FindDeps and opaque to
                    499:         * everyone but the Suff module)
                    500:         */
1.219     rillig    501:        struct Suffix *suffix;
                    502:
1.271     rillig    503:        /* Filename where the GNode got defined, unlimited lifetime */
1.219     rillig    504:        const char *fname;
1.285     rillig    505:        /* Line number where the GNode got defined, 1-based */
1.297     rillig    506:        unsigned lineno;
1.1       cgd       507: } GNode;
                    508:
1.188     rillig    509: /* Error levels for diagnostics during parsing. */
1.167     rillig    510: typedef enum ParseErrorLevel {
1.277     rillig    511:        /*
                    512:         * Exit when the current top-level makefile has been parsed
                    513:         * completely.
                    514:         */
1.219     rillig    515:        PARSE_FATAL = 1,
                    516:        /* Print "warning"; may be upgraded to fatal by the -w option. */
                    517:        PARSE_WARNING,
                    518:        /* Informational, mainly used during development of makefiles. */
                    519:        PARSE_INFO
1.167     rillig    520: } ParseErrorLevel;
1.1       cgd       521:
                    522: /*
1.141     rillig    523:  * Values returned by Cond_EvalLine and Cond_EvalCondition.
1.1       cgd       524:  */
1.284     rillig    525: typedef enum CondResult {
1.283     rillig    526:        CR_TRUE,                /* Parse the next lines */
                    527:        CR_FALSE,               /* Skip the next lines */
                    528:        CR_ERROR                /* Unknown directive or parse error */
1.284     rillig    529: } CondResult;
1.1       cgd       530:
1.190     rillig    531: /* Names of the variables that are "local" to a specific target. */
1.277     rillig    532: #define TARGET "@"             /* Target of dependency */
                    533: #define OODATE "?"             /* All out-of-date sources */
                    534: #define ALLSRC ">"             /* All sources */
                    535: #define IMPSRC "<"             /* Source implied by transformation */
                    536: #define PREFIX "*"             /* Common prefix */
                    537: #define ARCHIVE        "!"             /* Archive in "archive(member)" syntax */
                    538: #define MEMBER "%"             /* Member in "archive(member)" syntax */
1.148     rillig    539:
1.1       cgd       540: /*
1.11      christos  541:  * Global Variables
1.1       cgd       542:  */
                    543:
1.190     rillig    544: /* True if every target is precious */
1.257     rillig    545: extern bool allPrecious;
1.190     rillig    546: /* True if failed targets should be deleted */
1.257     rillig    547: extern bool deleteOnError;
                    548: /* true while processing .depend */
                    549: extern bool doing_depend;
1.190     rillig    550: /* .DEFAULT rule */
1.207     rillig    551: extern GNode *defaultNode;
1.190     rillig    552:
1.241     rillig    553: /*
                    554:  * Variables defined internally by make which should not override those set
                    555:  * by makefiles.
                    556:  */
1.252     rillig    557: extern GNode *SCOPE_INTERNAL;
1.255     rillig    558: /* Variables defined in a global scope, e.g in the makefile itself. */
1.252     rillig    559: extern GNode *SCOPE_GLOBAL;
1.190     rillig    560: /* Variables defined on the command line. */
1.252     rillig    561: extern GNode *SCOPE_CMDLINE;
1.190     rillig    562:
1.241     rillig    563: /*
                    564:  * Value returned by Var_Parse when an error is encountered. It actually
                    565:  * points to an empty string, so naive callers needn't worry about it.
                    566:  */
1.190     rillig    567: extern char var_Error[];
                    568:
                    569: /* The time at the start of this whole process */
                    570: extern time_t now;
1.1       cgd       571:
1.241     rillig    572: /*
                    573:  * The list of directories to search when looking for targets (set by the
                    574:  * special target .PATH).
                    575:  */
1.229     rillig    576: extern SearchPath dirSearchPath;
1.186     rillig    577: /* Used for .include "...". */
                    578: extern SearchPath *parseIncPath;
1.241     rillig    579: /*
1.249     rillig    580:  * Used for .include <...>, for the built-in sys.mk and for makefiles from
                    581:  * the command line arguments.
1.241     rillig    582:  */
1.186     rillig    583: extern SearchPath *sysIncPath;
                    584: /* The default for sysIncPath. */
                    585: extern SearchPath *defSysIncPath;
1.32      christos  586:
1.191     rillig    587: /* Startup directory */
                    588: extern char curdir[];
                    589: /* The basename of the program name, suffixed with [n] for sub-makes.  */
1.234     rillig    590: extern const char *progname;
1.248     rillig    591: extern int makelevel;
1.191     rillig    592: /* Name of the .depend makefile */
                    593: extern char *makeDependfile;
1.187     rillig    594: /* If we replaced environ, this will be non-NULL. */
                    595: extern char **savedEnv;
1.287     rillig    596: extern GNode *mainNode;
1.30      sommerfe  597:
1.190     rillig    598: extern pid_t myPid;
1.82      sjg       599:
1.219     rillig    600: #define MAKEFLAGS      ".MAKEFLAGS"
                    601: #define MAKEOVERRIDES  ".MAKEOVERRIDES"
                    602: /* prefix when printing the target of a job */
                    603: #define MAKE_JOB_PREFIX        ".MAKE.JOB.PREFIX"
                    604: #define MAKE_EXPORTED  ".MAKE.EXPORTED"        /* exported variables */
                    605: #define MAKE_MAKEFILES ".MAKE.MAKEFILES"       /* all loaded makefiles */
                    606: #define MAKE_LEVEL     ".MAKE.LEVEL"           /* recursion level */
1.185     rillig    607: #define MAKE_MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
1.215     rillig    608: #define MAKE_DEPENDFILE        ".MAKE.DEPENDFILE"      /* .depend */
1.80      sjg       609: #define MAKE_MODE      ".MAKE.MODE"
1.91      sjg       610: #ifndef MAKE_LEVEL_ENV
                    611: # define MAKE_LEVEL_ENV        "MAKELEVEL"
                    612: #endif
1.1       cgd       613:
1.272     rillig    614: typedef struct DebugFlags {
1.275     rillig    615:        bool DEBUG_ARCH:1;
                    616:        bool DEBUG_COND:1;
                    617:        bool DEBUG_CWD:1;
                    618:        bool DEBUG_DIR:1;
                    619:        bool DEBUG_ERROR:1;
                    620:        bool DEBUG_FOR:1;
                    621:        bool DEBUG_GRAPH1:1;
                    622:        bool DEBUG_GRAPH2:1;
                    623:        bool DEBUG_GRAPH3:1;
                    624:        bool DEBUG_HASH:1;
                    625:        bool DEBUG_JOB:1;
                    626:        bool DEBUG_LOUD:1;
                    627:        bool DEBUG_MAKE:1;
                    628:        bool DEBUG_META:1;
                    629:        bool DEBUG_PARSE:1;
                    630:        bool DEBUG_SCRIPT:1;
                    631:        bool DEBUG_SHELL:1;
                    632:        bool DEBUG_SUFF:1;
                    633:        bool DEBUG_TARG:1;
                    634:        bool DEBUG_VAR:1;
1.170     rillig    635: } DebugFlags;
                    636:
1.219     rillig    637: #define CONCAT(a, b) a##b
1.1       cgd       638:
1.272     rillig    639: #define DEBUG(module) (opts.debug.CONCAT(DEBUG_, module))
1.1       cgd       640:
1.151     rillig    641: void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
1.150     rillig    642:
1.232     rillig    643: #define DEBUG_IMPL(module, args) \
                    644:        do { \
                    645:                if (DEBUG(module)) \
                    646:                        debug_printf args; \
1.266     rillig    647:        } while (false)
1.232     rillig    648:
1.296     rillig    649: #define DEBUG0(module, fmt) \
                    650:        DEBUG_IMPL(module, (fmt))
1.149     rillig    651: #define DEBUG1(module, fmt, arg1) \
1.232     rillig    652:        DEBUG_IMPL(module, (fmt, arg1))
1.149     rillig    653: #define DEBUG2(module, fmt, arg1, arg2) \
1.232     rillig    654:        DEBUG_IMPL(module, (fmt, arg1, arg2))
1.149     rillig    655: #define DEBUG3(module, fmt, arg1, arg2, arg3) \
1.232     rillig    656:        DEBUG_IMPL(module, (fmt, arg1, arg2, arg3))
1.149     rillig    657: #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \
1.232     rillig    658:        DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4))
1.149     rillig    659: #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \
1.232     rillig    660:        DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5))
1.149     rillig    661:
1.173     rillig    662: typedef enum PrintVarsMode {
1.219     rillig    663:        PVM_NONE,
                    664:        PVM_UNEXPANDED,
                    665:        PVM_EXPANDED
1.173     rillig    666: } PrintVarsMode;
                    667:
                    668: /* Command line options */
                    669: typedef struct CmdOpts {
1.219     rillig    670:        /* -B: whether we are make compatible */
1.257     rillig    671:        bool compatMake;
1.173     rillig    672:
1.277     rillig    673:        /*
                    674:         * -d: debug control: There is one bit per module.  It is up to the
                    675:         * module what debug information to print.
                    676:         */
1.219     rillig    677:        DebugFlags debug;
1.173     rillig    678:
1.219     rillig    679:        /* -df: debug output is written here - default stderr */
                    680:        FILE *debug_file;
1.173     rillig    681:
1.277     rillig    682:        /*
                    683:         * -dL: lint mode
1.219     rillig    684:         *
                    685:         * Runs make in strict mode, with additional checks and better error
1.277     rillig    686:         * handling.
                    687:         */
1.257     rillig    688:        bool strict;
1.204     rillig    689:
1.219     rillig    690:        /* -dV: for the -V option, print unexpanded variable values */
1.257     rillig    691:        bool debugVflag;
1.174     rillig    692:
1.219     rillig    693:        /* -e: check environment variables before global variables */
1.257     rillig    694:        bool checkEnvFirst;
1.173     rillig    695:
1.219     rillig    696:        /* -f: the makefiles to read */
1.226     rillig    697:        StringList makefiles;
1.173     rillig    698:
1.219     rillig    699:        /* -i: if true, ignore all errors from shell commands */
1.257     rillig    700:        bool ignoreErrors;
1.173     rillig    701:
1.277     rillig    702:        /*
                    703:         * -j: the maximum number of jobs that can run in parallel; this is
                    704:         * coordinated with the submakes
                    705:         */
1.219     rillig    706:        int maxJobs;
1.173     rillig    707:
1.277     rillig    708:        /*
                    709:         * -k: if true and an error occurs while making a node, continue
                    710:         * making nodes that do not depend on the erroneous node
                    711:         */
1.257     rillig    712:        bool keepgoing;
1.173     rillig    713:
1.219     rillig    714:        /* -N: execute no commands from the targets */
1.257     rillig    715:        bool noRecursiveExecute;
1.173     rillig    716:
1.219     rillig    717:        /* -n: execute almost no commands from the targets */
1.257     rillig    718:        bool noExecute;
1.173     rillig    719:
1.250     rillig    720:        /*
                    721:         * -q: if true, do not really make anything, just see if the targets
                    722:         * are out-of-date
                    723:         */
1.279     rillig    724:        bool query;
1.173     rillig    725:
1.250     rillig    726:        /* -r: raw mode, do not load the builtin rules. */
1.257     rillig    727:        bool noBuiltins;
1.173     rillig    728:
1.219     rillig    729:        /* -s: don't echo the shell commands before executing them */
1.279     rillig    730:        bool silent;
1.173     rillig    731:
1.277     rillig    732:        /*
                    733:         * -t: touch the targets if they are out-of-date, but don't actually
                    734:         * make them
                    735:         */
1.279     rillig    736:        bool touch;
1.173     rillig    737:
1.219     rillig    738:        /* -[Vv]: print expanded or unexpanded selected variables */
                    739:        PrintVarsMode printVars;
                    740:        /* -[Vv]: the variables to print */
1.227     rillig    741:        StringList variables;
1.173     rillig    742:
1.219     rillig    743:        /* -W: if true, makefile parsing warnings are treated as errors */
1.257     rillig    744:        bool parseWarnFatal;
1.173     rillig    745:
1.250     rillig    746:        /* -w: print 'Entering' and 'Leaving' for submakes */
1.257     rillig    747:        bool enterFlag;
1.173     rillig    748:
1.277     rillig    749:        /*
                    750:         * -X: if true, do not export variables set on the command line to
                    751:         * the environment.
                    752:         */
1.257     rillig    753:        bool varNoExportEnv;
1.173     rillig    754:
1.277     rillig    755:        /*
                    756:         * The target names specified on the command line. Used to resolve
                    757:         * .if make(...) statements.
                    758:         */
1.228     rillig    759:        StringList create;
1.173     rillig    760:
                    761: } CmdOpts;
                    762:
                    763: extern CmdOpts opts;
                    764:
1.290     rillig    765: /* arch.c */
                    766: void Arch_Init(void);
                    767: void Arch_End(void);
                    768:
                    769: bool Arch_ParseArchive(char **, GNodeList *, GNode *);
                    770: void Arch_Touch(GNode *);
                    771: void Arch_TouchLib(GNode *);
                    772: void Arch_UpdateMTime(GNode *gn);
                    773: void Arch_UpdateMemberMTime(GNode *gn);
                    774: void Arch_FindLib(GNode *, SearchPath *);
                    775: bool Arch_LibOODate(GNode *) MAKE_ATTR_USE;
                    776: bool Arch_IsLib(GNode *) MAKE_ATTR_USE;
                    777:
                    778: /* compat.c */
                    779: bool Compat_RunCommand(const char *, GNode *, StringListNode *);
                    780: void Compat_Run(GNodeList *);
                    781: void Compat_Make(GNode *, GNode *);
                    782:
                    783: /* cond.c */
                    784: CondResult Cond_EvalCondition(const char *) MAKE_ATTR_USE;
                    785: CondResult Cond_EvalLine(const char *) MAKE_ATTR_USE;
                    786: void Cond_restore_depth(unsigned int);
                    787: unsigned int Cond_save_depth(void) MAKE_ATTR_USE;
1.1       cgd       788:
1.290     rillig    789: /* dir.c; see also dir.h */
                    790:
                    791: MAKE_INLINE const char * MAKE_ATTR_USE
                    792: str_basename(const char *pathname)
                    793: {
                    794:        const char *lastSlash = strrchr(pathname, '/');
                    795:        return lastSlash != NULL ? lastSlash + 1 : pathname;
                    796: }
                    797:
                    798: MAKE_INLINE SearchPath * MAKE_ATTR_USE
                    799: SearchPath_New(void)
                    800: {
                    801:        SearchPath *path = bmake_malloc(sizeof *path);
                    802:        Lst_Init(&path->dirs);
                    803:        return path;
                    804: }
                    805:
                    806: void SearchPath_Free(SearchPath *);
                    807:
                    808: /* for.c */
                    809: struct ForLoop;
                    810: int For_Eval(const char *) MAKE_ATTR_USE;
                    811: bool For_Accum(const char *, int *) MAKE_ATTR_USE;
1.297     rillig    812: void For_Run(unsigned, unsigned);
1.290     rillig    813: bool For_NextIteration(struct ForLoop *, Buffer *);
                    814: char *ForLoop_Details(struct ForLoop *);
                    815: void ForLoop_Free(struct ForLoop *);
                    816:
                    817: /* job.c */
                    818: void JobReapChild(pid_t, int, bool);
                    819:
                    820: /* main.c */
                    821: void Main_ParseArgLine(const char *);
                    822: char *Cmd_Exec(const char *, char **) MAKE_ATTR_USE;
                    823: void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
                    824: void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
                    825: void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
                    826: void DieHorribly(void) MAKE_ATTR_DEAD;
                    827: void Finish(int) MAKE_ATTR_DEAD;
                    828: bool unlink_file(const char *) MAKE_ATTR_USE;
                    829: void execDie(const char *, const char *);
                    830: char *getTmpdir(void) MAKE_ATTR_USE;
                    831: bool ParseBoolean(const char *, bool) MAKE_ATTR_USE;
                    832: const char *cached_realpath(const char *, char *);
1.291     sjg       833: bool GetBooleanExpr(const char *, bool);
1.290     rillig    834:
                    835: /* parse.c */
                    836: void Parse_Init(void);
                    837: void Parse_End(void);
                    838:
1.297     rillig    839: void PrintLocation(FILE *, bool, const char *, unsigned);
1.293     rillig    840: void PrintStackTrace(bool);
1.290     rillig    841: void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
                    842: bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE;
                    843: void Parse_AddIncludeDir(const char *);
                    844: void Parse_File(const char *, int);
1.297     rillig    845: void Parse_PushInput(const char *, unsigned, unsigned, Buffer,
                    846:                     struct ForLoop *);
1.290     rillig    847: void Parse_MainName(GNodeList *);
                    848: int Parse_NumErrors(void) MAKE_ATTR_USE;
                    849:
                    850:
                    851: /* suff.c */
                    852: void Suff_Init(void);
                    853: void Suff_End(void);
                    854:
                    855: void Suff_ClearSuffixes(void);
                    856: bool Suff_IsTransform(const char *) MAKE_ATTR_USE;
                    857: GNode *Suff_AddTransform(const char *);
                    858: void Suff_EndTransform(GNode *);
                    859: void Suff_AddSuffix(const char *);
                    860: SearchPath *Suff_GetPath(const char *) MAKE_ATTR_USE;
                    861: void Suff_ExtendPaths(void);
                    862: void Suff_AddInclude(const char *);
                    863: void Suff_AddLib(const char *);
                    864: void Suff_FindDeps(GNode *);
                    865: SearchPath *Suff_FindPath(GNode *) MAKE_ATTR_USE;
                    866: void Suff_SetNull(const char *);
                    867: void Suff_PrintAll(void);
                    868: char *Suff_NamesStr(void) MAKE_ATTR_USE;
                    869:
                    870: /* targ.c */
                    871: void Targ_Init(void);
                    872: void Targ_End(void);
                    873:
                    874: void Targ_Stats(void);
                    875: GNodeList *Targ_List(void) MAKE_ATTR_USE;
                    876: GNode *GNode_New(const char *) MAKE_ATTR_USE;
                    877: GNode *Targ_FindNode(const char *) MAKE_ATTR_USE;
                    878: GNode *Targ_GetNode(const char *) MAKE_ATTR_USE;
                    879: GNode *Targ_NewInternalNode(const char *) MAKE_ATTR_USE;
                    880: GNode *Targ_GetEndNode(void);
                    881: void Targ_FindList(GNodeList *, StringList *);
                    882: void Targ_PrintCmds(GNode *);
                    883: void Targ_PrintNode(GNode *, int);
                    884: void Targ_PrintNodes(GNodeList *, int);
                    885: const char *Targ_FmtTime(time_t) MAKE_ATTR_USE;
                    886: void Targ_PrintType(GNodeType);
                    887: void Targ_PrintGraph(int);
                    888: void Targ_Propagate(void);
                    889: const char *GNodeMade_Name(GNodeMade) MAKE_ATTR_USE;
                    890:
                    891: /* var.c */
                    892: void Var_Init(void);
                    893: void Var_End(void);
                    894:
                    895: typedef enum VarEvalMode {
                    896:
                    897:        /*
                    898:         * Only parse the expression but don't evaluate any part of it.
                    899:         *
                    900:         * TODO: Document what Var_Parse and Var_Subst return in this mode.
                    901:         *  As of 2021-03-15, they return unspecified, inconsistent results.
                    902:         */
                    903:        VARE_PARSE_ONLY,
                    904:
                    905:        /* Parse and evaluate the expression. */
                    906:        VARE_WANTRES,
                    907:
                    908:        /*
                    909:         * Parse and evaluate the expression.  It is an error if a
                    910:         * subexpression evaluates to undefined.
                    911:         */
                    912:        VARE_UNDEFERR,
                    913:
                    914:        /*
                    915:         * Parse and evaluate the expression.  Keep '$$' as '$$' instead of
                    916:         * reducing it to a single '$'.  Subexpressions that evaluate to
                    917:         * undefined expand to an empty string.
                    918:         *
                    919:         * Used in variable assignments using the ':=' operator.  It allows
                    920:         * multiple such assignments to be chained without accidentally
                    921:         * expanding '$$file' to '$file' in the first assignment and
                    922:         * interpreting it as '${f}' followed by 'ile' in the next assignment.
                    923:         */
                    924:        VARE_EVAL_KEEP_DOLLAR,
                    925:
                    926:        /*
                    927:         * Parse and evaluate the expression.  Keep undefined variables as-is
                    928:         * instead of expanding them to an empty string.
                    929:         *
                    930:         * Example for a ':=' assignment:
                    931:         *      CFLAGS = $(.INCLUDES)
                    932:         *      CFLAGS := -I.. $(CFLAGS)
                    933:         *      # If .INCLUDES (an undocumented special variable, by the
                    934:         *      # way) is still undefined, the updated CFLAGS becomes
                    935:         *      # "-I.. $(.INCLUDES)".
                    936:         */
                    937:        VARE_EVAL_KEEP_UNDEF,
                    938:
                    939:        /*
                    940:         * Parse and evaluate the expression.  Keep '$$' as '$$' and preserve
                    941:         * undefined subexpressions.
                    942:         */
                    943:        VARE_KEEP_DOLLAR_UNDEF
                    944: } VarEvalMode;
                    945:
                    946: typedef enum VarSetFlags {
                    947:        VAR_SET_NONE            = 0,
                    948:
                    949:        /* do not export */
                    950:        VAR_SET_NO_EXPORT       = 1 << 0,
                    951:
                    952:        /*
                    953:         * Make the variable read-only. No further modification is possible,
                    954:         * except for another call to Var_Set with the same flag.
                    955:         */
                    956:        VAR_SET_READONLY        = 1 << 1
                    957: } VarSetFlags;
                    958:
                    959: /* The state of error handling returned by Var_Parse. */
                    960: typedef enum VarParseResult {
                    961:
                    962:        /* Both parsing and evaluation succeeded. */
                    963:        VPR_OK,
                    964:
                    965:        /* Parsing or evaluating failed, with an error message. */
                    966:        VPR_ERR,
                    967:
                    968:        /*
                    969:         * Parsing succeeded, undefined expressions are allowed and the
                    970:         * expression was still undefined after applying all modifiers.
                    971:         * No error message is printed in this case.
                    972:         *
                    973:         * Some callers handle this case differently, so return this
                    974:         * information to them, for now.
                    975:         *
                    976:         * TODO: Instead of having this special return value, rather ensure
                    977:         *  that VARE_EVAL_KEEP_UNDEF is processed properly.
                    978:         */
                    979:        VPR_UNDEF
                    980:
                    981: } VarParseResult;
                    982:
                    983: typedef enum VarExportMode {
                    984:        /* .export-env */
                    985:        VEM_ENV,
                    986:        /* .export: Initial export or update an already exported variable. */
                    987:        VEM_PLAIN,
                    988:        /* .export-literal: Do not expand the variable value. */
                    989:        VEM_LITERAL
                    990: } VarExportMode;
                    991:
                    992: void Var_Delete(GNode *, const char *);
                    993: void Var_Undef(const char *);
                    994: void Var_Set(GNode *, const char *, const char *);
                    995: void Var_SetExpand(GNode *, const char *, const char *);
                    996: void Var_SetWithFlags(GNode *, const char *, const char *, VarSetFlags);
                    997: void Var_Append(GNode *, const char *, const char *);
                    998: void Var_AppendExpand(GNode *, const char *, const char *);
                    999: bool Var_Exists(GNode *, const char *) MAKE_ATTR_USE;
                   1000: bool Var_ExistsExpand(GNode *, const char *) MAKE_ATTR_USE;
                   1001: FStr Var_Value(GNode *, const char *) MAKE_ATTR_USE;
                   1002: const char *GNode_ValueDirect(GNode *, const char *) MAKE_ATTR_USE;
                   1003: VarParseResult Var_Parse(const char **, GNode *, VarEvalMode, FStr *);
                   1004: VarParseResult Var_Subst(const char *, GNode *, VarEvalMode, char **);
                   1005: void Var_Expand(FStr *, GNode *, VarEvalMode);
                   1006: void Var_Stats(void);
                   1007: void Var_Dump(GNode *);
                   1008: void Var_ReexportVars(void);
                   1009: void Var_Export(VarExportMode, const char *);
                   1010: void Var_ExportVars(const char *);
                   1011: void Var_UnExport(bool, const char *);
                   1012:
                   1013: void Global_Set(const char *, const char *);
                   1014: void Global_Append(const char *, const char *);
                   1015: void Global_Delete(const char *);
                   1016:
                   1017: /* util.c */
                   1018: typedef void (*SignalProc)(int);
                   1019: SignalProc bmake_signal(int, SignalProc);
                   1020:
                   1021: /* make.c */
1.199     rillig   1022: void GNode_UpdateYoungestChild(GNode *, GNode *);
1.274     rillig   1023: bool GNode_IsOODate(GNode *) MAKE_ATTR_USE;
1.144     rillig   1024: void Make_ExpandUse(GNodeList *);
1.274     rillig   1025: time_t Make_Recheck(GNode *) MAKE_ATTR_USE;
1.44      wiz      1026: void Make_HandleUse(GNode *, GNode *);
                   1027: void Make_Update(GNode *);
1.260     rillig   1028: void GNode_SetLocalVars(GNode *);
1.257     rillig   1029: bool Make_Run(GNodeList *);
1.274     rillig   1030: bool shouldDieQuietly(GNode *, int) MAKE_ATTR_USE;
1.80      sjg      1031: void PrintOnError(GNode *, const char *);
1.257     rillig   1032: void Main_ExportMAKEFLAGS(bool);
                   1033: bool Main_SetObjdir(bool, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
1.274     rillig   1034: int mkTempFile(const char *, char *, size_t) MAKE_ATTR_USE;
1.208     rillig   1035: int str2Lst_Append(StringList *, char *);
1.126     rillig   1036: void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *);
1.274     rillig   1037: bool GNode_ShouldExecute(GNode *gn) MAKE_ATTR_USE;
1.155     rillig   1038:
1.164     rillig   1039: /* See if the node was seen on the left-hand side of a dependency operator. */
1.274     rillig   1040: MAKE_INLINE bool MAKE_ATTR_USE
1.164     rillig   1041: GNode_IsTarget(const GNode *gn)
1.155     rillig   1042: {
1.270     rillig   1043:        return (gn->type & OP_OPMASK) != OP_NONE;
1.155     rillig   1044: }
                   1045:
1.274     rillig   1046: MAKE_INLINE const char * MAKE_ATTR_USE
1.172     rillig   1047: GNode_Path(const GNode *gn)
                   1048: {
1.219     rillig   1049:        return gn->path != NULL ? gn->path : gn->name;
1.172     rillig   1050: }
                   1051:
1.274     rillig   1052: MAKE_INLINE bool MAKE_ATTR_USE
1.218     rillig   1053: GNode_IsWaitingFor(const GNode *gn)
                   1054: {
1.268     rillig   1055:        return gn->flags.remake && gn->made <= REQUESTED;
1.218     rillig   1056: }
                   1057:
1.274     rillig   1058: MAKE_INLINE bool MAKE_ATTR_USE
1.218     rillig   1059: GNode_IsReady(const GNode *gn)
                   1060: {
                   1061:        return gn->made > DEFERRED;
                   1062: }
                   1063:
1.274     rillig   1064: MAKE_INLINE bool MAKE_ATTR_USE
1.218     rillig   1065: GNode_IsDone(const GNode *gn)
                   1066: {
                   1067:        return gn->made >= MADE;
                   1068: }
                   1069:
1.274     rillig   1070: MAKE_INLINE bool MAKE_ATTR_USE
1.217     rillig   1071: GNode_IsError(const GNode *gn)
                   1072: {
                   1073:        return gn->made == ERROR || gn->made == ABORTED;
                   1074: }
                   1075:
1.280     rillig   1076: MAKE_INLINE bool MAKE_ATTR_USE
                   1077: GNode_IsMainCandidate(const GNode *gn)
                   1078: {
1.281     rillig   1079:        return (gn->type & (OP_NOTMAIN | OP_USE | OP_USEBEFORE |
                   1080:                            OP_EXEC | OP_TRANSFORM)) == 0;
1.280     rillig   1081: }
                   1082:
1.286     rillig   1083: /* Return whether the target file should be preserved on interrupt. */
                   1084: MAKE_INLINE bool MAKE_ATTR_USE
                   1085: GNode_IsPrecious(const GNode *gn)
                   1086: {
                   1087:        /* XXX: Why are '::' targets precious? */
                   1088:        return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP);
                   1089: }
                   1090:
1.274     rillig   1091: MAKE_INLINE const char * MAKE_ATTR_USE
1.254     rillig   1092: GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); }
1.274     rillig   1093: MAKE_INLINE const char * MAKE_ATTR_USE
1.254     rillig   1094: GNode_VarOodate(GNode *gn) { return GNode_ValueDirect(gn, OODATE); }
1.274     rillig   1095: MAKE_INLINE const char * MAKE_ATTR_USE
1.254     rillig   1096: GNode_VarAllsrc(GNode *gn) { return GNode_ValueDirect(gn, ALLSRC); }
1.274     rillig   1097: MAKE_INLINE const char * MAKE_ATTR_USE
1.254     rillig   1098: GNode_VarImpsrc(GNode *gn) { return GNode_ValueDirect(gn, IMPSRC); }
1.274     rillig   1099: MAKE_INLINE const char * MAKE_ATTR_USE
1.254     rillig   1100: GNode_VarPrefix(GNode *gn) { return GNode_ValueDirect(gn, PREFIX); }
1.274     rillig   1101: MAKE_INLINE const char * MAKE_ATTR_USE
1.254     rillig   1102: GNode_VarArchive(GNode *gn) { return GNode_ValueDirect(gn, ARCHIVE); }
1.274     rillig   1103: MAKE_INLINE const char * MAKE_ATTR_USE
1.254     rillig   1104: GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); }
1.178     rillig   1105:
1.274     rillig   1106: MAKE_INLINE void * MAKE_ATTR_USE
1.264     rillig   1107: UNCONST(const void *ptr)
                   1108: {
                   1109:        void *ret;
                   1110:        memcpy(&ret, &ptr, sizeof(ret));
                   1111:        return ret;
                   1112: }
1.49      sjg      1113:
1.96      pooka    1114: /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */
                   1115: #include <limits.h>
                   1116: #ifndef MAXPATHLEN
                   1117: #define MAXPATHLEN     4096
                   1118: #endif
                   1119: #ifndef PATH_MAX
                   1120: #define PATH_MAX       MAXPATHLEN
                   1121: #endif
                   1122:
1.103     sjg      1123: #if defined(SYSV)
1.219     rillig   1124: #define KILLPG(pid, sig) kill(-(pid), (sig))
1.103     sjg      1125: #else
1.219     rillig   1126: #define KILLPG(pid, sig) killpg((pid), (sig))
1.103     sjg      1127: #endif
                   1128:
1.274     rillig   1129: MAKE_INLINE bool MAKE_ATTR_USE
1.195     rillig   1130: ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; }
1.274     rillig   1131: MAKE_INLINE bool MAKE_ATTR_USE
1.195     rillig   1132: ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; }
1.274     rillig   1133: MAKE_INLINE bool MAKE_ATTR_USE
1.195     rillig   1134: ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; }
1.274     rillig   1135: MAKE_INLINE bool MAKE_ATTR_USE
1.289     rillig   1136: ch_islower(char ch) { return islower((unsigned char)ch) != 0; }
                   1137: MAKE_INLINE bool MAKE_ATTR_USE
1.195     rillig   1138: ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; }
1.274     rillig   1139: MAKE_INLINE bool MAKE_ATTR_USE
1.195     rillig   1140: ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; }
1.274     rillig   1141: MAKE_INLINE char MAKE_ATTR_USE
1.195     rillig   1142: ch_tolower(char ch) { return (char)tolower((unsigned char)ch); }
1.274     rillig   1143: MAKE_INLINE char MAKE_ATTR_USE
1.195     rillig   1144: ch_toupper(char ch) { return (char)toupper((unsigned char)ch); }
1.139     rillig   1145:
1.205     rillig   1146: MAKE_INLINE void
1.155     rillig   1147: cpp_skip_whitespace(const char **pp)
                   1148: {
1.219     rillig   1149:        while (ch_isspace(**pp))
                   1150:                (*pp)++;
1.155     rillig   1151: }
                   1152:
1.205     rillig   1153: MAKE_INLINE void
1.196     rillig   1154: cpp_skip_hspace(const char **pp)
                   1155: {
1.219     rillig   1156:        while (**pp == ' ' || **pp == '\t')
                   1157:                (*pp)++;
1.196     rillig   1158: }
                   1159:
1.288     rillig   1160: MAKE_INLINE bool
                   1161: cpp_skip_string(const char **pp, const char *s)
                   1162: {
                   1163:        const char *p = *pp;
                   1164:        while (*p == *s && *s != '\0')
                   1165:                p++, s++;
                   1166:        if (*s == '\0')
                   1167:                *pp = p;
                   1168:        return *s == '\0';
                   1169: }
                   1170:
1.205     rillig   1171: MAKE_INLINE void
1.155     rillig   1172: pp_skip_whitespace(char **pp)
                   1173: {
1.219     rillig   1174:        while (ch_isspace(**pp))
                   1175:                (*pp)++;
1.155     rillig   1176: }
                   1177:
1.205     rillig   1178: MAKE_INLINE void
1.197     rillig   1179: pp_skip_hspace(char **pp)
                   1180: {
1.219     rillig   1181:        while (**pp == ' ' || **pp == '\t')
                   1182:                (*pp)++;
1.197     rillig   1183: }
                   1184:
1.238     rillig   1185: #if defined(lint)
1.249     rillig   1186: # define MAKE_RCSID(id) extern void do_not_define_rcsid(void)
1.238     rillig   1187: #elif defined(MAKE_NATIVE)
1.249     rillig   1188: # include <sys/cdefs.h>
                   1189: # define MAKE_RCSID(id) __RCSID(id)
1.238     rillig   1190: #elif defined(MAKE_ALL_IN_ONE) && defined(__COUNTER__)
1.249     rillig   1191: # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y)
                   1192: # define MAKE_RCSID(id) static volatile char \
1.238     rillig   1193:        MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id
1.220     rillig   1194: #elif defined(MAKE_ALL_IN_ONE)
1.249     rillig   1195: # define MAKE_RCSID(id) extern void do_not_define_rcsid(void)
1.142     rillig   1196: #else
1.249     rillig   1197: # define MAKE_RCSID(id) static volatile char rcsid[] = id
1.142     rillig   1198: #endif
                   1199:
1.276     rillig   1200: #endif

CVSweb <webmaster@jp.NetBSD.org>