Update copyright info.
[make/kirr.git] / make.h
blob6ce11d14e9a01bf4a7cae33a80123ac439fcb45a
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. */
42 /* Specify we want GNU source code. This must be defined before any
43 system headers are included. */
45 #define _GNU_SOURCE 1
47 /* Include libintl.h, if it was found: we don't even look for it unless we
48 want to use the system's gettext(). If not, use the included gettext.h. */
50 #ifdef HAVE_LIBINTL_H
51 # include <libintl.h>
52 # ifdef HAVE_LOCALE_H
53 # include <locale.h>
54 # endif
55 #else
56 # include "gettext.h"
57 #endif
59 #ifndef gettext_noop
60 /* For automatic extraction of messages sometimes no real translation is
61 needed. Instead the string itself is the result. */
62 # define gettext_noop(Str) (Str)
63 #endif
65 #define _(Text) gettext (Text)
66 #define N_(Text) gettext_noop (Text)
69 #if !HAVE_SETLOCALE
70 # define setlocale(Category, Locale) /* empty */
71 #endif
74 #ifdef CRAY
75 /* This must happen before #include <signal.h> so
76 that the declaration therein is changed. */
77 # define signal bsdsignal
78 #endif
80 /* If we're compiling for the dmalloc debugger, turn off string inlining. */
81 #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
82 # define __NO_STRING_INLINES
83 #endif
85 #include <sys/types.h>
86 #include <sys/stat.h>
87 #include <signal.h>
88 #include <stdio.h>
89 #include <ctype.h>
90 #ifdef HAVE_SYS_TIMEB_H
91 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
92 unless <sys/timeb.h> has been included first. Does every system have a
93 <sys/timeb.h>? If any does not, configure should check for it. */
94 # include <sys/timeb.h>
95 #endif
97 #if TIME_WITH_SYS_TIME
98 # include <sys/time.h>
99 # include <time.h>
100 #else
101 # if HAVE_SYS_TIME_H
102 # include <sys/time.h>
103 # else
104 # include <time.h>
105 # endif
106 #endif
108 #include <errno.h>
110 #ifndef errno
111 extern int errno;
112 #endif
114 #ifndef isblank
115 # define isblank(c) ((c) == ' ' || (c) == '\t')
116 #endif
118 #ifdef HAVE_UNISTD_H
119 # include <unistd.h>
120 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
121 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
122 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
123 # define POSIX 1
124 # endif
125 #endif
127 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
128 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
129 # undef POSIX
130 #endif
132 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
133 # define POSIX 1
134 #endif
136 #ifndef RETSIGTYPE
137 # define RETSIGTYPE void
138 #endif
140 #ifndef sigmask
141 # define sigmask(sig) (1 << ((sig) - 1))
142 #endif
144 #ifndef HAVE_SA_RESTART
145 # define SA_RESTART 0
146 #endif
148 #ifdef HAVE_LIMITS_H
149 # include <limits.h>
150 #endif
151 #ifdef HAVE_SYS_PARAM_H
152 # include <sys/param.h>
153 #endif
155 #ifndef PATH_MAX
156 # ifndef POSIX
157 # define PATH_MAX MAXPATHLEN
158 # endif
159 #endif
160 #ifndef MAXPATHLEN
161 # define MAXPATHLEN 1024
162 #endif
164 #ifdef PATH_MAX
165 # define GET_PATH_MAX PATH_MAX
166 # define PATH_VAR(var) char var[PATH_MAX]
167 #else
168 # define NEED_GET_PATH_MAX 1
169 # define GET_PATH_MAX (get_path_max ())
170 # define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
171 extern unsigned int get_path_max PARAMS ((void));
172 #endif
174 #ifndef CHAR_BIT
175 # define CHAR_BIT 8
176 #endif
178 /* Nonzero if the integer type T is signed. */
179 #define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
181 /* The minimum and maximum values for the integer type T.
182 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
183 #define INTEGER_TYPE_MINIMUM(t) \
184 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
185 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
187 #ifndef CHAR_MAX
188 # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
189 #endif
191 #ifdef STAT_MACROS_BROKEN
192 # ifdef S_ISREG
193 # undef S_ISREG
194 # endif
195 # ifdef S_ISDIR
196 # undef S_ISDIR
197 # endif
198 #endif /* STAT_MACROS_BROKEN. */
200 #ifndef S_ISREG
201 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
202 #endif
203 #ifndef S_ISDIR
204 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
205 #endif
207 #ifdef VMS
208 # include <types.h>
209 # include <unixlib.h>
210 # include <unixio.h>
211 # include <perror.h>
212 #endif
214 #ifndef __attribute__
215 /* This feature is available in gcc versions 2.5 and later. */
216 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
217 # define __attribute__(x)
218 # endif
219 /* The __-protected variants of `format' and `printf' attributes
220 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
221 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
222 # define __format__ format
223 # define __printf__ printf
224 # endif
225 #endif
227 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
228 # include <stdlib.h>
229 # include <string.h>
230 # define ANSI_STRING 1
231 #else /* No standard headers. */
232 # ifdef HAVE_STRING_H
233 # include <string.h>
234 # define ANSI_STRING 1
235 # else
236 # include <strings.h>
237 # endif
238 # ifdef HAVE_MEMORY_H
239 # include <memory.h>
240 # endif
241 # ifdef HAVE_STDLIB_H
242 # include <stdlib.h>
243 # else
244 extern char *malloc PARAMS ((int));
245 extern char *realloc PARAMS ((char *, int));
246 extern void free PARAMS ((char *));
248 extern void abort PARAMS ((void)) __attribute__ ((noreturn));
249 extern void exit PARAMS ((int)) __attribute__ ((noreturn));
250 # endif /* HAVE_STDLIB_H. */
252 #endif /* Standard headers. */
254 #ifdef ANSI_STRING
256 # ifndef bcmp
257 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
258 # endif
259 # ifndef bzero
260 # define bzero(s, n) memset ((s), 0, (n))
261 # endif
262 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
263 # define bcopy(s, d, n) memmove ((d), (s), (n))
264 # endif
266 #else /* Not ANSI_STRING. */
268 # ifndef HAVE_STRCHR
269 # define strchr(s, c) index((s), (c))
270 # define strrchr(s, c) rindex((s), (c))
271 # endif
273 # ifndef bcmp
274 extern int bcmp PARAMS ((const char *, const char *, int));
275 # endif
276 # ifndef bzero
277 extern void bzero PARAMS ((char *, int));
278 #endif
279 # ifndef bcopy
280 extern void bcopy PARAMS ((const char *b1, char *b2, int));
281 # endif
283 #endif /* ANSI_STRING. */
284 #undef ANSI_STRING
286 /* SCO Xenix has a buggy macro definition in <string.h>. */
287 #undef strerror
289 #if !defined(ANSI_STRING) && !defined(__DECC)
290 extern char *strerror PARAMS ((int errnum));
291 #endif
293 #ifdef __GNUC__
294 # undef alloca
295 # define alloca(n) __builtin_alloca (n)
296 #else /* Not GCC. */
297 # ifdef HAVE_ALLOCA_H
298 # include <alloca.h>
299 # else /* Not HAVE_ALLOCA_H. */
300 # ifndef _AIX
301 extern char *alloca ();
302 # endif /* Not AIX. */
303 # endif /* HAVE_ALLOCA_H. */
304 #endif /* GCC. */
306 #if HAVE_INTTYPES_H
307 # include <inttypes.h>
308 #endif
309 #define FILE_TIMESTAMP uintmax_t
311 /* ISDIGIT offers the following features:
312 - Its arg may be any int or unsigned int; it need not be an unsigned char.
313 - It's guaranteed to evaluate its argument exactly once.
314 NOTE! Make relies on this behavior, don't change it!
315 - It's typically faster.
316 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
317 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
318 it's important to use the locale's definition of `digit' even when the
319 host does not conform to Posix. */
320 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
322 #ifndef iAPX286
323 # define streq(a, b) \
324 ((a) == (b) || \
325 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
326 # ifdef HAVE_CASE_INSENSITIVE_FS
327 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
328 # define strieq(a, b) \
329 ((a) == (b) \
330 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
331 && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
332 # else
333 # define strieq(a, b) streq(a, b)
334 # endif
335 #else
336 /* Buggy compiler can't handle this. */
337 # define streq(a, b) (strcmp ((a), (b)) == 0)
338 # define strieq(a, b) (strcmp ((a), (b)) == 0)
339 #endif
340 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
341 #ifdef VMS
342 extern int strcmpi (const char *,const char *);
343 #endif
345 /* Add to VAR the hashing value of C, one character in a name. */
346 #define HASH(var, c) \
347 ((var += (c)), (var = ((var) << 7) + ((var) >> 20)))
348 #ifdef HAVE_CASE_INSENSITIVE_FS /* Fold filenames */
349 # define HASHI(var, c) \
350 ((var += tolower((unsigned char)(c))), (var = ((var) << 7) + ((var) >> 20)))
351 #else
352 # define HASHI(var, c) HASH(var,c)
353 #endif
355 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
356 # define ENUM_BITFIELD(bits) :bits
357 #else
358 # define ENUM_BITFIELD(bits)
359 #endif
361 #if defined(__MSDOS__) || defined(WINDOWS32)
362 # define PATH_SEPARATOR_CHAR ';'
363 #else
364 # if defined(VMS)
365 # define PATH_SEPARATOR_CHAR ','
366 # else
367 # define PATH_SEPARATOR_CHAR ':'
368 # endif
369 #endif
371 #ifdef WINDOWS32
372 # include <fcntl.h>
373 # include <malloc.h>
374 # define pipe(p) _pipe(p, 512, O_BINARY)
375 # define kill(pid,sig) w32_kill(pid,sig)
377 extern void sync_Path_environment(void);
378 extern int kill(int pid, int sig);
379 extern int safe_stat(char *file, struct stat *sb);
380 extern char *end_of_token_w32(char *s, char stopchar);
381 extern int find_and_set_default_shell(char *token);
383 /* indicates whether or not we have Bourne shell */
384 extern int no_default_sh_exe;
386 /* is default_shell unixy? */
387 extern int unixy_shell;
388 #endif /* WINDOWS32 */
390 struct floc
392 char *filenm;
393 unsigned long lineno;
395 #define NILF ((struct floc *)0)
398 /* Fancy processing for variadic functions in both ANSI and pre-ANSI
399 compilers. */
400 #if defined __STDC__ && __STDC__
401 extern void message (int prefix, const char *fmt, ...)
402 __attribute__ ((__format__ (__printf__, 2, 3)));
403 extern void error (const struct floc *flocp, const char *fmt, ...)
404 __attribute__ ((__format__ (__printf__, 2, 3)));
405 extern void fatal (const struct floc *flocp, const char *fmt, ...)
406 __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
407 #else
408 extern void message ();
409 extern void error ();
410 extern void fatal ();
411 #endif
413 extern void die PARAMS ((int)) __attribute__ ((noreturn));
414 extern void log_working_directory PARAMS ((int));
415 extern void pfatal_with_name PARAMS ((char *)) __attribute__ ((noreturn));
416 extern void perror_with_name PARAMS ((char *, char *));
417 extern char *savestring PARAMS ((const char *, unsigned int));
418 extern char *concat PARAMS ((char *, char *, char *));
419 extern char *xmalloc PARAMS ((unsigned int));
420 extern char *xrealloc PARAMS ((char *, unsigned int));
421 extern char *xstrdup PARAMS ((const char *));
422 extern char *find_next_token PARAMS ((char **, unsigned int *));
423 extern char *next_token PARAMS ((char *));
424 extern char *end_of_token PARAMS ((char *));
425 extern void collapse_continuations PARAMS ((char *));
426 extern void remove_comments PARAMS((char *));
427 extern char *sindex PARAMS ((const char *, unsigned int, \
428 const char *, unsigned int));
429 extern char *lindex PARAMS ((const char *, const char *, int));
430 extern int alpha_compare PARAMS ((const void *, const void *));
431 extern void print_spaces PARAMS ((unsigned int));
432 extern char *find_char_unquote PARAMS ((char *, char *, int));
433 extern char *find_percent PARAMS ((char *));
434 extern FILE *open_tmpfile PARAMS ((char **, const char *));
436 #ifndef NO_ARCHIVES
437 extern int ar_name PARAMS ((char *));
438 extern void ar_parse_name PARAMS ((char *, char **, char **));
439 extern int ar_touch PARAMS ((char *));
440 extern time_t ar_member_date PARAMS ((char *));
441 #endif
443 extern int dir_file_exists_p PARAMS ((char *, char *));
444 extern int file_exists_p PARAMS ((char *));
445 extern int file_impossible_p PARAMS ((char *));
446 extern void file_impossible PARAMS ((char *));
447 extern char *dir_name PARAMS ((char *));
449 extern void define_default_variables PARAMS ((void));
450 extern void set_default_suffixes PARAMS ((void));
451 extern void install_default_suffix_rules PARAMS ((void));
452 extern void install_default_implicit_rules PARAMS ((void));
454 extern void build_vpath_lists PARAMS ((void));
455 extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath));
456 extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr));
457 extern int gpath_search PARAMS ((char *file, int len));
459 extern void construct_include_path PARAMS ((char **arg_dirs));
461 extern void user_access PARAMS ((void));
462 extern void make_access PARAMS ((void));
463 extern void child_access PARAMS ((void));
465 #ifdef HAVE_VFORK_H
466 # include <vfork.h>
467 #endif
469 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
470 because such systems often declare them in header files anyway. */
472 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
474 extern long int atol ();
475 # ifndef VMS
476 extern long int lseek ();
477 # endif
479 #endif /* Not GNU C library or POSIX. */
481 #ifdef HAVE_GETCWD
482 # if !defined(VMS) && !defined(__DECC)
483 extern char *getcwd ();
484 #endif
485 #else
486 extern char *getwd ();
487 # define getcwd(buf, len) getwd (buf)
488 #endif
490 extern const struct floc *reading_file;
492 extern char **environ;
494 extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
495 extern int print_data_base_flag, question_flag, touch_flag;
496 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
497 extern int print_version_flag, print_directory_flag;
498 extern int warn_undefined_variables_flag, posix_pedantic, not_parallel;
499 extern int clock_skew_detected;
501 /* can we run commands via 'sh -c xxx' or must we use batch files? */
502 extern int batch_mode_shell;
504 extern unsigned int job_slots;
505 extern int job_fds[2];
506 extern int job_rfd;
507 #ifndef NO_FLOAT
508 extern double max_load_average;
509 #else
510 extern int max_load_average;
511 #endif
513 extern char *program;
514 extern char *starting_directory;
515 extern unsigned int makelevel;
516 extern char *version_string, *remote_description;
518 extern unsigned int commands_started;
520 extern int handling_fatal_signal;
523 #ifndef MIN
524 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
525 #endif
526 #ifndef MAX
527 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
528 #endif
530 #ifdef VMS
531 # define MAKE_SUCCESS 1
532 # define MAKE_TROUBLE 2
533 # define MAKE_FAILURE 3
534 #else
535 # define MAKE_SUCCESS 0
536 # define MAKE_TROUBLE 1
537 # define MAKE_FAILURE 2
538 #endif
540 /* Set up heap debugging library dmalloc. */
542 #ifdef HAVE_DMALLOC_H
543 #include <dmalloc.h>
544 #endif