1 /* $NetBSD: nonints.h,v 1.203 2021/02/14 21:32:58 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 void Arch_UpdateMTime(GNode *gn);
83 void Arch_UpdateMemberMTime(GNode *gn);
84 void Arch_FindLib(GNode *, SearchPath *);
85 Boolean Arch_LibOODate(GNode *);
86 Boolean 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 *, Boolean *);
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 Boolean For_Accum(const char *);
125 void JobReapChild(pid_t, WAIT_T, Boolean);
129 Boolean GetBooleanVar(const char *, Boolean);
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 Boolean ParseBoolean(const char *, Boolean);
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 Boolean Parse_IsVar(const char *, VarAssign *out_var);
165 void Parse_DoVar(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);
174 /* A read-only string that may need to be freed after use. */
175 typedef struct FStr {
180 /* A modifiable string that may need to be freed after use. */
181 typedef struct MFStr {
186 typedef struct Words {
192 /* Return a string that is the sole owner of str. */
194 FStr_InitOwn(char *str)
196 return (FStr){ str, str };
199 /* Return a string that refers to the shared str. */
201 FStr_InitRefer(const char *str)
203 return (FStr){ str, NULL };
207 FStr_Done(FStr *fstr)
216 /* Return a string that is the sole owner of str. */
218 MFStr_InitOwn(char *str)
220 return (MFStr){ str, str };
223 /* Return a string that refers to the shared str. */
225 MFStr_InitRefer(char *str)
227 return (MFStr){ str, NULL };
231 MFStr_Done(MFStr *mfstr)
236 mfstr->freeIt = NULL;
240 Words Str_Words(const char *, Boolean);
248 char *str_concat2(const char *, const char *);
249 char *str_concat3(const char *, const char *, const char *);
250 char *str_concat4(const char *, const char *, const char *, const char *);
251 Boolean Str_Match(const char *, const char *);
255 size_t strlcpy(char *, const char *, size_t);
259 void Suff_Init(void);
262 void Suff_ClearSuffixes(void);
263 Boolean Suff_IsTransform(const char *);
264 GNode *Suff_AddTransform(const char *);
265 void Suff_EndTransform(GNode *);
266 void Suff_AddSuffix(const char *, GNode **);
267 SearchPath *Suff_GetPath(const char *);
268 void Suff_DoPaths(void);
269 void Suff_AddInclude(const char *);
270 void Suff_AddLib(const char *);
271 void Suff_FindDeps(GNode *);
272 SearchPath *Suff_FindPath(GNode *);
273 void Suff_SetNull(const char *);
274 void Suff_PrintAll(void);
277 void Targ_Init(void);
280 void Targ_Stats(void);
281 GNodeList *Targ_List(void);
282 GNode *GNode_New(const char *);
283 GNode *Targ_FindNode(const char *);
284 GNode *Targ_GetNode(const char *);
285 GNode *Targ_NewInternalNode(const char *);
286 GNode *Targ_GetEndNode(void);
287 void Targ_FindList(GNodeList *, StringList *);
288 Boolean Targ_Precious(const GNode *);
289 void Targ_SetMain(GNode *);
290 void Targ_PrintCmds(GNode *);
291 void Targ_PrintNode(GNode *, int);
292 void Targ_PrintNodes(GNodeList *, int);
293 const char *Targ_FmtTime(time_t);
294 void Targ_PrintType(int);
295 void Targ_PrintGraph(int);
296 void Targ_Propagate(void);
297 const char *GNodeMade_Name(GNodeMade);
303 typedef enum VarEvalFlags {
307 * Expand and evaluate variables during parsing.
309 * TODO: Document what Var_Parse and Var_Subst return when this flag
312 VARE_WANTRES = 1 << 0,
315 * Treat undefined variables as errors.
316 * Must only be used in combination with VARE_WANTRES.
318 VARE_UNDEFERR = 1 << 1,
321 * Keep '$$' as '$$' instead of reducing it to a single '$'.
323 * Used in variable assignments using the ':=' operator. It allows
324 * multiple such assignments to be chained without accidentally
325 * expanding '$$file' to '$file' in the first assignment and
326 * interpreting it as '${f}' followed by 'ile' in the next assignment.
328 VARE_KEEP_DOLLAR = 1 << 2,
331 * Keep undefined variables as-is instead of expanding them to an
334 * Example for a ':=' assignment:
335 * CFLAGS = $(.INCLUDES)
336 * CFLAGS := -I.. $(CFLAGS)
337 * # If .INCLUDES (an undocumented special variable, by the
338 * # way) is still undefined, the updated CFLAGS becomes
339 * # "-I.. $(.INCLUDES)".
341 VARE_KEEP_UNDEF = 1 << 3
344 typedef enum VarSetFlags {
348 VAR_SET_NO_EXPORT = 1 << 0,
350 /* Make the variable read-only. No further modification is possible,
351 * except for another call to Var_Set with the same flag. */
352 VAR_SET_READONLY = 1 << 1
355 /* The state of error handling returned by Var_Parse. */
356 typedef enum VarParseResult {
358 /* Both parsing and evaluation succeeded. */
361 /* Parsing or evaluating failed, with an error message. */
365 * Parsing succeeded, undefined expressions are allowed and the
366 * expression was still undefined after applying all modifiers.
367 * No error message is printed in this case.
369 * Some callers handle this case differently, so return this
370 * information to them, for now.
372 * TODO: Replace this with a new flag VARE_KEEP_UNDEFINED.
378 typedef enum VarExportMode {
381 /* .export: Initial export or update an already exported variable. */
383 /* .export-literal: Do not expand the variable value. */
387 void Var_Delete(GNode *, const char *);
388 void Var_DeleteExpand(GNode *, const char *);
389 void Var_Undef(const char *);
390 void Var_Set(GNode *, const char *, const char *);
391 void Var_SetExpand(GNode *, const char *, const char *);
392 void Var_SetWithFlags(GNode *, const char *, const char *, VarSetFlags);
393 void Var_SetExpandWithFlags(GNode *, const char *, const char *, VarSetFlags);
394 void Var_Append(GNode *, const char *, const char *);
395 void Var_AppendExpand(GNode *, const char *, const char *);
396 Boolean Var_Exists(GNode *, const char *);
397 Boolean Var_ExistsExpand(GNode *, const char *);
398 FStr Var_Value(GNode *, const char *);
399 const char *GNode_ValueDirect(GNode *, const char *);
400 VarParseResult Var_Parse(const char **, GNode *, VarEvalFlags, FStr *);
401 VarParseResult Var_Subst(const char *, GNode *, VarEvalFlags, char **);
402 void Var_Stats(void);
403 void Var_Dump(GNode *);
404 void Var_ReexportVars(void);
405 void Var_Export(VarExportMode, const char *);
406 void Var_ExportVars(const char *);
407 void Var_UnExport(Boolean, const char *);
409 void Global_Set(const char *, const char *);
410 void Global_SetExpand(const char *, const char *);
411 void Global_Append(const char *, const char *);
412 void Global_Delete(const char *);
415 typedef void (*SignalProc)(int);
416 SignalProc bmake_signal(int, SignalProc);