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