1*8c973ee2SSimon J. Gerraty /* $NetBSD: make.h,v 1.319 2023/03/28 14:39:31 rillig Exp $ */ 23955d011SMarcel Moolenaar 33955d011SMarcel Moolenaar /* 43955d011SMarcel Moolenaar * Copyright (c) 1988, 1989, 1990, 1993 53955d011SMarcel Moolenaar * The Regents of the University of California. All rights reserved. 63955d011SMarcel Moolenaar * 73955d011SMarcel Moolenaar * This code is derived from software contributed to Berkeley by 83955d011SMarcel Moolenaar * Adam de Boor. 93955d011SMarcel Moolenaar * 103955d011SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 113955d011SMarcel Moolenaar * modification, are permitted provided that the following conditions 123955d011SMarcel Moolenaar * are met: 133955d011SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 143955d011SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 153955d011SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 163955d011SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 173955d011SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 183955d011SMarcel Moolenaar * 3. Neither the name of the University nor the names of its contributors 193955d011SMarcel Moolenaar * may be used to endorse or promote products derived from this software 203955d011SMarcel Moolenaar * without specific prior written permission. 213955d011SMarcel Moolenaar * 223955d011SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 233955d011SMarcel Moolenaar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 243955d011SMarcel Moolenaar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 253955d011SMarcel Moolenaar * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 263955d011SMarcel Moolenaar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 273955d011SMarcel Moolenaar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 283955d011SMarcel Moolenaar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 293955d011SMarcel Moolenaar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 303955d011SMarcel Moolenaar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 313955d011SMarcel Moolenaar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 323955d011SMarcel Moolenaar * SUCH DAMAGE. 333955d011SMarcel Moolenaar * 343955d011SMarcel Moolenaar * from: @(#)make.h 8.3 (Berkeley) 6/13/95 353955d011SMarcel Moolenaar */ 363955d011SMarcel Moolenaar 373955d011SMarcel Moolenaar /* 383955d011SMarcel Moolenaar * Copyright (c) 1989 by Berkeley Softworks 393955d011SMarcel Moolenaar * All rights reserved. 403955d011SMarcel Moolenaar * 413955d011SMarcel Moolenaar * This code is derived from software contributed to Berkeley by 423955d011SMarcel Moolenaar * Adam de Boor. 433955d011SMarcel Moolenaar * 443955d011SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 453955d011SMarcel Moolenaar * modification, are permitted provided that the following conditions 463955d011SMarcel Moolenaar * are met: 473955d011SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 483955d011SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 493955d011SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 503955d011SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 513955d011SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 523955d011SMarcel Moolenaar * 3. All advertising materials mentioning features or use of this software 533955d011SMarcel Moolenaar * must display the following acknowledgement: 543955d011SMarcel Moolenaar * This product includes software developed by the University of 553955d011SMarcel Moolenaar * California, Berkeley and its contributors. 563955d011SMarcel Moolenaar * 4. Neither the name of the University nor the names of its contributors 573955d011SMarcel Moolenaar * may be used to endorse or promote products derived from this software 583955d011SMarcel Moolenaar * without specific prior written permission. 593955d011SMarcel Moolenaar * 603955d011SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 613955d011SMarcel Moolenaar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 623955d011SMarcel Moolenaar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 633955d011SMarcel Moolenaar * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 643955d011SMarcel Moolenaar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 653955d011SMarcel Moolenaar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 663955d011SMarcel Moolenaar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 673955d011SMarcel Moolenaar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 683955d011SMarcel Moolenaar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 693955d011SMarcel Moolenaar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 703955d011SMarcel Moolenaar * SUCH DAMAGE. 713955d011SMarcel Moolenaar * 723955d011SMarcel Moolenaar * from: @(#)make.h 8.3 (Berkeley) 6/13/95 733955d011SMarcel Moolenaar */ 743955d011SMarcel Moolenaar 75dba7b0efSSimon J. Gerraty /* 763955d011SMarcel Moolenaar * make.h -- 779f45a3c8SSimon J. Gerraty * The global definitions for make 783955d011SMarcel Moolenaar */ 793955d011SMarcel Moolenaar 802c3632d1SSimon J. Gerraty #ifndef MAKE_MAKE_H 812c3632d1SSimon J. Gerraty #define MAKE_MAKE_H 823955d011SMarcel Moolenaar 833955d011SMarcel Moolenaar #ifdef HAVE_CONFIG_H 843955d011SMarcel Moolenaar # include "config.h" 853955d011SMarcel Moolenaar #endif 863955d011SMarcel Moolenaar 873955d011SMarcel Moolenaar #include <sys/types.h> 883955d011SMarcel Moolenaar #include <sys/param.h> 892c3632d1SSimon J. Gerraty #include <sys/stat.h> 903955d011SMarcel Moolenaar 912c3632d1SSimon J. Gerraty #include <assert.h> 923955d011SMarcel Moolenaar #include <ctype.h> 93be19d90bSSimon J. Gerraty #include <fcntl.h> 94956e45f6SSimon J. Gerraty #include <stdarg.h> 953955d011SMarcel Moolenaar #include <stdio.h> 963955d011SMarcel Moolenaar #include <stdlib.h> 973955d011SMarcel Moolenaar #ifdef HAVE_STRING_H 983955d011SMarcel Moolenaar #include <string.h> 993955d011SMarcel Moolenaar #else 1003955d011SMarcel Moolenaar #include <strings.h> 1013955d011SMarcel Moolenaar #endif 1023955d011SMarcel Moolenaar #include <unistd.h> 1033955d011SMarcel Moolenaar #include <sys/cdefs.h> 1043955d011SMarcel Moolenaar 105be19d90bSSimon J. Gerraty #ifndef FD_CLOEXEC 106be19d90bSSimon J. Gerraty #define FD_CLOEXEC 1 107be19d90bSSimon J. Gerraty #endif 108be19d90bSSimon J. Gerraty 1093955d011SMarcel Moolenaar #if defined(__GNUC__) 1103955d011SMarcel Moolenaar #define MAKE_GNUC_PREREQ(x, y) \ 1113955d011SMarcel Moolenaar ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 1123955d011SMarcel Moolenaar (__GNUC__ > (x))) 1139f45a3c8SSimon J. Gerraty #else 1141748de26SSimon J. Gerraty #define MAKE_GNUC_PREREQ(x, y) 0 1159f45a3c8SSimon J. Gerraty #endif 1163955d011SMarcel Moolenaar 1173955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 7) 1183955d011SMarcel Moolenaar #define MAKE_ATTR_UNUSED __attribute__((__unused__)) 1193955d011SMarcel Moolenaar #else 1203955d011SMarcel Moolenaar #define MAKE_ATTR_UNUSED /* delete */ 1213955d011SMarcel Moolenaar #endif 1223955d011SMarcel Moolenaar 1233955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 5) 1243955d011SMarcel Moolenaar #define MAKE_ATTR_DEAD __attribute__((__noreturn__)) 1253955d011SMarcel Moolenaar #elif defined(__GNUC__) 1263955d011SMarcel Moolenaar #define MAKE_ATTR_DEAD __volatile 1273955d011SMarcel Moolenaar #else 1283955d011SMarcel Moolenaar #define MAKE_ATTR_DEAD /* delete */ 1293955d011SMarcel Moolenaar #endif 1303955d011SMarcel Moolenaar 1313955d011SMarcel Moolenaar #if MAKE_GNUC_PREREQ(2, 7) 1323955d011SMarcel Moolenaar #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) \ 1333955d011SMarcel Moolenaar __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 1343955d011SMarcel Moolenaar #else 1353955d011SMarcel Moolenaar #define MAKE_ATTR_PRINTFLIKE(fmtarg, firstvararg) /* delete */ 1363955d011SMarcel Moolenaar #endif 1373955d011SMarcel Moolenaar 1389f45a3c8SSimon J. Gerraty #if MAKE_GNUC_PREREQ(4, 0) 1399f45a3c8SSimon J. Gerraty #define MAKE_ATTR_USE __attribute__((__warn_unused_result__)) 1409f45a3c8SSimon J. Gerraty #else 1419f45a3c8SSimon J. Gerraty #define MAKE_ATTR_USE /* delete */ 1429f45a3c8SSimon J. Gerraty #endif 1439f45a3c8SSimon J. Gerraty 1441d3f2ddcSSimon J. Gerraty #if __STDC_VERSION__ >= 199901L || defined(lint) 145e2eeea75SSimon J. Gerraty #define MAKE_INLINE static inline MAKE_ATTR_UNUSED 1469f45a3c8SSimon J. Gerraty #else 1479f45a3c8SSimon J. Gerraty #define MAKE_INLINE static MAKE_ATTR_UNUSED 1489f45a3c8SSimon J. Gerraty #endif 14912904384SSimon J. Gerraty 15012904384SSimon J. Gerraty /* MAKE_STATIC marks a function that may or may not be inlined. */ 15112904384SSimon J. Gerraty #if defined(lint) 15212904384SSimon J. Gerraty /* As of 2021-07-31, NetBSD lint ignores __attribute__((unused)). */ 15312904384SSimon J. Gerraty #define MAKE_STATIC MAKE_INLINE 15412904384SSimon J. Gerraty #else 155b0c40a00SSimon J. Gerraty #define MAKE_STATIC static MAKE_ATTR_UNUSED 15612904384SSimon J. Gerraty #endif 157e2eeea75SSimon J. Gerraty 158b0c40a00SSimon J. Gerraty #if __STDC_VERSION__ >= 199901L || defined(lint) || defined(USE_C99_BOOLEAN) 15906b9b3e0SSimon J. Gerraty #include <stdbool.h> 16012904384SSimon J. Gerraty #elif defined(__bool_true_false_are_defined) 16112904384SSimon J. Gerraty /* 16212904384SSimon J. Gerraty * All files of make must be compiled with the same definition of bool. 16312904384SSimon J. Gerraty * Since one of the files includes <stdbool.h>, that means the header is 16412904384SSimon J. Gerraty * available on this platform. Recompile everything with -DUSE_C99_BOOLEAN. 16512904384SSimon J. Gerraty */ 16612904384SSimon J. Gerraty #error "<stdbool.h> is included in pre-C99 mode" 16712904384SSimon J. Gerraty #elif defined(bool) || defined(true) || defined(false) 16812904384SSimon J. Gerraty /* 16912904384SSimon J. Gerraty * In pre-C99 mode, make does not expect that bool is already defined. 17012904384SSimon J. Gerraty * You need to ensure that all translation units use the same definition for 17112904384SSimon J. Gerraty * bool. 17212904384SSimon J. Gerraty */ 17312904384SSimon J. Gerraty #error "bool/true/false is defined in pre-C99 mode" 1742c3632d1SSimon J. Gerraty #else 17512904384SSimon J. Gerraty typedef unsigned char bool; 176b0c40a00SSimon J. Gerraty #define true 1 177b0c40a00SSimon J. Gerraty #define false 0 178956e45f6SSimon J. Gerraty #endif 1792c3632d1SSimon J. Gerraty 1803955d011SMarcel Moolenaar #include "lst.h" 181b0c40a00SSimon J. Gerraty #include "make_malloc.h" 182b0c40a00SSimon J. Gerraty #include "str.h" 1833955d011SMarcel Moolenaar #include "hash.h" 1843955d011SMarcel Moolenaar #include "make-conf.h" 1853955d011SMarcel Moolenaar #include "buf.h" 1863955d011SMarcel Moolenaar 1873955d011SMarcel Moolenaar /* 1883955d011SMarcel Moolenaar * some vendors don't have this --sjg 1893955d011SMarcel Moolenaar */ 1903955d011SMarcel Moolenaar #if defined(S_IFDIR) && !defined(S_ISDIR) 1913955d011SMarcel Moolenaar # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 1923955d011SMarcel Moolenaar #endif 1933955d011SMarcel Moolenaar 1943955d011SMarcel Moolenaar #if defined(sun) && (defined(__svr4__) || defined(__SVR4)) 1953955d011SMarcel Moolenaar # define POSIX_SIGNALS 1963955d011SMarcel Moolenaar #endif 1973955d011SMarcel Moolenaar 19806b9b3e0SSimon J. Gerraty /* 19906b9b3e0SSimon J. Gerraty * The typical flow of states is: 20006b9b3e0SSimon J. Gerraty * 20106b9b3e0SSimon J. Gerraty * The direct successful path: 20206b9b3e0SSimon J. Gerraty * UNMADE -> BEINGMADE -> MADE. 20306b9b3e0SSimon J. Gerraty * 20406b9b3e0SSimon J. Gerraty * The direct error path: 20506b9b3e0SSimon J. Gerraty * UNMADE -> BEINGMADE -> ERROR. 20606b9b3e0SSimon J. Gerraty * 20706b9b3e0SSimon J. Gerraty * The successful path when dependencies need to be made first: 20806b9b3e0SSimon J. Gerraty * UNMADE -> DEFERRED -> REQUESTED -> BEINGMADE -> MADE. 20906b9b3e0SSimon J. Gerraty * 21006b9b3e0SSimon J. Gerraty * A node that has dependencies, and one of the dependencies cannot be made: 21106b9b3e0SSimon J. Gerraty * UNMADE -> DEFERRED -> ABORTED. 21206b9b3e0SSimon J. Gerraty * 21306b9b3e0SSimon J. Gerraty * A node that turns out to be up-to-date: 21406b9b3e0SSimon J. Gerraty * UNMADE -> BEINGMADE -> UPTODATE. 21506b9b3e0SSimon J. Gerraty */ 216e2eeea75SSimon J. Gerraty typedef enum GNodeMade { 21706b9b3e0SSimon J. Gerraty /* Not examined yet. */ 21806b9b3e0SSimon J. Gerraty UNMADE, 2199f45a3c8SSimon J. Gerraty /* 2209f45a3c8SSimon J. Gerraty * The node has been examined but is not yet ready since its 2219f45a3c8SSimon J. Gerraty * dependencies have to be made first. 2229f45a3c8SSimon J. Gerraty */ 22306b9b3e0SSimon J. Gerraty DEFERRED, 22406b9b3e0SSimon J. Gerraty 22506b9b3e0SSimon J. Gerraty /* The node is on the toBeMade list. */ 22606b9b3e0SSimon J. Gerraty REQUESTED, 22706b9b3e0SSimon J. Gerraty 2289f45a3c8SSimon J. Gerraty /* 2299f45a3c8SSimon J. Gerraty * The node is already being made. Trying to build a node in this 2309f45a3c8SSimon J. Gerraty * state indicates a cycle in the graph. 2319f45a3c8SSimon J. Gerraty */ 23206b9b3e0SSimon J. Gerraty BEINGMADE, 23306b9b3e0SSimon J. Gerraty 23406b9b3e0SSimon J. Gerraty /* Was out-of-date and has been made. */ 23506b9b3e0SSimon J. Gerraty MADE, 23606b9b3e0SSimon J. Gerraty /* Was already up-to-date, does not need to be made. */ 23706b9b3e0SSimon J. Gerraty UPTODATE, 2389f45a3c8SSimon J. Gerraty /* 2399f45a3c8SSimon J. Gerraty * An error occurred while it was being made. Used only in compat 2409f45a3c8SSimon J. Gerraty * mode. 2419f45a3c8SSimon J. Gerraty */ 24206b9b3e0SSimon J. Gerraty ERROR, 2439f45a3c8SSimon J. Gerraty /* 2449f45a3c8SSimon J. Gerraty * The target was aborted due to an error making a dependency. Used 2459f45a3c8SSimon J. Gerraty * only in compat mode. 2469f45a3c8SSimon J. Gerraty */ 24706b9b3e0SSimon J. Gerraty ABORTED 2482c3632d1SSimon J. Gerraty } GNodeMade; 2493955d011SMarcel Moolenaar 25006b9b3e0SSimon J. Gerraty /* 25106b9b3e0SSimon J. Gerraty * The OP_ constants are used when parsing a dependency line as a way of 2522c3632d1SSimon J. Gerraty * communicating to other parts of the program the way in which a target 2532c3632d1SSimon J. Gerraty * should be made. 2542c3632d1SSimon J. Gerraty * 25506b9b3e0SSimon J. Gerraty * Some of the OP_ constants can be combined, others cannot. 256b0c40a00SSimon J. Gerraty * 257b0c40a00SSimon J. Gerraty * See the tests depsrc-*.mk and deptgt-*.mk. 25806b9b3e0SSimon J. Gerraty */ 259956e45f6SSimon J. Gerraty typedef enum GNodeType { 260e2eeea75SSimon J. Gerraty OP_NONE = 0, 261e2eeea75SSimon J. Gerraty 2629f45a3c8SSimon J. Gerraty /* 2639f45a3c8SSimon J. Gerraty * The dependency operator ':' is the most common one. The commands 2649f45a3c8SSimon J. Gerraty * of this node are executed if any child is out-of-date. 2659f45a3c8SSimon J. Gerraty */ 2662c3632d1SSimon J. Gerraty OP_DEPENDS = 1 << 0, 2679f45a3c8SSimon J. Gerraty /* 2689f45a3c8SSimon J. Gerraty * The dependency operator '!' always executes its commands, even if 2699f45a3c8SSimon J. Gerraty * its children are up-to-date. 2709f45a3c8SSimon J. Gerraty */ 2712c3632d1SSimon J. Gerraty OP_FORCE = 1 << 1, 2729f45a3c8SSimon J. Gerraty /* 2739f45a3c8SSimon J. Gerraty * The dependency operator '::' behaves like ':', except that it 27406b9b3e0SSimon J. Gerraty * allows multiple dependency groups to be defined. Each of these 2759f45a3c8SSimon J. Gerraty * groups is executed on its own, independently from the others. Each 2769f45a3c8SSimon J. Gerraty * individual dependency group is called a cohort. 2779f45a3c8SSimon J. Gerraty */ 2782c3632d1SSimon J. Gerraty OP_DOUBLEDEP = 1 << 2, 2792c3632d1SSimon J. Gerraty 280956e45f6SSimon J. Gerraty /* Matches the dependency operators ':', '!' and '::'. */ 2812c3632d1SSimon J. Gerraty OP_OPMASK = OP_DEPENDS | OP_FORCE | OP_DOUBLEDEP, 2822c3632d1SSimon J. Gerraty 28306b9b3e0SSimon J. Gerraty /* Don't care if the target doesn't exist and can't be created. */ 2842c3632d1SSimon J. Gerraty OP_OPTIONAL = 1 << 3, 28506b9b3e0SSimon J. Gerraty /* Use associated commands for parents. */ 2862c3632d1SSimon J. Gerraty OP_USE = 1 << 4, 2879f45a3c8SSimon J. Gerraty /* 2889f45a3c8SSimon J. Gerraty * Target is never out of date, but always execute commands anyway. 2899f45a3c8SSimon J. Gerraty * Its time doesn't matter, so it has none...sort of. 2909f45a3c8SSimon J. Gerraty */ 2912c3632d1SSimon J. Gerraty OP_EXEC = 1 << 5, 2929f45a3c8SSimon J. Gerraty /* 2939f45a3c8SSimon J. Gerraty * Ignore non-zero exit status from shell commands when creating the 2949f45a3c8SSimon J. Gerraty * node. 2959f45a3c8SSimon J. Gerraty */ 2962c3632d1SSimon J. Gerraty OP_IGNORE = 1 << 6, 29706b9b3e0SSimon J. Gerraty /* Don't remove the target when interrupted. */ 2982c3632d1SSimon J. Gerraty OP_PRECIOUS = 1 << 7, 29906b9b3e0SSimon J. Gerraty /* Don't echo commands when executed. */ 3002c3632d1SSimon J. Gerraty OP_SILENT = 1 << 8, 3019f45a3c8SSimon J. Gerraty /* 3029f45a3c8SSimon J. Gerraty * Target is a recursive make so its commands should always be 3039f45a3c8SSimon J. Gerraty * executed when it is out of date, regardless of the state of the -n 3049f45a3c8SSimon J. Gerraty * or -t flags. 3059f45a3c8SSimon J. Gerraty */ 3062c3632d1SSimon J. Gerraty OP_MAKE = 1 << 9, 3079f45a3c8SSimon J. Gerraty /* 3089f45a3c8SSimon J. Gerraty * Target is out-of-date only if any of its children was out-of-date. 3099f45a3c8SSimon J. Gerraty */ 3102c3632d1SSimon J. Gerraty OP_JOIN = 1 << 10, 31106b9b3e0SSimon J. Gerraty /* Assume the children of the node have been already made. */ 3122c3632d1SSimon J. Gerraty OP_MADE = 1 << 11, 31306b9b3e0SSimon J. Gerraty /* Special .BEGIN, .END or .INTERRUPT. */ 3142c3632d1SSimon J. Gerraty OP_SPECIAL = 1 << 12, 31506b9b3e0SSimon J. Gerraty /* Like .USE, only prepend commands. */ 3162c3632d1SSimon J. Gerraty OP_USEBEFORE = 1 << 13, 3179f45a3c8SSimon J. Gerraty /* 3189f45a3c8SSimon J. Gerraty * The node is invisible to its parents. I.e. it doesn't show up in 3199f45a3c8SSimon J. Gerraty * the parents' local variables (.IMPSRC, .ALLSRC). 3209f45a3c8SSimon J. Gerraty */ 3212c3632d1SSimon J. Gerraty OP_INVISIBLE = 1 << 14, 3229f45a3c8SSimon J. Gerraty /* 3239f45a3c8SSimon J. Gerraty * The node does not become the main target, even if it is the first 3249f45a3c8SSimon J. Gerraty * target in the first makefile. 3259f45a3c8SSimon J. Gerraty */ 3262c3632d1SSimon J. Gerraty OP_NOTMAIN = 1 << 15, 32706b9b3e0SSimon J. Gerraty /* Not a file target; run always. */ 3282c3632d1SSimon J. Gerraty OP_PHONY = 1 << 16, 32906b9b3e0SSimon J. Gerraty /* Don't search for the file in the path. */ 3302c3632d1SSimon J. Gerraty OP_NOPATH = 1 << 17, 3319f45a3c8SSimon J. Gerraty /* 3329f45a3c8SSimon J. Gerraty * In a dependency line "target: source1 .WAIT source2", source1 is 33306b9b3e0SSimon J. Gerraty * made first, including its children. Once that is finished, 33406b9b3e0SSimon J. Gerraty * source2 is made, including its children. The .WAIT keyword may 3359f45a3c8SSimon J. Gerraty * appear more than once in a single dependency declaration. 3369f45a3c8SSimon J. Gerraty */ 3372c3632d1SSimon J. Gerraty OP_WAIT = 1 << 18, 3382c3632d1SSimon J. Gerraty /* .NOMETA do not create a .meta file */ 3392c3632d1SSimon J. Gerraty OP_NOMETA = 1 << 19, 3402c3632d1SSimon J. Gerraty /* .META we _do_ want a .meta file */ 3412c3632d1SSimon J. Gerraty OP_META = 1 << 20, 3422c3632d1SSimon J. Gerraty /* Do not compare commands in .meta file */ 3432c3632d1SSimon J. Gerraty OP_NOMETA_CMP = 1 << 21, 3442c3632d1SSimon J. Gerraty /* Possibly a submake node */ 3452c3632d1SSimon J. Gerraty OP_SUBMAKE = 1 << 22, 3462c3632d1SSimon J. Gerraty 3472c3632d1SSimon J. Gerraty /* Attributes applied by PMake */ 3482c3632d1SSimon J. Gerraty 349e2eeea75SSimon J. Gerraty /* The node is a transformation rule, such as ".c.o". */ 35006b9b3e0SSimon J. Gerraty OP_TRANSFORM = 1 << 30, 3512c3632d1SSimon J. Gerraty /* Target is a member of an archive */ 352956e45f6SSimon J. Gerraty /* XXX: How does this differ from OP_ARCHV? */ 35306b9b3e0SSimon J. Gerraty OP_MEMBER = 1 << 29, 3549f45a3c8SSimon J. Gerraty /* 3559f45a3c8SSimon J. Gerraty * The node is a library, its name has the form "-l<libname>". 3569f45a3c8SSimon J. Gerraty */ 35706b9b3e0SSimon J. Gerraty OP_LIB = 1 << 28, 3589f45a3c8SSimon J. Gerraty /* 3599f45a3c8SSimon J. Gerraty * The node is an archive member, its name has the form 3609f45a3c8SSimon J. Gerraty * "archive(member)". 3619f45a3c8SSimon J. Gerraty */ 362956e45f6SSimon J. Gerraty /* XXX: How does this differ from OP_MEMBER? */ 36306b9b3e0SSimon J. Gerraty OP_ARCHV = 1 << 27, 3649f45a3c8SSimon J. Gerraty /* 3659f45a3c8SSimon J. Gerraty * Target has all the commands it should. Used when parsing to catch 36606b9b3e0SSimon J. Gerraty * multiple command groups for a target. Only applies to the 3679f45a3c8SSimon J. Gerraty * dependency operators ':' and '!', but not to '::'. 3689f45a3c8SSimon J. Gerraty */ 36906b9b3e0SSimon J. Gerraty OP_HAS_COMMANDS = 1 << 26, 3709f45a3c8SSimon J. Gerraty /* 3719f45a3c8SSimon J. Gerraty * The special command "..." has been seen. All further commands from 3729f45a3c8SSimon J. Gerraty * this node will be saved on the .END node instead, to be executed 3739f45a3c8SSimon J. Gerraty * at the very end. 3749f45a3c8SSimon J. Gerraty */ 37506b9b3e0SSimon J. Gerraty OP_SAVE_CMDS = 1 << 25, 3769f45a3c8SSimon J. Gerraty /* 3779f45a3c8SSimon J. Gerraty * Already processed by Suff_FindDeps, to find dependencies from 3789f45a3c8SSimon J. Gerraty * suffix transformation rules. 3799f45a3c8SSimon J. Gerraty */ 38006b9b3e0SSimon J. Gerraty OP_DEPS_FOUND = 1 << 24, 3812c3632d1SSimon J. Gerraty /* Node found while expanding .ALLSRC */ 3829f45a3c8SSimon J. Gerraty OP_MARK = 1 << 23 3832c3632d1SSimon J. Gerraty } GNodeType; 3842c3632d1SSimon J. Gerraty 38512904384SSimon J. Gerraty typedef struct GNodeFlags { 38606b9b3e0SSimon J. Gerraty /* this target needs to be (re)made */ 38712904384SSimon J. Gerraty bool remake:1; 38806b9b3e0SSimon J. Gerraty /* children of this target were made */ 38912904384SSimon J. Gerraty bool childMade:1; 39006b9b3e0SSimon J. Gerraty /* children don't exist, and we pretend made */ 39112904384SSimon J. Gerraty bool force:1; 39206b9b3e0SSimon J. Gerraty /* Set by Make_ProcessWait() */ 39312904384SSimon J. Gerraty bool doneWait:1; 39406b9b3e0SSimon J. Gerraty /* Build requested by .ORDER processing */ 39512904384SSimon J. Gerraty bool doneOrder:1; 39606b9b3e0SSimon J. Gerraty /* Node created from .depend */ 39712904384SSimon J. Gerraty bool fromDepend:1; 39806b9b3e0SSimon J. Gerraty /* We do it once only */ 39912904384SSimon J. Gerraty bool doneAllsrc:1; 40006b9b3e0SSimon J. Gerraty /* Used by MakePrintStatus */ 40112904384SSimon J. Gerraty bool cycle:1; 40206b9b3e0SSimon J. Gerraty /* Used by MakePrintStatus */ 40312904384SSimon J. Gerraty bool doneCycle:1; 4042c3632d1SSimon J. Gerraty } GNodeFlags; 4052c3632d1SSimon J. Gerraty 406956e45f6SSimon J. Gerraty typedef struct List StringList; 407956e45f6SSimon J. Gerraty typedef struct ListNode StringListNode; 408956e45f6SSimon J. Gerraty 409956e45f6SSimon J. Gerraty typedef struct List GNodeList; 410956e45f6SSimon J. Gerraty typedef struct ListNode GNodeListNode; 411956e45f6SSimon J. Gerraty 412dba7b0efSSimon J. Gerraty typedef struct SearchPath { 413dba7b0efSSimon J. Gerraty List /* of CachedDir */ dirs; 414dba7b0efSSimon J. Gerraty } SearchPath; 415956e45f6SSimon J. Gerraty 41606b9b3e0SSimon J. Gerraty /* 41706b9b3e0SSimon J. Gerraty * A graph node represents a target that can possibly be made, including its 41806b9b3e0SSimon J. Gerraty * relation to other targets and a lot of other details. 41906b9b3e0SSimon J. Gerraty */ 4202c3632d1SSimon J. Gerraty typedef struct GNode { 4212c3632d1SSimon J. Gerraty /* The target's name, such as "clean" or "make.c" */ 4222c3632d1SSimon J. Gerraty char *name; 4232c3632d1SSimon J. Gerraty /* The unexpanded name of a .USE node */ 4242c3632d1SSimon J. Gerraty char *uname; 4259f45a3c8SSimon J. Gerraty /* 4269f45a3c8SSimon J. Gerraty * The full pathname of the file belonging to the target. 4279f45a3c8SSimon J. Gerraty * 42806b9b3e0SSimon J. Gerraty * XXX: What about .PHONY targets? These don't have an associated 4299f45a3c8SSimon J. Gerraty * path. 4309f45a3c8SSimon J. Gerraty */ 4312c3632d1SSimon J. Gerraty char *path; 4322c3632d1SSimon J. Gerraty 4339f45a3c8SSimon J. Gerraty /* 4349f45a3c8SSimon J. Gerraty * The type of operator used to define the sources (see the OP flags 43506b9b3e0SSimon J. Gerraty * below). 4369f45a3c8SSimon J. Gerraty * 4379f45a3c8SSimon J. Gerraty * XXX: This looks like a wild mixture of type and flags. 4389f45a3c8SSimon J. Gerraty */ 4392c3632d1SSimon J. Gerraty GNodeType type; 4402c3632d1SSimon J. Gerraty GNodeFlags flags; 4412c3632d1SSimon J. Gerraty 4422c3632d1SSimon J. Gerraty /* The state of processing on this node */ 4432c3632d1SSimon J. Gerraty GNodeMade made; 44406b9b3e0SSimon J. Gerraty /* The number of unmade children */ 44506b9b3e0SSimon J. Gerraty int unmade; 4463955d011SMarcel Moolenaar 4479f45a3c8SSimon J. Gerraty /* 4489f45a3c8SSimon J. Gerraty * The modification time; 0 means the node does not have a 4499f45a3c8SSimon J. Gerraty * corresponding file; see GNode_IsOODate. 4509f45a3c8SSimon J. Gerraty */ 451956e45f6SSimon J. Gerraty time_t mtime; 452956e45f6SSimon J. Gerraty struct GNode *youngestChild; 4533955d011SMarcel Moolenaar 4549f45a3c8SSimon J. Gerraty /* 4559f45a3c8SSimon J. Gerraty * The GNodes for which this node is an implied source. May be empty. 4569f45a3c8SSimon J. Gerraty * For example, when there is an inference rule for .c.o, the node 4579f45a3c8SSimon J. Gerraty * for file.c has the node for file.o in this list. 4589f45a3c8SSimon J. Gerraty */ 45906b9b3e0SSimon J. Gerraty GNodeList implicitParents; 4603955d011SMarcel Moolenaar 4619f45a3c8SSimon J. Gerraty /* 4629f45a3c8SSimon J. Gerraty * The nodes that depend on this one, or in other words, the nodes 4639f45a3c8SSimon J. Gerraty * for which this is a source. 4649f45a3c8SSimon J. Gerraty */ 46506b9b3e0SSimon J. Gerraty GNodeList parents; 4662c3632d1SSimon J. Gerraty /* The nodes on which this one depends. */ 46706b9b3e0SSimon J. Gerraty GNodeList children; 4683955d011SMarcel Moolenaar 4699f45a3c8SSimon J. Gerraty /* 4709f45a3c8SSimon J. Gerraty * .ORDER nodes we need made. The nodes that must be made (if they're 4712c3632d1SSimon J. Gerraty * made) before this node can be made, but that do not enter into the 4729f45a3c8SSimon J. Gerraty * datedness of this node. 4739f45a3c8SSimon J. Gerraty */ 47406b9b3e0SSimon J. Gerraty GNodeList order_pred; 4759f45a3c8SSimon J. Gerraty /* 4769f45a3c8SSimon J. Gerraty * .ORDER nodes who need us. The nodes that must be made (if they're 47706b9b3e0SSimon J. Gerraty * made at all) after this node is made, but that do not depend on 4789f45a3c8SSimon J. Gerraty * this node, in the normal sense. 4799f45a3c8SSimon J. Gerraty */ 48006b9b3e0SSimon J. Gerraty GNodeList order_succ; 4812c3632d1SSimon J. Gerraty 482dba7b0efSSimon J. Gerraty /* 483dba7b0efSSimon J. Gerraty * Other nodes of the same name, for targets that were defined using 484dba7b0efSSimon J. Gerraty * the '::' dependency operator (OP_DOUBLEDEP). 485dba7b0efSSimon J. Gerraty */ 48606b9b3e0SSimon J. Gerraty GNodeList cohorts; 487956e45f6SSimon J. Gerraty /* The "#n" suffix for this cohort, or "" for other nodes */ 4882c3632d1SSimon J. Gerraty char cohort_num[8]; 4892c3632d1SSimon J. Gerraty /* The number of unmade instances on the cohorts list */ 4902c3632d1SSimon J. Gerraty int unmade_cohorts; 4919f45a3c8SSimon J. Gerraty /* 4929f45a3c8SSimon J. Gerraty * Pointer to the first instance of a '::' node; only set when on a 4939f45a3c8SSimon J. Gerraty * cohorts list 4949f45a3c8SSimon J. Gerraty */ 4952c3632d1SSimon J. Gerraty struct GNode *centurion; 4962c3632d1SSimon J. Gerraty 4972c3632d1SSimon J. Gerraty /* Last time (sequence number) we tried to make this node */ 498956e45f6SSimon J. Gerraty unsigned int checked_seqno; 4992c3632d1SSimon J. Gerraty 500dba7b0efSSimon J. Gerraty /* 501dba7b0efSSimon J. Gerraty * The "local" variables that are specific to this target and this 50206b9b3e0SSimon J. Gerraty * target only, such as $@, $<, $?. 503956e45f6SSimon J. Gerraty * 504dba7b0efSSimon J. Gerraty * Also used for the global variable scopes SCOPE_GLOBAL, 505dba7b0efSSimon J. Gerraty * SCOPE_CMDLINE, SCOPE_INTERNAL, which contain variables with 506dba7b0efSSimon J. Gerraty * arbitrary names. 507dba7b0efSSimon J. Gerraty */ 50806b9b3e0SSimon J. Gerraty HashTable /* of Var pointer */ vars; 5092c3632d1SSimon J. Gerraty 5102c3632d1SSimon J. Gerraty /* The commands to be given to a shell to create this target. */ 51106b9b3e0SSimon J. Gerraty StringList commands; 5122c3632d1SSimon J. Gerraty 5139f45a3c8SSimon J. Gerraty /* 5149f45a3c8SSimon J. Gerraty * Suffix for the node (determined by Suff_FindDeps and opaque to 5159f45a3c8SSimon J. Gerraty * everyone but the Suff module) 5169f45a3c8SSimon J. Gerraty */ 51706b9b3e0SSimon J. Gerraty struct Suffix *suffix; 5182c3632d1SSimon J. Gerraty 5199f45a3c8SSimon J. Gerraty /* Filename where the GNode got defined, unlimited lifetime */ 5202c3632d1SSimon J. Gerraty const char *fname; 5219f45a3c8SSimon J. Gerraty /* Line number where the GNode got defined, 1-based */ 5229f45a3c8SSimon J. Gerraty unsigned lineno; 5233955d011SMarcel Moolenaar } GNode; 5243955d011SMarcel Moolenaar 5252f2a5ecdSSimon J. Gerraty /* 5262f2a5ecdSSimon J. Gerraty * Keep track of whether to include <posix.mk> when parsing the line 5272f2a5ecdSSimon J. Gerraty * '.POSIX:'. 5282f2a5ecdSSimon J. Gerraty */ 5292f2a5ecdSSimon J. Gerraty extern enum PosixState { 5302f2a5ecdSSimon J. Gerraty PS_NOT_YET, 5312f2a5ecdSSimon J. Gerraty PS_MAYBE_NEXT_LINE, 5322f2a5ecdSSimon J. Gerraty PS_NOW_OR_NEVER, 5332f2a5ecdSSimon J. Gerraty PS_TOO_LATE 5342f2a5ecdSSimon J. Gerraty } posix_state; 5352f2a5ecdSSimon J. Gerraty 536e2eeea75SSimon J. Gerraty /* Error levels for diagnostics during parsing. */ 537956e45f6SSimon J. Gerraty typedef enum ParseErrorLevel { 5389f45a3c8SSimon J. Gerraty /* 5399f45a3c8SSimon J. Gerraty * Exit when the current top-level makefile has been parsed 5409f45a3c8SSimon J. Gerraty * completely. 5419f45a3c8SSimon J. Gerraty */ 542956e45f6SSimon J. Gerraty PARSE_FATAL = 1, 543e2eeea75SSimon J. Gerraty /* Print "warning"; may be upgraded to fatal by the -w option. */ 544956e45f6SSimon J. Gerraty PARSE_WARNING, 545e2eeea75SSimon J. Gerraty /* Informational, mainly used during development of makefiles. */ 546956e45f6SSimon J. Gerraty PARSE_INFO 547956e45f6SSimon J. Gerraty } ParseErrorLevel; 5483955d011SMarcel Moolenaar 5493955d011SMarcel Moolenaar /* 550956e45f6SSimon J. Gerraty * Values returned by Cond_EvalLine and Cond_EvalCondition. 5513955d011SMarcel Moolenaar */ 5529f45a3c8SSimon J. Gerraty typedef enum CondResult { 5539f45a3c8SSimon J. Gerraty CR_TRUE, /* Parse the next lines */ 5549f45a3c8SSimon J. Gerraty CR_FALSE, /* Skip the next lines */ 5559f45a3c8SSimon J. Gerraty CR_ERROR /* Unknown directive or parse error */ 5569f45a3c8SSimon J. Gerraty } CondResult; 5573955d011SMarcel Moolenaar 558e2eeea75SSimon J. Gerraty /* Names of the variables that are "local" to a specific target. */ 5593955d011SMarcel Moolenaar #define TARGET "@" /* Target of dependency */ 5603955d011SMarcel Moolenaar #define OODATE "?" /* All out-of-date sources */ 5613955d011SMarcel Moolenaar #define ALLSRC ">" /* All sources */ 5623955d011SMarcel Moolenaar #define IMPSRC "<" /* Source implied by transformation */ 5633955d011SMarcel Moolenaar #define PREFIX "*" /* Common prefix */ 5643955d011SMarcel Moolenaar #define ARCHIVE "!" /* Archive in "archive(member)" syntax */ 5653955d011SMarcel Moolenaar #define MEMBER "%" /* Member in "archive(member)" syntax */ 5663955d011SMarcel Moolenaar 5673955d011SMarcel Moolenaar /* 5683955d011SMarcel Moolenaar * Global Variables 5693955d011SMarcel Moolenaar */ 5703955d011SMarcel Moolenaar 571e2eeea75SSimon J. Gerraty /* True if every target is precious */ 572b0c40a00SSimon J. Gerraty extern bool allPrecious; 573e2eeea75SSimon J. Gerraty /* True if failed targets should be deleted */ 574b0c40a00SSimon J. Gerraty extern bool deleteOnError; 575b0c40a00SSimon J. Gerraty /* true while processing .depend */ 576b0c40a00SSimon J. Gerraty extern bool doing_depend; 577e2eeea75SSimon J. Gerraty /* .DEFAULT rule */ 578e2eeea75SSimon J. Gerraty extern GNode *defaultNode; 5793955d011SMarcel Moolenaar 58006b9b3e0SSimon J. Gerraty /* 58106b9b3e0SSimon J. Gerraty * Variables defined internally by make which should not override those set 58206b9b3e0SSimon J. Gerraty * by makefiles. 58306b9b3e0SSimon J. Gerraty */ 584dba7b0efSSimon J. Gerraty extern GNode *SCOPE_INTERNAL; 585dba7b0efSSimon J. Gerraty /* Variables defined in a global scope, e.g in the makefile itself. */ 586dba7b0efSSimon J. Gerraty extern GNode *SCOPE_GLOBAL; 587e2eeea75SSimon J. Gerraty /* Variables defined on the command line. */ 588dba7b0efSSimon J. Gerraty extern GNode *SCOPE_CMDLINE; 589e2eeea75SSimon J. Gerraty 59006b9b3e0SSimon J. Gerraty /* 59106b9b3e0SSimon J. Gerraty * Value returned by Var_Parse when an error is encountered. It actually 59206b9b3e0SSimon J. Gerraty * points to an empty string, so naive callers needn't worry about it. 59306b9b3e0SSimon J. Gerraty */ 594e2eeea75SSimon J. Gerraty extern char var_Error[]; 595e2eeea75SSimon J. Gerraty 596e2eeea75SSimon J. Gerraty /* The time at the start of this whole process */ 597e2eeea75SSimon J. Gerraty extern time_t now; 598e2eeea75SSimon J. Gerraty 599e2eeea75SSimon J. Gerraty /* 60006b9b3e0SSimon J. Gerraty * The list of directories to search when looking for targets (set by the 60106b9b3e0SSimon J. Gerraty * special target .PATH). 6021bbe5942SSimon J. Gerraty */ 60306b9b3e0SSimon J. Gerraty extern SearchPath dirSearchPath; 604e2eeea75SSimon J. Gerraty /* Used for .include "...". */ 605e2eeea75SSimon J. Gerraty extern SearchPath *parseIncPath; 60606b9b3e0SSimon J. Gerraty /* 607dba7b0efSSimon J. Gerraty * Used for .include <...>, for the built-in sys.mk and for makefiles from 608dba7b0efSSimon J. Gerraty * the command line arguments. 60906b9b3e0SSimon J. Gerraty */ 610e2eeea75SSimon J. Gerraty extern SearchPath *sysIncPath; 611e2eeea75SSimon J. Gerraty /* The default for sysIncPath. */ 612e2eeea75SSimon J. Gerraty extern SearchPath *defSysIncPath; 6133955d011SMarcel Moolenaar 614e2eeea75SSimon J. Gerraty /* Startup directory */ 615e2eeea75SSimon J. Gerraty extern char curdir[]; 616e2eeea75SSimon J. Gerraty /* The basename of the program name, suffixed with [n] for sub-makes. */ 61706b9b3e0SSimon J. Gerraty extern const char *progname; 618dba7b0efSSimon J. Gerraty extern int makelevel; 619e2eeea75SSimon J. Gerraty /* Name of the .depend makefile */ 620e2eeea75SSimon J. Gerraty extern char *makeDependfile; 621e2eeea75SSimon J. Gerraty /* If we replaced environ, this will be non-NULL. */ 622e2eeea75SSimon J. Gerraty extern char **savedEnv; 6239f45a3c8SSimon J. Gerraty extern GNode *mainNode; 6243955d011SMarcel Moolenaar 6253955d011SMarcel Moolenaar extern pid_t myPid; 6263955d011SMarcel Moolenaar 6273955d011SMarcel Moolenaar #define MAKEFLAGS ".MAKEFLAGS" 62851ee2c1cSSimon J. Gerraty #ifndef MAKE_LEVEL_ENV 62951ee2c1cSSimon J. Gerraty # define MAKE_LEVEL_ENV "MAKELEVEL" 6303955d011SMarcel Moolenaar #endif 6313955d011SMarcel Moolenaar 6329f45a3c8SSimon J. Gerraty typedef struct DebugFlags { 6339f45a3c8SSimon J. Gerraty bool DEBUG_ARCH:1; 6349f45a3c8SSimon J. Gerraty bool DEBUG_COND:1; 6359f45a3c8SSimon J. Gerraty bool DEBUG_CWD:1; 6369f45a3c8SSimon J. Gerraty bool DEBUG_DIR:1; 6379f45a3c8SSimon J. Gerraty bool DEBUG_ERROR:1; 6389f45a3c8SSimon J. Gerraty bool DEBUG_FOR:1; 6399f45a3c8SSimon J. Gerraty bool DEBUG_GRAPH1:1; 6409f45a3c8SSimon J. Gerraty bool DEBUG_GRAPH2:1; 6419f45a3c8SSimon J. Gerraty bool DEBUG_GRAPH3:1; 6429f45a3c8SSimon J. Gerraty bool DEBUG_HASH:1; 6439f45a3c8SSimon J. Gerraty bool DEBUG_JOB:1; 6449f45a3c8SSimon J. Gerraty bool DEBUG_LOUD:1; 6459f45a3c8SSimon J. Gerraty bool DEBUG_MAKE:1; 6469f45a3c8SSimon J. Gerraty bool DEBUG_META:1; 6479f45a3c8SSimon J. Gerraty bool DEBUG_PARSE:1; 6489f45a3c8SSimon J. Gerraty bool DEBUG_SCRIPT:1; 6499f45a3c8SSimon J. Gerraty bool DEBUG_SHELL:1; 6509f45a3c8SSimon J. Gerraty bool DEBUG_SUFF:1; 6519f45a3c8SSimon J. Gerraty bool DEBUG_TARG:1; 6529f45a3c8SSimon J. Gerraty bool DEBUG_VAR:1; 653956e45f6SSimon J. Gerraty } DebugFlags; 6542c3632d1SSimon J. Gerraty 6553955d011SMarcel Moolenaar #define CONCAT(a, b) a##b 6563955d011SMarcel Moolenaar 6579f45a3c8SSimon J. Gerraty #define DEBUG(module) (opts.debug.CONCAT(DEBUG_, module)) 658956e45f6SSimon J. Gerraty 659956e45f6SSimon J. Gerraty void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2); 660956e45f6SSimon J. Gerraty 66106b9b3e0SSimon J. Gerraty #define DEBUG_IMPL(module, args) \ 66206b9b3e0SSimon J. Gerraty do { \ 66306b9b3e0SSimon J. Gerraty if (DEBUG(module)) \ 66406b9b3e0SSimon J. Gerraty debug_printf args; \ 66512904384SSimon J. Gerraty } while (false) 66606b9b3e0SSimon J. Gerraty 6679f45a3c8SSimon J. Gerraty #define DEBUG0(module, fmt) \ 6689f45a3c8SSimon J. Gerraty DEBUG_IMPL(module, (fmt)) 669956e45f6SSimon J. Gerraty #define DEBUG1(module, fmt, arg1) \ 67006b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1)) 671956e45f6SSimon J. Gerraty #define DEBUG2(module, fmt, arg1, arg2) \ 67206b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1, arg2)) 673956e45f6SSimon J. Gerraty #define DEBUG3(module, fmt, arg1, arg2, arg3) \ 67406b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1, arg2, arg3)) 675956e45f6SSimon J. Gerraty #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \ 67606b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4)) 677956e45f6SSimon J. Gerraty #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \ 67806b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5)) 679956e45f6SSimon J. Gerraty 680956e45f6SSimon J. Gerraty typedef enum PrintVarsMode { 681e2eeea75SSimon J. Gerraty PVM_NONE, 682e2eeea75SSimon J. Gerraty PVM_UNEXPANDED, 683e2eeea75SSimon J. Gerraty PVM_EXPANDED 684956e45f6SSimon J. Gerraty } PrintVarsMode; 685956e45f6SSimon J. Gerraty 686956e45f6SSimon J. Gerraty /* Command line options */ 687956e45f6SSimon J. Gerraty typedef struct CmdOpts { 688956e45f6SSimon J. Gerraty /* -B: whether we are make compatible */ 689b0c40a00SSimon J. Gerraty bool compatMake; 690956e45f6SSimon J. Gerraty 6919f45a3c8SSimon J. Gerraty /* 6929f45a3c8SSimon J. Gerraty * -d: debug control: There is one bit per module. It is up to the 6939f45a3c8SSimon J. Gerraty * module what debug information to print. 6949f45a3c8SSimon J. Gerraty */ 695956e45f6SSimon J. Gerraty DebugFlags debug; 696956e45f6SSimon J. Gerraty 697956e45f6SSimon J. Gerraty /* -df: debug output is written here - default stderr */ 698956e45f6SSimon J. Gerraty FILE *debug_file; 699956e45f6SSimon J. Gerraty 7009f45a3c8SSimon J. Gerraty /* 7019f45a3c8SSimon J. Gerraty * -dL: lint mode 702e2eeea75SSimon J. Gerraty * 703e2eeea75SSimon J. Gerraty * Runs make in strict mode, with additional checks and better error 7049f45a3c8SSimon J. Gerraty * handling. 7059f45a3c8SSimon J. Gerraty */ 706b0c40a00SSimon J. Gerraty bool strict; 707e2eeea75SSimon J. Gerraty 708956e45f6SSimon J. Gerraty /* -dV: for the -V option, print unexpanded variable values */ 709b0c40a00SSimon J. Gerraty bool debugVflag; 710956e45f6SSimon J. Gerraty 711956e45f6SSimon J. Gerraty /* -e: check environment variables before global variables */ 712b0c40a00SSimon J. Gerraty bool checkEnvFirst; 713956e45f6SSimon J. Gerraty 714956e45f6SSimon J. Gerraty /* -f: the makefiles to read */ 71506b9b3e0SSimon J. Gerraty StringList makefiles; 716956e45f6SSimon J. Gerraty 717956e45f6SSimon J. Gerraty /* -i: if true, ignore all errors from shell commands */ 718b0c40a00SSimon J. Gerraty bool ignoreErrors; 719956e45f6SSimon J. Gerraty 7209f45a3c8SSimon J. Gerraty /* 7219f45a3c8SSimon J. Gerraty * -j: the maximum number of jobs that can run in parallel; this is 7229f45a3c8SSimon J. Gerraty * coordinated with the submakes 7239f45a3c8SSimon J. Gerraty */ 724956e45f6SSimon J. Gerraty int maxJobs; 725956e45f6SSimon J. Gerraty 7269f45a3c8SSimon J. Gerraty /* 7279f45a3c8SSimon J. Gerraty * -k: if true and an error occurs while making a node, continue 7289f45a3c8SSimon J. Gerraty * making nodes that do not depend on the erroneous node 7299f45a3c8SSimon J. Gerraty */ 730b0c40a00SSimon J. Gerraty bool keepgoing; 731956e45f6SSimon J. Gerraty 732956e45f6SSimon J. Gerraty /* -N: execute no commands from the targets */ 733b0c40a00SSimon J. Gerraty bool noRecursiveExecute; 734956e45f6SSimon J. Gerraty 735956e45f6SSimon J. Gerraty /* -n: execute almost no commands from the targets */ 736b0c40a00SSimon J. Gerraty bool noExecute; 737956e45f6SSimon J. Gerraty 738dba7b0efSSimon J. Gerraty /* 739dba7b0efSSimon J. Gerraty * -q: if true, do not really make anything, just see if the targets 740dba7b0efSSimon J. Gerraty * are out-of-date 741dba7b0efSSimon J. Gerraty */ 7429f45a3c8SSimon J. Gerraty bool query; 743956e45f6SSimon J. Gerraty 744dba7b0efSSimon J. Gerraty /* -r: raw mode, do not load the builtin rules. */ 745b0c40a00SSimon J. Gerraty bool noBuiltins; 746956e45f6SSimon J. Gerraty 747956e45f6SSimon J. Gerraty /* -s: don't echo the shell commands before executing them */ 7489f45a3c8SSimon J. Gerraty bool silent; 749956e45f6SSimon J. Gerraty 7509f45a3c8SSimon J. Gerraty /* 7519f45a3c8SSimon J. Gerraty * -t: touch the targets if they are out-of-date, but don't actually 7529f45a3c8SSimon J. Gerraty * make them 7539f45a3c8SSimon J. Gerraty */ 7549f45a3c8SSimon J. Gerraty bool touch; 755956e45f6SSimon J. Gerraty 756956e45f6SSimon J. Gerraty /* -[Vv]: print expanded or unexpanded selected variables */ 757956e45f6SSimon J. Gerraty PrintVarsMode printVars; 758956e45f6SSimon J. Gerraty /* -[Vv]: the variables to print */ 75906b9b3e0SSimon J. Gerraty StringList variables; 760956e45f6SSimon J. Gerraty 761956e45f6SSimon J. Gerraty /* -W: if true, makefile parsing warnings are treated as errors */ 762b0c40a00SSimon J. Gerraty bool parseWarnFatal; 763956e45f6SSimon J. Gerraty 764dba7b0efSSimon J. Gerraty /* -w: print 'Entering' and 'Leaving' for submakes */ 765b0c40a00SSimon J. Gerraty bool enterFlag; 766956e45f6SSimon J. Gerraty 7679f45a3c8SSimon J. Gerraty /* 7689f45a3c8SSimon J. Gerraty * -X: if true, do not export variables set on the command line to 7699f45a3c8SSimon J. Gerraty * the environment. 7709f45a3c8SSimon J. Gerraty */ 771b0c40a00SSimon J. Gerraty bool varNoExportEnv; 772956e45f6SSimon J. Gerraty 7739f45a3c8SSimon J. Gerraty /* 7749f45a3c8SSimon J. Gerraty * The target names specified on the command line. Used to resolve 7759f45a3c8SSimon J. Gerraty * .if make(...) statements. 7769f45a3c8SSimon J. Gerraty */ 77706b9b3e0SSimon J. Gerraty StringList create; 778956e45f6SSimon J. Gerraty 779954401e6SSimon J. Gerraty /* 780954401e6SSimon J. Gerraty * Randomize the order in which the targets from toBeMade are made, 781954401e6SSimon J. Gerraty * to catch undeclared dependencies. 782954401e6SSimon J. Gerraty */ 783954401e6SSimon J. Gerraty bool randomizeTargets; 784956e45f6SSimon J. Gerraty } CmdOpts; 785956e45f6SSimon J. Gerraty 786956e45f6SSimon J. Gerraty extern CmdOpts opts; 787*8c973ee2SSimon J. Gerraty extern bool forceJobs; 788*8c973ee2SSimon J. Gerraty extern char **environ; 7893955d011SMarcel Moolenaar 7909f45a3c8SSimon J. Gerraty /* arch.c */ 7919f45a3c8SSimon J. Gerraty void Arch_Init(void); 7929f45a3c8SSimon J. Gerraty void Arch_End(void); 7933955d011SMarcel Moolenaar 7949f45a3c8SSimon J. Gerraty bool Arch_ParseArchive(char **, GNodeList *, GNode *); 7959f45a3c8SSimon J. Gerraty void Arch_Touch(GNode *); 7969f45a3c8SSimon J. Gerraty void Arch_TouchLib(GNode *); 7979f45a3c8SSimon J. Gerraty void Arch_UpdateMTime(GNode *gn); 7989f45a3c8SSimon J. Gerraty void Arch_UpdateMemberMTime(GNode *gn); 7999f45a3c8SSimon J. Gerraty void Arch_FindLib(GNode *, SearchPath *); 8009f45a3c8SSimon J. Gerraty bool Arch_LibOODate(GNode *) MAKE_ATTR_USE; 8019f45a3c8SSimon J. Gerraty bool Arch_IsLib(GNode *) MAKE_ATTR_USE; 8029f45a3c8SSimon J. Gerraty 8039f45a3c8SSimon J. Gerraty /* compat.c */ 8049f45a3c8SSimon J. Gerraty bool Compat_RunCommand(const char *, GNode *, StringListNode *); 805954401e6SSimon J. Gerraty void Compat_MakeAll(GNodeList *); 8069f45a3c8SSimon J. Gerraty void Compat_Make(GNode *, GNode *); 8079f45a3c8SSimon J. Gerraty 8089f45a3c8SSimon J. Gerraty /* cond.c */ 8094fde40d9SSimon J. Gerraty extern unsigned int cond_depth; 8109f45a3c8SSimon J. Gerraty CondResult Cond_EvalCondition(const char *) MAKE_ATTR_USE; 8119f45a3c8SSimon J. Gerraty CondResult Cond_EvalLine(const char *) MAKE_ATTR_USE; 8124fde40d9SSimon J. Gerraty void Cond_EndFile(void); 8139f45a3c8SSimon J. Gerraty 8149f45a3c8SSimon J. Gerraty /* dir.c; see also dir.h */ 8159f45a3c8SSimon J. Gerraty 8169f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 8179f45a3c8SSimon J. Gerraty str_basename(const char *pathname) 8189f45a3c8SSimon J. Gerraty { 8199f45a3c8SSimon J. Gerraty const char *lastSlash = strrchr(pathname, '/'); 8209f45a3c8SSimon J. Gerraty return lastSlash != NULL ? lastSlash + 1 : pathname; 8219f45a3c8SSimon J. Gerraty } 8229f45a3c8SSimon J. Gerraty 8239f45a3c8SSimon J. Gerraty MAKE_INLINE SearchPath * MAKE_ATTR_USE 8249f45a3c8SSimon J. Gerraty SearchPath_New(void) 8259f45a3c8SSimon J. Gerraty { 8269f45a3c8SSimon J. Gerraty SearchPath *path = bmake_malloc(sizeof *path); 8279f45a3c8SSimon J. Gerraty Lst_Init(&path->dirs); 8289f45a3c8SSimon J. Gerraty return path; 8299f45a3c8SSimon J. Gerraty } 8309f45a3c8SSimon J. Gerraty 8319f45a3c8SSimon J. Gerraty void SearchPath_Free(SearchPath *); 8329f45a3c8SSimon J. Gerraty 8339f45a3c8SSimon J. Gerraty /* for.c */ 8349f45a3c8SSimon J. Gerraty struct ForLoop; 8359f45a3c8SSimon J. Gerraty int For_Eval(const char *) MAKE_ATTR_USE; 8369f45a3c8SSimon J. Gerraty bool For_Accum(const char *, int *) MAKE_ATTR_USE; 8379f45a3c8SSimon J. Gerraty void For_Run(unsigned, unsigned); 8389f45a3c8SSimon J. Gerraty bool For_NextIteration(struct ForLoop *, Buffer *); 8399f45a3c8SSimon J. Gerraty char *ForLoop_Details(struct ForLoop *); 8409f45a3c8SSimon J. Gerraty void ForLoop_Free(struct ForLoop *); 8414fde40d9SSimon J. Gerraty void For_Break(struct ForLoop *); 8429f45a3c8SSimon J. Gerraty 8439f45a3c8SSimon J. Gerraty /* job.c */ 8449f45a3c8SSimon J. Gerraty void JobReapChild(pid_t, int, bool); 8459f45a3c8SSimon J. Gerraty 8469f45a3c8SSimon J. Gerraty /* main.c */ 8479f45a3c8SSimon J. Gerraty void Main_ParseArgLine(const char *); 8489f45a3c8SSimon J. Gerraty char *Cmd_Exec(const char *, char **) MAKE_ATTR_USE; 8499f45a3c8SSimon J. Gerraty void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2); 8509f45a3c8SSimon J. Gerraty void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD; 8519f45a3c8SSimon J. Gerraty void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD; 8529f45a3c8SSimon J. Gerraty void DieHorribly(void) MAKE_ATTR_DEAD; 8539f45a3c8SSimon J. Gerraty void Finish(int) MAKE_ATTR_DEAD; 8544fde40d9SSimon J. Gerraty int unlink_file(const char *) MAKE_ATTR_USE; 8559f45a3c8SSimon J. Gerraty void execDie(const char *, const char *); 8569f45a3c8SSimon J. Gerraty char *getTmpdir(void) MAKE_ATTR_USE; 8579f45a3c8SSimon J. Gerraty bool ParseBoolean(const char *, bool) MAKE_ATTR_USE; 8589f45a3c8SSimon J. Gerraty const char *cached_realpath(const char *, char *); 8599f45a3c8SSimon J. Gerraty bool GetBooleanExpr(const char *, bool); 8609f45a3c8SSimon J. Gerraty 8619f45a3c8SSimon J. Gerraty /* parse.c */ 8629f45a3c8SSimon J. Gerraty void Parse_Init(void); 8639f45a3c8SSimon J. Gerraty void Parse_End(void); 8649f45a3c8SSimon J. Gerraty 865954401e6SSimon J. Gerraty void PrintLocation(FILE *, bool, const GNode *); 8669f45a3c8SSimon J. Gerraty void PrintStackTrace(bool); 8679f45a3c8SSimon J. Gerraty void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3); 8689f45a3c8SSimon J. Gerraty bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE; 8699f45a3c8SSimon J. Gerraty void Parse_AddIncludeDir(const char *); 8709f45a3c8SSimon J. Gerraty void Parse_File(const char *, int); 8719f45a3c8SSimon J. Gerraty void Parse_PushInput(const char *, unsigned, unsigned, Buffer, 8729f45a3c8SSimon J. Gerraty struct ForLoop *); 8739f45a3c8SSimon J. Gerraty void Parse_MainName(GNodeList *); 8749f45a3c8SSimon J. Gerraty int Parse_NumErrors(void) MAKE_ATTR_USE; 8754fde40d9SSimon J. Gerraty unsigned int CurFile_CondMinDepth(void) MAKE_ATTR_USE; 8769f45a3c8SSimon J. Gerraty 8779f45a3c8SSimon J. Gerraty 8789f45a3c8SSimon J. Gerraty /* suff.c */ 8799f45a3c8SSimon J. Gerraty void Suff_Init(void); 8809f45a3c8SSimon J. Gerraty void Suff_End(void); 8819f45a3c8SSimon J. Gerraty 8829f45a3c8SSimon J. Gerraty void Suff_ClearSuffixes(void); 8839f45a3c8SSimon J. Gerraty bool Suff_IsTransform(const char *) MAKE_ATTR_USE; 8849f45a3c8SSimon J. Gerraty GNode *Suff_AddTransform(const char *); 8859f45a3c8SSimon J. Gerraty void Suff_EndTransform(GNode *); 8869f45a3c8SSimon J. Gerraty void Suff_AddSuffix(const char *); 8879f45a3c8SSimon J. Gerraty SearchPath *Suff_GetPath(const char *) MAKE_ATTR_USE; 8889f45a3c8SSimon J. Gerraty void Suff_ExtendPaths(void); 8899f45a3c8SSimon J. Gerraty void Suff_AddInclude(const char *); 8909f45a3c8SSimon J. Gerraty void Suff_AddLib(const char *); 8919f45a3c8SSimon J. Gerraty void Suff_FindDeps(GNode *); 8929f45a3c8SSimon J. Gerraty SearchPath *Suff_FindPath(GNode *) MAKE_ATTR_USE; 8939f45a3c8SSimon J. Gerraty void Suff_SetNull(const char *); 8949f45a3c8SSimon J. Gerraty void Suff_PrintAll(void); 8959f45a3c8SSimon J. Gerraty char *Suff_NamesStr(void) MAKE_ATTR_USE; 8969f45a3c8SSimon J. Gerraty 8979f45a3c8SSimon J. Gerraty /* targ.c */ 8989f45a3c8SSimon J. Gerraty void Targ_Init(void); 8999f45a3c8SSimon J. Gerraty void Targ_End(void); 9009f45a3c8SSimon J. Gerraty 9019f45a3c8SSimon J. Gerraty void Targ_Stats(void); 9029f45a3c8SSimon J. Gerraty GNodeList *Targ_List(void) MAKE_ATTR_USE; 9039f45a3c8SSimon J. Gerraty GNode *GNode_New(const char *) MAKE_ATTR_USE; 9049f45a3c8SSimon J. Gerraty GNode *Targ_FindNode(const char *) MAKE_ATTR_USE; 9059f45a3c8SSimon J. Gerraty GNode *Targ_GetNode(const char *) MAKE_ATTR_USE; 9069f45a3c8SSimon J. Gerraty GNode *Targ_NewInternalNode(const char *) MAKE_ATTR_USE; 9079f45a3c8SSimon J. Gerraty GNode *Targ_GetEndNode(void); 9089f45a3c8SSimon J. Gerraty void Targ_FindList(GNodeList *, StringList *); 9099f45a3c8SSimon J. Gerraty void Targ_PrintCmds(GNode *); 9109f45a3c8SSimon J. Gerraty void Targ_PrintNode(GNode *, int); 9119f45a3c8SSimon J. Gerraty void Targ_PrintNodes(GNodeList *, int); 9129f45a3c8SSimon J. Gerraty const char *Targ_FmtTime(time_t) MAKE_ATTR_USE; 9139f45a3c8SSimon J. Gerraty void Targ_PrintType(GNodeType); 9149f45a3c8SSimon J. Gerraty void Targ_PrintGraph(int); 9159f45a3c8SSimon J. Gerraty void Targ_Propagate(void); 9169f45a3c8SSimon J. Gerraty const char *GNodeMade_Name(GNodeMade) MAKE_ATTR_USE; 9179f45a3c8SSimon J. Gerraty 9189f45a3c8SSimon J. Gerraty /* var.c */ 9199f45a3c8SSimon J. Gerraty void Var_Init(void); 9209f45a3c8SSimon J. Gerraty void Var_End(void); 9219f45a3c8SSimon J. Gerraty 9229f45a3c8SSimon J. Gerraty typedef enum VarEvalMode { 9239f45a3c8SSimon J. Gerraty 9249f45a3c8SSimon J. Gerraty /* 9259f45a3c8SSimon J. Gerraty * Only parse the expression but don't evaluate any part of it. 9269f45a3c8SSimon J. Gerraty * 9279f45a3c8SSimon J. Gerraty * TODO: Document what Var_Parse and Var_Subst return in this mode. 9289f45a3c8SSimon J. Gerraty * As of 2021-03-15, they return unspecified, inconsistent results. 9299f45a3c8SSimon J. Gerraty */ 9309f45a3c8SSimon J. Gerraty VARE_PARSE_ONLY, 9319f45a3c8SSimon J. Gerraty 932*8c973ee2SSimon J. Gerraty /* 933*8c973ee2SSimon J. Gerraty * Parse text in which '${...}' and '$(...)' are not parsed as 934*8c973ee2SSimon J. Gerraty * subexpressions (with all their individual escaping rules) but 935*8c973ee2SSimon J. Gerraty * instead simply as text with balanced '${}' or '$()'. Other '$' 936*8c973ee2SSimon J. Gerraty * are copied verbatim. 937*8c973ee2SSimon J. Gerraty */ 938*8c973ee2SSimon J. Gerraty VARE_PARSE_BALANCED, 939*8c973ee2SSimon J. Gerraty 9409f45a3c8SSimon J. Gerraty /* Parse and evaluate the expression. */ 9419f45a3c8SSimon J. Gerraty VARE_WANTRES, 9429f45a3c8SSimon J. Gerraty 9439f45a3c8SSimon J. Gerraty /* 9449f45a3c8SSimon J. Gerraty * Parse and evaluate the expression. It is an error if a 9459f45a3c8SSimon J. Gerraty * subexpression evaluates to undefined. 9469f45a3c8SSimon J. Gerraty */ 9479f45a3c8SSimon J. Gerraty VARE_UNDEFERR, 9489f45a3c8SSimon J. Gerraty 9499f45a3c8SSimon J. Gerraty /* 9509f45a3c8SSimon J. Gerraty * Parse and evaluate the expression. Keep '$$' as '$$' instead of 9519f45a3c8SSimon J. Gerraty * reducing it to a single '$'. Subexpressions that evaluate to 9529f45a3c8SSimon J. Gerraty * undefined expand to an empty string. 9539f45a3c8SSimon J. Gerraty * 9549f45a3c8SSimon J. Gerraty * Used in variable assignments using the ':=' operator. It allows 9559f45a3c8SSimon J. Gerraty * multiple such assignments to be chained without accidentally 9569f45a3c8SSimon J. Gerraty * expanding '$$file' to '$file' in the first assignment and 9579f45a3c8SSimon J. Gerraty * interpreting it as '${f}' followed by 'ile' in the next assignment. 9589f45a3c8SSimon J. Gerraty */ 9599f45a3c8SSimon J. Gerraty VARE_EVAL_KEEP_DOLLAR, 9609f45a3c8SSimon J. Gerraty 9619f45a3c8SSimon J. Gerraty /* 9629f45a3c8SSimon J. Gerraty * Parse and evaluate the expression. Keep undefined variables as-is 9639f45a3c8SSimon J. Gerraty * instead of expanding them to an empty string. 9649f45a3c8SSimon J. Gerraty * 9659f45a3c8SSimon J. Gerraty * Example for a ':=' assignment: 9669f45a3c8SSimon J. Gerraty * CFLAGS = $(.INCLUDES) 9679f45a3c8SSimon J. Gerraty * CFLAGS := -I.. $(CFLAGS) 9689f45a3c8SSimon J. Gerraty * # If .INCLUDES (an undocumented special variable, by the 9699f45a3c8SSimon J. Gerraty * # way) is still undefined, the updated CFLAGS becomes 9709f45a3c8SSimon J. Gerraty * # "-I.. $(.INCLUDES)". 9719f45a3c8SSimon J. Gerraty */ 9729f45a3c8SSimon J. Gerraty VARE_EVAL_KEEP_UNDEF, 9739f45a3c8SSimon J. Gerraty 9749f45a3c8SSimon J. Gerraty /* 9759f45a3c8SSimon J. Gerraty * Parse and evaluate the expression. Keep '$$' as '$$' and preserve 9769f45a3c8SSimon J. Gerraty * undefined subexpressions. 9779f45a3c8SSimon J. Gerraty */ 9789f45a3c8SSimon J. Gerraty VARE_KEEP_DOLLAR_UNDEF 9799f45a3c8SSimon J. Gerraty } VarEvalMode; 9809f45a3c8SSimon J. Gerraty 9819f45a3c8SSimon J. Gerraty typedef enum VarSetFlags { 9829f45a3c8SSimon J. Gerraty VAR_SET_NONE = 0, 9839f45a3c8SSimon J. Gerraty 9849f45a3c8SSimon J. Gerraty /* do not export */ 9859f45a3c8SSimon J. Gerraty VAR_SET_NO_EXPORT = 1 << 0, 9869f45a3c8SSimon J. Gerraty 9879f45a3c8SSimon J. Gerraty /* 9889f45a3c8SSimon J. Gerraty * Make the variable read-only. No further modification is possible, 989*8c973ee2SSimon J. Gerraty * except for another call to Var_Set with the same flag. See the 990*8c973ee2SSimon J. Gerraty * special targets '.NOREADONLY' and '.READONLY'. 9919f45a3c8SSimon J. Gerraty */ 9929f45a3c8SSimon J. Gerraty VAR_SET_READONLY = 1 << 1 9939f45a3c8SSimon J. Gerraty } VarSetFlags; 9949f45a3c8SSimon J. Gerraty 9959f45a3c8SSimon J. Gerraty typedef enum VarExportMode { 9969f45a3c8SSimon J. Gerraty /* .export-env */ 9979f45a3c8SSimon J. Gerraty VEM_ENV, 9989f45a3c8SSimon J. Gerraty /* .export: Initial export or update an already exported variable. */ 9999f45a3c8SSimon J. Gerraty VEM_PLAIN, 10009f45a3c8SSimon J. Gerraty /* .export-literal: Do not expand the variable value. */ 10019f45a3c8SSimon J. Gerraty VEM_LITERAL 10029f45a3c8SSimon J. Gerraty } VarExportMode; 10039f45a3c8SSimon J. Gerraty 10049f45a3c8SSimon J. Gerraty void Var_Delete(GNode *, const char *); 10059f45a3c8SSimon J. Gerraty void Var_Undef(const char *); 10069f45a3c8SSimon J. Gerraty void Var_Set(GNode *, const char *, const char *); 10079f45a3c8SSimon J. Gerraty void Var_SetExpand(GNode *, const char *, const char *); 10089f45a3c8SSimon J. Gerraty void Var_SetWithFlags(GNode *, const char *, const char *, VarSetFlags); 10099f45a3c8SSimon J. Gerraty void Var_Append(GNode *, const char *, const char *); 10109f45a3c8SSimon J. Gerraty void Var_AppendExpand(GNode *, const char *, const char *); 10119f45a3c8SSimon J. Gerraty bool Var_Exists(GNode *, const char *) MAKE_ATTR_USE; 10129f45a3c8SSimon J. Gerraty bool Var_ExistsExpand(GNode *, const char *) MAKE_ATTR_USE; 10139f45a3c8SSimon J. Gerraty FStr Var_Value(GNode *, const char *) MAKE_ATTR_USE; 10149f45a3c8SSimon J. Gerraty const char *GNode_ValueDirect(GNode *, const char *) MAKE_ATTR_USE; 1015*8c973ee2SSimon J. Gerraty FStr Var_Parse(const char **, GNode *, VarEvalMode); 1016*8c973ee2SSimon J. Gerraty char *Var_Subst(const char *, GNode *, VarEvalMode); 10179f45a3c8SSimon J. Gerraty void Var_Expand(FStr *, GNode *, VarEvalMode); 10189f45a3c8SSimon J. Gerraty void Var_Stats(void); 10199f45a3c8SSimon J. Gerraty void Var_Dump(GNode *); 10209f45a3c8SSimon J. Gerraty void Var_ReexportVars(void); 10219f45a3c8SSimon J. Gerraty void Var_Export(VarExportMode, const char *); 10229f45a3c8SSimon J. Gerraty void Var_ExportVars(const char *); 10239f45a3c8SSimon J. Gerraty void Var_UnExport(bool, const char *); 10244fde40d9SSimon J. Gerraty void Var_ReadOnly(const char *, bool); 10259f45a3c8SSimon J. Gerraty 10269f45a3c8SSimon J. Gerraty void Global_Set(const char *, const char *); 10279f45a3c8SSimon J. Gerraty void Global_Append(const char *, const char *); 10289f45a3c8SSimon J. Gerraty void Global_Delete(const char *); 10294fde40d9SSimon J. Gerraty void Global_Set_ReadOnly(const char *, const char *); 10309f45a3c8SSimon J. Gerraty 10319f45a3c8SSimon J. Gerraty /* util.c */ 10329f45a3c8SSimon J. Gerraty typedef void (*SignalProc)(int); 10339f45a3c8SSimon J. Gerraty SignalProc bmake_signal(int, SignalProc); 10349f45a3c8SSimon J. Gerraty 10359f45a3c8SSimon J. Gerraty /* make.c */ 1036e2eeea75SSimon J. Gerraty void GNode_UpdateYoungestChild(GNode *, GNode *); 10379f45a3c8SSimon J. Gerraty bool GNode_IsOODate(GNode *) MAKE_ATTR_USE; 1038956e45f6SSimon J. Gerraty void Make_ExpandUse(GNodeList *); 10399f45a3c8SSimon J. Gerraty time_t Make_Recheck(GNode *) MAKE_ATTR_USE; 10403955d011SMarcel Moolenaar void Make_HandleUse(GNode *, GNode *); 10413955d011SMarcel Moolenaar void Make_Update(GNode *); 1042b0c40a00SSimon J. Gerraty void GNode_SetLocalVars(GNode *); 1043b0c40a00SSimon J. Gerraty bool Make_Run(GNodeList *); 10449f45a3c8SSimon J. Gerraty bool shouldDieQuietly(GNode *, int) MAKE_ATTR_USE; 10453955d011SMarcel Moolenaar void PrintOnError(GNode *, const char *); 1046b0c40a00SSimon J. Gerraty void Main_ExportMAKEFLAGS(bool); 1047b0c40a00SSimon J. Gerraty bool Main_SetObjdir(bool, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3); 10489f45a3c8SSimon J. Gerraty int mkTempFile(const char *, char *, size_t) MAKE_ATTR_USE; 1049e2eeea75SSimon J. Gerraty int str2Lst_Append(StringList *, char *); 10502c3632d1SSimon J. Gerraty void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *); 10519f45a3c8SSimon J. Gerraty bool GNode_ShouldExecute(GNode *gn) MAKE_ATTR_USE; 1052956e45f6SSimon J. Gerraty 10534fde40d9SSimon J. Gerraty #ifndef HAVE_STRLCPY 10544fde40d9SSimon J. Gerraty size_t strlcpy(char *, const char *, size_t); 10554fde40d9SSimon J. Gerraty #endif 10564fde40d9SSimon J. Gerraty 1057956e45f6SSimon J. Gerraty /* See if the node was seen on the left-hand side of a dependency operator. */ 10589f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1059956e45f6SSimon J. Gerraty GNode_IsTarget(const GNode *gn) 1060956e45f6SSimon J. Gerraty { 106112904384SSimon J. Gerraty return (gn->type & OP_OPMASK) != OP_NONE; 1062956e45f6SSimon J. Gerraty } 1063956e45f6SSimon J. Gerraty 10649f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1065956e45f6SSimon J. Gerraty GNode_Path(const GNode *gn) 1066956e45f6SSimon J. Gerraty { 1067956e45f6SSimon J. Gerraty return gn->path != NULL ? gn->path : gn->name; 1068956e45f6SSimon J. Gerraty } 1069956e45f6SSimon J. Gerraty 10709f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 107106b9b3e0SSimon J. Gerraty GNode_IsWaitingFor(const GNode *gn) 107206b9b3e0SSimon J. Gerraty { 107312904384SSimon J. Gerraty return gn->flags.remake && gn->made <= REQUESTED; 107406b9b3e0SSimon J. Gerraty } 107506b9b3e0SSimon J. Gerraty 10769f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 107706b9b3e0SSimon J. Gerraty GNode_IsReady(const GNode *gn) 107806b9b3e0SSimon J. Gerraty { 107906b9b3e0SSimon J. Gerraty return gn->made > DEFERRED; 108006b9b3e0SSimon J. Gerraty } 108106b9b3e0SSimon J. Gerraty 10829f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 108306b9b3e0SSimon J. Gerraty GNode_IsDone(const GNode *gn) 108406b9b3e0SSimon J. Gerraty { 108506b9b3e0SSimon J. Gerraty return gn->made >= MADE; 108606b9b3e0SSimon J. Gerraty } 108706b9b3e0SSimon J. Gerraty 10889f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 108906b9b3e0SSimon J. Gerraty GNode_IsError(const GNode *gn) 109006b9b3e0SSimon J. Gerraty { 109106b9b3e0SSimon J. Gerraty return gn->made == ERROR || gn->made == ABORTED; 109206b9b3e0SSimon J. Gerraty } 109306b9b3e0SSimon J. Gerraty 10949f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 10959f45a3c8SSimon J. Gerraty GNode_IsMainCandidate(const GNode *gn) 10969f45a3c8SSimon J. Gerraty { 10979f45a3c8SSimon J. Gerraty return (gn->type & (OP_NOTMAIN | OP_USE | OP_USEBEFORE | 10989f45a3c8SSimon J. Gerraty OP_EXEC | OP_TRANSFORM)) == 0; 10999f45a3c8SSimon J. Gerraty } 11009f45a3c8SSimon J. Gerraty 11019f45a3c8SSimon J. Gerraty /* Return whether the target file should be preserved on interrupt. */ 11029f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 11039f45a3c8SSimon J. Gerraty GNode_IsPrecious(const GNode *gn) 11049f45a3c8SSimon J. Gerraty { 11059f45a3c8SSimon J. Gerraty /* XXX: Why are '::' targets precious? */ 11069f45a3c8SSimon J. Gerraty return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP); 11079f45a3c8SSimon J. Gerraty } 11089f45a3c8SSimon J. Gerraty 11099f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1110dba7b0efSSimon J. Gerraty GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); } 11119f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1112dba7b0efSSimon J. Gerraty GNode_VarOodate(GNode *gn) { return GNode_ValueDirect(gn, OODATE); } 11139f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1114dba7b0efSSimon J. Gerraty GNode_VarAllsrc(GNode *gn) { return GNode_ValueDirect(gn, ALLSRC); } 11159f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1116dba7b0efSSimon J. Gerraty GNode_VarImpsrc(GNode *gn) { return GNode_ValueDirect(gn, IMPSRC); } 11179f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1118dba7b0efSSimon J. Gerraty GNode_VarPrefix(GNode *gn) { return GNode_ValueDirect(gn, PREFIX); } 11199f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1120dba7b0efSSimon J. Gerraty GNode_VarArchive(GNode *gn) { return GNode_ValueDirect(gn, ARCHIVE); } 11219f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1122dba7b0efSSimon J. Gerraty GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); } 11233955d011SMarcel Moolenaar 11249f45a3c8SSimon J. Gerraty MAKE_INLINE void * MAKE_ATTR_USE 112512904384SSimon J. Gerraty UNCONST(const void *ptr) 112612904384SSimon J. Gerraty { 112712904384SSimon J. Gerraty void *ret; 112812904384SSimon J. Gerraty memcpy(&ret, &ptr, sizeof(ret)); 112912904384SSimon J. Gerraty return ret; 113012904384SSimon J. Gerraty } 11313955d011SMarcel Moolenaar 11324c620fe5SSimon J. Gerraty /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */ 11334c620fe5SSimon J. Gerraty #ifdef HAVE_LIMITS_H 11344c620fe5SSimon J. Gerraty #include <limits.h> 11354c620fe5SSimon J. Gerraty #endif 11360dede8b0SSimon J. Gerraty #ifndef MAXPATHLEN 11370dede8b0SSimon J. Gerraty #define MAXPATHLEN BMAKE_PATH_MAX 11380dede8b0SSimon J. Gerraty #endif 11394c620fe5SSimon J. Gerraty #ifndef PATH_MAX 11404c620fe5SSimon J. Gerraty #define PATH_MAX MAXPATHLEN 11414c620fe5SSimon J. Gerraty #endif 11420dede8b0SSimon J. Gerraty 1143c7019bf7SSimon J. Gerraty #if defined(SYSV) 1144c7019bf7SSimon J. Gerraty #define KILLPG(pid, sig) kill(-(pid), (sig)) 1145c7019bf7SSimon J. Gerraty #else 1146c7019bf7SSimon J. Gerraty #define KILLPG(pid, sig) killpg((pid), (sig)) 1147c7019bf7SSimon J. Gerraty #endif 1148c7019bf7SSimon J. Gerraty 11499f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1150e2eeea75SSimon J. Gerraty ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; } 11519f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1152e2eeea75SSimon J. Gerraty ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; } 11539f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1154e2eeea75SSimon J. Gerraty ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; } 11559f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 11569f45a3c8SSimon J. Gerraty ch_islower(char ch) { return islower((unsigned char)ch) != 0; } 11579f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1158e2eeea75SSimon J. Gerraty ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; } 11599f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1160e2eeea75SSimon J. Gerraty ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; } 11619f45a3c8SSimon J. Gerraty MAKE_INLINE char MAKE_ATTR_USE 1162e2eeea75SSimon J. Gerraty ch_tolower(char ch) { return (char)tolower((unsigned char)ch); } 11639f45a3c8SSimon J. Gerraty MAKE_INLINE char MAKE_ATTR_USE 1164e2eeea75SSimon J. Gerraty ch_toupper(char ch) { return (char)toupper((unsigned char)ch); } 1165956e45f6SSimon J. Gerraty 1166e2eeea75SSimon J. Gerraty MAKE_INLINE void 1167956e45f6SSimon J. Gerraty cpp_skip_whitespace(const char **pp) 1168956e45f6SSimon J. Gerraty { 1169956e45f6SSimon J. Gerraty while (ch_isspace(**pp)) 1170956e45f6SSimon J. Gerraty (*pp)++; 1171956e45f6SSimon J. Gerraty } 1172956e45f6SSimon J. Gerraty 1173e2eeea75SSimon J. Gerraty MAKE_INLINE void 1174e2eeea75SSimon J. Gerraty cpp_skip_hspace(const char **pp) 1175e2eeea75SSimon J. Gerraty { 1176e2eeea75SSimon J. Gerraty while (**pp == ' ' || **pp == '\t') 1177e2eeea75SSimon J. Gerraty (*pp)++; 1178e2eeea75SSimon J. Gerraty } 1179e2eeea75SSimon J. Gerraty 11809f45a3c8SSimon J. Gerraty MAKE_INLINE bool 11819f45a3c8SSimon J. Gerraty cpp_skip_string(const char **pp, const char *s) 11829f45a3c8SSimon J. Gerraty { 11839f45a3c8SSimon J. Gerraty const char *p = *pp; 11849f45a3c8SSimon J. Gerraty while (*p == *s && *s != '\0') 11859f45a3c8SSimon J. Gerraty p++, s++; 11869f45a3c8SSimon J. Gerraty if (*s == '\0') 11879f45a3c8SSimon J. Gerraty *pp = p; 11889f45a3c8SSimon J. Gerraty return *s == '\0'; 11899f45a3c8SSimon J. Gerraty } 11909f45a3c8SSimon J. Gerraty 1191e2eeea75SSimon J. Gerraty MAKE_INLINE void 1192956e45f6SSimon J. Gerraty pp_skip_whitespace(char **pp) 1193956e45f6SSimon J. Gerraty { 1194956e45f6SSimon J. Gerraty while (ch_isspace(**pp)) 1195956e45f6SSimon J. Gerraty (*pp)++; 1196956e45f6SSimon J. Gerraty } 1197956e45f6SSimon J. Gerraty 1198e2eeea75SSimon J. Gerraty MAKE_INLINE void 1199e2eeea75SSimon J. Gerraty pp_skip_hspace(char **pp) 1200e2eeea75SSimon J. Gerraty { 1201e2eeea75SSimon J. Gerraty while (**pp == ' ' || **pp == '\t') 1202e2eeea75SSimon J. Gerraty (*pp)++; 1203e2eeea75SSimon J. Gerraty } 1204e2eeea75SSimon J. Gerraty 120506b9b3e0SSimon J. Gerraty #if defined(lint) 1206*8c973ee2SSimon J. Gerraty extern void do_not_define_rcsid(void); /* for lint */ 120706b9b3e0SSimon J. Gerraty # define MAKE_RCSID(id) extern void do_not_define_rcsid(void) 120806b9b3e0SSimon J. Gerraty #elif defined(MAKE_NATIVE) 1209956e45f6SSimon J. Gerraty # include <sys/cdefs.h> 121012904384SSimon J. Gerraty # ifndef __IDSTRING 121112904384SSimon J. Gerraty # define __IDSTRING(name,string) \ 121212904384SSimon J. Gerraty static const char name[] MAKE_ATTR_UNUSED = string 121312904384SSimon J. Gerraty # endif 121412904384SSimon J. Gerraty # ifndef __RCSID 121512904384SSimon J. Gerraty # define __RCSID(s) __IDSTRING(rcsid,s) 121612904384SSimon J. Gerraty # endif 121712904384SSimon J. Gerraty # ifndef __COPYRIGHT 121812904384SSimon J. Gerraty # define __COPYRIGHT(s) __IDSTRING(copyright,s) 121912904384SSimon J. Gerraty # endif 1220956e45f6SSimon J. Gerraty # define MAKE_RCSID(id) __RCSID(id) 122106b9b3e0SSimon J. Gerraty #elif defined(MAKE_ALL_IN_ONE) && defined(__COUNTER__) 122206b9b3e0SSimon J. Gerraty # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y) 122306b9b3e0SSimon J. Gerraty # define MAKE_RCSID(id) static volatile char \ 122406b9b3e0SSimon J. Gerraty MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id 122506b9b3e0SSimon J. Gerraty #elif defined(MAKE_ALL_IN_ONE) 122606b9b3e0SSimon J. Gerraty # define MAKE_RCSID(id) extern void do_not_define_rcsid(void) 1227956e45f6SSimon J. Gerraty #else 1228956e45f6SSimon J. Gerraty # define MAKE_RCSID(id) static volatile char rcsid[] = id 1229956e45f6SSimon J. Gerraty #endif 1230956e45f6SSimon J. Gerraty 12319f45a3c8SSimon J. Gerraty #endif 1232