remake  4.3+dbg-1.5
make.h
Go to the documentation of 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 #ifdef VMS
181 # include <types.h>
182 # include <unixlib.h>
183 # include <unixio.h>
184 # include <perror.h>
185 /* Needed to use alloca on VMS. */
186 # include <builtins.h>
187 #endif
188 
189 #ifndef __attribute__
190 /* This feature is available in gcc versions 2.5 and later. */
191 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
192 # define __attribute__(x)
193 # endif
194 /* The __-protected variants of `format' and `printf' attributes
195  are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
196 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
197 # define __format__ format
198 # define __printf__ printf
199 # endif
200 #endif
201 // #define UNUSED __attribute__ ((unused))
202 
203 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
204 # include <stdlib.h>
205 # include <string.h>
206 # define ANSI_STRING 1
207 #else /* No standard headers. */
208 # ifdef HAVE_STRING_H
209 # include <string.h>
210 # define ANSI_STRING 1
211 # else
212 # include <strings.h>
213 # endif
214 # ifdef HAVE_MEMORY_H
215 # include <memory.h>
216 # endif
217 # ifdef HAVE_STDLIB_H
218 # include <stdlib.h>
219 # else
220 void *malloc (int);
221 void *realloc (void *, int);
222 void free (void *);
223 
224 void abort (void) __attribute__ ((noreturn));
225 void exit (int) __attribute__ ((noreturn));
226 # endif /* HAVE_STDLIB_H. */
227 
228 #endif /* Standard headers. */
229 
230 /* These should be in stdlib.h. Make sure we have them. */
231 #ifndef EXIT_SUCCESS
232 # define EXIT_SUCCESS 0
233 #endif
234 #ifndef EXIT_FAILURE
235 # define EXIT_FAILURE 1
236 #endif
237 
238 #ifndef ANSI_STRING
239 
240 /* SCO Xenix has a buggy macro definition in <string.h>. */
241 #undef strerror
242 #if !defined(__DECC)
243 char *strerror (int errnum);
244 #endif
245 
246 #endif /* !ANSI_STRING. */
247 #undef ANSI_STRING
248 
249 #if HAVE_INTTYPES_H
250 # include <inttypes.h>
251 #endif
252 #define FILE_TIMESTAMP uintmax_t
253 
254 #if !defined(HAVE_STRSIGNAL)
255 char *strsignal (int signum);
256 #endif
257 
258 /* Test if two strings are equal. Is this worthwhile? Should be profiled. */
259 #define streq(a, b) \
260  ((a) == (b) || \
261  (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
262 
263 /* Test if two strings are equal, but match case-insensitively on systems
264  which have case-insensitive filesystems. Should only be used for
265  filenames! */
266 #ifdef HAVE_CASE_INSENSITIVE_FS
267 # define patheq(a, b) \
268  ((a) == (b) \
269  || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
270  && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1))))
271 #else
272 # define patheq(a, b) streq(a, b)
273 #endif
274 
275 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
276 
277 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
278 # define ENUM_BITFIELD(bits) :bits
279 #else
280 # define ENUM_BITFIELD(bits)
281 #endif
282 
283 /* Handle gettext and locales. */
284 
285 #if HAVE_LOCALE_H
286 # include <locale.h>
287 #else
288 # define setlocale(category, locale)
289 #endif
290 
291 #include <gettext.h>
292 
293 #define _(msgid) gettext (msgid)
294 #define N_(msgid) gettext_noop (msgid)
295 #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
296 
297 /* Handle other OSs. */
298 #ifndef PATH_SEPARATOR_CHAR
299 # if defined(HAVE_DOS_PATHS)
300 # define PATH_SEPARATOR_CHAR ';'
301 # elif defined(VMS)
302 # define PATH_SEPARATOR_CHAR ','
303 # else
304 # define PATH_SEPARATOR_CHAR ':'
305 # endif
306 #endif
307 
308 /* This is needed for getcwd() and chdir(), on some W32 systems. */
309 #if defined(HAVE_DIRECT_H)
310 # include <direct.h>
311 #endif
312 
313 #ifdef WINDOWS32
314 # include <fcntl.h>
315 # include <malloc.h>
316 # define pipe(_p) _pipe((_p), 512, O_BINARY)
317 # define kill(_pid,_sig) w32_kill((_pid),(_sig))
318 
319 void sync_Path_environment (void);
320 int w32_kill (pid_t pid, int sig);
321 char *end_of_token_w32 (const char *s, char stopchar);
322 int find_and_set_default_shell (const char *token);
323 
324 /* indicates whether or not we have Bourne shell */
325 extern int no_default_sh_exe;
326 
327 /* is default_shell unixy? */
328 extern int unixy_shell;
329 #endif /* WINDOWS32 */
330 
331 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
332 # define SET_STACK_SIZE
333 #endif
334 #ifdef SET_STACK_SIZE
335 # include <sys/resource.h>
336 struct rlimit stack_limit;
337 #endif
338 
339 /* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
340  variadic versions of these functions. */
341 
342 #if HAVE_STDARG_H || HAVE_VARARGS_H
343 # if HAVE_VPRINTF || HAVE_DOPRNT
344 # define USE_VARIADIC 1
345 # endif
346 #endif
347 
348 void die (int);
349 void pfatal_with_name (const char *);
350 void perror_with_name (const char *, const char *);
351 void *xmalloc (size_t);
352 void *xcalloc (size_t);
353 void *xrealloc (void *, size_t);
354 char *xstrdup (const char *);
355 char *xstrndup (const char *, size_t);
356 //char *find_next_token (const char **, unsigned int *);
357 char *next_token (const char *);
358 char *end_of_token (const char *);
359 void collapse_continuations (char *);
360 char *lindex (const char *, const char *, int);
361 int alpha_compare (const void *, const void *);
362 void print_spaces (unsigned int);
363 char *find_percent (char *);
364 const char *find_percent_cached (const char **);
365 FILE *open_tmpfile (char **, const char *);
366 
367 #ifndef NO_ARCHIVES
368 int ar_name (const char *);
369 void ar_parse_name (const char *, char **, char **);
370 int ar_touch (const char *);
371 int ar_member_date (const char *, time_t *);
372 
373 
374 #endif
375 
376 int dir_file_exists_p (const char *, const char *);
377 int file_exists_p (const char *);
378 int file_impossible_p (const char *);
379 void file_impossible (const char *);
380 const char *dir_name (const char *);
381 void hash_init_directories (void);
382 
383 void define_default_variables (void);
384 void set_default_suffixes (void);
385 void install_default_suffix_rules (void);
387 
388 void build_vpath_lists (void);
389 void construct_vpath_list (char *pattern, char *dirpath);
390 const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr,
391  unsigned int* vpath_index, unsigned int* path_index);
392 int gpath_search (const char *file, size_t len);
393 
397 extern void construct_include_path (const char **arg_dirs);
398 
399 void user_access (void);
400 void make_access (void);
401 void child_access (void);
402 
403 char *strip_whitespace (const char **begpp, const char **endpp);
404 
405 /* String caching */
406 void strcache_init (void);
407 void strcache_print_stats (const char *prefix);
408 int strcache_iscached (const char *str);
409 const char *strcache_add (const char *str);
410 
411 #ifdef HAVE_VFORK_H
412 # include <vfork.h>
413 #endif
414 
415 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
416  because such systems often declare them in header files anyway. */
417 
418 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
419 
420 long int atol ();
421 # ifndef VMS
422 long int lseek ();
423 # endif
424 
425 #endif /* Not GNU C library or POSIX. */
426 
427 #ifdef HAVE_GETCWD
428 # if !defined(VMS) && !defined(__DECC)
429 char *getcwd ();
430 # endif
431 #else
432 char *getwd ();
433 # define getcwd(buf, len) getwd (buf)
434 #endif
435 
436 #if !HAVE_STRCASECMP
437 # if HAVE_STRICMP
438 # define strcasecmp stricmp
439 # elif HAVE_STRCMPI
440 # define strcasecmp strcmpi
441 # else
442 /* Create our own, in misc.c */
443 int strcasecmp (const char *s1, const char *s2);
444 # endif
445 #endif
446 
447 #if !HAVE_STRNCASECMP
448 # if HAVE_STRNICMP
449 # define strncasecmp strnicmp
450 # elif HAVE_STRNCMPI
451 # define strncasecmp strncmpi
452 # else
453 /* Create our own, in misc.c */
454 int strncasecmp (const char *s1, const char *s2, int n);
455 # endif
456 #endif
457 
458 extern char **environ;
459 
466 extern int one_shell;
467 
468 /* can we run commands via 'sh -c xxx' or must we use batch files? */
469 extern int batch_mode_shell;
470 
471 /* Resetting the command script introduction prefix character. */
472 #define RECIPEPREFIX_NAME ".RECIPEPREFIX"
473 #define RECIPEPREFIX_DEFAULT '\t'
474 extern char cmd_prefix;
475 
476 extern unsigned int job_slots;
477 extern int job_fds[2];
478 extern int job_rfd;
479 #ifndef NO_FLOAT
480 extern double max_load_average;
481 #else
482 extern int max_load_average;
483 #endif
484 
487 extern char *argv0;
488 
490 extern const char * const *global_argv;
491 
492 extern char *starting_directory;
493 
495 extern char *directory_before_chdir;
496 
498 extern unsigned int makelevel;
500 
501 extern unsigned int commands_started;
502 
503 extern int handling_fatal_signal;
504 
505 
506 #ifndef MIN
507 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
508 #endif
509 #ifndef MAX
510 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
511 #endif
512 
513 /* Set up heap debugging library dmalloc. */
514 
515 #ifdef HAVE_DMALLOC_H
516 #include <dmalloc.h>
517 #endif
518 
519 #ifndef initialize_main
520 # ifdef __EMX__
521 # define initialize_main(pargc, pargv) \
522  { _wildcard(pargc, pargv); _response(pargc, pargv); }
523 # else
524 # define initialize_main(pargc, pargv)
525 # endif
526 #endif
527 
528 #ifdef __EMX__
529 # if !defined chdir
530 # define chdir _chdir2
531 # endif
532 # if !defined getcwd
533 # define getcwd _getcwd2
534 # endif
535 
536 /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
537  chdir() and getcwd(). This avoids some error messages for the
538  make testsuite but restricts the drive letter support. */
539 # ifdef NO_CHDIR2
540 # warning NO_CHDIR2: usage of drive letters restricted
541 # undef chdir
542 # undef getcwd
543 # endif
544 #endif
545 
546 #ifndef initialize_main
547 # define initialize_main(pargc, pargv)
548 #endif
549 
550 
551 /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
552  properly according to POSIX. So, we try to wrap common system calls with
553  checks for EINTR. Note that there are still plenty of system calls that
554  can fail with EINTR but this, reportedly, gets the vast majority of
555  failure cases. If you still experience failures you'll need to either get
556  a system where SA_RESTART works, or you need to avoid -j. */
557 
558 #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
559 
560 /* While system calls that return integers are pretty consistent about
561  returning -1 on failure and setting errno in that case, functions that
562  return pointers are not always so well behaved. Sometimes they return
563  NULL for expected behavior: one good example is readdir() which returns
564  NULL at the end of the directory--and _doesn't_ reset errno. So, we have
565  to do it ourselves here. */
566 
567 #endif /*MAKE_H*/
int strcache_iscached(const char *str)
void * xmalloc(size_t)
FILE * open_tmpfile(char **, const char *)
int print_directory_flag
int alpha_compare(const void *, const void *)
char * xstrndup(const char *, size_t)
char * next_token(const char *)
void ar_parse_name(const char *, char **, char **)
char * find_percent(char *)
char * getcwd()
Miscellaneous types.
int handling_fatal_signal
char * make_host
char ** environ
int no_builtin_variables_flag
char * xstrdup(const char *)
char * argv0
void print_spaces(unsigned int)
int touch_flag
int clock_skew_detected
char * starting_directory
int rebuilding_makefiles
char * version_string
int no_builtin_rules_flag
int keep_going_flag
const char * find_percent_cached(const char **)
int ignore_errors_flag
void user_access(void)
const char * strcache_add(const char *str)
void perror_with_name(const char *, const char *)
int check_symlink_flag
int always_make_flag
int ar_member_date(const char *, time_t *)
const char *const * global_argv
void install_default_suffix_rules(void)
void define_default_variables(void)
struct rlimit stack_limit
Definition: make.h:336
int not_parallel
void child_access(void)
int second_expansion
int file_impossible_p(const char *)
int posix_pedantic
int job_fds[2]
char * strip_whitespace(const char **begpp, const char **endpp)
unsigned int makelevel
int file_exists_p(const char *)
void file_impossible(const char *)
char * directory_before_chdir
void pfatal_with_name(const char *)
void hash_init_directories(void)
const char * vpath_search(const char *file, FILE_TIMESTAMP *mtime_ptr, unsigned int *vpath_index, unsigned int *path_index)
void build_vpath_lists(void)
int just_print_flag
void strcache_init(void)
int print_data_base_flag
int ar_touch(const char *)
int batch_mode_shell
void construct_include_path(const char **arg_dirs)
void construct_vpath_list(char *pattern, char *dirpath)
int warn_undefined_variables_flag
void set_default_suffixes(void)
void die(int)
void install_default_implicit_rules(void)
unsigned int commands_started
int job_rfd
char * lindex(const char *, const char *, int)
int errno
int silent_flag
#define __attribute__(x)
Definition: make.h:192
char cmd_prefix
long int atol()
int gpath_search(const char *file, size_t len)
int env_overrides
int question_flag
int unixy_shell
void collapse_continuations(char *)
long int lseek()
int ar_name(const char *)
double max_load_average
void * xcalloc(size_t)
const char * dir_name(const char *)
void make_access(void)
int one_shell
char * end_of_token(const char *)
int dir_file_exists_p(const char *, const char *)
char * remote_description
void strcache_print_stats(const char *prefix)
#define FILE_TIMESTAMP
Definition: make.h:252
void * xrealloc(void *, size_t)
int print_version_flag
unsigned int job_slots
Definition: filedef.h:34