Debian Codegraph @

src/make.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /* Miscellaneous global declarations and portability cruft for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
5 This file is part of GNU Make.
6
7 GNU Make is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 3 of the License, or (at your option) any later
10 version.
11
12 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 /* We use <config.h> instead of "config.h" so that a compilation
20 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
21 (which it would do because make.h was found in $srcdir). */
22 #ifndef MAKE_H
23 #define MAKE_H
24
25 #include <config.h>
26 #undef HAVE_CONFIG_H
27 #define HAVE_CONFIG_H 1
28
29 /* Specify we want GNU source code. This must be defined before any
30 system headers are included. */
31
32 #define _GNU_SOURCE 1
33
34 /* AIX requires this to be the first thing in the file. */
35 #if HAVE_ALLOCA_H
36 # include <alloca.h>
37 #else
38 # ifdef _AIX
39 #pragma alloca
40 # else
41 # if !defined(__GNUC__) && !defined(WINDOWS32)
42 # ifndef alloca /* predefined by HP cc +Olibcalls */
43 char *alloca ();
44 # endif
45 # endif
46 # endif
47 #endif
48
49
50 #ifdef CRAY
51 /* This must happen before #include <signal.h> so
52 that the declaration therein is changed. */
53 # define signal bsdsignal
54 #endif
55
56 /* If we're compiling for the dmalloc debugger, turn off string inlining. */
57 #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
58 # define __NO_STRING_INLINES
59 #endif
60
61 #include <sys/types.h>
62 #include <sys/stat.h>
63 #include <signal.h>
64 #include <stdio.h>
65 #include <ctype.h>
66 #ifdef HAVE_SYS_TIMEB_H
67 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
68 unless <sys/timeb.h> has been included first. Does every system have a
69 <sys/timeb.h>? If any does not, configure should check for it. */
70 # include <sys/timeb.h>
71 #endif
72
73 #if TIME_WITH_SYS_TIME
74 # include <sys/time.h>
75 # include <time.h>
76 #else
77 # if HAVE_SYS_TIME_H
78 # include <sys/time.h>
79 # else
80 # include <time.h>
81 # endif
82 #endif
83
84 #include <errno.h>
85
86 #ifndef errno
87 extern int errno;
88 #endif
89
90 #ifndef isblank
91 # define isblank(c) ((c) == ' ' || (c) == '\t')
92 #endif
93
94 #ifdef HAVE_UNISTD_H
95 # include <unistd.h>
96 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
97 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
98 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
99 # define POSIX 1
100 # endif
101 #endif
102
103 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
104 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
105 # undef POSIX
106 #endif
107
108 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
109 # define POSIX 1
110 #endif
111
112 #ifndef RETSIGTYPE
113 # define RETSIGTYPE void
114 #endif
115
116 #ifndef sigmask
117 # define sigmask(sig) (1 << ((sig) - 1))
118 #endif
119
120 #ifndef HAVE_SA_RESTART
121 # define SA_RESTART 0
122 #endif
123
124 #ifdef HAVE_LIMITS_H
125 # include <limits.h>
126 #endif
127 #ifdef HAVE_SYS_PARAM_H
128 # include <sys/param.h>
129 #endif
130
131 #ifndef PATH_MAX
132 # ifndef POSIX
133 # define PATH_MAX MAXPATHLEN
134 # endif
135 #endif
136 #ifndef MAXPATHLEN
137 # define MAXPATHLEN 1024
138 #endif
139
140 #ifdef PATH_MAX
141 # define GET_PATH_MAX PATH_MAX
142 //# define PATH_VAR(var) char var[PATH_MAX]
143 #else
144 # define NEED_GET_PATH_MAX 1
145 # define GET_PATH_MAX (get_path_max ())
146 // # define PATH_VAR(var) char *var = alloca (GET_PATH_MAX)
147 unsigned int get_path_max (void);
148 #endif
149
150 #ifndef CHAR_BIT
151 # define CHAR_BIT 8
152 #endif
153
154 /* The minimum and maximum values for the integer type T.
155 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
156 #define INTEGER_TYPE_MINIMUM(t) \
157 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
158 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
159
160 #ifndef CHAR_MAX
161 # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
162 #endif
163
164 #ifdef STAT_MACROS_BROKEN
165 # ifdef S_ISREG
166 # undef S_ISREG
167 # endif
168 # ifdef S_ISDIR
169 # undef S_ISDIR
170 # endif
171 #endif /* STAT_MACROS_BROKEN. */
172
173 #ifndef S_ISREG
174 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
175 #endif
176 #ifndef S_ISDIR
177 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
178 #endif
179
180 #ifndef __attribute__
181 /* This feature is available in gcc versions 2.5 and later. */
182 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
183 # define __attribute__(x)
184 # endif
185 /* The __-protected variants of `format' and `printf' attributes
186 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
187 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
188 # define __format__ format
189 # define __printf__ printf
190 # endif
191 #endif
192 // #define UNUSED __attribute__ ((unused))
193
194 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
195 # include <stdlib.h>
196 # include <string.h>
197 # define ANSI_STRING 1
198 #else /* No standard headers. */
199 # ifdef HAVE_STRING_H
200 # include <string.h>
201 # define ANSI_STRING 1
202 # else
203 # include <strings.h>
204 # endif
205 # ifdef HAVE_MEMORY_H
206 # include <memory.h>
207 # endif
208 # ifdef HAVE_STDLIB_H
209 # include <stdlib.h>
210 # else
211 void *malloc (int);
212 void *realloc (void *, int);
213 void free (void *);
214
215 void abort (void) __attribute__ ((noreturn));
216 void exit (int) __attribute__ ((noreturn));
217 # endif /* HAVE_STDLIB_H. */
218
219 #endif /* Standard headers. */
220
221 /* These should be in stdlib.h. Make sure we have them. */
222 #ifndef EXIT_SUCCESS
223 # define EXIT_SUCCESS 0
224 #endif
225 #ifndef EXIT_FAILURE
226 # define EXIT_FAILURE 1
227 #endif
228
229 #ifndef ANSI_STRING
230
231 /* SCO Xenix has a buggy macro definition in <string.h>. */
232 #undef strerror
233 #if !defined(__DECC)
234 char *strerror (int errnum);
235 #endif
236
237 #endif /* !ANSI_STRING. */
238 #undef ANSI_STRING
239
240 #if HAVE_INTTYPES_H
241 # include <inttypes.h>
242 #endif
243 #define FILE_TIMESTAMP uintmax_t
244
245 #if !defined(HAVE_STRSIGNAL)
246 char *strsignal (int signum);
247 #endif
248
249 /* Test if two strings are equal. Is this worthwhile? Should be profiled. */
250 #define streq(a, b) \
251 ((a) == (b) || \
252 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
253
254 /* Test if two strings are equal, but match case-insensitively on systems
255 which have case-insensitive filesystems. Should only be used for
256 filenames! */
257 #ifdef HAVE_CASE_INSENSITIVE_FS
258 # define patheq(a, b) \
259 ((a) == (b) \
260 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
261 && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1))))
262 #else
263 # define patheq(a, b) streq(a, b)
264 #endif
265
266 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
267
268 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
269 # define ENUM_BITFIELD(bits) :bits
270 #else
271 # define ENUM_BITFIELD(bits)
272 #endif
273
274 /* Handle gettext and locales. */
275
276 #if HAVE_LOCALE_H
277 # include <locale.h>
278 #else
279 # define setlocale(category, locale)
280 #endif
281
282 #include <gettext.h>
283
284 #define _(msgid) gettext (msgid)
285 #define N_(msgid) gettext_noop (msgid)
286 #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
287
288 /* Handle other OSs. */
289 #ifndef PATH_SEPARATOR_CHAR
290 # if defined(HAVE_DOS_PATHS)
291 # define PATH_SEPARATOR_CHAR ';'
292 # elif defined(VMS)
293 # define PATH_SEPARATOR_CHAR ','
294 # else
295 # define PATH_SEPARATOR_CHAR ':'
296 # endif
297 #endif
298
299 /* This is needed for getcwd() and chdir(), on some W32 systems. */
300 #if defined(HAVE_DIRECT_H)
301 # include <direct.h>
302 #endif
303
304 #ifdef WINDOWS32
305 # include <fcntl.h>
306 # include <malloc.h>
307 # define pipe(_p) _pipe((_p), 512, O_BINARY)
308 # define kill(_pid,_sig) w32_kill((_pid),(_sig))
309
310 void sync_Path_environment (void);
311 int w32_kill (pid_t pid, int sig);
312 char *end_of_token_w32 (const char *s, char stopchar);
313 int find_and_set_default_shell (const char *token);
314
315 /* indicates whether or not we have Bourne shell */
316 extern int no_default_sh_exe;
317
318 /* is default_shell unixy? */
319 extern int unixy_shell;
320 #endif /* WINDOWS32 */
321
322 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
323 # define SET_STACK_SIZE
324 #endif
325 #ifdef SET_STACK_SIZE
326 # include <sys/resource.h>
327 extern struct rlimit stack_limit;
328 #endif
329
330 /* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
331 variadic versions of these functions. */
332
333 #if HAVE_STDARG_H || HAVE_VARARGS_H
334 # if HAVE_VPRINTF || HAVE_DOPRNT
335 # define USE_VARIADIC 1
336 # endif
337 #endif
338
339 void die (int);
340 void pfatal_with_name (const char *);
341 void perror_with_name (const char *, const char *);
342 void *xmalloc (size_t);
343 void *xcalloc (size_t);
344 void *xrealloc (void *, size_t);
345 char *xstrdup (const char *);
346 char *xstrndup (const char *, size_t);
347 //char *find_next_token (const char **, unsigned int *);
348 char *next_token (const char *);
349 char *end_of_token (const char *);
350 void collapse_continuations (char *);
351 char *lindex (const char *, const char *, int);
352 int alpha_compare (const void *, const void *);
353 void print_spaces (unsigned int);
354 char *find_percent (char *);
355 const char *find_percent_cached (const char **);
356 FILE *open_tmpfile (char **, const char *);
357
358 #ifndef NO_ARCHIVES
359 int ar_name (const char *);
360 void ar_parse_name (const char *, char **, char **);
361 int ar_touch (const char *);
362 int ar_member_date (const char *, time_t *);
363
364
365 #endif
366
367 int dir_file_exists_p (const char *, const char *);
368 int file_exists_p (const char *);
369 int file_impossible_p (const char *);
370 void file_impossible (const char *);
371 const char *dir_name (const char *);
372 void hash_init_directories (void);
373
374 void define_default_variables (void);
375 void set_default_suffixes (void);
376 void install_default_suffix_rules (void);
377 void install_default_implicit_rules (void);
378
379 void build_vpath_lists (void);
380 void construct_vpath_list (char *pattern, char *dirpath);
381 const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr,
382 unsigned int* vpath_index, unsigned int* path_index);
383 int gpath_search (const char *file, size_t len);
384
385 /*! Construct the list of include directories
386 from the arguments and the default list.
387 */
388 extern void construct_include_path (const char **arg_dirs);
389
390 void user_access (void);
391 void make_access (void);
392 void child_access (void);
393
394 char *strip_whitespace (const char **begpp, const char **endpp);
395
396 /* String caching */
397 void strcache_init (void);
398 void strcache_print_stats (const char *prefix);
399 int strcache_iscached (const char *str);
400 const char *strcache_add (const char *str);
401
402 #ifdef HAVE_VFORK_H
403 # include <vfork.h>
404 #endif
405
406 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
407 because such systems often declare them in header files anyway. */
408
409 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
410
411 long int atol ();
412 # ifndef VMS
413 long int lseek ();
414 # endif
415
416 #endif /* Not GNU C library or POSIX. */
417
418 #ifdef HAVE_GETCWD
419 #else
420 char *getwd ();
421 # define getcwd(buf, len) getwd (buf)
422 #endif
423
424 #if !HAVE_STRCASECMP
425 # if HAVE_STRICMP
426 # define strcasecmp stricmp
427 # elif HAVE_STRCMPI
428 # define strcasecmp strcmpi
429 # else
430 /* Create our own, in misc.c */
431 int strcasecmp (const char *s1, const char *s2);
432 # endif
433 #endif
434
435 #if !HAVE_STRNCASECMP
436 # if HAVE_STRNICMP
437 # define strncasecmp strnicmp
438 # elif HAVE_STRNCMPI
439 # define strncasecmp strncmpi
440 # else
441 /* Create our own, in misc.c */
442 int strncasecmp (const char *s1, const char *s2, int n);
443 # endif
444 #endif
445
446 extern char **environ;
447
448 extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
449 extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
450 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
451 extern int print_version_flag, print_directory, check_symlink_flag;
452 extern int warn_undefined_variables_flag, posix_pedantic, not_parallel;
453 extern int second_expansion, clock_skew_detected, rebuilding_makefiles;
454 extern int one_shell;
455
456 /* can we run commands via 'sh -c xxx' or must we use batch files? */
457 extern int batch_mode_shell;
458
459 /* Resetting the command script introduction prefix character. */
460 #define RECIPEPREFIX_NAME ".RECIPEPREFIX"
461 #define RECIPEPREFIX_DEFAULT '\t'
462 extern char cmd_prefix;
463
464 extern unsigned int job_slots;
465 extern int job_fds[2];
466 extern int job_rfd;
467 #ifndef NO_FLOAT
468 extern double max_load_average;
469 #else
470 extern int max_load_average;
471 #endif
472
473 /*! Value of argv[0] which seems to get modified. Can we merge this with
474 program below? */
475 extern char *argv0;
476
477 /*! Our initial arguments -- used for debugger restart execvp. */
478 extern const char * const *global_argv;
479
480 extern char *starting_directory;
481
482 /*! Our current directory before processing any -C options. */
483 extern char *directory_before_chdir;
484
485 /*! Value of the MAKELEVEL variable at startup (or 0). */
486 extern unsigned int makelevel;
487
488 /*! Value of the MAKEPARENT variable at startup (or 0). */
489 extern pid_t makeparent_pid;
490
491 /*! Value of the MAKEPARENT_TARGET variable at startup (or NULL). */
492 extern char *makeparent_target;
493
494 extern char *version_string, *remote_description, *make_host;
495
496 extern unsigned int commands_started;
497
498 extern int handling_fatal_signal;
499
500
501 #ifndef MIN
502 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
503 #endif
504 #ifndef MAX
505 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
506 #endif
507
508 /* Set up heap debugging library dmalloc. */
509
510 #ifdef HAVE_DMALLOC_H
511 #include <dmalloc.h>
512 #endif
513
514 #ifndef initialize_main
515 # ifdef __EMX__
516 # define initialize_main(pargc, pargv) \
517 { _wildcard(pargc, pargv); _response(pargc, pargv); }
518 # else
519 # define initialize_main(pargc, pargv)
520 # endif
521 #endif
522
523 #ifdef __EMX__
524 # if !defined chdir
525 # define chdir _chdir2
526 # endif
527 # if !defined getcwd
528 # define getcwd _getcwd2
529 # endif
530
531 /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
532 chdir() and getcwd(). This avoids some error messages for the
533 make testsuite but restricts the drive letter support. */
534 # ifdef NO_CHDIR2
535 # warning NO_CHDIR2: usage of drive letters restricted
536 # undef chdir
537 # undef getcwd
538 # endif
539 #endif
540
541 #ifndef initialize_main
542 # define initialize_main(pargc, pargv)
543 #endif
544
545
546 /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
547 properly according to POSIX. So, we try to wrap common system calls with
548 checks for EINTR. Note that there are still plenty of system calls that
549 can fail with EINTR but this, reportedly, gets the vast majority of
550 failure cases. If you still experience failures you'll need to either get
551 a system where SA_RESTART works, or you need to avoid -j. */
552
553 #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
554
555 /* While system calls that return integers are pretty consistent about
556 returning -1 on failure and setting errno in that case, functions that
557 return pointers are not always so well behaved. Sometimes they return
558 NULL for expected behavior: one good example is readdir() which returns
559 NULL at the end of the directory--and _doesn't_ reset errno. So, we have
560 to do it ourselves here. */
561
562 #endif /*MAKE_H*/