1 /* $NetBSD: nonints.h,v 1.149 2020/11/01 00:24:57 rillig Exp $ */
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * from: @(#)nonints.h 8.3 (Berkeley) 3/19/94
38 * Copyright (c) 1989 by Berkeley Softworks
39 * All rights reserved.
41 * This code is derived from software contributed to Berkeley by
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by the University of
55 * California, Berkeley and its contributors.
56 * 4. Neither the name of the University nor the names of its contributors
57 * may be used to endorse or promote products derived from this software
58 * without specific prior written permission.
60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * from: @(#)nonints.h 8.3 (Berkeley) 3/19/94
79 Boolean Arch_ParseArchive(char **, GNodeList *, GNode *);
80 void Arch_Touch(GNode *);
81 void Arch_TouchLib(GNode *);
82 time_t Arch_MTime(GNode *);
83 time_t Arch_MemMTime(GNode *);
84 void Arch_FindLib(GNode *, SearchPath *);
85 Boolean Arch_LibOODate(GNode *);
86 Boolean Arch_IsLib(GNode *);
89 int Compat_RunCommand(const char *, GNode *);
90 void Compat_Run(GNodeList *);
91 void Compat_Make(GNode *, GNode *);
94 CondEvalResult Cond_EvalCondition(const char *, Boolean *);
95 CondEvalResult Cond_EvalLine(const char *);
96 void Cond_restore_depth(unsigned int);
97 unsigned int Cond_save_depth(void);
100 int For_Eval(const char *);
101 Boolean For_Accum(const char *);
106 void JobReapChild(pid_t, WAIT_T, Boolean);
110 void Main_ParseArgLine(const char *);
111 void MakeMode(const char *);
112 char *Cmd_Exec(const char *, const char **);
113 void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
114 void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
115 void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
116 void DieHorribly(void) MAKE_ATTR_DEAD;
117 void Finish(int) MAKE_ATTR_DEAD;
118 int eunlink(const char *);
119 void execDie(const char *, const char *);
120 char *getTmpdir(void);
121 Boolean s2Boolean(const char *, Boolean);
122 Boolean getBoolean(const char *, Boolean);
123 char *cached_realpath(const char *, char *);
126 void Parse_Init(void);
127 void Parse_End(void);
129 typedef enum VarAssignOp {
132 VAR_SHELL, /* != or :sh= */
137 typedef struct VarAssign {
138 char *varname; /* unexpanded */
140 const char *value; /* unexpanded */
143 typedef char *(*NextBufProc)(void *, size_t *);
145 void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
146 Boolean Parse_IsVar(const char *, VarAssign *out_var);
147 void Parse_DoVar(VarAssign *, GNode *);
148 void Parse_AddIncludeDir(const char *);
149 void Parse_File(const char *, int);
150 void Parse_SetInput(const char *, int, int, NextBufProc, void *);
151 GNodeList *Parse_MainName(void);
152 int Parse_GetFatals(void);
155 typedef struct Words {
161 Words Str_Words(const char *, Boolean);
162 static inline MAKE_ATTR_UNUSED void
163 Words_Free(Words w) {
168 char *str_concat2(const char *, const char *);
169 char *str_concat3(const char *, const char *, const char *);
170 char *str_concat4(const char *, const char *, const char *, const char *);
171 Boolean Str_Match(const char *, const char *);
175 size_t strlcpy(char *, const char *, size_t);
179 void Suff_Init(void);
182 void Suff_ClearSuffixes(void);
183 Boolean Suff_IsTransform(const char *);
184 GNode *Suff_AddTransform(const char *);
185 void Suff_EndTransform(GNode *);
186 void Suff_AddSuffix(const char *, GNode **);
187 SearchPath *Suff_GetPath(const char *);
188 void Suff_DoPaths(void);
189 void Suff_AddInclude(const char *);
190 void Suff_AddLib(const char *);
191 void Suff_FindDeps(GNode *);
192 SearchPath *Suff_FindPath(GNode *);
193 void Suff_SetNull(const char *);
194 void Suff_PrintAll(void);
197 void Targ_Init(void);
200 void Targ_Stats(void);
201 GNodeList *Targ_List(void);
202 GNode *Targ_NewGN(const char *);
203 GNode *Targ_FindNode(const char *);
204 GNode *Targ_GetNode(const char *);
205 GNode *Targ_NewInternalNode(const char *);
206 GNode *Targ_GetEndNode(void);
207 GNodeList *Targ_FindList(StringList *);
208 Boolean Targ_Ignore(GNode *);
209 Boolean Targ_Silent(GNode *);
210 Boolean Targ_Precious(GNode *);
211 void Targ_SetMain(GNode *);
212 void Targ_PrintCmds(GNode *);
213 void Targ_PrintNode(GNode *, int);
214 void Targ_PrintNodes(GNodeList *, int);
215 char *Targ_FmtTime(time_t);
216 void Targ_PrintType(int);
217 void Targ_PrintGraph(int);
218 void Targ_Propagate(void);
224 typedef enum VarEvalFlags {
226 /* Treat undefined variables as errors. */
227 VARE_UNDEFERR = 0x01,
228 /* Expand and evaluate variables during parsing. */
230 /* In an assignment using the ':=' operator, keep '$$' as '$$' instead
231 * of reducing it to a single '$'. */
235 typedef enum VarSet_Flags {
236 VAR_NO_EXPORT = 0x01, /* do not export */
237 /* Make the variable read-only. No further modification is possible,
238 * except for another call to Var_Set with the same flag. */
239 VAR_SET_READONLY = 0x02
242 /* The state of error handling returned by Var_Parse.
244 * As of 2020-09-13, this bitset looks quite bloated,
245 * with all the constants doubled.
247 * Its purpose is to first document the existing behavior,
248 * and then migrate away from the SILENT constants, step by step,
249 * as these are not suited for reliable, consistent error handling
251 typedef enum VarParseResult {
253 /* Both parsing and evaluation succeeded. */
256 /* See if a message has already been printed for this error. */
257 VPR_ANY_MSG = 0x0001,
260 * No error message has been printed yet.
261 * Deprecated, migrate to VPR_PARSE_MSG instead. */
262 VPR_PARSE_SILENT = 0x0002,
265 * An error message has already been printed. */
266 VPR_PARSE_MSG = VPR_PARSE_SILENT | VPR_ANY_MSG,
268 /* Parsing succeeded.
269 * During evaluation, VARE_UNDEFERR was set and there was an undefined
271 * No error message has been printed yet.
272 * Deprecated, migrate to VPR_UNDEF_MSG instead. */
273 VPR_UNDEF_SILENT = 0x0004,
275 /* Parsing succeeded.
276 * During evaluation, VARE_UNDEFERR was set and there was an undefined
278 * An error message has already been printed. */
279 VPR_UNDEF_MSG = VPR_UNDEF_SILENT | VPR_ANY_MSG,
281 /* Parsing succeeded.
283 * No error message has been printed yet.
284 * Deprecated, migrate to VPR_EVAL_MSG instead. */
285 VPR_EVAL_SILENT = 0x0006,
287 /* Parsing succeeded.
289 * An error message has already been printed. */
290 VPR_EVAL_MSG = VPR_EVAL_SILENT | VPR_ANY_MSG,
292 /* The exact error handling status is not known yet.
293 * Deprecated, migrate to VPR_OK or any VPE_*_MSG instead. */
297 void Var_Delete(const char *, GNode *);
298 void Var_Set(const char *, const char *, GNode *);
299 void Var_Set_with_flags(const char *, const char *, GNode *, VarSet_Flags);
300 void Var_Append(const char *, const char *, GNode *);
301 Boolean Var_Exists(const char *, GNode *);
302 const char *Var_Value(const char *, GNode *, void **);
303 const char *Var_ValueDirect(const char *, GNode *);
304 VarParseResult Var_Parse(const char **, GNode *, VarEvalFlags,
305 const char **, void **);
306 VarParseResult Var_Subst(const char *, GNode *, VarEvalFlags, char **);
307 void Var_Stats(void);
308 void Var_Dump(GNode *);
309 void Var_ExportVars(void);
310 void Var_Export(const char *, Boolean);
311 void Var_UnExport(const char *);
314 typedef void (*SignalProc)(int);
315 SignalProc bmake_signal(int, SignalProc);