* Release 3.77.92.
[make.git] / make.h
blob26eaec909c31b8deaa4e077b40bbd6fbde2c825b
1 /* Miscellaneous global declarations and portability cruft for GNU Make.
2 Copyright (C) 1988,89,90,91,92,93,94,95,96,97,99 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* AIX requires this to be the first thing in the file. */
21 #if defined (_AIX) && !defined (__GNUC__)
22 #pragma alloca
23 #endif
25 /* We use <config.h> instead of "config.h" so that a compilation
26 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
27 (which it would do because make.h was found in $srcdir). */
28 #include <config.h>
29 #undef HAVE_CONFIG_H
30 #define HAVE_CONFIG_H 1
33 /* Use prototypes if available. */
34 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
35 # undef PARAMS
36 # define PARAMS(protos) protos
37 #else /* Not C++ or ANSI C. */
38 # undef PARAMS
39 # define PARAMS(protos) ()
40 #endif /* C++ or ANSI C. */
43 /* For now, set gettext macro to a no-op. */
44 #undef _
45 #undef N_
46 #define _(s) s
47 #define N_(s) s
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
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
61 #define _GNU_SOURCE 1
62 #include <sys/types.h>
63 #include <sys/stat.h>
64 #include <signal.h>
65 #include <stdio.h>
66 #include <ctype.h>
67 #ifdef HAVE_SYS_TIMEB_H
68 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
69 unless <sys/timeb.h> has been included first. Does every system have a
70 <sys/timeb.h>? If any does not, configure should check for it. */
71 # include <sys/timeb.h>
72 #endif
73 #include <time.h>
74 #include <errno.h>
76 #ifndef errno
77 extern int errno;
78 #endif
80 /* A shortcut for EINTR checking. Note you should never negate this! That
81 very likely doesn't mean what you want if EINTR is not available. */
82 #ifdef EINTR
83 # define EINTR_SET (errno == EINTR)
84 #else
85 # define EINTR_SET (0)
86 #endif
88 #ifndef isblank
89 # define isblank(c) ((c) == ' ' || (c) == '\t')
90 #endif
92 #ifdef HAVE_UNISTD_H
93 # include <unistd.h>
94 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
95 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
96 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
97 # define POSIX 1
98 # endif
99 #endif
101 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
102 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
103 # undef POSIX
104 #endif
106 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
107 # define POSIX 1
108 #endif
110 #if defined (HAVE_SYS_SIGLIST) && !defined (SYS_SIGLIST_DECLARED)
111 extern char *sys_siglist[];
112 #endif
114 #if !defined (HAVE_SYS_SIGLIST) || !defined (HAVE_STRSIGNAL)
115 # include "signame.h"
116 #endif
118 /* Some systems do not define NSIG in <signal.h>. */
119 #ifndef NSIG
120 # ifdef _NSIG
121 # define NSIG _NSIG
122 # else
123 # define NSIG 32
124 # endif
125 #endif
127 #ifndef RETSIGTYPE
128 # define RETSIGTYPE void
129 #endif
131 #ifndef sigmask
132 # define sigmask(sig) (1 << ((sig) - 1))
133 #endif
135 #ifdef HAVE_LIMITS_H
136 # include <limits.h>
137 #endif
138 #ifdef HAVE_SYS_PARAM_H
139 # include <sys/param.h>
140 #endif
142 #ifndef PATH_MAX
143 # ifndef POSIX
144 # define PATH_MAX MAXPATHLEN
145 # endif
146 #endif
147 #ifndef MAXPATHLEN
148 # define MAXPATHLEN 1024
149 #endif
151 #ifdef PATH_MAX
152 # define GET_PATH_MAX PATH_MAX
153 # define PATH_VAR(var) char var[PATH_MAX]
154 #else
155 # define NEED_GET_PATH_MAX 1
156 # define GET_PATH_MAX (get_path_max ())
157 # define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
158 extern unsigned int get_path_max PARAMS ((void));
159 #endif
161 #ifndef CHAR_BIT
162 # define CHAR_BIT 8
163 #endif
165 /* Nonzero if the integer type T is signed. */
166 #define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
168 /* The minimum and maximum values for the integer type T.
169 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
170 #define INTEGER_TYPE_MINIMUM(t) \
171 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
172 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
174 #ifdef STAT_MACROS_BROKEN
175 # ifdef S_ISREG
176 # undef S_ISREG
177 # endif
178 # ifdef S_ISDIR
179 # undef S_ISDIR
180 # endif
181 #endif /* STAT_MACROS_BROKEN. */
183 #ifndef S_ISREG
184 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
185 #endif
186 #ifndef S_ISDIR
187 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
188 #endif
190 #ifdef VMS
191 # include <stdio.h>
192 # include <types.h>
193 # include <unixlib.h>
194 # include <unixio.h>
195 # include <errno.h>
196 # include <perror.h>
197 #endif
199 #ifndef __attribute__
200 /* This feature is available in gcc versions 2.5 and later. */
201 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
202 # define __attribute__(x)
203 # endif
204 /* The __-protected variants of `format' and `printf' attributes
205 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
206 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
207 # define __format__ format
208 # define __printf__ printf
209 # endif
210 #endif
212 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
213 # include <stdlib.h>
214 # include <string.h>
215 # define ANSI_STRING 1
216 #else /* No standard headers. */
217 # ifdef HAVE_STRING_H
218 # include <string.h>
219 # define ANSI_STRING 1
220 # else
221 # include <strings.h>
222 # endif
223 # ifdef HAVE_MEMORY_H
224 # include <memory.h>
225 # endif
226 # ifdef HAVE_STDLIB_H
227 # include <stdlib.h>
228 # else
229 extern char *malloc PARAMS ((int));
230 extern char *realloc PARAMS ((char *, int));
231 extern void free PARAMS ((char *));
233 extern void abort PARAMS ((void)) __attribute__ ((noreturn));
234 extern void exit PARAMS ((int)) __attribute__ ((noreturn));
235 # endif /* HAVE_STDLIB_H. */
237 #endif /* Standard headers. */
239 #if ST_MTIM_NSEC
240 # if HAVE_INTTYPES_H
241 # include <inttypes.h>
242 # endif
243 # define FILE_TIMESTAMP uintmax_t
244 #else
245 # define FILE_TIMESTAMP time_t
246 #endif
248 #ifdef ANSI_STRING
250 # ifndef index
251 # define index(s, c) strchr((s), (c))
252 # endif
253 # ifndef rindex
254 # define rindex(s, c) strrchr((s), (c))
255 # endif
257 # ifndef bcmp
258 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
259 # endif
260 # ifndef bzero
261 # define bzero(s, n) memset ((s), 0, (n))
262 # endif
263 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
264 # define bcopy(s, d, n) memmove ((d), (s), (n))
265 # endif
267 #else /* Not ANSI_STRING. */
269 # ifndef bcmp
270 extern int bcmp PARAMS ((const char *, const char *, int));
271 # endif
272 # ifndef bzero
273 extern void bzero PARAMS ((char *, int));
274 #endif
275 # ifndef bcopy
276 extern void bcopy PARAMS ((const char *b1, char *b2, int));
277 # endif
279 #endif /* ANSI_STRING. */
280 #undef ANSI_STRING
282 /* SCO Xenix has a buggy macro definition in <string.h>. */
283 #undef strerror
285 #if !defined(ANSI_STRING) && !defined(__DECC)
286 extern char *strerror PARAMS ((int errnum));
287 #endif
289 #ifdef __GNUC__
290 # undef alloca
291 # define alloca(n) __builtin_alloca (n)
292 #else /* Not GCC. */
293 # ifdef HAVE_ALLOCA_H
294 # include <alloca.h>
295 # else /* Not HAVE_ALLOCA_H. */
296 # ifndef _AIX
297 extern char *alloca ();
298 # endif /* Not AIX. */
299 # endif /* HAVE_ALLOCA_H. */
300 #endif /* GCC. */
302 #ifndef iAPX286
303 # define streq(a, b) \
304 ((a) == (b) || \
305 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
306 # ifdef HAVE_CASE_INSENSITIVE_FS
307 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
308 # define strieq(a, b) \
309 ((a) == (b) || \
310 (tolower(*(a)) == tolower(*(b)) && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
311 # else
312 # define strieq(a, b) streq(a, b)
313 # endif
314 #else
315 /* Buggy compiler can't handle this. */
316 # define streq(a, b) (strcmp ((a), (b)) == 0)
317 # define strieq(a, b) (strcmp ((a), (b)) == 0)
318 #endif
319 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
321 /* Add to VAR the hashing value of C, one character in a name. */
322 #define HASH(var, c) \
323 ((var += (c)), (var = ((var) << 7) + ((var) >> 20)))
324 #ifdef HAVE_CASE_INSENSITIVE_FS /* Fold filenames */
325 # define HASHI(var, c) \
326 ((var += tolower((c))), (var = ((var) << 7) + ((var) >> 20)))
327 #else
328 # define HASHI(var, c) HASH(var,c)
329 #endif
331 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
332 # define ENUM_BITFIELD(bits) :bits
333 #else
334 # define ENUM_BITFIELD(bits)
335 #endif
337 #if defined(__MSDOS__) || defined(WINDOWS32)
338 # define PATH_SEPARATOR_CHAR ';'
339 #else
340 # if defined(VMS)
341 # define PATH_SEPARATOR_CHAR ','
342 # else
343 # define PATH_SEPARATOR_CHAR ':'
344 # endif
345 #endif
347 #ifdef WINDOWS32
348 # include <fcntl.h>
349 # include <malloc.h>
350 # define pipe(p) _pipe(p, 512, O_BINARY)
351 # define kill(pid,sig) w32_kill(pid,sig)
353 extern void sync_Path_environment(void);
354 extern int kill(int pid, int sig);
355 extern int safe_stat(char *file, struct stat *sb);
356 extern char *end_of_token_w32(char *s, char stopchar);
357 extern int find_and_set_default_shell(char *token);
359 /* indicates whether or not we have Bourne shell */
360 extern int no_default_sh_exe;
362 /* is default_shell unixy? */
363 extern int unixy_shell;
364 #endif /* WINDOWS32 */
366 struct floc
368 char *filenm;
369 unsigned long lineno;
371 #define NILF ((struct floc *)0)
374 /* Fancy processing for variadic functions in both ANSI and pre-ANSI
375 compilers. */
376 #if defined __STDC__ && __STDC__
377 extern void message (int prefix, const char *fmt, ...)
378 __attribute__ ((__format__ (__printf__, 2, 3)));
379 extern void error (const struct floc *flocp, const char *fmt, ...)
380 __attribute__ ((__format__ (__printf__, 2, 3)));
381 extern void fatal (const struct floc *flocp, const char *fmt, ...)
382 __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
383 #else
384 extern void message ();
385 extern void error ();
386 extern void fatal ();
387 #endif
389 extern void die PARAMS ((int)) __attribute__ ((noreturn));
390 extern void log_working_directory PARAMS ((int));
391 extern void pfatal_with_name PARAMS ((char *)) __attribute__ ((noreturn));
392 extern void perror_with_name PARAMS ((char *, char *));
393 extern char *savestring PARAMS ((const char *, unsigned int));
394 extern char *concat PARAMS ((char *, char *, char *));
395 extern char *xmalloc PARAMS ((unsigned int));
396 extern char *xrealloc PARAMS ((char *, unsigned int));
397 extern char *xstrdup PARAMS ((const char *));
398 extern char *find_next_token PARAMS ((char **, unsigned int *));
399 extern char *next_token PARAMS ((char *));
400 extern char *end_of_token PARAMS ((char *));
401 extern void collapse_continuations PARAMS ((char *));
402 extern void remove_comments PARAMS((char *));
403 extern char *sindex PARAMS ((const char *, unsigned int, \
404 const char *, unsigned int));
405 extern char *lindex PARAMS ((const char *, const char *, int));
406 extern int alpha_compare PARAMS ((const void *, const void *));
407 extern void print_spaces PARAMS ((unsigned int));
408 extern char *find_char_unquote PARAMS ((char *, char *, int));
409 extern char *find_percent PARAMS ((char *));
411 #ifndef NO_ARCHIVES
412 extern int ar_name PARAMS ((char *));
413 extern void ar_parse_name PARAMS ((char *, char **, char **));
414 extern int ar_touch PARAMS ((char *));
415 extern time_t ar_member_date PARAMS ((char *));
416 #endif
418 extern int dir_file_exists_p PARAMS ((char *, char *));
419 extern int file_exists_p PARAMS ((char *));
420 extern int file_impossible_p PARAMS ((char *));
421 extern void file_impossible PARAMS ((char *));
422 extern char *dir_name PARAMS ((char *));
424 extern void define_default_variables PARAMS ((void));
425 extern void set_default_suffixes PARAMS ((void));
426 extern void install_default_suffix_rules PARAMS ((void));
427 extern void install_default_implicit_rules PARAMS ((void));
429 extern void build_vpath_lists PARAMS ((void));
430 extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath));
431 extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr));
432 extern int gpath_search PARAMS ((char *file, int len));
434 extern void construct_include_path PARAMS ((char **arg_dirs));
436 extern void user_access PARAMS ((void));
437 extern void make_access PARAMS ((void));
438 extern void child_access PARAMS ((void));
440 #ifdef HAVE_VFORK_H
441 # include <vfork.h>
442 #endif
444 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
445 because such systems often declare them in header files anyway. */
447 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
449 extern long int atol ();
450 # ifndef VMS
451 extern long int lseek ();
452 # endif
454 #endif /* Not GNU C library or POSIX. */
456 #ifdef HAVE_GETCWD
457 extern char *getcwd ();
458 # ifdef VMS
459 extern char *getwd PARAMS ((char *));
460 # endif
461 #else
462 extern char *getwd ();
463 # define getcwd(buf, len) getwd (buf)
464 #endif
466 extern const struct floc *reading_file;
468 extern char **environ;
470 extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
471 extern int debug_flag, print_data_base_flag, question_flag, touch_flag;
472 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
473 extern int print_version_flag, print_directory_flag;
474 extern int warn_undefined_variables_flag, posix_pedantic;
475 extern int clock_skew_detected;
477 /* can we run commands via 'sh -c xxx' or must we use batch files? */
478 extern int batch_mode_shell;
480 extern unsigned int job_slots;
481 extern int job_fds[2];
482 #ifndef NO_FLOAT
483 extern double max_load_average;
484 #else
485 extern int max_load_average;
486 #endif
488 extern char *program;
489 extern char *starting_directory;
490 extern unsigned int makelevel;
491 extern char *version_string, *remote_description;
493 extern unsigned int commands_started;
495 extern int handling_fatal_signal;
498 #ifndef MIN
499 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
500 #endif
501 #ifndef MAX
502 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
503 #endif
505 #define DEBUGPR(msg) \
506 do if (debug_flag) { print_spaces (depth); printf (msg, file->name); \
507 fflush (stdout); } while (0)
509 #ifdef VMS
510 # ifndef EXIT_FAILURE
511 # define EXIT_FAILURE 3
512 # endif
513 # ifndef EXIT_SUCCESS
514 # define EXIT_SUCCESS 1
515 # endif
516 # ifndef EXIT_TROUBLE
517 # define EXIT_TROUBLE 2
518 # endif
519 #else
520 # ifndef EXIT_FAILURE
521 # define EXIT_FAILURE 2
522 # endif
523 # ifndef EXIT_SUCCESS
524 # define EXIT_SUCCESS 0
525 # endif
526 # ifndef EXIT_TROUBLE
527 # define EXIT_TROUBLE 1
528 # endif
529 #endif
531 /* Set up heap debugging library dmalloc. */
533 #ifdef HAVE_DMALLOC_H
534 #include <dmalloc.h>
535 #endif