* New feature: .LIBPATTERNS controls the way -lfoo dependencies are expanded.
[make/kirr.git] / make.h
blob9f5af966c635483d17884e0cf242754ee8a996ce
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
19 /* AIX requires this to be the first thing in the file. */
20 #if defined (_AIX) && !defined (__GNUC__)
21 #pragma alloca
22 #endif
24 /* We use <config.h> instead of "config.h" so that a compilation
25 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
26 (which it would do because make.h was found in $srcdir). */
27 #include <config.h>
28 #undef HAVE_CONFIG_H
29 #define HAVE_CONFIG_H 1
32 /* Use prototypes if available. */
33 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
34 # undef PARAMS
35 # define PARAMS(protos) protos
36 #else /* Not C++ or ANSI C. */
37 # undef PARAMS
38 # define PARAMS(protos) ()
39 #endif /* C++ or ANSI C. */
42 #ifdef CRAY
43 /* This must happen before #include <signal.h> so
44 that the declaration therein is changed. */
45 # define signal bsdsignal
46 #endif
48 #define _GNU_SOURCE 1
49 #include <sys/types.h>
50 #include <sys/stat.h>
51 #include <signal.h>
52 #include <stdio.h>
53 #include <ctype.h>
54 #ifdef HAVE_SYS_TIMEB_H
55 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
56 unless <sys/timeb.h> has been included first. Does every system have a
57 <sys/timeb.h>? If any does not, configure should check for it. */
58 # include <sys/timeb.h>
59 #endif
60 #include <time.h>
61 #include <errno.h>
63 #ifndef errno
64 extern int errno;
65 #endif
67 #ifndef isblank
68 # define isblank(c) ((c) == ' ' || (c) == '\t')
69 #endif
71 #ifdef HAVE_UNISTD_H
72 # include <unistd.h>
73 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
74 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
75 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
76 # define POSIX 1
77 # endif
78 #endif
80 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
81 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
82 # undef POSIX
83 #endif
85 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
86 # define POSIX 1
87 #endif
89 #if defined (HAVE_SYS_SIGLIST) && !defined (SYS_SIGLIST_DECLARED)
90 extern char *sys_siglist[];
91 #endif
93 #if !defined (HAVE_SYS_SIGLIST) || !defined (HAVE_STRSIGNAL)
94 # include "signame.h"
95 #endif
97 /* Some systems do not define NSIG in <signal.h>. */
98 #ifndef NSIG
99 # ifdef _NSIG
100 # define NSIG _NSIG
101 # else
102 # define NSIG 32
103 # endif
104 #endif
106 #ifndef RETSIGTYPE
107 # define RETSIGTYPE void
108 #endif
110 #ifndef sigmask
111 # define sigmask(sig) (1 << ((sig) - 1))
112 #endif
114 #ifdef HAVE_LIMITS_H
115 # include <limits.h>
116 #endif
117 #ifdef HAVE_SYS_PARAM_H
118 # include <sys/param.h>
119 #endif
121 #ifndef PATH_MAX
122 # ifndef POSIX
123 # define PATH_MAX MAXPATHLEN
124 # endif
125 #endif
126 #ifndef MAXPATHLEN
127 # define MAXPATHLEN 1024
128 #endif
130 #ifdef PATH_MAX
131 # define GET_PATH_MAX PATH_MAX
132 # define PATH_VAR(var) char var[PATH_MAX]
133 #else
134 # define NEED_GET_PATH_MAX 1
135 # define GET_PATH_MAX (get_path_max ())
136 # define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
137 extern unsigned int get_path_max PARAMS ((void));
138 #endif
140 #ifndef CHAR_BIT
141 # define CHAR_BIT 8
142 #endif
144 /* Nonzero if the integer type T is signed. */
145 #define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
147 /* The minimum and maximum values for the integer type T.
148 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
149 #define INTEGER_TYPE_MINIMUM(t) \
150 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
151 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
153 #ifdef STAT_MACROS_BROKEN
154 # ifdef S_ISREG
155 # undef S_ISREG
156 # endif
157 # ifdef S_ISDIR
158 # undef S_ISDIR
159 # endif
160 #endif /* STAT_MACROS_BROKEN. */
162 #ifndef S_ISREG
163 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
164 #endif
165 #ifndef S_ISDIR
166 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
167 #endif
169 #ifdef VMS
170 # include <stdio.h>
171 # include <types.h>
172 # include <unixlib.h>
173 # include <unixio.h>
174 # include <errno.h>
175 # include <perror.h>
176 #endif
178 #ifndef __attribute__
179 /* This feature is available in gcc versions 2.5 and later. */
180 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
181 # define __attribute__(x)
182 # endif
183 /* The __-protected variants of `format' and `printf' attributes
184 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
185 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
186 # define __format__ format
187 # define __printf__ printf
188 # endif
189 #endif
191 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
192 # include <stdlib.h>
193 # include <string.h>
194 # define ANSI_STRING 1
195 #else /* No standard headers. */
196 # ifdef HAVE_STRING_H
197 # include <string.h>
198 # define ANSI_STRING 1
199 # else
200 # include <strings.h>
201 # endif
202 # ifdef HAVE_MEMORY_H
203 # include <memory.h>
204 # endif
205 # ifdef HAVE_STDLIB_H
206 # include <stdlib.h>
207 # else
208 extern char *malloc PARAMS ((int));
209 extern char *realloc PARAMS ((char *, int));
210 extern void free PARAMS ((char *));
212 extern void abort PARAMS ((void)) __attribute__ ((noreturn));
213 extern void exit PARAMS ((int)) __attribute__ ((noreturn));
214 # endif /* HAVE_STDLIB_H. */
216 #endif /* Standard headers. */
218 #if ST_MTIM_NSEC
219 # if HAVE_INTTYPES_H
220 # include <inttypes.h>
221 # endif
222 # define FILE_TIMESTAMP uintmax_t
223 #else
224 # define FILE_TIMESTAMP time_t
225 #endif
227 #ifdef ANSI_STRING
229 # ifndef index
230 # define index(s, c) strchr((s), (c))
231 # endif
232 # ifndef rindex
233 # define rindex(s, c) strrchr((s), (c))
234 # endif
236 # ifndef bcmp
237 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
238 # endif
239 # ifndef bzero
240 # define bzero(s, n) memset ((s), 0, (n))
241 # endif
242 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
243 # define bcopy(s, d, n) memmove ((d), (s), (n))
244 # endif
246 #else /* Not ANSI_STRING. */
248 # ifndef bcmp
249 extern int bcmp PARAMS ((const char *, const char *, int));
250 # endif
251 # ifndef bzero
252 extern void bzero PARAMS ((char *, int));
253 #endif
254 # ifndef bcopy
255 extern void bcopy PARAMS ((const char *b1, char *b2, int));
256 # endif
258 #endif /* ANSI_STRING. */
259 #undef ANSI_STRING
261 /* SCO Xenix has a buggy macro definition in <string.h>. */
262 #undef strerror
264 #if !defined(ANSI_STRING) && !defined(__DECC)
265 extern char *strerror PARAMS ((int errnum));
266 #endif
268 #ifdef __GNUC__
269 # undef alloca
270 # define alloca(n) __builtin_alloca (n)
271 #else /* Not GCC. */
272 # ifdef HAVE_ALLOCA_H
273 # include <alloca.h>
274 # else /* Not HAVE_ALLOCA_H. */
275 # ifndef _AIX
276 extern char *alloca ();
277 # endif /* Not AIX. */
278 # endif /* HAVE_ALLOCA_H. */
279 #endif /* GCC. */
281 #ifndef iAPX286
282 # define streq(a, b) \
283 ((a) == (b) || \
284 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
285 # ifdef HAVE_CASE_INSENSITIVE_FS
286 # define strieq(a, b) \
287 ((a) == (b) || \
288 (tolower(*(a)) == tolower(*(b)) && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
289 # else
290 # define strieq(a, b) \
291 ((a) == (b) || \
292 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
293 # endif
294 #else
295 /* Buggy compiler can't handle this. */
296 # define streq(a, b) (strcmp ((a), (b)) == 0)
297 # define strieq(a, b) (strcmp ((a), (b)) == 0)
298 #endif
300 /* Add to VAR the hashing value of C, one character in a name. */
301 #define HASH(var, c) \
302 ((var += (c)), (var = ((var) << 7) + ((var) >> 20)))
303 #ifdef HAVE_CASE_INSENSITIVE_FS /* Fold filenames */
304 # define HASHI(var, c) \
305 ((var += tolower((c))), (var = ((var) << 7) + ((var) >> 20)))
306 #else
307 # define HASHI(var, c) HASH(var,c)
308 #endif
310 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
311 # define ENUM_BITFIELD(bits) :bits
312 #else
313 # define ENUM_BITFIELD(bits)
314 #endif
316 #if defined(__MSDOS__) || defined(WINDOWS32)
317 # define PATH_SEPARATOR_CHAR ';'
318 #else
319 # if defined(VMS)
320 # define PATH_SEPARATOR_CHAR ','
321 # else
322 # define PATH_SEPARATOR_CHAR ':'
323 # endif
324 #endif
326 #ifdef WINDOWS32
327 # include <fcntl.h>
328 # include <malloc.h>
329 # define pipe(p) _pipe(p, 512, O_BINARY)
330 # define kill(pid,sig) w32_kill(pid,sig)
332 extern void sync_Path_environment(void);
333 extern int kill(int pid, int sig);
334 extern int safe_stat(char *file, struct stat *sb);
335 extern char *end_of_token_w32(char *s, char stopchar);
336 extern int find_and_set_default_shell(char *token);
338 /* indicates whether or not we have Bourne shell */
339 extern int no_default_sh_exe;
341 /* is default_shell unixy? */
342 extern int unixy_shell;
343 #endif /* WINDOWS32 */
345 struct floc
347 char *filenm;
348 unsigned long lineno;
350 #define NILF ((struct floc *)0)
353 /* Fancy processing for variadic functions in both ANSI and pre-ANSI
354 compilers. */
355 #if defined __STDC__ && __STDC__
356 extern void message (int prefix, const char *fmt, ...)
357 __attribute__ ((__format__ (__printf__, 2, 3)));
358 extern void error (const struct floc *flocp, const char *fmt, ...)
359 __attribute__ ((__format__ (__printf__, 2, 3)));
360 extern void fatal (const struct floc *flocp, const char *fmt, ...)
361 __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
362 #else
363 extern void message ();
364 extern void error ();
365 extern void fatal ();
366 #endif
368 extern void die PARAMS ((int)) __attribute__ ((noreturn));
369 extern void log_working_directory PARAMS ((int));
370 extern void pfatal_with_name PARAMS ((char *)) __attribute__ ((noreturn));
371 extern void perror_with_name PARAMS ((char *, char *));
372 extern char *savestring PARAMS ((char *, unsigned int));
373 extern char *concat PARAMS ((char *, char *, char *));
374 extern char *xmalloc PARAMS ((unsigned int));
375 extern char *xrealloc PARAMS ((char *, unsigned int));
376 extern char *find_next_token PARAMS ((char **, unsigned int *));
377 extern char *next_token PARAMS ((char *));
378 extern char *end_of_token PARAMS ((char *));
379 extern void collapse_continuations PARAMS ((char *));
380 extern void remove_comments PARAMS((char *));
381 extern char *sindex PARAMS ((char *, unsigned int, char *, unsigned int));
382 extern char *lindex PARAMS ((char *, char *, int));
383 extern int alpha_compare PARAMS ((const void *, const void *));
384 extern void print_spaces PARAMS ((unsigned int));
385 extern char *find_char_unquote PARAMS ((char *, char *, int));
386 extern char *find_percent PARAMS ((char *));
388 #ifndef NO_ARCHIVES
389 extern int ar_name PARAMS ((char *));
390 extern void ar_parse_name PARAMS ((char *, char **, char **));
391 extern int ar_touch PARAMS ((char *));
392 extern time_t ar_member_date PARAMS ((char *));
393 #endif
395 extern int dir_file_exists_p PARAMS ((char *, char *));
396 extern int file_exists_p PARAMS ((char *));
397 extern int file_impossible_p PARAMS ((char *));
398 extern void file_impossible PARAMS ((char *));
399 extern char *dir_name PARAMS ((char *));
401 extern void define_default_variables PARAMS ((void));
402 extern void set_default_suffixes PARAMS ((void));
403 extern void install_default_suffix_rules PARAMS ((void));
404 extern void install_default_implicit_rules PARAMS ((void));
406 extern void build_vpath_lists PARAMS ((void));
407 extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath));
408 extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr));
409 extern int gpath_search PARAMS ((char *file, int len));
411 extern void construct_include_path PARAMS ((char **arg_dirs));
413 extern void user_access PARAMS ((void));
414 extern void make_access PARAMS ((void));
415 extern void child_access PARAMS ((void));
417 #ifdef HAVE_VFORK_H
418 # include <vfork.h>
419 #endif
421 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
422 because such systems often declare them in header files anyway. */
424 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
426 extern long int atol ();
427 # ifndef VMS
428 extern long int lseek ();
429 # endif
431 #endif /* Not GNU C library or POSIX. */
433 #ifdef HAVE_GETCWD
434 extern char *getcwd ();
435 # ifdef VMS
436 extern char *getwd PARAMS ((char *));
437 # endif
438 #else
439 extern char *getwd ();
440 # define getcwd(buf, len) getwd (buf)
441 #endif
443 extern const struct floc *reading_file;
445 extern char **environ;
447 extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
448 extern int debug_flag, print_data_base_flag, question_flag, touch_flag;
449 extern int env_overrides, no_builtin_rules_flag, print_version_flag;
450 extern int print_directory_flag, warn_undefined_variables_flag;
451 extern int posix_pedantic;
452 extern int clock_skew_detected;
454 /* can we run commands via 'sh -c xxx' or must we use batch files? */
455 extern int batch_mode_shell;
457 extern unsigned int job_slots;
458 #ifndef NO_FLOAT
459 extern double max_load_average;
460 #else
461 extern int max_load_average;
462 #endif
464 extern char *program;
465 extern char *starting_directory;
466 extern unsigned int makelevel;
467 extern char *version_string, *remote_description;
469 extern unsigned int commands_started;
471 extern int handling_fatal_signal;
474 #ifndef MIN
475 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
476 #endif
477 #ifndef MAX
478 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
479 #endif
481 #define DEBUGPR(msg) \
482 do if (debug_flag) { print_spaces (depth); printf (msg, file->name); \
483 fflush (stdout); } while (0)
485 #ifdef VMS
486 # ifndef EXIT_FAILURE
487 # define EXIT_FAILURE 3
488 # endif
489 # ifndef EXIT_SUCCESS
490 # define EXIT_SUCCESS 1
491 # endif
492 # ifndef EXIT_TROUBLE
493 # define EXIT_TROUBLE 2
494 # endif
495 #else
496 # ifndef EXIT_FAILURE
497 # define EXIT_FAILURE 2
498 # endif
499 # ifndef EXIT_SUCCESS
500 # define EXIT_SUCCESS 0
501 # endif
502 # ifndef EXIT_TROUBLE
503 # define EXIT_TROUBLE 1
504 # endif
505 #endif