1 /* $NetBSD: nonints.h,v 1.213 2021/04/11 13:35:56 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 bool Arch_ParseArchive(char **, GNodeList *, GNode *);
80 void Arch_Touch(GNode *);
81 void Arch_TouchLib(GNode *);
82 void Arch_UpdateMTime(GNode *gn);
83 void Arch_UpdateMemberMTime(GNode *gn);
84 void Arch_FindLib(GNode *, SearchPath *);
85 bool Arch_LibOODate(GNode *);
86 bool Arch_IsLib(GNode *);
89 int Compat_RunCommand(const char *, GNode *, StringListNode *);
90 void Compat_Run(GNodeList *);
91 void Compat_Make(GNode *, GNode *);
94 CondEvalResult Cond_EvalCondition(const char *, bool *);
95 CondEvalResult Cond_EvalLine(const char *);
96 void Cond_restore_depth(unsigned int);
97 unsigned int Cond_save_depth(void);
99 /* dir.c; see also dir.h */
101 MAKE_INLINE const char *
102 str_basename(const char *pathname)
104 const char *lastSlash = strrchr(pathname, '/');
105 return lastSlash != NULL ? lastSlash + 1 : pathname;
108 MAKE_INLINE SearchPath *
111 SearchPath *path = bmake_malloc(sizeof *path);
112 Lst_Init(&path->dirs);
116 void SearchPath_Free(SearchPath *);
119 int For_Eval(const char *);
120 bool For_Accum(const char *);
125 void JobReapChild(pid_t, WAIT_T, bool);
129 bool GetBooleanExpr(const char *, bool);
130 void Main_ParseArgLine(const char *);
131 char *Cmd_Exec(const char *, const char **);
132 void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
133 void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
134 void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
135 void DieHorribly(void) MAKE_ATTR_DEAD;
136 void Finish(int) MAKE_ATTR_DEAD;
137 int eunlink(const char *);
138 void execDie(const char *, const char *);
139 char *getTmpdir(void);
140 bool ParseBoolean(const char *, bool);
141 char *cached_realpath(const char *, char *);
144 void Parse_Init(void);
145 void Parse_End(void);
147 typedef enum VarAssignOp {
150 VAR_SHELL, /* != or :sh= */
155 typedef struct VarAssign {
156 char *varname; /* unexpanded */
158 const char *value; /* unexpanded */
161 typedef char *(*ReadMoreProc)(void *, size_t *);
163 void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
164 bool Parse_IsVar(const char *, VarAssign *out_var);
165 void Parse_Var(VarAssign *, GNode *);
166 void Parse_AddIncludeDir(const char *);
167 void Parse_File(const char *, int);
168 void Parse_SetInput(const char *, int, int, ReadMoreProc, void *);
169 void Parse_MainName(GNodeList *);
170 int Parse_GetFatals(void);
175 size_t strlcpy(char *, const char *, size_t);
179 void Suff_Init(void);
182 void Suff_ClearSuffixes(void);
183 bool 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_ExtendPaths(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 *GNode_New(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 void Targ_FindList(GNodeList *, StringList *);
208 bool Targ_Precious(const GNode *);
209 void Targ_SetMain(GNode *);
210 void Targ_PrintCmds(GNode *);
211 void Targ_PrintNode(GNode *, int);
212 void Targ_PrintNodes(GNodeList *, int);
213 const char *Targ_FmtTime(time_t);
214 void Targ_PrintType(int);
215 void Targ_PrintGraph(int);
216 void Targ_Propagate(void);
217 const char *GNodeMade_Name(GNodeMade);
223 typedef enum VarEvalMode {
226 * Only parse the expression but don't evaluate any part of it.
228 * TODO: Document what Var_Parse and Var_Subst return in this mode.
229 * As of 2021-03-15, they return unspecified, inconsistent results.
233 /* Parse and evaluate the expression. */
237 * Parse and evaluate the expression. It is an error if a
238 * subexpression evaluates to undefined.
243 * Parse and evaluate the expression. Keep '$$' as '$$' instead of
244 * reducing it to a single '$'. Subexpressions that evaluate to
245 * undefined expand to an empty string.
247 * Used in variable assignments using the ':=' operator. It allows
248 * multiple such assignments to be chained without accidentally
249 * expanding '$$file' to '$file' in the first assignment and
250 * interpreting it as '${f}' followed by 'ile' in the next assignment.
252 VARE_EVAL_KEEP_DOLLAR,
255 * Parse and evaluate the expression. Keep undefined variables as-is
256 * instead of expanding them to an empty string.
258 * Example for a ':=' assignment:
259 * CFLAGS = $(.INCLUDES)
260 * CFLAGS := -I.. $(CFLAGS)
261 * # If .INCLUDES (an undocumented special variable, by the
262 * # way) is still undefined, the updated CFLAGS becomes
263 * # "-I.. $(.INCLUDES)".
265 VARE_EVAL_KEEP_UNDEF,
268 * Parse and evaluate the expression. Keep '$$' as '$$' and preserve
269 * undefined subexpressions.
271 VARE_KEEP_DOLLAR_UNDEF
274 typedef enum VarSetFlags {
278 VAR_SET_NO_EXPORT = 1 << 0,
280 /* Make the variable read-only. No further modification is possible,
281 * except for another call to Var_Set with the same flag. */
282 VAR_SET_READONLY = 1 << 1
285 /* The state of error handling returned by Var_Parse. */
286 typedef enum VarParseResult {
288 /* Both parsing and evaluation succeeded. */
291 /* Parsing or evaluating failed, with an error message. */
295 * Parsing succeeded, undefined expressions are allowed and the
296 * expression was still undefined after applying all modifiers.
297 * No error message is printed in this case.
299 * Some callers handle this case differently, so return this
300 * information to them, for now.
302 * TODO: Instead of having this special return value, rather ensure
303 * that VARE_EVAL_KEEP_UNDEF is processed properly.
309 typedef enum VarExportMode {
312 /* .export: Initial export or update an already exported variable. */
314 /* .export-literal: Do not expand the variable value. */
318 void Var_Delete(GNode *, const char *);
319 void Var_DeleteExpand(GNode *, const char *);
320 void Var_Undef(const char *);
321 void Var_Set(GNode *, const char *, const char *);
322 void Var_SetExpand(GNode *, const char *, const char *);
323 void Var_SetWithFlags(GNode *, const char *, const char *, VarSetFlags);
324 void Var_SetExpandWithFlags(GNode *, const char *, const char *, VarSetFlags);
325 void Var_Append(GNode *, const char *, const char *);
326 void Var_AppendExpand(GNode *, const char *, const char *);
327 bool Var_Exists(GNode *, const char *);
328 bool Var_ExistsExpand(GNode *, const char *);
329 FStr Var_Value(GNode *, const char *);
330 const char *GNode_ValueDirect(GNode *, const char *);
331 VarParseResult Var_Parse(const char **, GNode *, VarEvalMode, FStr *);
332 VarParseResult Var_Subst(const char *, GNode *, VarEvalMode, char **);
333 void Var_Stats(void);
334 void Var_Dump(GNode *);
335 void Var_ReexportVars(void);
336 void Var_Export(VarExportMode, const char *);
337 void Var_ExportVars(const char *);
338 void Var_UnExport(bool, const char *);
340 void Global_Set(const char *, const char *);
341 void Global_SetExpand(const char *, const char *);
342 void Global_Append(const char *, const char *);
343 void Global_Delete(const char *);
346 typedef void (*SignalProc)(int);
347 SignalProc bmake_signal(int, SignalProc);