1*148ee845SSimon J. Gerraty /* $NetBSD: make.h,v 1.323 2023/06/20 09:25:33 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 558*148ee845SSimon J. Gerraty typedef struct { 559*148ee845SSimon J. Gerraty enum GuardKind { 560*148ee845SSimon J. Gerraty GK_VARIABLE, 561*148ee845SSimon J. Gerraty GK_TARGET 562*148ee845SSimon J. Gerraty } kind; 563*148ee845SSimon J. Gerraty char *name; 564*148ee845SSimon J. Gerraty } Guard; 565*148ee845SSimon J. Gerraty 566e2eeea75SSimon J. Gerraty /* Names of the variables that are "local" to a specific target. */ 5673955d011SMarcel Moolenaar #define TARGET "@" /* Target of dependency */ 5683955d011SMarcel Moolenaar #define OODATE "?" /* All out-of-date sources */ 5693955d011SMarcel Moolenaar #define ALLSRC ">" /* All sources */ 5703955d011SMarcel Moolenaar #define IMPSRC "<" /* Source implied by transformation */ 5713955d011SMarcel Moolenaar #define PREFIX "*" /* Common prefix */ 5723955d011SMarcel Moolenaar #define ARCHIVE "!" /* Archive in "archive(member)" syntax */ 5733955d011SMarcel Moolenaar #define MEMBER "%" /* Member in "archive(member)" syntax */ 5743955d011SMarcel Moolenaar 5753955d011SMarcel Moolenaar /* 5763955d011SMarcel Moolenaar * Global Variables 5773955d011SMarcel Moolenaar */ 5783955d011SMarcel Moolenaar 579e2eeea75SSimon J. Gerraty /* True if every target is precious */ 580b0c40a00SSimon J. Gerraty extern bool allPrecious; 581e2eeea75SSimon J. Gerraty /* True if failed targets should be deleted */ 582b0c40a00SSimon J. Gerraty extern bool deleteOnError; 583b0c40a00SSimon J. Gerraty /* true while processing .depend */ 584b0c40a00SSimon J. Gerraty extern bool doing_depend; 585e2eeea75SSimon J. Gerraty /* .DEFAULT rule */ 586e2eeea75SSimon J. Gerraty extern GNode *defaultNode; 5873955d011SMarcel Moolenaar 58806b9b3e0SSimon J. Gerraty /* 58906b9b3e0SSimon J. Gerraty * Variables defined internally by make which should not override those set 59006b9b3e0SSimon J. Gerraty * by makefiles. 59106b9b3e0SSimon J. Gerraty */ 592dba7b0efSSimon J. Gerraty extern GNode *SCOPE_INTERNAL; 593dba7b0efSSimon J. Gerraty /* Variables defined in a global scope, e.g in the makefile itself. */ 594dba7b0efSSimon J. Gerraty extern GNode *SCOPE_GLOBAL; 595e2eeea75SSimon J. Gerraty /* Variables defined on the command line. */ 596dba7b0efSSimon J. Gerraty extern GNode *SCOPE_CMDLINE; 597e2eeea75SSimon J. Gerraty 59806b9b3e0SSimon J. Gerraty /* 59906b9b3e0SSimon J. Gerraty * Value returned by Var_Parse when an error is encountered. It actually 60006b9b3e0SSimon J. Gerraty * points to an empty string, so naive callers needn't worry about it. 60106b9b3e0SSimon J. Gerraty */ 602e2eeea75SSimon J. Gerraty extern char var_Error[]; 603e2eeea75SSimon J. Gerraty 604e2eeea75SSimon J. Gerraty /* The time at the start of this whole process */ 605e2eeea75SSimon J. Gerraty extern time_t now; 606e2eeea75SSimon J. Gerraty 607e2eeea75SSimon J. Gerraty /* 60806b9b3e0SSimon J. Gerraty * The list of directories to search when looking for targets (set by the 60906b9b3e0SSimon J. Gerraty * special target .PATH). 6101bbe5942SSimon J. Gerraty */ 61106b9b3e0SSimon J. Gerraty extern SearchPath dirSearchPath; 612e2eeea75SSimon J. Gerraty /* Used for .include "...". */ 613e2eeea75SSimon J. Gerraty extern SearchPath *parseIncPath; 61406b9b3e0SSimon J. Gerraty /* 615dba7b0efSSimon J. Gerraty * Used for .include <...>, for the built-in sys.mk and for makefiles from 616dba7b0efSSimon J. Gerraty * the command line arguments. 61706b9b3e0SSimon J. Gerraty */ 618e2eeea75SSimon J. Gerraty extern SearchPath *sysIncPath; 619e2eeea75SSimon J. Gerraty /* The default for sysIncPath. */ 620e2eeea75SSimon J. Gerraty extern SearchPath *defSysIncPath; 6213955d011SMarcel Moolenaar 622e2eeea75SSimon J. Gerraty /* Startup directory */ 623e2eeea75SSimon J. Gerraty extern char curdir[]; 624e2eeea75SSimon J. Gerraty /* The basename of the program name, suffixed with [n] for sub-makes. */ 62506b9b3e0SSimon J. Gerraty extern const char *progname; 626dba7b0efSSimon J. Gerraty extern int makelevel; 627e2eeea75SSimon J. Gerraty /* Name of the .depend makefile */ 628e2eeea75SSimon J. Gerraty extern char *makeDependfile; 629e2eeea75SSimon J. Gerraty /* If we replaced environ, this will be non-NULL. */ 630e2eeea75SSimon J. Gerraty extern char **savedEnv; 6319f45a3c8SSimon J. Gerraty extern GNode *mainNode; 6323955d011SMarcel Moolenaar 6333955d011SMarcel Moolenaar extern pid_t myPid; 6343955d011SMarcel Moolenaar 6353955d011SMarcel Moolenaar #define MAKEFLAGS ".MAKEFLAGS" 63651ee2c1cSSimon J. Gerraty #ifndef MAKE_LEVEL_ENV 63751ee2c1cSSimon J. Gerraty # define MAKE_LEVEL_ENV "MAKELEVEL" 6383955d011SMarcel Moolenaar #endif 6393955d011SMarcel Moolenaar 6409f45a3c8SSimon J. Gerraty typedef struct DebugFlags { 6419f45a3c8SSimon J. Gerraty bool DEBUG_ARCH:1; 6429f45a3c8SSimon J. Gerraty bool DEBUG_COND:1; 6439f45a3c8SSimon J. Gerraty bool DEBUG_CWD:1; 6449f45a3c8SSimon J. Gerraty bool DEBUG_DIR:1; 6459f45a3c8SSimon J. Gerraty bool DEBUG_ERROR:1; 6469f45a3c8SSimon J. Gerraty bool DEBUG_FOR:1; 6479f45a3c8SSimon J. Gerraty bool DEBUG_GRAPH1:1; 6489f45a3c8SSimon J. Gerraty bool DEBUG_GRAPH2:1; 6499f45a3c8SSimon J. Gerraty bool DEBUG_GRAPH3:1; 6509f45a3c8SSimon J. Gerraty bool DEBUG_HASH:1; 6519f45a3c8SSimon J. Gerraty bool DEBUG_JOB:1; 6529f45a3c8SSimon J. Gerraty bool DEBUG_LOUD:1; 6539f45a3c8SSimon J. Gerraty bool DEBUG_MAKE:1; 6549f45a3c8SSimon J. Gerraty bool DEBUG_META:1; 6559f45a3c8SSimon J. Gerraty bool DEBUG_PARSE:1; 6569f45a3c8SSimon J. Gerraty bool DEBUG_SCRIPT:1; 6579f45a3c8SSimon J. Gerraty bool DEBUG_SHELL:1; 6589f45a3c8SSimon J. Gerraty bool DEBUG_SUFF:1; 6599f45a3c8SSimon J. Gerraty bool DEBUG_TARG:1; 6609f45a3c8SSimon J. Gerraty bool DEBUG_VAR:1; 661956e45f6SSimon J. Gerraty } DebugFlags; 6622c3632d1SSimon J. Gerraty 6633955d011SMarcel Moolenaar #define CONCAT(a, b) a##b 6643955d011SMarcel Moolenaar 6659f45a3c8SSimon J. Gerraty #define DEBUG(module) (opts.debug.CONCAT(DEBUG_, module)) 666956e45f6SSimon J. Gerraty 667956e45f6SSimon J. Gerraty void debug_printf(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2); 668956e45f6SSimon J. Gerraty 66906b9b3e0SSimon J. Gerraty #define DEBUG_IMPL(module, args) \ 67006b9b3e0SSimon J. Gerraty do { \ 67106b9b3e0SSimon J. Gerraty if (DEBUG(module)) \ 67206b9b3e0SSimon J. Gerraty debug_printf args; \ 67312904384SSimon J. Gerraty } while (false) 67406b9b3e0SSimon J. Gerraty 6759f45a3c8SSimon J. Gerraty #define DEBUG0(module, fmt) \ 6769f45a3c8SSimon J. Gerraty DEBUG_IMPL(module, (fmt)) 677956e45f6SSimon J. Gerraty #define DEBUG1(module, fmt, arg1) \ 67806b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1)) 679956e45f6SSimon J. Gerraty #define DEBUG2(module, fmt, arg1, arg2) \ 68006b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1, arg2)) 681956e45f6SSimon J. Gerraty #define DEBUG3(module, fmt, arg1, arg2, arg3) \ 68206b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1, arg2, arg3)) 683956e45f6SSimon J. Gerraty #define DEBUG4(module, fmt, arg1, arg2, arg3, arg4) \ 68406b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4)) 685956e45f6SSimon J. Gerraty #define DEBUG5(module, fmt, arg1, arg2, arg3, arg4, arg5) \ 68606b9b3e0SSimon J. Gerraty DEBUG_IMPL(module, (fmt, arg1, arg2, arg3, arg4, arg5)) 687956e45f6SSimon J. Gerraty 688956e45f6SSimon J. Gerraty typedef enum PrintVarsMode { 689e2eeea75SSimon J. Gerraty PVM_NONE, 690e2eeea75SSimon J. Gerraty PVM_UNEXPANDED, 691e2eeea75SSimon J. Gerraty PVM_EXPANDED 692956e45f6SSimon J. Gerraty } PrintVarsMode; 693956e45f6SSimon J. Gerraty 694956e45f6SSimon J. Gerraty /* Command line options */ 695956e45f6SSimon J. Gerraty typedef struct CmdOpts { 696956e45f6SSimon J. Gerraty /* -B: whether we are make compatible */ 697b0c40a00SSimon J. Gerraty bool compatMake; 698956e45f6SSimon J. Gerraty 6999f45a3c8SSimon J. Gerraty /* 7009f45a3c8SSimon J. Gerraty * -d: debug control: There is one bit per module. It is up to the 7019f45a3c8SSimon J. Gerraty * module what debug information to print. 7029f45a3c8SSimon J. Gerraty */ 703956e45f6SSimon J. Gerraty DebugFlags debug; 704956e45f6SSimon J. Gerraty 705956e45f6SSimon J. Gerraty /* -df: debug output is written here - default stderr */ 706956e45f6SSimon J. Gerraty FILE *debug_file; 707956e45f6SSimon J. Gerraty 7089f45a3c8SSimon J. Gerraty /* 7099f45a3c8SSimon J. Gerraty * -dL: lint mode 710e2eeea75SSimon J. Gerraty * 711e2eeea75SSimon J. Gerraty * Runs make in strict mode, with additional checks and better error 7129f45a3c8SSimon J. Gerraty * handling. 7139f45a3c8SSimon J. Gerraty */ 714b0c40a00SSimon J. Gerraty bool strict; 715e2eeea75SSimon J. Gerraty 716956e45f6SSimon J. Gerraty /* -dV: for the -V option, print unexpanded variable values */ 717b0c40a00SSimon J. Gerraty bool debugVflag; 718956e45f6SSimon J. Gerraty 719956e45f6SSimon J. Gerraty /* -e: check environment variables before global variables */ 720b0c40a00SSimon J. Gerraty bool checkEnvFirst; 721956e45f6SSimon J. Gerraty 722956e45f6SSimon J. Gerraty /* -f: the makefiles to read */ 72306b9b3e0SSimon J. Gerraty StringList makefiles; 724956e45f6SSimon J. Gerraty 725956e45f6SSimon J. Gerraty /* -i: if true, ignore all errors from shell commands */ 726b0c40a00SSimon J. Gerraty bool ignoreErrors; 727956e45f6SSimon J. Gerraty 7289f45a3c8SSimon J. Gerraty /* 7299f45a3c8SSimon J. Gerraty * -j: the maximum number of jobs that can run in parallel; this is 7309f45a3c8SSimon J. Gerraty * coordinated with the submakes 7319f45a3c8SSimon J. Gerraty */ 732956e45f6SSimon J. Gerraty int maxJobs; 733956e45f6SSimon J. Gerraty 7349f45a3c8SSimon J. Gerraty /* 7359f45a3c8SSimon J. Gerraty * -k: if true and an error occurs while making a node, continue 7369f45a3c8SSimon J. Gerraty * making nodes that do not depend on the erroneous node 7379f45a3c8SSimon J. Gerraty */ 738b0c40a00SSimon J. Gerraty bool keepgoing; 739956e45f6SSimon J. Gerraty 740956e45f6SSimon J. Gerraty /* -N: execute no commands from the targets */ 741b0c40a00SSimon J. Gerraty bool noRecursiveExecute; 742956e45f6SSimon J. Gerraty 743956e45f6SSimon J. Gerraty /* -n: execute almost no commands from the targets */ 744b0c40a00SSimon J. Gerraty bool noExecute; 745956e45f6SSimon J. Gerraty 746dba7b0efSSimon J. Gerraty /* 747dba7b0efSSimon J. Gerraty * -q: if true, do not really make anything, just see if the targets 748dba7b0efSSimon J. Gerraty * are out-of-date 749dba7b0efSSimon J. Gerraty */ 7509f45a3c8SSimon J. Gerraty bool query; 751956e45f6SSimon J. Gerraty 752dba7b0efSSimon J. Gerraty /* -r: raw mode, do not load the builtin rules. */ 753b0c40a00SSimon J. Gerraty bool noBuiltins; 754956e45f6SSimon J. Gerraty 755956e45f6SSimon J. Gerraty /* -s: don't echo the shell commands before executing them */ 7569f45a3c8SSimon J. Gerraty bool silent; 757956e45f6SSimon J. Gerraty 7589f45a3c8SSimon J. Gerraty /* 7599f45a3c8SSimon J. Gerraty * -t: touch the targets if they are out-of-date, but don't actually 7609f45a3c8SSimon J. Gerraty * make them 7619f45a3c8SSimon J. Gerraty */ 7629f45a3c8SSimon J. Gerraty bool touch; 763956e45f6SSimon J. Gerraty 764956e45f6SSimon J. Gerraty /* -[Vv]: print expanded or unexpanded selected variables */ 765956e45f6SSimon J. Gerraty PrintVarsMode printVars; 766956e45f6SSimon J. Gerraty /* -[Vv]: the variables to print */ 76706b9b3e0SSimon J. Gerraty StringList variables; 768956e45f6SSimon J. Gerraty 769956e45f6SSimon J. Gerraty /* -W: if true, makefile parsing warnings are treated as errors */ 770b0c40a00SSimon J. Gerraty bool parseWarnFatal; 771956e45f6SSimon J. Gerraty 772dba7b0efSSimon J. Gerraty /* -w: print 'Entering' and 'Leaving' for submakes */ 773b0c40a00SSimon J. Gerraty bool enterFlag; 774956e45f6SSimon J. Gerraty 7759f45a3c8SSimon J. Gerraty /* 7769f45a3c8SSimon J. Gerraty * -X: if true, do not export variables set on the command line to 7779f45a3c8SSimon J. Gerraty * the environment. 7789f45a3c8SSimon J. Gerraty */ 779b0c40a00SSimon J. Gerraty bool varNoExportEnv; 780956e45f6SSimon J. Gerraty 7819f45a3c8SSimon J. Gerraty /* 7829f45a3c8SSimon J. Gerraty * The target names specified on the command line. Used to resolve 7839f45a3c8SSimon J. Gerraty * .if make(...) statements. 7849f45a3c8SSimon J. Gerraty */ 78506b9b3e0SSimon J. Gerraty StringList create; 786956e45f6SSimon J. Gerraty 787954401e6SSimon J. Gerraty /* 788954401e6SSimon J. Gerraty * Randomize the order in which the targets from toBeMade are made, 789954401e6SSimon J. Gerraty * to catch undeclared dependencies. 790954401e6SSimon J. Gerraty */ 791954401e6SSimon J. Gerraty bool randomizeTargets; 792956e45f6SSimon J. Gerraty } CmdOpts; 793956e45f6SSimon J. Gerraty 794956e45f6SSimon J. Gerraty extern CmdOpts opts; 7958c973ee2SSimon J. Gerraty extern bool forceJobs; 7968c973ee2SSimon J. Gerraty extern char **environ; 7973955d011SMarcel Moolenaar 7989f45a3c8SSimon J. Gerraty /* arch.c */ 7999f45a3c8SSimon J. Gerraty void Arch_Init(void); 8009f45a3c8SSimon J. Gerraty void Arch_End(void); 8013955d011SMarcel Moolenaar 8029f45a3c8SSimon J. Gerraty bool Arch_ParseArchive(char **, GNodeList *, GNode *); 8039f45a3c8SSimon J. Gerraty void Arch_Touch(GNode *); 8049f45a3c8SSimon J. Gerraty void Arch_TouchLib(GNode *); 805*148ee845SSimon J. Gerraty void Arch_UpdateMTime(GNode *); 806*148ee845SSimon J. Gerraty void Arch_UpdateMemberMTime(GNode *); 8079f45a3c8SSimon J. Gerraty void Arch_FindLib(GNode *, SearchPath *); 8089f45a3c8SSimon J. Gerraty bool Arch_LibOODate(GNode *) MAKE_ATTR_USE; 8099f45a3c8SSimon J. Gerraty bool Arch_IsLib(GNode *) MAKE_ATTR_USE; 8109f45a3c8SSimon J. Gerraty 8119f45a3c8SSimon J. Gerraty /* compat.c */ 8129f45a3c8SSimon J. Gerraty bool Compat_RunCommand(const char *, GNode *, StringListNode *); 813954401e6SSimon J. Gerraty void Compat_MakeAll(GNodeList *); 8149f45a3c8SSimon J. Gerraty void Compat_Make(GNode *, GNode *); 8159f45a3c8SSimon J. Gerraty 8169f45a3c8SSimon J. Gerraty /* cond.c */ 8174fde40d9SSimon J. Gerraty extern unsigned int cond_depth; 8189f45a3c8SSimon J. Gerraty CondResult Cond_EvalCondition(const char *) MAKE_ATTR_USE; 8199f45a3c8SSimon J. Gerraty CondResult Cond_EvalLine(const char *) MAKE_ATTR_USE; 820*148ee845SSimon J. Gerraty Guard *Cond_ExtractGuard(const char *) MAKE_ATTR_USE; 8214fde40d9SSimon J. Gerraty void Cond_EndFile(void); 8229f45a3c8SSimon J. Gerraty 8239f45a3c8SSimon J. Gerraty /* dir.c; see also dir.h */ 8249f45a3c8SSimon J. Gerraty 8259f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 8269f45a3c8SSimon J. Gerraty str_basename(const char *pathname) 8279f45a3c8SSimon J. Gerraty { 8289f45a3c8SSimon J. Gerraty const char *lastSlash = strrchr(pathname, '/'); 8299f45a3c8SSimon J. Gerraty return lastSlash != NULL ? lastSlash + 1 : pathname; 8309f45a3c8SSimon J. Gerraty } 8319f45a3c8SSimon J. Gerraty 8329f45a3c8SSimon J. Gerraty MAKE_INLINE SearchPath * MAKE_ATTR_USE 8339f45a3c8SSimon J. Gerraty SearchPath_New(void) 8349f45a3c8SSimon J. Gerraty { 8359f45a3c8SSimon J. Gerraty SearchPath *path = bmake_malloc(sizeof *path); 8369f45a3c8SSimon J. Gerraty Lst_Init(&path->dirs); 8379f45a3c8SSimon J. Gerraty return path; 8389f45a3c8SSimon J. Gerraty } 8399f45a3c8SSimon J. Gerraty 8409f45a3c8SSimon J. Gerraty void SearchPath_Free(SearchPath *); 8419f45a3c8SSimon J. Gerraty 8429f45a3c8SSimon J. Gerraty /* for.c */ 8439f45a3c8SSimon J. Gerraty struct ForLoop; 8449f45a3c8SSimon J. Gerraty int For_Eval(const char *) MAKE_ATTR_USE; 8459f45a3c8SSimon J. Gerraty bool For_Accum(const char *, int *) MAKE_ATTR_USE; 8469f45a3c8SSimon J. Gerraty void For_Run(unsigned, unsigned); 8479f45a3c8SSimon J. Gerraty bool For_NextIteration(struct ForLoop *, Buffer *); 848*148ee845SSimon J. Gerraty char *ForLoop_Details(const struct ForLoop *); 8499f45a3c8SSimon J. Gerraty void ForLoop_Free(struct ForLoop *); 8504fde40d9SSimon J. Gerraty void For_Break(struct ForLoop *); 8519f45a3c8SSimon J. Gerraty 8529f45a3c8SSimon J. Gerraty /* job.c */ 8539f45a3c8SSimon J. Gerraty void JobReapChild(pid_t, int, bool); 8549f45a3c8SSimon J. Gerraty 8559f45a3c8SSimon J. Gerraty /* main.c */ 8569f45a3c8SSimon J. Gerraty void Main_ParseArgLine(const char *); 8579f45a3c8SSimon J. Gerraty char *Cmd_Exec(const char *, char **) MAKE_ATTR_USE; 8589f45a3c8SSimon J. Gerraty void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2); 8599f45a3c8SSimon J. Gerraty void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD; 8609f45a3c8SSimon J. Gerraty void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD; 8619f45a3c8SSimon J. Gerraty void DieHorribly(void) MAKE_ATTR_DEAD; 8629f45a3c8SSimon J. Gerraty void Finish(int) MAKE_ATTR_DEAD; 8634fde40d9SSimon J. Gerraty int unlink_file(const char *) MAKE_ATTR_USE; 8649f45a3c8SSimon J. Gerraty void execDie(const char *, const char *); 8659f45a3c8SSimon J. Gerraty char *getTmpdir(void) MAKE_ATTR_USE; 8669f45a3c8SSimon J. Gerraty bool ParseBoolean(const char *, bool) MAKE_ATTR_USE; 8679f45a3c8SSimon J. Gerraty const char *cached_realpath(const char *, char *); 8689f45a3c8SSimon J. Gerraty bool GetBooleanExpr(const char *, bool); 8699f45a3c8SSimon J. Gerraty 8709f45a3c8SSimon J. Gerraty /* parse.c */ 8719f45a3c8SSimon J. Gerraty void Parse_Init(void); 8729f45a3c8SSimon J. Gerraty void Parse_End(void); 8739f45a3c8SSimon J. Gerraty 874954401e6SSimon J. Gerraty void PrintLocation(FILE *, bool, const GNode *); 8759f45a3c8SSimon J. Gerraty void PrintStackTrace(bool); 8769f45a3c8SSimon J. Gerraty void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3); 8779f45a3c8SSimon J. Gerraty bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE; 8789f45a3c8SSimon J. Gerraty void Parse_AddIncludeDir(const char *); 8799f45a3c8SSimon J. Gerraty void Parse_File(const char *, int); 8809f45a3c8SSimon J. Gerraty void Parse_PushInput(const char *, unsigned, unsigned, Buffer, 8819f45a3c8SSimon J. Gerraty struct ForLoop *); 8829f45a3c8SSimon J. Gerraty void Parse_MainName(GNodeList *); 8839f45a3c8SSimon J. Gerraty int Parse_NumErrors(void) MAKE_ATTR_USE; 8844fde40d9SSimon J. Gerraty unsigned int CurFile_CondMinDepth(void) MAKE_ATTR_USE; 885*148ee845SSimon J. Gerraty void Parse_GuardElse(void); 886*148ee845SSimon J. Gerraty void Parse_GuardEndif(void); 8879f45a3c8SSimon J. Gerraty 8889f45a3c8SSimon J. Gerraty 8899f45a3c8SSimon J. Gerraty /* suff.c */ 8909f45a3c8SSimon J. Gerraty void Suff_Init(void); 8919f45a3c8SSimon J. Gerraty void Suff_End(void); 8929f45a3c8SSimon J. Gerraty 8939f45a3c8SSimon J. Gerraty void Suff_ClearSuffixes(void); 8949f45a3c8SSimon J. Gerraty bool Suff_IsTransform(const char *) MAKE_ATTR_USE; 8959f45a3c8SSimon J. Gerraty GNode *Suff_AddTransform(const char *); 8969f45a3c8SSimon J. Gerraty void Suff_EndTransform(GNode *); 8979f45a3c8SSimon J. Gerraty void Suff_AddSuffix(const char *); 8989f45a3c8SSimon J. Gerraty SearchPath *Suff_GetPath(const char *) MAKE_ATTR_USE; 8999f45a3c8SSimon J. Gerraty void Suff_ExtendPaths(void); 9009f45a3c8SSimon J. Gerraty void Suff_AddInclude(const char *); 9019f45a3c8SSimon J. Gerraty void Suff_AddLib(const char *); 9029f45a3c8SSimon J. Gerraty void Suff_FindDeps(GNode *); 9039f45a3c8SSimon J. Gerraty SearchPath *Suff_FindPath(GNode *) MAKE_ATTR_USE; 9049f45a3c8SSimon J. Gerraty void Suff_SetNull(const char *); 9059f45a3c8SSimon J. Gerraty void Suff_PrintAll(void); 9069f45a3c8SSimon J. Gerraty char *Suff_NamesStr(void) MAKE_ATTR_USE; 9079f45a3c8SSimon J. Gerraty 9089f45a3c8SSimon J. Gerraty /* targ.c */ 9099f45a3c8SSimon J. Gerraty void Targ_Init(void); 9109f45a3c8SSimon J. Gerraty void Targ_End(void); 9119f45a3c8SSimon J. Gerraty 9129f45a3c8SSimon J. Gerraty void Targ_Stats(void); 9139f45a3c8SSimon J. Gerraty GNodeList *Targ_List(void) MAKE_ATTR_USE; 9149f45a3c8SSimon J. Gerraty GNode *GNode_New(const char *) MAKE_ATTR_USE; 9159f45a3c8SSimon J. Gerraty GNode *Targ_FindNode(const char *) MAKE_ATTR_USE; 9169f45a3c8SSimon J. Gerraty GNode *Targ_GetNode(const char *) MAKE_ATTR_USE; 9179f45a3c8SSimon J. Gerraty GNode *Targ_NewInternalNode(const char *) MAKE_ATTR_USE; 9189f45a3c8SSimon J. Gerraty GNode *Targ_GetEndNode(void); 9199f45a3c8SSimon J. Gerraty void Targ_FindList(GNodeList *, StringList *); 9209f45a3c8SSimon J. Gerraty void Targ_PrintCmds(GNode *); 9219f45a3c8SSimon J. Gerraty void Targ_PrintNode(GNode *, int); 9229f45a3c8SSimon J. Gerraty void Targ_PrintNodes(GNodeList *, int); 9239f45a3c8SSimon J. Gerraty const char *Targ_FmtTime(time_t) MAKE_ATTR_USE; 9249f45a3c8SSimon J. Gerraty void Targ_PrintType(GNodeType); 9259f45a3c8SSimon J. Gerraty void Targ_PrintGraph(int); 9269f45a3c8SSimon J. Gerraty void Targ_Propagate(void); 9279f45a3c8SSimon J. Gerraty const char *GNodeMade_Name(GNodeMade) MAKE_ATTR_USE; 9289f45a3c8SSimon J. Gerraty 9299f45a3c8SSimon J. Gerraty /* var.c */ 9309f45a3c8SSimon J. Gerraty void Var_Init(void); 9319f45a3c8SSimon J. Gerraty void Var_End(void); 9329f45a3c8SSimon J. Gerraty 9339f45a3c8SSimon J. Gerraty typedef enum VarEvalMode { 9349f45a3c8SSimon J. Gerraty 9359f45a3c8SSimon J. Gerraty /* 9369f45a3c8SSimon J. Gerraty * Only parse the expression but don't evaluate any part of it. 9379f45a3c8SSimon J. Gerraty * 9389f45a3c8SSimon J. Gerraty * TODO: Document what Var_Parse and Var_Subst return in this mode. 9399f45a3c8SSimon J. Gerraty * As of 2021-03-15, they return unspecified, inconsistent results. 9409f45a3c8SSimon J. Gerraty */ 9419f45a3c8SSimon J. Gerraty VARE_PARSE_ONLY, 9429f45a3c8SSimon J. Gerraty 9438c973ee2SSimon J. Gerraty /* 9448c973ee2SSimon J. Gerraty * Parse text in which '${...}' and '$(...)' are not parsed as 9458c973ee2SSimon J. Gerraty * subexpressions (with all their individual escaping rules) but 9468c973ee2SSimon J. Gerraty * instead simply as text with balanced '${}' or '$()'. Other '$' 9478c973ee2SSimon J. Gerraty * are copied verbatim. 9488c973ee2SSimon J. Gerraty */ 9498c973ee2SSimon J. Gerraty VARE_PARSE_BALANCED, 9508c973ee2SSimon J. Gerraty 9519f45a3c8SSimon J. Gerraty /* Parse and evaluate the expression. */ 9529f45a3c8SSimon J. Gerraty VARE_WANTRES, 9539f45a3c8SSimon J. Gerraty 9549f45a3c8SSimon J. Gerraty /* 9559f45a3c8SSimon J. Gerraty * Parse and evaluate the expression. It is an error if a 9569f45a3c8SSimon J. Gerraty * subexpression evaluates to undefined. 9579f45a3c8SSimon J. Gerraty */ 9589f45a3c8SSimon J. Gerraty VARE_UNDEFERR, 9599f45a3c8SSimon J. Gerraty 9609f45a3c8SSimon J. Gerraty /* 9619f45a3c8SSimon J. Gerraty * Parse and evaluate the expression. Keep '$$' as '$$' instead of 9629f45a3c8SSimon J. Gerraty * reducing it to a single '$'. Subexpressions that evaluate to 9639f45a3c8SSimon J. Gerraty * undefined expand to an empty string. 9649f45a3c8SSimon J. Gerraty * 9659f45a3c8SSimon J. Gerraty * Used in variable assignments using the ':=' operator. It allows 9669f45a3c8SSimon J. Gerraty * multiple such assignments to be chained without accidentally 9679f45a3c8SSimon J. Gerraty * expanding '$$file' to '$file' in the first assignment and 9689f45a3c8SSimon J. Gerraty * interpreting it as '${f}' followed by 'ile' in the next assignment. 9699f45a3c8SSimon J. Gerraty */ 9709f45a3c8SSimon J. Gerraty VARE_EVAL_KEEP_DOLLAR, 9719f45a3c8SSimon J. Gerraty 9729f45a3c8SSimon J. Gerraty /* 9739f45a3c8SSimon J. Gerraty * Parse and evaluate the expression. Keep undefined variables as-is 9749f45a3c8SSimon J. Gerraty * instead of expanding them to an empty string. 9759f45a3c8SSimon J. Gerraty * 9769f45a3c8SSimon J. Gerraty * Example for a ':=' assignment: 9779f45a3c8SSimon J. Gerraty * CFLAGS = $(.INCLUDES) 9789f45a3c8SSimon J. Gerraty * CFLAGS := -I.. $(CFLAGS) 9799f45a3c8SSimon J. Gerraty * # If .INCLUDES (an undocumented special variable, by the 9809f45a3c8SSimon J. Gerraty * # way) is still undefined, the updated CFLAGS becomes 9819f45a3c8SSimon J. Gerraty * # "-I.. $(.INCLUDES)". 9829f45a3c8SSimon J. Gerraty */ 9839f45a3c8SSimon J. Gerraty VARE_EVAL_KEEP_UNDEF, 9849f45a3c8SSimon J. Gerraty 9859f45a3c8SSimon J. Gerraty /* 9869f45a3c8SSimon J. Gerraty * Parse and evaluate the expression. Keep '$$' as '$$' and preserve 9879f45a3c8SSimon J. Gerraty * undefined subexpressions. 9889f45a3c8SSimon J. Gerraty */ 9899f45a3c8SSimon J. Gerraty VARE_KEEP_DOLLAR_UNDEF 9909f45a3c8SSimon J. Gerraty } VarEvalMode; 9919f45a3c8SSimon J. Gerraty 9929f45a3c8SSimon J. Gerraty typedef enum VarSetFlags { 9939f45a3c8SSimon J. Gerraty VAR_SET_NONE = 0, 9949f45a3c8SSimon J. Gerraty 9959f45a3c8SSimon J. Gerraty /* do not export */ 9969f45a3c8SSimon J. Gerraty VAR_SET_NO_EXPORT = 1 << 0, 9979f45a3c8SSimon J. Gerraty 9989f45a3c8SSimon J. Gerraty /* 9999f45a3c8SSimon J. Gerraty * Make the variable read-only. No further modification is possible, 10008c973ee2SSimon J. Gerraty * except for another call to Var_Set with the same flag. See the 10018c973ee2SSimon J. Gerraty * special targets '.NOREADONLY' and '.READONLY'. 10029f45a3c8SSimon J. Gerraty */ 10039f45a3c8SSimon J. Gerraty VAR_SET_READONLY = 1 << 1 10049f45a3c8SSimon J. Gerraty } VarSetFlags; 10059f45a3c8SSimon J. Gerraty 10069f45a3c8SSimon J. Gerraty typedef enum VarExportMode { 10079f45a3c8SSimon J. Gerraty /* .export-env */ 10089f45a3c8SSimon J. Gerraty VEM_ENV, 10099f45a3c8SSimon J. Gerraty /* .export: Initial export or update an already exported variable. */ 10109f45a3c8SSimon J. Gerraty VEM_PLAIN, 10119f45a3c8SSimon J. Gerraty /* .export-literal: Do not expand the variable value. */ 10129f45a3c8SSimon J. Gerraty VEM_LITERAL 10139f45a3c8SSimon J. Gerraty } VarExportMode; 10149f45a3c8SSimon J. Gerraty 10159f45a3c8SSimon J. Gerraty void Var_Delete(GNode *, const char *); 10169f45a3c8SSimon J. Gerraty void Var_Undef(const char *); 10179f45a3c8SSimon J. Gerraty void Var_Set(GNode *, const char *, const char *); 10189f45a3c8SSimon J. Gerraty void Var_SetExpand(GNode *, const char *, const char *); 10199f45a3c8SSimon J. Gerraty void Var_SetWithFlags(GNode *, const char *, const char *, VarSetFlags); 10209f45a3c8SSimon J. Gerraty void Var_Append(GNode *, const char *, const char *); 10219f45a3c8SSimon J. Gerraty void Var_AppendExpand(GNode *, const char *, const char *); 10229f45a3c8SSimon J. Gerraty bool Var_Exists(GNode *, const char *) MAKE_ATTR_USE; 10239f45a3c8SSimon J. Gerraty bool Var_ExistsExpand(GNode *, const char *) MAKE_ATTR_USE; 10249f45a3c8SSimon J. Gerraty FStr Var_Value(GNode *, const char *) MAKE_ATTR_USE; 10259f45a3c8SSimon J. Gerraty const char *GNode_ValueDirect(GNode *, const char *) MAKE_ATTR_USE; 10268c973ee2SSimon J. Gerraty FStr Var_Parse(const char **, GNode *, VarEvalMode); 10278c973ee2SSimon J. Gerraty char *Var_Subst(const char *, GNode *, VarEvalMode); 10289f45a3c8SSimon J. Gerraty void Var_Expand(FStr *, GNode *, VarEvalMode); 10299f45a3c8SSimon J. Gerraty void Var_Stats(void); 10309f45a3c8SSimon J. Gerraty void Var_Dump(GNode *); 10319f45a3c8SSimon J. Gerraty void Var_ReexportVars(void); 10329f45a3c8SSimon J. Gerraty void Var_Export(VarExportMode, const char *); 10339f45a3c8SSimon J. Gerraty void Var_ExportVars(const char *); 10349f45a3c8SSimon J. Gerraty void Var_UnExport(bool, const char *); 10354fde40d9SSimon J. Gerraty void Var_ReadOnly(const char *, bool); 10369f45a3c8SSimon J. Gerraty 10379f45a3c8SSimon J. Gerraty void Global_Set(const char *, const char *); 10389f45a3c8SSimon J. Gerraty void Global_Append(const char *, const char *); 10399f45a3c8SSimon J. Gerraty void Global_Delete(const char *); 10404fde40d9SSimon J. Gerraty void Global_Set_ReadOnly(const char *, const char *); 10419f45a3c8SSimon J. Gerraty 10429f45a3c8SSimon J. Gerraty /* util.c */ 10439f45a3c8SSimon J. Gerraty typedef void (*SignalProc)(int); 10449f45a3c8SSimon J. Gerraty SignalProc bmake_signal(int, SignalProc); 10459f45a3c8SSimon J. Gerraty 10469f45a3c8SSimon J. Gerraty /* make.c */ 1047e2eeea75SSimon J. Gerraty void GNode_UpdateYoungestChild(GNode *, GNode *); 10489f45a3c8SSimon J. Gerraty bool GNode_IsOODate(GNode *) MAKE_ATTR_USE; 1049956e45f6SSimon J. Gerraty void Make_ExpandUse(GNodeList *); 10509f45a3c8SSimon J. Gerraty time_t Make_Recheck(GNode *) MAKE_ATTR_USE; 10513955d011SMarcel Moolenaar void Make_HandleUse(GNode *, GNode *); 10523955d011SMarcel Moolenaar void Make_Update(GNode *); 1053b0c40a00SSimon J. Gerraty void GNode_SetLocalVars(GNode *); 1054b0c40a00SSimon J. Gerraty bool Make_Run(GNodeList *); 10559f45a3c8SSimon J. Gerraty bool shouldDieQuietly(GNode *, int) MAKE_ATTR_USE; 10563955d011SMarcel Moolenaar void PrintOnError(GNode *, const char *); 1057b0c40a00SSimon J. Gerraty void Main_ExportMAKEFLAGS(bool); 1058b0c40a00SSimon J. Gerraty bool Main_SetObjdir(bool, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3); 10599f45a3c8SSimon J. Gerraty int mkTempFile(const char *, char *, size_t) MAKE_ATTR_USE; 1060e2eeea75SSimon J. Gerraty int str2Lst_Append(StringList *, char *); 10612c3632d1SSimon J. Gerraty void GNode_FprintDetails(FILE *, const char *, const GNode *, const char *); 10629f45a3c8SSimon J. Gerraty bool GNode_ShouldExecute(GNode *gn) MAKE_ATTR_USE; 1063956e45f6SSimon J. Gerraty 10644fde40d9SSimon J. Gerraty #ifndef HAVE_STRLCPY 10654fde40d9SSimon J. Gerraty size_t strlcpy(char *, const char *, size_t); 10664fde40d9SSimon J. Gerraty #endif 10674fde40d9SSimon J. Gerraty 1068956e45f6SSimon J. Gerraty /* See if the node was seen on the left-hand side of a dependency operator. */ 10699f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1070956e45f6SSimon J. Gerraty GNode_IsTarget(const GNode *gn) 1071956e45f6SSimon J. Gerraty { 107212904384SSimon J. Gerraty return (gn->type & OP_OPMASK) != OP_NONE; 1073956e45f6SSimon J. Gerraty } 1074956e45f6SSimon J. Gerraty 10759f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1076956e45f6SSimon J. Gerraty GNode_Path(const GNode *gn) 1077956e45f6SSimon J. Gerraty { 1078956e45f6SSimon J. Gerraty return gn->path != NULL ? gn->path : gn->name; 1079956e45f6SSimon J. Gerraty } 1080956e45f6SSimon J. Gerraty 10819f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 108206b9b3e0SSimon J. Gerraty GNode_IsWaitingFor(const GNode *gn) 108306b9b3e0SSimon J. Gerraty { 108412904384SSimon J. Gerraty return gn->flags.remake && gn->made <= REQUESTED; 108506b9b3e0SSimon J. Gerraty } 108606b9b3e0SSimon J. Gerraty 10879f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 108806b9b3e0SSimon J. Gerraty GNode_IsReady(const GNode *gn) 108906b9b3e0SSimon J. Gerraty { 109006b9b3e0SSimon J. Gerraty return gn->made > DEFERRED; 109106b9b3e0SSimon J. Gerraty } 109206b9b3e0SSimon J. Gerraty 10939f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 109406b9b3e0SSimon J. Gerraty GNode_IsDone(const GNode *gn) 109506b9b3e0SSimon J. Gerraty { 109606b9b3e0SSimon J. Gerraty return gn->made >= MADE; 109706b9b3e0SSimon J. Gerraty } 109806b9b3e0SSimon J. Gerraty 10999f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 110006b9b3e0SSimon J. Gerraty GNode_IsError(const GNode *gn) 110106b9b3e0SSimon J. Gerraty { 110206b9b3e0SSimon J. Gerraty return gn->made == ERROR || gn->made == ABORTED; 110306b9b3e0SSimon J. Gerraty } 110406b9b3e0SSimon J. Gerraty 11059f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 11069f45a3c8SSimon J. Gerraty GNode_IsMainCandidate(const GNode *gn) 11079f45a3c8SSimon J. Gerraty { 11089f45a3c8SSimon J. Gerraty return (gn->type & (OP_NOTMAIN | OP_USE | OP_USEBEFORE | 11099f45a3c8SSimon J. Gerraty OP_EXEC | OP_TRANSFORM)) == 0; 11109f45a3c8SSimon J. Gerraty } 11119f45a3c8SSimon J. Gerraty 11129f45a3c8SSimon J. Gerraty /* Return whether the target file should be preserved on interrupt. */ 11139f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 11149f45a3c8SSimon J. Gerraty GNode_IsPrecious(const GNode *gn) 11159f45a3c8SSimon J. Gerraty { 11169f45a3c8SSimon J. Gerraty /* XXX: Why are '::' targets precious? */ 11179f45a3c8SSimon J. Gerraty return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP); 11189f45a3c8SSimon J. Gerraty } 11199f45a3c8SSimon J. Gerraty 11209f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1121dba7b0efSSimon J. Gerraty GNode_VarTarget(GNode *gn) { return GNode_ValueDirect(gn, TARGET); } 11229f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1123dba7b0efSSimon J. Gerraty GNode_VarOodate(GNode *gn) { return GNode_ValueDirect(gn, OODATE); } 11249f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1125dba7b0efSSimon J. Gerraty GNode_VarAllsrc(GNode *gn) { return GNode_ValueDirect(gn, ALLSRC); } 11269f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1127dba7b0efSSimon J. Gerraty GNode_VarImpsrc(GNode *gn) { return GNode_ValueDirect(gn, IMPSRC); } 11289f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1129dba7b0efSSimon J. Gerraty GNode_VarPrefix(GNode *gn) { return GNode_ValueDirect(gn, PREFIX); } 11309f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1131dba7b0efSSimon J. Gerraty GNode_VarArchive(GNode *gn) { return GNode_ValueDirect(gn, ARCHIVE); } 11329f45a3c8SSimon J. Gerraty MAKE_INLINE const char * MAKE_ATTR_USE 1133dba7b0efSSimon J. Gerraty GNode_VarMember(GNode *gn) { return GNode_ValueDirect(gn, MEMBER); } 11343955d011SMarcel Moolenaar 11359f45a3c8SSimon J. Gerraty MAKE_INLINE void * MAKE_ATTR_USE 113612904384SSimon J. Gerraty UNCONST(const void *ptr) 113712904384SSimon J. Gerraty { 113812904384SSimon J. Gerraty void *ret; 113912904384SSimon J. Gerraty memcpy(&ret, &ptr, sizeof(ret)); 114012904384SSimon J. Gerraty return ret; 114112904384SSimon J. Gerraty } 11423955d011SMarcel Moolenaar 11434c620fe5SSimon J. Gerraty /* At least GNU/Hurd systems lack hardcoded MAXPATHLEN/PATH_MAX */ 11444c620fe5SSimon J. Gerraty #ifdef HAVE_LIMITS_H 11454c620fe5SSimon J. Gerraty #include <limits.h> 11464c620fe5SSimon J. Gerraty #endif 11470dede8b0SSimon J. Gerraty #ifndef MAXPATHLEN 11480dede8b0SSimon J. Gerraty #define MAXPATHLEN BMAKE_PATH_MAX 11490dede8b0SSimon J. Gerraty #endif 11504c620fe5SSimon J. Gerraty #ifndef PATH_MAX 11514c620fe5SSimon J. Gerraty #define PATH_MAX MAXPATHLEN 11524c620fe5SSimon J. Gerraty #endif 11530dede8b0SSimon J. Gerraty 1154c7019bf7SSimon J. Gerraty #if defined(SYSV) 1155c7019bf7SSimon J. Gerraty #define KILLPG(pid, sig) kill(-(pid), (sig)) 1156c7019bf7SSimon J. Gerraty #else 1157c7019bf7SSimon J. Gerraty #define KILLPG(pid, sig) killpg((pid), (sig)) 1158c7019bf7SSimon J. Gerraty #endif 1159c7019bf7SSimon J. Gerraty 11609f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1161e2eeea75SSimon J. Gerraty ch_isalnum(char ch) { return isalnum((unsigned char)ch) != 0; } 11629f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1163e2eeea75SSimon J. Gerraty ch_isalpha(char ch) { return isalpha((unsigned char)ch) != 0; } 11649f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1165e2eeea75SSimon J. Gerraty ch_isdigit(char ch) { return isdigit((unsigned char)ch) != 0; } 11669f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 11679f45a3c8SSimon J. Gerraty ch_islower(char ch) { return islower((unsigned char)ch) != 0; } 11689f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1169e2eeea75SSimon J. Gerraty ch_isspace(char ch) { return isspace((unsigned char)ch) != 0; } 11709f45a3c8SSimon J. Gerraty MAKE_INLINE bool MAKE_ATTR_USE 1171e2eeea75SSimon J. Gerraty ch_isupper(char ch) { return isupper((unsigned char)ch) != 0; } 11729f45a3c8SSimon J. Gerraty MAKE_INLINE char MAKE_ATTR_USE 1173e2eeea75SSimon J. Gerraty ch_tolower(char ch) { return (char)tolower((unsigned char)ch); } 11749f45a3c8SSimon J. Gerraty MAKE_INLINE char MAKE_ATTR_USE 1175e2eeea75SSimon J. Gerraty ch_toupper(char ch) { return (char)toupper((unsigned char)ch); } 1176956e45f6SSimon J. Gerraty 1177e2eeea75SSimon J. Gerraty MAKE_INLINE void 1178956e45f6SSimon J. Gerraty cpp_skip_whitespace(const char **pp) 1179956e45f6SSimon J. Gerraty { 1180956e45f6SSimon J. Gerraty while (ch_isspace(**pp)) 1181956e45f6SSimon J. Gerraty (*pp)++; 1182956e45f6SSimon J. Gerraty } 1183956e45f6SSimon J. Gerraty 1184e2eeea75SSimon J. Gerraty MAKE_INLINE void 1185e2eeea75SSimon J. Gerraty cpp_skip_hspace(const char **pp) 1186e2eeea75SSimon J. Gerraty { 1187e2eeea75SSimon J. Gerraty while (**pp == ' ' || **pp == '\t') 1188e2eeea75SSimon J. Gerraty (*pp)++; 1189e2eeea75SSimon J. Gerraty } 1190e2eeea75SSimon J. Gerraty 11919f45a3c8SSimon J. Gerraty MAKE_INLINE bool 11929f45a3c8SSimon J. Gerraty cpp_skip_string(const char **pp, const char *s) 11939f45a3c8SSimon J. Gerraty { 11949f45a3c8SSimon J. Gerraty const char *p = *pp; 11959f45a3c8SSimon J. Gerraty while (*p == *s && *s != '\0') 11969f45a3c8SSimon J. Gerraty p++, s++; 11979f45a3c8SSimon J. Gerraty if (*s == '\0') 11989f45a3c8SSimon J. Gerraty *pp = p; 11999f45a3c8SSimon J. Gerraty return *s == '\0'; 12009f45a3c8SSimon J. Gerraty } 12019f45a3c8SSimon J. Gerraty 1202e2eeea75SSimon J. Gerraty MAKE_INLINE void 1203956e45f6SSimon J. Gerraty pp_skip_whitespace(char **pp) 1204956e45f6SSimon J. Gerraty { 1205956e45f6SSimon J. Gerraty while (ch_isspace(**pp)) 1206956e45f6SSimon J. Gerraty (*pp)++; 1207956e45f6SSimon J. Gerraty } 1208956e45f6SSimon J. Gerraty 1209e2eeea75SSimon J. Gerraty MAKE_INLINE void 1210e2eeea75SSimon J. Gerraty pp_skip_hspace(char **pp) 1211e2eeea75SSimon J. Gerraty { 1212e2eeea75SSimon J. Gerraty while (**pp == ' ' || **pp == '\t') 1213e2eeea75SSimon J. Gerraty (*pp)++; 1214e2eeea75SSimon J. Gerraty } 1215e2eeea75SSimon J. Gerraty 121606b9b3e0SSimon J. Gerraty #if defined(lint) 12178c973ee2SSimon J. Gerraty extern void do_not_define_rcsid(void); /* for lint */ 121806b9b3e0SSimon J. Gerraty # define MAKE_RCSID(id) extern void do_not_define_rcsid(void) 121906b9b3e0SSimon J. Gerraty #elif defined(MAKE_NATIVE) 1220956e45f6SSimon J. Gerraty # include <sys/cdefs.h> 122112904384SSimon J. Gerraty # ifndef __IDSTRING 122212904384SSimon J. Gerraty # define __IDSTRING(name,string) \ 122312904384SSimon J. Gerraty static const char name[] MAKE_ATTR_UNUSED = string 122412904384SSimon J. Gerraty # endif 122512904384SSimon J. Gerraty # ifndef __RCSID 122612904384SSimon J. Gerraty # define __RCSID(s) __IDSTRING(rcsid,s) 122712904384SSimon J. Gerraty # endif 122812904384SSimon J. Gerraty # ifndef __COPYRIGHT 122912904384SSimon J. Gerraty # define __COPYRIGHT(s) __IDSTRING(copyright,s) 123012904384SSimon J. Gerraty # endif 1231956e45f6SSimon J. Gerraty # define MAKE_RCSID(id) __RCSID(id) 123206b9b3e0SSimon J. Gerraty #elif defined(MAKE_ALL_IN_ONE) && defined(__COUNTER__) 123306b9b3e0SSimon J. Gerraty # define MAKE_RCSID_CONCAT(x, y) CONCAT(x, y) 123406b9b3e0SSimon J. Gerraty # define MAKE_RCSID(id) static volatile char \ 123506b9b3e0SSimon J. Gerraty MAKE_RCSID_CONCAT(rcsid_, __COUNTER__)[] = id 123606b9b3e0SSimon J. Gerraty #elif defined(MAKE_ALL_IN_ONE) 123706b9b3e0SSimon J. Gerraty # define MAKE_RCSID(id) extern void do_not_define_rcsid(void) 1238956e45f6SSimon J. Gerraty #else 1239956e45f6SSimon J. Gerraty # define MAKE_RCSID(id) static volatile char rcsid[] = id 1240956e45f6SSimon J. Gerraty #endif 1241956e45f6SSimon J. Gerraty 12429f45a3c8SSimon J. Gerraty #endif 1243