* Update the manual.
[make.git] / make.h
bloba2f26062a60e385e0e98f3a1d09beee2dcb43fd7
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 #ifdef CRAY
44 /* This must happen before #include <signal.h> so
45 that the declaration therein is changed. */
46 # define signal bsdsignal
47 #endif
49 /* If we're compiling for the dmalloc debugger, turn off string inlining. */
50 #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
51 # define __NO_STRING_INLINES
52 #endif
54 #define _GNU_SOURCE 1
55 #include <sys/types.h>
56 #include <sys/stat.h>
57 #include <signal.h>
58 #include <stdio.h>
59 #include <ctype.h>
60 #ifdef HAVE_SYS_TIMEB_H
61 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
62 unless <sys/timeb.h> has been included first. Does every system have a
63 <sys/timeb.h>? If any does not, configure should check for it. */
64 # include <sys/timeb.h>
65 #endif
66 #include <time.h>
67 #include <errno.h>
69 #ifndef errno
70 extern int errno;
71 #endif
73 #ifndef isblank
74 # define isblank(c) ((c) == ' ' || (c) == '\t')
75 #endif
77 #ifdef HAVE_UNISTD_H
78 # include <unistd.h>
79 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
80 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
81 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
82 # define POSIX 1
83 # endif
84 #endif
86 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
87 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
88 # undef POSIX
89 #endif
91 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
92 # define POSIX 1
93 #endif
95 #if defined (HAVE_SYS_SIGLIST) && !defined (SYS_SIGLIST_DECLARED)
96 extern char *sys_siglist[];
97 #endif
99 #if !defined (HAVE_SYS_SIGLIST) || !defined (HAVE_STRSIGNAL)
100 # include "signame.h"
101 #endif
103 /* Some systems do not define NSIG in <signal.h>. */
104 #ifndef NSIG
105 # ifdef _NSIG
106 # define NSIG _NSIG
107 # else
108 # define NSIG 32
109 # endif
110 #endif
112 #ifndef RETSIGTYPE
113 # define RETSIGTYPE void
114 #endif
116 #ifndef sigmask
117 # define sigmask(sig) (1 << ((sig) - 1))
118 #endif
120 #ifdef HAVE_LIMITS_H
121 # include <limits.h>
122 #endif
123 #ifdef HAVE_SYS_PARAM_H
124 # include <sys/param.h>
125 #endif
127 #ifndef PATH_MAX
128 # ifndef POSIX
129 # define PATH_MAX MAXPATHLEN
130 # endif
131 #endif
132 #ifndef MAXPATHLEN
133 # define MAXPATHLEN 1024
134 #endif
136 #ifdef PATH_MAX
137 # define GET_PATH_MAX PATH_MAX
138 # define PATH_VAR(var) char var[PATH_MAX]
139 #else
140 # define NEED_GET_PATH_MAX 1
141 # define GET_PATH_MAX (get_path_max ())
142 # define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
143 extern unsigned int get_path_max PARAMS ((void));
144 #endif
146 #ifndef CHAR_BIT
147 # define CHAR_BIT 8
148 #endif
150 /* Nonzero if the integer type T is signed. */
151 #define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
153 /* The minimum and maximum values for the integer type T.
154 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
155 #define INTEGER_TYPE_MINIMUM(t) \
156 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
157 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
159 #ifdef STAT_MACROS_BROKEN
160 # ifdef S_ISREG
161 # undef S_ISREG
162 # endif
163 # ifdef S_ISDIR
164 # undef S_ISDIR
165 # endif
166 #endif /* STAT_MACROS_BROKEN. */
168 #ifndef S_ISREG
169 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
170 #endif
171 #ifndef S_ISDIR
172 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
173 #endif
175 #ifdef VMS
176 # include <stdio.h>
177 # include <types.h>
178 # include <unixlib.h>
179 # include <unixio.h>
180 # include <errno.h>
181 # include <perror.h>
182 #endif
184 #ifndef __attribute__
185 /* This feature is available in gcc versions 2.5 and later. */
186 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
187 # define __attribute__(x)
188 # endif
189 /* The __-protected variants of `format' and `printf' attributes
190 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
191 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
192 # define __format__ format
193 # define __printf__ printf
194 # endif
195 #endif
197 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
198 # include <stdlib.h>
199 # include <string.h>
200 # define ANSI_STRING 1
201 #else /* No standard headers. */
202 # ifdef HAVE_STRING_H
203 # include <string.h>
204 # define ANSI_STRING 1
205 # else
206 # include <strings.h>
207 # endif
208 # ifdef HAVE_MEMORY_H
209 # include <memory.h>
210 # endif
211 # ifdef HAVE_STDLIB_H
212 # include <stdlib.h>
213 # else
214 extern char *malloc PARAMS ((int));
215 extern char *realloc PARAMS ((char *, int));
216 extern void free PARAMS ((char *));
218 extern void abort PARAMS ((void)) __attribute__ ((noreturn));
219 extern void exit PARAMS ((int)) __attribute__ ((noreturn));
220 # endif /* HAVE_STDLIB_H. */
222 #endif /* Standard headers. */
224 #if ST_MTIM_NSEC
225 # if HAVE_INTTYPES_H
226 # include <inttypes.h>
227 # endif
228 # define FILE_TIMESTAMP uintmax_t
229 #else
230 # define FILE_TIMESTAMP time_t
231 #endif
233 #ifdef ANSI_STRING
235 # ifndef index
236 # define index(s, c) strchr((s), (c))
237 # endif
238 # ifndef rindex
239 # define rindex(s, c) strrchr((s), (c))
240 # endif
242 # ifndef bcmp
243 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
244 # endif
245 # ifndef bzero
246 # define bzero(s, n) memset ((s), 0, (n))
247 # endif
248 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
249 # define bcopy(s, d, n) memmove ((d), (s), (n))
250 # endif
252 #else /* Not ANSI_STRING. */
254 # ifndef bcmp
255 extern int bcmp PARAMS ((const char *, const char *, int));
256 # endif
257 # ifndef bzero
258 extern void bzero PARAMS ((char *, int));
259 #endif
260 # ifndef bcopy
261 extern void bcopy PARAMS ((const char *b1, char *b2, int));
262 # endif
264 #endif /* ANSI_STRING. */
265 #undef ANSI_STRING
267 /* SCO Xenix has a buggy macro definition in <string.h>. */
268 #undef strerror
270 #if !defined(ANSI_STRING) && !defined(__DECC)
271 extern char *strerror PARAMS ((int errnum));
272 #endif
274 #ifdef __GNUC__
275 # undef alloca
276 # define alloca(n) __builtin_alloca (n)
277 #else /* Not GCC. */
278 # ifdef HAVE_ALLOCA_H
279 # include <alloca.h>
280 # else /* Not HAVE_ALLOCA_H. */
281 # ifndef _AIX
282 extern char *alloca ();
283 # endif /* Not AIX. */
284 # endif /* HAVE_ALLOCA_H. */
285 #endif /* GCC. */
287 #ifndef iAPX286
288 # define streq(a, b) \
289 ((a) == (b) || \
290 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
291 # ifdef HAVE_CASE_INSENSITIVE_FS
292 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
293 # define strieq(a, b) \
294 ((a) == (b) || \
295 (tolower(*(a)) == tolower(*(b)) && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
296 # else
297 # define strieq(a, b) streq(a, b)
298 # endif
299 #else
300 /* Buggy compiler can't handle this. */
301 # define streq(a, b) (strcmp ((a), (b)) == 0)
302 # define strieq(a, b) (strcmp ((a), (b)) == 0)
303 #endif
304 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
306 /* Add to VAR the hashing value of C, one character in a name. */
307 #define HASH(var, c) \
308 ((var += (c)), (var = ((var) << 7) + ((var) >> 20)))
309 #ifdef HAVE_CASE_INSENSITIVE_FS /* Fold filenames */
310 # define HASHI(var, c) \
311 ((var += tolower((c))), (var = ((var) << 7) + ((var) >> 20)))
312 #else
313 # define HASHI(var, c) HASH(var,c)
314 #endif
316 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
317 # define ENUM_BITFIELD(bits) :bits
318 #else
319 # define ENUM_BITFIELD(bits)
320 #endif
322 #if defined(__MSDOS__) || defined(WINDOWS32)
323 # define PATH_SEPARATOR_CHAR ';'
324 #else
325 # if defined(VMS)
326 # define PATH_SEPARATOR_CHAR ','
327 # else
328 # define PATH_SEPARATOR_CHAR ':'
329 # endif
330 #endif
332 #ifdef WINDOWS32
333 # include <fcntl.h>
334 # include <malloc.h>
335 # define pipe(p) _pipe(p, 512, O_BINARY)
336 # define kill(pid,sig) w32_kill(pid,sig)
338 extern void sync_Path_environment(void);
339 extern int kill(int pid, int sig);
340 extern int safe_stat(char *file, struct stat *sb);
341 extern char *end_of_token_w32(char *s, char stopchar);
342 extern int find_and_set_default_shell(char *token);
344 /* indicates whether or not we have Bourne shell */
345 extern int no_default_sh_exe;
347 /* is default_shell unixy? */
348 extern int unixy_shell;
349 #endif /* WINDOWS32 */
351 struct floc
353 char *filenm;
354 unsigned long lineno;
356 #define NILF ((struct floc *)0)
359 /* Fancy processing for variadic functions in both ANSI and pre-ANSI
360 compilers. */
361 #if defined __STDC__ && __STDC__
362 extern void message (int prefix, const char *fmt, ...)
363 __attribute__ ((__format__ (__printf__, 2, 3)));
364 extern void error (const struct floc *flocp, const char *fmt, ...)
365 __attribute__ ((__format__ (__printf__, 2, 3)));
366 extern void fatal (const struct floc *flocp, const char *fmt, ...)
367 __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
368 #else
369 extern void message ();
370 extern void error ();
371 extern void fatal ();
372 #endif
374 extern void die PARAMS ((int)) __attribute__ ((noreturn));
375 extern void log_working_directory PARAMS ((int));
376 extern void pfatal_with_name PARAMS ((char *)) __attribute__ ((noreturn));
377 extern void perror_with_name PARAMS ((char *, char *));
378 extern char *savestring PARAMS ((const char *, unsigned int));
379 extern char *concat PARAMS ((char *, char *, char *));
380 extern char *xmalloc PARAMS ((unsigned int));
381 extern char *xrealloc PARAMS ((char *, unsigned int));
382 extern char *xstrdup PARAMS ((const char *));
383 extern char *find_next_token PARAMS ((char **, unsigned int *));
384 extern char *next_token PARAMS ((char *));
385 extern char *end_of_token PARAMS ((char *));
386 extern void collapse_continuations PARAMS ((char *));
387 extern void remove_comments PARAMS((char *));
388 extern char *sindex PARAMS ((const char *, unsigned int, \
389 const char *, unsigned int));
390 extern char *lindex PARAMS ((const char *, const char *, int));
391 extern int alpha_compare PARAMS ((const void *, const void *));
392 extern void print_spaces PARAMS ((unsigned int));
393 extern char *find_char_unquote PARAMS ((char *, char *, int));
394 extern char *find_percent PARAMS ((char *));
396 #ifndef NO_ARCHIVES
397 extern int ar_name PARAMS ((char *));
398 extern void ar_parse_name PARAMS ((char *, char **, char **));
399 extern int ar_touch PARAMS ((char *));
400 extern time_t ar_member_date PARAMS ((char *));
401 #endif
403 extern int dir_file_exists_p PARAMS ((char *, char *));
404 extern int file_exists_p PARAMS ((char *));
405 extern int file_impossible_p PARAMS ((char *));
406 extern void file_impossible PARAMS ((char *));
407 extern char *dir_name PARAMS ((char *));
409 extern void define_default_variables PARAMS ((void));
410 extern void set_default_suffixes PARAMS ((void));
411 extern void install_default_suffix_rules PARAMS ((void));
412 extern void install_default_implicit_rules PARAMS ((void));
414 extern void build_vpath_lists PARAMS ((void));
415 extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath));
416 extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr));
417 extern int gpath_search PARAMS ((char *file, int len));
419 extern void construct_include_path PARAMS ((char **arg_dirs));
421 extern void user_access PARAMS ((void));
422 extern void make_access PARAMS ((void));
423 extern void child_access PARAMS ((void));
425 #ifdef HAVE_VFORK_H
426 # include <vfork.h>
427 #endif
429 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
430 because such systems often declare them in header files anyway. */
432 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
434 extern long int atol ();
435 # ifndef VMS
436 extern long int lseek ();
437 # endif
439 #endif /* Not GNU C library or POSIX. */
441 #ifdef HAVE_GETCWD
442 extern char *getcwd ();
443 # ifdef VMS
444 extern char *getwd PARAMS ((char *));
445 # endif
446 #else
447 extern char *getwd ();
448 # define getcwd(buf, len) getwd (buf)
449 #endif
451 extern const struct floc *reading_file;
453 extern char **environ;
455 extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
456 extern int debug_flag, print_data_base_flag, question_flag, touch_flag;
457 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
458 extern int print_version_flag, print_directory_flag;
459 extern int warn_undefined_variables_flag, posix_pedantic;
460 extern int clock_skew_detected;
462 /* can we run commands via 'sh -c xxx' or must we use batch files? */
463 extern int batch_mode_shell;
465 extern unsigned int job_slots;
466 extern int job_fds[2];
467 #ifndef NO_FLOAT
468 extern double max_load_average;
469 #else
470 extern int max_load_average;
471 #endif
473 extern char *program;
474 extern char *starting_directory;
475 extern unsigned int makelevel;
476 extern char *version_string, *remote_description;
478 extern unsigned int commands_started;
480 extern int handling_fatal_signal;
483 #ifndef MIN
484 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
485 #endif
486 #ifndef MAX
487 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
488 #endif
490 #define DEBUGPR(msg) \
491 do if (debug_flag) { print_spaces (depth); printf (msg, file->name); \
492 fflush (stdout); } while (0)
494 #ifdef VMS
495 # ifndef EXIT_FAILURE
496 # define EXIT_FAILURE 3
497 # endif
498 # ifndef EXIT_SUCCESS
499 # define EXIT_SUCCESS 1
500 # endif
501 # ifndef EXIT_TROUBLE
502 # define EXIT_TROUBLE 2
503 # endif
504 #else
505 # ifndef EXIT_FAILURE
506 # define EXIT_FAILURE 2
507 # endif
508 # ifndef EXIT_SUCCESS
509 # define EXIT_SUCCESS 0
510 # endif
511 # ifndef EXIT_TROUBLE
512 # define EXIT_TROUBLE 1
513 # endif
514 #endif
516 /* Set up heap debugging library dmalloc. */
518 #ifdef HAVE_DMALLOC_H
519 #include <dmalloc.h>
520 #endif