1 | /* Miscellaneous global declarations and portability cruft for GNU Make.
|
---|
2 | Copyright (C) 1988-2016 Free Software Foundation, Inc.
|
---|
3 | This file is part of GNU Make.
|
---|
4 |
|
---|
5 | GNU Make is free software; you can redistribute it and/or modify it under the
|
---|
6 | terms of the GNU General Public License as published by the Free Software
|
---|
7 | Foundation; either version 3 of the License, or (at your option) any later
|
---|
8 | version.
|
---|
9 |
|
---|
10 | GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
---|
12 | A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License along with
|
---|
15 | this program. If not, see <http://www.gnu.org/licenses/>. */
|
---|
16 |
|
---|
17 | /* We use <config.h> instead of "config.h" so that a compilation
|
---|
18 | using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
|
---|
19 | (which it would do because makeint.h was found in $srcdir). */
|
---|
20 | #include <config.h>
|
---|
21 | #undef HAVE_CONFIG_H
|
---|
22 | #define HAVE_CONFIG_H 1
|
---|
23 |
|
---|
24 | /* Specify we want GNU source code. This must be defined before any
|
---|
25 | system headers are included. */
|
---|
26 |
|
---|
27 | #define _GNU_SOURCE 1
|
---|
28 |
|
---|
29 | /* AIX requires this to be the first thing in the file. */
|
---|
30 | #if HAVE_ALLOCA_H
|
---|
31 | # include <alloca.h>
|
---|
32 | #else
|
---|
33 | # ifdef _AIX
|
---|
34 | #pragma alloca
|
---|
35 | # else
|
---|
36 | # if !defined(__GNUC__) && !defined(WINDOWS32)
|
---|
37 | # ifndef alloca /* predefined by HP cc +Olibcalls */
|
---|
38 | char *alloca ();
|
---|
39 | # endif
|
---|
40 | # endif
|
---|
41 | # endif
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | /* Disable assert() unless we're a maintainer.
|
---|
45 | Some asserts are compute-intensive. */
|
---|
46 | #ifndef MAKE_MAINTAINER_MODE
|
---|
47 | # define NDEBUG 1
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | /* Include the externally-visible content.
|
---|
51 | Be sure to use the local one, and not one installed on the system.
|
---|
52 | Define GMK_BUILDING_MAKE for proper selection of dllexport/dllimport
|
---|
53 | declarations for MS-Windows. */
|
---|
54 | #ifdef WINDOWS32
|
---|
55 | # define GMK_BUILDING_MAKE
|
---|
56 | #endif
|
---|
57 | #include "gnumake.h"
|
---|
58 |
|
---|
59 | #ifdef CRAY
|
---|
60 | /* This must happen before #include <signal.h> so
|
---|
61 | that the declaration therein is changed. */
|
---|
62 | # define signal bsdsignal
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | /* If we're compiling for the dmalloc debugger, turn off string inlining. */
|
---|
66 | #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
|
---|
67 | # define __NO_STRING_INLINES
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | #include <sys/types.h>
|
---|
71 | #include <sys/stat.h>
|
---|
72 | #include <signal.h>
|
---|
73 | #include <stdio.h>
|
---|
74 | #include <ctype.h>
|
---|
75 |
|
---|
76 | #ifdef HAVE_SYS_TIMEB_H
|
---|
77 | /* SCO 3.2 "devsys 4.2" has a prototype for 'ftime' in <time.h> that bombs
|
---|
78 | unless <sys/timeb.h> has been included first. */
|
---|
79 | # include <sys/timeb.h>
|
---|
80 | #endif
|
---|
81 | #if TIME_WITH_SYS_TIME
|
---|
82 | # include <sys/time.h>
|
---|
83 | # include <time.h>
|
---|
84 | #else
|
---|
85 | # if HAVE_SYS_TIME_H
|
---|
86 | # include <sys/time.h>
|
---|
87 | # else
|
---|
88 | # include <time.h>
|
---|
89 | # endif
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | #include <errno.h>
|
---|
93 |
|
---|
94 | #ifndef errno
|
---|
95 | extern int errno;
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | #ifdef __VMS
|
---|
99 | /* In strict ANSI mode, VMS compilers should not be defining the
|
---|
100 | VMS macro. Define it here instead of a bulk edit for the correct code.
|
---|
101 | */
|
---|
102 | # ifndef VMS
|
---|
103 | # define VMS
|
---|
104 | # endif
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | #ifdef HAVE_UNISTD_H
|
---|
108 | # include <unistd.h>
|
---|
109 | /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
|
---|
110 | POSIX.1 behavior with 'cc -YPOSIX', which predefines POSIX itself! */
|
---|
111 | # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
|
---|
112 | # define POSIX 1
|
---|
113 | # endif
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
|
---|
117 | #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
|
---|
118 | # undef POSIX
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
|
---|
122 | # define POSIX 1
|
---|
123 | #endif
|
---|
124 |
|
---|
125 | #ifndef RETSIGTYPE
|
---|
126 | # define RETSIGTYPE void
|
---|
127 | #endif
|
---|
128 |
|
---|
129 | #ifndef sigmask
|
---|
130 | # define sigmask(sig) (1 << ((sig) - 1))
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | #ifndef HAVE_SA_RESTART
|
---|
134 | # define SA_RESTART 0
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | #ifdef HAVE_VFORK_H
|
---|
138 | # include <vfork.h>
|
---|
139 | #endif
|
---|
140 |
|
---|
141 | #ifdef HAVE_LIMITS_H
|
---|
142 | # include <limits.h>
|
---|
143 | #endif
|
---|
144 | #ifdef HAVE_SYS_PARAM_H
|
---|
145 | # include <sys/param.h>
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | #ifndef PATH_MAX
|
---|
149 | # ifndef POSIX
|
---|
150 | # define PATH_MAX MAXPATHLEN
|
---|
151 | # endif
|
---|
152 | #endif
|
---|
153 | #ifndef MAXPATHLEN
|
---|
154 | # define MAXPATHLEN 1024
|
---|
155 | #endif
|
---|
156 |
|
---|
157 | #ifdef PATH_MAX
|
---|
158 | # define GET_PATH_MAX PATH_MAX
|
---|
159 | # define PATH_VAR(var) char var[PATH_MAX]
|
---|
160 | #else
|
---|
161 | # define NEED_GET_PATH_MAX 1
|
---|
162 | # define GET_PATH_MAX (get_path_max ())
|
---|
163 | # define PATH_VAR(var) char *var = alloca (GET_PATH_MAX)
|
---|
164 | unsigned int get_path_max (void);
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | #ifndef CHAR_BIT
|
---|
168 | # define CHAR_BIT 8
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | #ifndef USHRT_MAX
|
---|
172 | # define USHRT_MAX 65535
|
---|
173 | #endif
|
---|
174 |
|
---|
175 | /* Nonzero if the integer type T is signed.
|
---|
176 | Use <= to avoid GCC warnings about always-false expressions. */
|
---|
177 | #define INTEGER_TYPE_SIGNED(t) ((t) -1 <= 0)
|
---|
178 |
|
---|
179 | /* The minimum and maximum values for the integer type T.
|
---|
180 | Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
|
---|
181 | #define INTEGER_TYPE_MINIMUM(t) \
|
---|
182 | (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
|
---|
183 | #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
|
---|
184 |
|
---|
185 | #ifndef CHAR_MAX
|
---|
186 | # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | #ifdef STAT_MACROS_BROKEN
|
---|
190 | # ifdef S_ISREG
|
---|
191 | # undef S_ISREG
|
---|
192 | # endif
|
---|
193 | # ifdef S_ISDIR
|
---|
194 | # undef S_ISDIR
|
---|
195 | # endif
|
---|
196 | #endif /* STAT_MACROS_BROKEN. */
|
---|
197 |
|
---|
198 | #ifndef S_ISREG
|
---|
199 | # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
---|
200 | #endif
|
---|
201 | #ifndef S_ISDIR
|
---|
202 | # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
---|
203 | #endif
|
---|
204 |
|
---|
205 | #ifdef VMS
|
---|
206 | # include <fcntl.h>
|
---|
207 | # include <types.h>
|
---|
208 | # include <unixlib.h>
|
---|
209 | # include <unixio.h>
|
---|
210 | # include <perror.h>
|
---|
211 | /* Needed to use alloca on VMS. */
|
---|
212 | # include <builtins.h>
|
---|
213 |
|
---|
214 | extern int vms_use_mcr_command;
|
---|
215 | extern int vms_always_use_cmd_file;
|
---|
216 | extern int vms_gnv_shell;
|
---|
217 | extern int vms_comma_separator;
|
---|
218 | extern int vms_legacy_behavior;
|
---|
219 | extern int vms_unix_simulation;
|
---|
220 | #endif
|
---|
221 |
|
---|
222 | #ifndef __attribute__
|
---|
223 | /* This feature is available in gcc versions 2.5 and later. */
|
---|
224 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
|
---|
225 | # define __attribute__(x)
|
---|
226 | # endif
|
---|
227 | /* The __-protected variants of 'format' and 'printf' attributes
|
---|
228 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
---|
229 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
---|
230 | # define __format__ format
|
---|
231 | # define __printf__ printf
|
---|
232 | # endif
|
---|
233 | #endif
|
---|
234 | #define UNUSED __attribute__ ((unused))
|
---|
235 |
|
---|
236 | #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
|
---|
237 | # include <stdlib.h>
|
---|
238 | # include <string.h>
|
---|
239 | # define ANSI_STRING 1
|
---|
240 | #else /* No standard headers. */
|
---|
241 | # ifdef HAVE_STRING_H
|
---|
242 | # include <string.h>
|
---|
243 | # define ANSI_STRING 1
|
---|
244 | # else
|
---|
245 | # include <strings.h>
|
---|
246 | # endif
|
---|
247 | # ifdef HAVE_MEMORY_H
|
---|
248 | # include <memory.h>
|
---|
249 | # endif
|
---|
250 | # ifdef HAVE_STDLIB_H
|
---|
251 | # include <stdlib.h>
|
---|
252 | # else
|
---|
253 | void *malloc (int);
|
---|
254 | void *realloc (void *, int);
|
---|
255 | void free (void *);
|
---|
256 |
|
---|
257 | void abort (void) __attribute__ ((noreturn));
|
---|
258 | void exit (int) __attribute__ ((noreturn));
|
---|
259 | # endif /* HAVE_STDLIB_H. */
|
---|
260 |
|
---|
261 | #endif /* Standard headers. */
|
---|
262 |
|
---|
263 | /* These should be in stdlib.h. Make sure we have them. */
|
---|
264 | #ifndef EXIT_SUCCESS
|
---|
265 | # define EXIT_SUCCESS 0
|
---|
266 | #endif
|
---|
267 | #ifndef EXIT_FAILURE
|
---|
268 | # define EXIT_FAILURE 1
|
---|
269 | #endif
|
---|
270 |
|
---|
271 | #ifndef ANSI_STRING
|
---|
272 |
|
---|
273 | /* SCO Xenix has a buggy macro definition in <string.h>. */
|
---|
274 | #undef strerror
|
---|
275 | #if !defined(__DECC)
|
---|
276 | char *strerror (int errnum);
|
---|
277 | #endif
|
---|
278 |
|
---|
279 | #endif /* !ANSI_STRING. */
|
---|
280 | #undef ANSI_STRING
|
---|
281 |
|
---|
282 | #if HAVE_INTTYPES_H
|
---|
283 | # include <inttypes.h>
|
---|
284 | #endif
|
---|
285 | #if HAVE_STDINT_H
|
---|
286 | # include <stdint.h>
|
---|
287 | #endif
|
---|
288 | #define FILE_TIMESTAMP uintmax_t
|
---|
289 |
|
---|
290 | #if !defined(HAVE_STRSIGNAL)
|
---|
291 | char *strsignal (int signum);
|
---|
292 | #endif
|
---|
293 |
|
---|
294 | /* ISDIGIT offers the following features:
|
---|
295 | - Its arg may be any int or unsigned int; it need not be an unsigned char.
|
---|
296 | - It's guaranteed to evaluate its argument exactly once.
|
---|
297 | NOTE! Make relies on this behavior, don't change it!
|
---|
298 | - It's typically faster.
|
---|
299 | POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
|
---|
300 | only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
|
---|
301 | it's important to use the locale's definition of 'digit' even when the
|
---|
302 | host does not conform to POSIX. */
|
---|
303 | #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
|
---|
304 |
|
---|
305 | /* Test if two strings are equal. Is this worthwhile? Should be profiled. */
|
---|
306 | #define streq(a, b) \
|
---|
307 | ((a) == (b) || \
|
---|
308 | (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
|
---|
309 |
|
---|
310 | /* Test if two strings are equal, but match case-insensitively on systems
|
---|
311 | which have case-insensitive filesystems. Should only be used for
|
---|
312 | filenames! */
|
---|
313 | #ifdef HAVE_CASE_INSENSITIVE_FS
|
---|
314 | # define patheq(a, b) \
|
---|
315 | ((a) == (b) \
|
---|
316 | || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
|
---|
317 | && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1))))
|
---|
318 | #else
|
---|
319 | # define patheq(a, b) streq(a, b)
|
---|
320 | #endif
|
---|
321 |
|
---|
322 | #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
|
---|
323 |
|
---|
324 | #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
|
---|
325 | # define ENUM_BITFIELD(bits) :bits
|
---|
326 | #else
|
---|
327 | # define ENUM_BITFIELD(bits)
|
---|
328 | #endif
|
---|
329 |
|
---|
330 | /* Handle gettext and locales. */
|
---|
331 |
|
---|
332 | #if HAVE_LOCALE_H
|
---|
333 | # include <locale.h>
|
---|
334 | #else
|
---|
335 | # define setlocale(category, locale)
|
---|
336 | #endif
|
---|
337 |
|
---|
338 | #include <gettext.h>
|
---|
339 |
|
---|
340 | #define _(msgid) gettext (msgid)
|
---|
341 | #define N_(msgid) gettext_noop (msgid)
|
---|
342 | #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
|
---|
343 |
|
---|
344 | /* This is needed for getcwd() and chdir(), on some W32 systems. */
|
---|
345 | #if defined(HAVE_DIRECT_H)
|
---|
346 | # include <direct.h>
|
---|
347 | #endif
|
---|
348 |
|
---|
349 | #ifdef WINDOWS32
|
---|
350 | # include <fcntl.h>
|
---|
351 | # include <malloc.h>
|
---|
352 | # define pipe(_p) _pipe((_p), 512, O_BINARY)
|
---|
353 | # define kill(_pid,_sig) w32_kill((_pid),(_sig))
|
---|
354 | /* MSVC and Watcom C don't have ftruncate. */
|
---|
355 | # if defined(_MSC_VER) || defined(__WATCOMC__)
|
---|
356 | # define ftruncate(_fd,_len) _chsize(_fd,_len)
|
---|
357 | # endif
|
---|
358 | /* MinGW64 doesn't have _S_ISDIR. */
|
---|
359 | # ifndef _S_ISDIR
|
---|
360 | # define _S_ISDIR(m) S_ISDIR(m)
|
---|
361 | # endif
|
---|
362 |
|
---|
363 | void sync_Path_environment (void);
|
---|
364 | int w32_kill (pid_t pid, int sig);
|
---|
365 | int find_and_set_default_shell (const char *token);
|
---|
366 |
|
---|
367 | /* indicates whether or not we have Bourne shell */
|
---|
368 | extern int no_default_sh_exe;
|
---|
369 |
|
---|
370 | /* is default_shell unixy? */
|
---|
371 | extern int unixy_shell;
|
---|
372 |
|
---|
373 | /* We don't have a preferred fixed value for LOCALEDIR. */
|
---|
374 | # ifndef LOCALEDIR
|
---|
375 | # define LOCALEDIR NULL
|
---|
376 | # endif
|
---|
377 |
|
---|
378 | /* Include only the minimal stuff from windows.h. */
|
---|
379 | # define WIN32_LEAN_AND_MEAN
|
---|
380 | #endif /* WINDOWS32 */
|
---|
381 |
|
---|
382 | #define ANY_SET(_v,_m) (((_v)&(_m)) != 0)
|
---|
383 | #define NONE_SET(_v,_m) (! ANY_SET ((_v),(_m)))
|
---|
384 |
|
---|
385 | #define MAP_NUL 0x0001
|
---|
386 | #define MAP_BLANK 0x0002
|
---|
387 | #define MAP_NEWLINE 0x0004
|
---|
388 | #define MAP_COMMENT 0x0008
|
---|
389 | #define MAP_SEMI 0x0010
|
---|
390 | #define MAP_EQUALS 0x0020
|
---|
391 | #define MAP_COLON 0x0040
|
---|
392 | #define MAP_PERCENT 0x0080
|
---|
393 | #define MAP_PIPE 0x0100
|
---|
394 | #define MAP_DOT 0x0200
|
---|
395 | #define MAP_COMMA 0x0400
|
---|
396 |
|
---|
397 | /* These are the valid characters for a user-defined function. */
|
---|
398 | #define MAP_USERFUNC 0x2000
|
---|
399 | /* This means not only a '$', but skip the variable reference. */
|
---|
400 | #define MAP_VARIABLE 0x4000
|
---|
401 | /* The set of characters which are directory separators is OS-specific. */
|
---|
402 | #define MAP_DIRSEP 0x8000
|
---|
403 |
|
---|
404 | #ifdef VMS
|
---|
405 | # define MAP_VMSCOMMA MAP_COMMA
|
---|
406 | #else
|
---|
407 | # define MAP_VMSCOMMA 0x0000
|
---|
408 | #endif
|
---|
409 |
|
---|
410 | #define MAP_SPACE (MAP_BLANK|MAP_NEWLINE)
|
---|
411 |
|
---|
412 | /* Handle other OSs.
|
---|
413 | To overcome an issue parsing paths in a DOS/Windows environment when
|
---|
414 | built in a unix based environment, override the PATH_SEPARATOR_CHAR
|
---|
415 | definition unless being built for Cygwin. */
|
---|
416 | #if defined(HAVE_DOS_PATHS) && !defined(__CYGWIN__)
|
---|
417 | # undef PATH_SEPARATOR_CHAR
|
---|
418 | # define PATH_SEPARATOR_CHAR ';'
|
---|
419 | # define MAP_PATHSEP MAP_SEMI
|
---|
420 | #elif !defined(PATH_SEPARATOR_CHAR)
|
---|
421 | # if defined (VMS)
|
---|
422 | # define PATH_SEPARATOR_CHAR (vms_comma_separator ? ',' : ':')
|
---|
423 | # define MAP_PATHSEP (vms_comma_separator ? MAP_COMMA : MAP_SEMI)
|
---|
424 | # else
|
---|
425 | # define PATH_SEPARATOR_CHAR ':'
|
---|
426 | # define MAP_PATHSEP MAP_COLON
|
---|
427 | # endif
|
---|
428 | #elif PATH_SEPARATOR_CHAR == ':'
|
---|
429 | # define MAP_PATHSEP MAP_COLON
|
---|
430 | #elif PATH_SEPARATOR_CHAR == ';'
|
---|
431 | # define MAP_PATHSEP MAP_SEMI
|
---|
432 | #elif PATH_SEPARATOR_CHAR == ','
|
---|
433 | # define MAP_PATHSEP MAP_COMMA
|
---|
434 | #else
|
---|
435 | # error "Unknown PATH_SEPARATOR_CHAR"
|
---|
436 | #endif
|
---|
437 |
|
---|
438 | #define STOP_SET(_v,_m) ANY_SET(stopchar_map[(unsigned char)(_v)],(_m))
|
---|
439 |
|
---|
440 | #define ISBLANK(c) STOP_SET((c),MAP_BLANK)
|
---|
441 | #define ISSPACE(c) STOP_SET((c),MAP_SPACE)
|
---|
442 | #define NEXT_TOKEN(s) while (ISSPACE (*(s))) ++(s)
|
---|
443 | #define END_OF_TOKEN(s) while (! STOP_SET (*(s), MAP_SPACE|MAP_NUL)) ++(s)
|
---|
444 |
|
---|
445 | #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
|
---|
446 | # define SET_STACK_SIZE
|
---|
447 | #endif
|
---|
448 | #ifdef SET_STACK_SIZE
|
---|
449 | # include <sys/resource.h>
|
---|
450 | extern struct rlimit stack_limit;
|
---|
451 | #endif
|
---|
452 |
|
---|
453 | #include <glob.h>
|
---|
454 |
|
---|
455 | #define NILF ((floc *)0)
|
---|
456 |
|
---|
457 | #define CSTRLEN(_s) (sizeof (_s)-1)
|
---|
458 | #define STRING_SIZE_TUPLE(_s) (_s), CSTRLEN(_s)
|
---|
459 |
|
---|
460 | /* The number of bytes needed to represent the largest integer as a string. */
|
---|
461 | #define INTSTR_LENGTH CSTRLEN ("18446744073709551616")
|
---|
462 |
|
---|
463 | #define DEFAULT_TTYNAME "true"
|
---|
464 | #ifdef HAVE_TTYNAME
|
---|
465 | # define TTYNAME(_f) ttyname (_f)
|
---|
466 | #else
|
---|
467 | # define TTYNAME(_f) DEFAULT_TTYNAME
|
---|
468 | #endif
|
---|
469 |
|
---|
470 | |
---|
471 |
|
---|
472 |
|
---|
473 | /* Specify the location of elements read from makefiles. */
|
---|
474 | typedef struct
|
---|
475 | {
|
---|
476 | const char *filenm;
|
---|
477 | unsigned long lineno;
|
---|
478 | unsigned long offset;
|
---|
479 | } floc;
|
---|
480 |
|
---|
481 | const char *concat (unsigned int, ...);
|
---|
482 | void message (int prefix, size_t length, const char *fmt, ...)
|
---|
483 | __attribute__ ((__format__ (__printf__, 3, 4)));
|
---|
484 | void error (const floc *flocp, size_t length, const char *fmt, ...)
|
---|
485 | __attribute__ ((__format__ (__printf__, 3, 4)));
|
---|
486 | void fatal (const floc *flocp, size_t length, const char *fmt, ...)
|
---|
487 | __attribute__ ((noreturn, __format__ (__printf__, 3, 4)));
|
---|
488 |
|
---|
489 | #define O(_t,_a,_f) _t((_a), 0, (_f))
|
---|
490 | #define OS(_t,_a,_f,_s) _t((_a), strlen (_s), (_f), (_s))
|
---|
491 | #define OSS(_t,_a,_f,_s1,_s2) _t((_a), strlen (_s1) + strlen (_s2), \
|
---|
492 | (_f), (_s1), (_s2))
|
---|
493 | #define OSSS(_t,_a,_f,_s1,_s2,_s3) _t((_a), strlen (_s1) + strlen (_s2) + strlen (_s3), \
|
---|
494 | (_f), (_s1), (_s2), (_s3))
|
---|
495 | #define ON(_t,_a,_f,_n) _t((_a), INTSTR_LENGTH, (_f), (_n))
|
---|
496 | #define ONN(_t,_a,_f,_n1,_n2) _t((_a), INTSTR_LENGTH*2, (_f), (_n1), (_n2))
|
---|
497 |
|
---|
498 | #define OSN(_t,_a,_f,_s,_n) _t((_a), strlen (_s) + INTSTR_LENGTH, \
|
---|
499 | (_f), (_s), (_n))
|
---|
500 | #define ONS(_t,_a,_f,_n,_s) _t((_a), INTSTR_LENGTH + strlen (_s), \
|
---|
501 | (_f), (_n), (_s))
|
---|
502 |
|
---|
503 | #define OUT_OF_MEM() O (fatal, NILF, _("virtual memory exhausted"))
|
---|
504 |
|
---|
505 | void die (int) __attribute__ ((noreturn));
|
---|
506 | void pfatal_with_name (const char *) __attribute__ ((noreturn));
|
---|
507 | void perror_with_name (const char *, const char *);
|
---|
508 | #define xstrlen(_s) ((_s)==NULL ? 0 : strlen (_s))
|
---|
509 | void *xmalloc (unsigned int);
|
---|
510 | void *xcalloc (unsigned int);
|
---|
511 | void *xrealloc (void *, unsigned int);
|
---|
512 | char *xstrdup (const char *);
|
---|
513 | char *xstrndup (const char *, unsigned int);
|
---|
514 | char *find_next_token (const char **, unsigned int *);
|
---|
515 | char *next_token (const char *);
|
---|
516 | char *end_of_token (const char *);
|
---|
517 | void collapse_continuations (char *);
|
---|
518 | char *lindex (const char *, const char *, int);
|
---|
519 | int alpha_compare (const void *, const void *);
|
---|
520 | void print_spaces (unsigned int);
|
---|
521 | char *find_percent (char *);
|
---|
522 | const char *find_percent_cached (const char **);
|
---|
523 |
|
---|
524 | #ifndef NO_ARCHIVES
|
---|
525 | int ar_name (const char *);
|
---|
526 | void ar_parse_name (const char *, char **, char **);
|
---|
527 | int ar_touch (const char *);
|
---|
528 | time_t ar_member_date (const char *);
|
---|
529 |
|
---|
530 | typedef long int (*ar_member_func_t) (int desc, const char *mem, int truncated,
|
---|
531 | long int hdrpos, long int datapos,
|
---|
532 | long int size, long int date, int uid,
|
---|
533 | int gid, unsigned int mode,
|
---|
534 | const void *arg);
|
---|
535 |
|
---|
536 | long int ar_scan (const char *archive, ar_member_func_t function, const void *arg);
|
---|
537 | int ar_name_equal (const char *name, const char *mem, int truncated);
|
---|
538 | #ifndef VMS
|
---|
539 | int ar_member_touch (const char *arname, const char *memname);
|
---|
540 | #endif
|
---|
541 | #endif
|
---|
542 |
|
---|
543 | int dir_file_exists_p (const char *, const char *);
|
---|
544 | int file_exists_p (const char *);
|
---|
545 | int file_impossible_p (const char *);
|
---|
546 | void file_impossible (const char *);
|
---|
547 | const char *dir_name (const char *);
|
---|
548 | void print_dir_data_base (void);
|
---|
549 | void dir_setup_glob (glob_t *);
|
---|
550 | void hash_init_directories (void);
|
---|
551 |
|
---|
552 | void define_default_variables (void);
|
---|
553 | void undefine_default_variables (void);
|
---|
554 | void set_default_suffixes (void);
|
---|
555 | void install_default_suffix_rules (void);
|
---|
556 | void install_default_implicit_rules (void);
|
---|
557 |
|
---|
558 | void build_vpath_lists (void);
|
---|
559 | void construct_vpath_list (char *pattern, char *dirpath);
|
---|
560 | const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr,
|
---|
561 | unsigned int* vpath_index, unsigned int* path_index);
|
---|
562 | int gpath_search (const char *file, unsigned int len);
|
---|
563 |
|
---|
564 | void construct_include_path (const char **arg_dirs);
|
---|
565 |
|
---|
566 | void user_access (void);
|
---|
567 | void make_access (void);
|
---|
568 | void child_access (void);
|
---|
569 |
|
---|
570 | char *strip_whitespace (const char **begpp, const char **endpp);
|
---|
571 |
|
---|
572 | void show_goal_error (void);
|
---|
573 |
|
---|
574 | /* String caching */
|
---|
575 | void strcache_init (void);
|
---|
576 | void strcache_print_stats (const char *prefix);
|
---|
577 | int strcache_iscached (const char *str);
|
---|
578 | const char *strcache_add (const char *str);
|
---|
579 | const char *strcache_add_len (const char *str, unsigned int len);
|
---|
580 |
|
---|
581 | /* Guile support */
|
---|
582 | int guile_gmake_setup (const floc *flocp);
|
---|
583 |
|
---|
584 | /* Loadable object support. Sets to the strcached name of the loaded file. */
|
---|
585 | typedef int (*load_func_t)(const floc *flocp);
|
---|
586 | int load_file (const floc *flocp, const char **filename, int noerror);
|
---|
587 | void unload_file (const char *name);
|
---|
588 |
|
---|
589 | /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
|
---|
590 | because such systems often declare them in header files anyway. */
|
---|
591 |
|
---|
592 | #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
|
---|
593 |
|
---|
594 | long int atol ();
|
---|
595 | # ifndef VMS
|
---|
596 | long int lseek ();
|
---|
597 | # endif
|
---|
598 |
|
---|
599 | # ifdef HAVE_GETCWD
|
---|
600 | # if !defined(VMS) && !defined(__DECC)
|
---|
601 | char *getcwd ();
|
---|
602 | # endif
|
---|
603 | # else
|
---|
604 | char *getwd ();
|
---|
605 | # define getcwd(buf, len) getwd (buf)
|
---|
606 | # endif
|
---|
607 |
|
---|
608 | #endif /* Not GNU C library or POSIX. */
|
---|
609 |
|
---|
610 | #if !HAVE_STRCASECMP
|
---|
611 | # if HAVE_STRICMP
|
---|
612 | # define strcasecmp stricmp
|
---|
613 | # elif HAVE_STRCMPI
|
---|
614 | # define strcasecmp strcmpi
|
---|
615 | # else
|
---|
616 | /* Create our own, in misc.c */
|
---|
617 | int strcasecmp (const char *s1, const char *s2);
|
---|
618 | # endif
|
---|
619 | #endif
|
---|
620 |
|
---|
621 | #if !HAVE_STRNCASECMP
|
---|
622 | # if HAVE_STRNICMP
|
---|
623 | # define strncasecmp strnicmp
|
---|
624 | # elif HAVE_STRNCMPI
|
---|
625 | # define strncasecmp strncmpi
|
---|
626 | # else
|
---|
627 | /* Create our own, in misc.c */
|
---|
628 | int strncasecmp (const char *s1, const char *s2, int n);
|
---|
629 | # endif
|
---|
630 | #endif
|
---|
631 |
|
---|
632 | #define OUTPUT_SYNC_NONE 0
|
---|
633 | #define OUTPUT_SYNC_LINE 1
|
---|
634 | #define OUTPUT_SYNC_TARGET 2
|
---|
635 | #define OUTPUT_SYNC_RECURSE 3
|
---|
636 |
|
---|
637 | /* Non-GNU systems may not declare this in unistd.h. */
|
---|
638 | extern char **environ;
|
---|
639 |
|
---|
640 | extern const floc *reading_file;
|
---|
641 | extern const floc **expanding_var;
|
---|
642 |
|
---|
643 | extern unsigned short stopchar_map[];
|
---|
644 |
|
---|
645 | extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
|
---|
646 | extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
|
---|
647 | extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
|
---|
648 | extern int print_version_flag, print_directory_flag, check_symlink_flag;
|
---|
649 | extern int warn_undefined_variables_flag, trace_flag, posix_pedantic;
|
---|
650 | extern int not_parallel, second_expansion, clock_skew_detected;
|
---|
651 | extern int rebuilding_makefiles, one_shell, output_sync, verify_flag;
|
---|
652 |
|
---|
653 | extern const char *default_shell;
|
---|
654 |
|
---|
655 | /* can we run commands via 'sh -c xxx' or must we use batch files? */
|
---|
656 | extern int batch_mode_shell;
|
---|
657 |
|
---|
658 | /* Resetting the command script introduction prefix character. */
|
---|
659 | #define RECIPEPREFIX_NAME ".RECIPEPREFIX"
|
---|
660 | #define RECIPEPREFIX_DEFAULT '\t'
|
---|
661 | extern char cmd_prefix;
|
---|
662 |
|
---|
663 | extern unsigned int job_slots;
|
---|
664 | #ifndef NO_FLOAT
|
---|
665 | extern double max_load_average;
|
---|
666 | #else
|
---|
667 | extern int max_load_average;
|
---|
668 | #endif
|
---|
669 |
|
---|
670 | #ifdef WINDOWS32
|
---|
671 | extern char *program;
|
---|
672 | #else
|
---|
673 | extern const char *program;
|
---|
674 | #endif
|
---|
675 |
|
---|
676 | #ifdef VMS
|
---|
677 | const char *vms_command (const char *argv0);
|
---|
678 | const char *vms_progname (const char *argv0);
|
---|
679 |
|
---|
680 | void vms_exit (int);
|
---|
681 | # define _exit(foo) vms_exit(foo)
|
---|
682 | # define exit(foo) vms_exit(foo)
|
---|
683 |
|
---|
684 | extern char *program_name;
|
---|
685 |
|
---|
686 | void
|
---|
687 | set_program_name (const char *arv0);
|
---|
688 |
|
---|
689 | int
|
---|
690 | need_vms_symbol (void);
|
---|
691 |
|
---|
692 | int
|
---|
693 | create_foreign_command (const char *command, const char *image);
|
---|
694 |
|
---|
695 | int
|
---|
696 | vms_export_dcl_symbol (const char *name, const char *value);
|
---|
697 |
|
---|
698 | int
|
---|
699 | vms_putenv_symbol (const char *string);
|
---|
700 |
|
---|
701 | void
|
---|
702 | vms_restore_symbol (const char *string);
|
---|
703 |
|
---|
704 | #endif
|
---|
705 |
|
---|
706 | void remote_setup (void);
|
---|
707 | void remote_cleanup (void);
|
---|
708 | int start_remote_job_p (int);
|
---|
709 | int start_remote_job (char **, char **, int, int *, int *, int *);
|
---|
710 | int remote_status (int *, int *, int *, int);
|
---|
711 | void block_remote_children (void);
|
---|
712 | void unblock_remote_children (void);
|
---|
713 | int remote_kill (int id, int sig);
|
---|
714 | void print_variable_data_base (void);
|
---|
715 | void print_vpath_data_base (void);
|
---|
716 |
|
---|
717 | extern char *starting_directory;
|
---|
718 | extern unsigned int makelevel;
|
---|
719 | extern char *version_string, *remote_description, *make_host;
|
---|
720 |
|
---|
721 | extern unsigned int commands_started;
|
---|
722 |
|
---|
723 | extern int handling_fatal_signal;
|
---|
724 |
|
---|
725 |
|
---|
726 | #ifndef MIN
|
---|
727 | #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
|
---|
728 | #endif
|
---|
729 | #ifndef MAX
|
---|
730 | #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
|
---|
731 | #endif
|
---|
732 |
|
---|
733 |
|
---|
734 | #define MAKE_SUCCESS 0
|
---|
735 | #define MAKE_TROUBLE 1
|
---|
736 | #define MAKE_FAILURE 2
|
---|
737 |
|
---|
738 | /* Set up heap debugging library dmalloc. */
|
---|
739 |
|
---|
740 | #ifdef HAVE_DMALLOC_H
|
---|
741 | #include <dmalloc.h>
|
---|
742 | #endif
|
---|
743 |
|
---|
744 | #ifndef initialize_main
|
---|
745 | # ifdef __EMX__
|
---|
746 | # define initialize_main(pargc, pargv) \
|
---|
747 | { _wildcard(pargc, pargv); _response(pargc, pargv); }
|
---|
748 | # else
|
---|
749 | # define initialize_main(pargc, pargv)
|
---|
750 | # endif
|
---|
751 | #endif
|
---|
752 |
|
---|
753 | #ifdef __EMX__
|
---|
754 | # if !defined chdir
|
---|
755 | # define chdir _chdir2
|
---|
756 | # endif
|
---|
757 | # if !defined getcwd
|
---|
758 | # define getcwd _getcwd2
|
---|
759 | # endif
|
---|
760 |
|
---|
761 | /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
|
---|
762 | chdir() and getcwd(). This avoids some error messages for the
|
---|
763 | make testsuite but restricts the drive letter support. */
|
---|
764 | # ifdef NO_CHDIR2
|
---|
765 | # warning NO_CHDIR2: usage of drive letters restricted
|
---|
766 | # undef chdir
|
---|
767 | # undef getcwd
|
---|
768 | # endif
|
---|
769 | #endif
|
---|
770 |
|
---|
771 | #ifndef initialize_main
|
---|
772 | # define initialize_main(pargc, pargv)
|
---|
773 | #endif
|
---|
774 |
|
---|
775 |
|
---|
776 | /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
|
---|
777 | properly according to POSIX. So, we try to wrap common system calls with
|
---|
778 | checks for EINTR. Note that there are still plenty of system calls that
|
---|
779 | can fail with EINTR but this, reportedly, gets the vast majority of
|
---|
780 | failure cases. If you still experience failures you'll need to either get
|
---|
781 | a system where SA_RESTART works, or you need to avoid -j. */
|
---|
782 |
|
---|
783 | #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
|
---|
784 |
|
---|
785 | /* While system calls that return integers are pretty consistent about
|
---|
786 | returning -1 on failure and setting errno in that case, functions that
|
---|
787 | return pointers are not always so well behaved. Sometimes they return
|
---|
788 | NULL for expected behavior: one good example is readdir() which returns
|
---|
789 | NULL at the end of the directory--and _doesn't_ reset errno. So, we have
|
---|
790 | to do it ourselves here. */
|
---|
791 |
|
---|
792 | #define ENULLLOOP(_v,_c) do { errno = 0; (_v) = _c; } \
|
---|
793 | while((_v)==0 && errno==EINTR)
|
---|