]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/nonints.h
kern: cpuset: allow jails to modify child jails' roots
[FreeBSD/FreeBSD.git] / contrib / bmake / nonints.h
1 /*      $NetBSD: nonints.h,v 1.162 2020/11/16 21:48:18 rillig Exp $     */
2
3 /*-
4  * Copyright (c) 1988, 1989, 1990, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Adam de Boor.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
21  *
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
32  * SUCH DAMAGE.
33  *
34  *      from: @(#)nonints.h     8.3 (Berkeley) 3/19/94
35  */
36
37 /*-
38  * Copyright (c) 1989 by Berkeley Softworks
39  * All rights reserved.
40  *
41  * This code is derived from software contributed to Berkeley by
42  * Adam de Boor.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
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.
59  *
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
70  * SUCH DAMAGE.
71  *
72  *      from: @(#)nonints.h     8.3 (Berkeley) 3/19/94
73  */
74
75 /* arch.c */
76 void Arch_Init(void);
77 void Arch_End(void);
78
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 *);
87
88 /* compat.c */
89 int Compat_RunCommand(const char *, GNode *);
90 void Compat_Run(GNodeList *);
91 void Compat_Make(GNode *, GNode *);
92
93 /* cond.c */
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);
98
99 /* for.c */
100 int For_Eval(const char *);
101 Boolean For_Accum(const char *);
102 void For_Run(int);
103
104 /* job.c */
105 #ifdef WAIT_T
106 void JobReapChild(pid_t, WAIT_T, Boolean);
107 #endif
108
109 /* main.c */
110 Boolean GetBooleanVar(const char *, Boolean);
111 void Main_ParseArgLine(const char *);
112 void MakeMode(const char *);
113 char *Cmd_Exec(const char *, const char **);
114 void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
115 void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
116 void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
117 void DieHorribly(void) MAKE_ATTR_DEAD;
118 void Finish(int) MAKE_ATTR_DEAD;
119 int eunlink(const char *);
120 void execDie(const char *, const char *);
121 char *getTmpdir(void);
122 Boolean ParseBoolean(const char *, Boolean);
123 char *cached_realpath(const char *, char *);
124
125 /* parse.c */
126 void Parse_Init(void);
127 void Parse_End(void);
128
129 typedef enum VarAssignOp {
130     VAR_NORMAL,                 /* = */
131     VAR_SUBST,                  /* := */
132     VAR_SHELL,                  /* != or :sh= */
133     VAR_APPEND,                 /* += */
134     VAR_DEFAULT                 /* ?= */
135 } VarAssignOp;
136
137 typedef struct VarAssign {
138     char *varname;              /* unexpanded */
139     VarAssignOp op;
140     const char *value;          /* unexpanded */
141 } VarAssign;
142
143 typedef char *(*NextBufProc)(void *, size_t *);
144
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);
153
154 /* str.c */
155 typedef struct Words {
156     char **words;
157     size_t len;
158     void *freeIt;
159 } Words;
160
161 Words Str_Words(const char *, Boolean);
162 MAKE_INLINE void
163 Words_Free(Words w) {
164     free(w.words);
165     free(w.freeIt);
166 }
167
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 *);
172
173 #ifndef HAVE_STRLCPY
174 /* strlcpy.c */
175 size_t strlcpy(char *, const char *, size_t);
176 #endif
177
178 /* suff.c */
179 void Suff_Init(void);
180 void Suff_End(void);
181
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);
195
196 /* targ.c */
197 void Targ_Init(void);
198 void Targ_End(void);
199
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 GNodeList *Targ_FindList(StringList *);
208 Boolean Targ_Ignore(const GNode *);
209 Boolean Targ_Silent(const GNode *);
210 Boolean Targ_Precious(const 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);
219
220 /* var.c */
221 void Var_Init(void);
222 void Var_End(void);
223
224 typedef enum VarEvalFlags {
225     VARE_NONE           = 0,
226
227     /* Expand and evaluate variables during parsing.
228      *
229      * TODO: Document what Var_Parse and Var_Subst return when this flag
230      * is not set. */
231     VARE_WANTRES        = 1 << 0,
232
233     /* Treat undefined variables as errors.
234      * Must only be used in combination with VARE_WANTRES. */
235     VARE_UNDEFERR       = 1 << 1,
236
237     /* Keep '$$' as '$$' instead of reducing it to a single '$'.
238      *
239      * Used in variable assignments using the ':=' operator.  It allows
240      * multiple such assignments to be chained without accidentally expanding
241      * '$$file' to '$file' in the first assignment and interpreting it as
242      * '${f}' followed by 'ile' in the next assignment.
243      *
244      * See also preserveUndefined, which preserves subexpressions that are
245      * based on undefined variables; maybe that can be converted to a flag
246      * as well. */
247     VARE_KEEP_DOLLAR    = 1 << 2
248 } VarEvalFlags;
249
250 typedef enum VarSetFlags {
251     VAR_SET_NONE        = 0,
252
253     /* do not export */
254     VAR_SET_NO_EXPORT   = 1 << 0,
255
256     /* Make the variable read-only. No further modification is possible,
257      * except for another call to Var_Set with the same flag. */
258     VAR_SET_READONLY    = 1 << 1
259 } VarSetFlags;
260
261 /* The state of error handling returned by Var_Parse.
262  *
263  * As of 2020-09-13, this bitset looks quite bloated,
264  * with all the constants doubled.
265  *
266  * Its purpose is to first document the existing behavior,
267  * and then migrate away from the SILENT constants, step by step,
268  * as these are not suited for reliable, consistent error handling
269  * and reporting. */
270 typedef enum VarParseResult {
271
272     /* Both parsing and evaluation succeeded. */
273     VPR_OK              = 0x0000,
274
275     /* See if a message has already been printed for this error. */
276     VPR_ANY_MSG         = 0x0001,
277
278     /* Parsing failed.
279      * No error message has been printed yet.
280      * Deprecated, migrate to VPR_PARSE_MSG instead. */
281     VPR_PARSE_SILENT    = 0x0002,
282
283     /* Parsing failed.
284      * An error message has already been printed. */
285     VPR_PARSE_MSG       = VPR_PARSE_SILENT | VPR_ANY_MSG,
286
287     /* Parsing succeeded.
288      * During evaluation, VARE_UNDEFERR was set and there was an undefined
289      * variable.
290      * No error message has been printed yet.
291      * Deprecated, migrate to VPR_UNDEF_MSG instead. */
292     VPR_UNDEF_SILENT    = 0x0004,
293
294     /* Parsing succeeded.
295      * During evaluation, VARE_UNDEFERR was set and there was an undefined
296      * variable.
297      * An error message has already been printed. */
298     VPR_UNDEF_MSG       = VPR_UNDEF_SILENT | VPR_ANY_MSG,
299
300     /* Parsing succeeded.
301      * Evaluation failed.
302      * No error message has been printed yet.
303      * Deprecated, migrate to VPR_EVAL_MSG instead. */
304     VPR_EVAL_SILENT     = 0x0006,
305
306     /* Parsing succeeded.
307      * Evaluation failed.
308      * An error message has already been printed. */
309     VPR_EVAL_MSG        = VPR_EVAL_SILENT | VPR_ANY_MSG,
310
311     /* The exact error handling status is not known yet.
312      * Deprecated, migrate to VPR_OK or any VPE_*_MSG instead. */
313     VPR_UNKNOWN         = 0x0008
314 } VarParseResult;
315
316 void Var_Delete(const char *, GNode *);
317 void Var_Set(const char *, const char *, GNode *);
318 void Var_SetWithFlags(const char *, const char *, GNode *, VarSetFlags);
319 void Var_Append(const char *, const char *, GNode *);
320 Boolean Var_Exists(const char *, GNode *);
321 const char *Var_Value(const char *, GNode *, void **);
322 const char *Var_ValueDirect(const char *, GNode *);
323 VarParseResult Var_Parse(const char **, GNode *, VarEvalFlags,
324                          const char **, void **);
325 VarParseResult Var_Subst(const char *, GNode *, VarEvalFlags, char **);
326 void Var_Stats(void);
327 void Var_Dump(GNode *);
328 void Var_ExportVars(void);
329 void Var_Export(const char *, Boolean);
330 void Var_UnExport(const char *);
331
332 /* util.c */
333 typedef void (*SignalProc)(int);
334 SignalProc bmake_signal(int, SignalProc);