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)
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__)
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). */
30 #define HAVE_CONFIG_H 1
33 /* Use prototypes if available. */
34 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
36 # define PARAMS(protos) protos
37 #else /* Not C++ or ANSI C. */
39 # define PARAMS(protos) ()
40 #endif /* C++ or ANSI C. */
43 /* For now, set gettext macro to a no-op. */
51 /* This must happen before #include <signal.h> so
52 that the declaration therein is changed. */
53 # define signal bsdsignal
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
62 #include <sys/types.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>
80 /* A shortcut for EINTR checking. Note you should be careful when negating
81 this! That might not mean what you want if EINTR is not available. */
83 # define EINTR_SET (errno == EINTR)
85 # define EINTR_SET (0)
89 # define isblank(c) ((c) == ' ' || (c) == '\t')
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)
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)))
106 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
110 #if defined (HAVE_SYS_SIGLIST) && !defined (SYS_SIGLIST_DECLARED)
111 extern char *sys_siglist
[];
114 #if !defined (HAVE_SYS_SIGLIST) || !defined (HAVE_STRSIGNAL)
115 # include "signame.h"
118 /* Some systems do not define NSIG in <signal.h>. */
128 # define RETSIGTYPE void
132 # define sigmask(sig) (1 << ((sig) - 1))
138 #ifdef HAVE_SYS_PARAM_H
139 # include <sys/param.h>
144 # define PATH_MAX MAXPATHLEN
148 # define MAXPATHLEN 1024
152 # define GET_PATH_MAX PATH_MAX
153 # define PATH_VAR(var) char var[PATH_MAX]
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));
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))
175 # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
178 #ifdef STAT_MACROS_BROKEN
185 #endif /* STAT_MACROS_BROKEN. */
188 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
191 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
197 # include <unixlib.h>
203 #ifndef __attribute__
204 /* This feature is available in gcc versions 2.5 and later. */
205 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
206 # define __attribute__(x)
208 /* The __-protected variants of `format' and `printf' attributes
209 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
210 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
211 # define __format__ format
212 # define __printf__ printf
216 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
219 # define ANSI_STRING 1
220 #else /* No standard headers. */
221 # ifdef HAVE_STRING_H
223 # define ANSI_STRING 1
225 # include <strings.h>
227 # ifdef HAVE_MEMORY_H
230 # ifdef HAVE_STDLIB_H
233 extern char *malloc
PARAMS ((int));
234 extern char *realloc
PARAMS ((char *, int));
235 extern void free
PARAMS ((char *));
237 extern void abort
PARAMS ((void)) __attribute__ ((noreturn
));
238 extern void exit
PARAMS ((int)) __attribute__ ((noreturn
));
239 # endif /* HAVE_STDLIB_H. */
241 #endif /* Standard headers. */
246 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
249 # define bzero(s, n) memset ((s), 0, (n))
251 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
252 # define bcopy(s, d, n) memmove ((d), (s), (n))
255 #else /* Not ANSI_STRING. */
258 # define strchr(s, c) index((s), (c))
259 # define strrchr(s, c) rindex((s), (c))
263 extern int bcmp
PARAMS ((const char *, const char *, int));
266 extern void bzero
PARAMS ((char *, int));
269 extern void bcopy
PARAMS ((const char *b1
, char *b2
, int));
272 #endif /* ANSI_STRING. */
275 /* SCO Xenix has a buggy macro definition in <string.h>. */
278 #if !defined(ANSI_STRING) && !defined(__DECC)
279 extern char *strerror
PARAMS ((int errnum
));
284 # define alloca(n) __builtin_alloca (n)
286 # ifdef HAVE_ALLOCA_H
288 # else /* Not HAVE_ALLOCA_H. */
290 extern char *alloca ();
291 # endif /* Not AIX. */
292 # endif /* HAVE_ALLOCA_H. */
297 # include <inttypes.h>
299 # define FILE_TIMESTAMP uintmax_t
301 # define FILE_TIMESTAMP time_t
304 /* ISDIGIT offers the following features:
305 - Its arg may be any int or unsigned int; it need not be an unsigned char.
306 - It's guaranteed to evaluate its argument exactly once.
307 NOTE! Make relies on this behavior, don't change it!
308 - It's typically faster.
309 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
310 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
311 it's important to use the locale's definition of `digit' even when the
312 host does not conform to Posix. */
313 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
316 # define streq(a, b) \
318 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
319 # ifdef HAVE_CASE_INSENSITIVE_FS
320 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
321 # define strieq(a, b) \
323 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
324 && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
326 # define strieq(a, b) streq(a, b)
329 /* Buggy compiler can't handle this. */
330 # define streq(a, b) (strcmp ((a), (b)) == 0)
331 # define strieq(a, b) (strcmp ((a), (b)) == 0)
333 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
335 /* Add to VAR the hashing value of C, one character in a name. */
336 #define HASH(var, c) \
337 ((var += (c)), (var = ((var) << 7) + ((var) >> 20)))
338 #ifdef HAVE_CASE_INSENSITIVE_FS /* Fold filenames */
339 # define HASHI(var, c) \
340 ((var += tolower((unsigned char)(c))), (var = ((var) << 7) + ((var) >> 20)))
342 # define HASHI(var, c) HASH(var,c)
345 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
346 # define ENUM_BITFIELD(bits) :bits
348 # define ENUM_BITFIELD(bits)
351 #if defined(__MSDOS__) || defined(WINDOWS32)
352 # define PATH_SEPARATOR_CHAR ';'
355 # define PATH_SEPARATOR_CHAR ','
357 # define PATH_SEPARATOR_CHAR ':'
364 # define pipe(p) _pipe(p, 512, O_BINARY)
365 # define kill(pid,sig) w32_kill(pid,sig)
367 extern void sync_Path_environment(void);
368 extern int kill(int pid
, int sig
);
369 extern int safe_stat(char *file
, struct stat
*sb
);
370 extern char *end_of_token_w32(char *s
, char stopchar
);
371 extern int find_and_set_default_shell(char *token
);
373 /* indicates whether or not we have Bourne shell */
374 extern int no_default_sh_exe
;
376 /* is default_shell unixy? */
377 extern int unixy_shell
;
378 #endif /* WINDOWS32 */
383 unsigned long lineno
;
385 #define NILF ((struct floc *)0)
388 /* Fancy processing for variadic functions in both ANSI and pre-ANSI
390 #if defined __STDC__ && __STDC__
391 extern void message (int prefix
, const char *fmt
, ...)
392 __attribute__ ((__format__ (__printf__
, 2, 3)));
393 extern void error (const struct floc
*flocp
, const char *fmt
, ...)
394 __attribute__ ((__format__ (__printf__
, 2, 3)));
395 extern void fatal (const struct floc
*flocp
, const char *fmt
, ...)
396 __attribute__ ((noreturn
, __format__ (__printf__
, 2, 3)));
398 extern void message ();
399 extern void error ();
400 extern void fatal ();
403 extern void die
PARAMS ((int)) __attribute__ ((noreturn
));
404 extern void log_working_directory
PARAMS ((int));
405 extern void pfatal_with_name
PARAMS ((char *)) __attribute__ ((noreturn
));
406 extern void perror_with_name
PARAMS ((char *, char *));
407 extern char *savestring
PARAMS ((const char *, unsigned int));
408 extern char *concat
PARAMS ((char *, char *, char *));
409 extern char *xmalloc
PARAMS ((unsigned int));
410 extern char *xrealloc
PARAMS ((char *, unsigned int));
411 extern char *xstrdup
PARAMS ((const char *));
412 extern char *find_next_token
PARAMS ((char **, unsigned int *));
413 extern char *next_token
PARAMS ((char *));
414 extern char *end_of_token
PARAMS ((char *));
415 extern void collapse_continuations
PARAMS ((char *));
416 extern void remove_comments
PARAMS((char *));
417 extern char *sindex
PARAMS ((const char *, unsigned int, \
418 const char *, unsigned int));
419 extern char *lindex
PARAMS ((const char *, const char *, int));
420 extern int alpha_compare
PARAMS ((const void *, const void *));
421 extern void print_spaces
PARAMS ((unsigned int));
422 extern char *find_char_unquote
PARAMS ((char *, char *, int));
423 extern char *find_percent
PARAMS ((char *));
426 extern int ar_name
PARAMS ((char *));
427 extern void ar_parse_name
PARAMS ((char *, char **, char **));
428 extern int ar_touch
PARAMS ((char *));
429 extern time_t ar_member_date
PARAMS ((char *));
432 extern int dir_file_exists_p
PARAMS ((char *, char *));
433 extern int file_exists_p
PARAMS ((char *));
434 extern int file_impossible_p
PARAMS ((char *));
435 extern void file_impossible
PARAMS ((char *));
436 extern char *dir_name
PARAMS ((char *));
438 extern void define_default_variables
PARAMS ((void));
439 extern void set_default_suffixes
PARAMS ((void));
440 extern void install_default_suffix_rules
PARAMS ((void));
441 extern void install_default_implicit_rules
PARAMS ((void));
443 extern void build_vpath_lists
PARAMS ((void));
444 extern void construct_vpath_list
PARAMS ((char *pattern
, char *dirpath
));
445 extern int vpath_search
PARAMS ((char **file
, FILE_TIMESTAMP
*mtime_ptr
));
446 extern int gpath_search
PARAMS ((char *file
, int len
));
448 extern void construct_include_path
PARAMS ((char **arg_dirs
));
450 extern void user_access
PARAMS ((void));
451 extern void make_access
PARAMS ((void));
452 extern void child_access
PARAMS ((void));
458 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
459 because such systems often declare them in header files anyway. */
461 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
463 extern long int atol ();
465 extern long int lseek ();
468 #endif /* Not GNU C library or POSIX. */
471 extern char *getcwd ();
473 extern char *getwd
PARAMS ((char *));
476 extern char *getwd ();
477 # define getcwd(buf, len) getwd (buf)
480 extern const struct floc
*reading_file
;
482 extern char **environ
;
484 extern int just_print_flag
, silent_flag
, ignore_errors_flag
, keep_going_flag
;
485 extern int debug_flag
, print_data_base_flag
, question_flag
, touch_flag
;
486 extern int env_overrides
, no_builtin_rules_flag
, no_builtin_variables_flag
;
487 extern int print_version_flag
, print_directory_flag
;
488 extern int warn_undefined_variables_flag
, posix_pedantic
;
489 extern int clock_skew_detected
;
491 /* can we run commands via 'sh -c xxx' or must we use batch files? */
492 extern int batch_mode_shell
;
494 extern unsigned int job_slots
;
495 extern int job_fds
[2];
498 extern double max_load_average
;
500 extern int max_load_average
;
503 extern char *program
;
504 extern char *starting_directory
;
505 extern unsigned int makelevel
;
506 extern char *version_string
, *remote_description
;
508 extern unsigned int commands_started
;
510 extern int handling_fatal_signal
;
514 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
517 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
520 #define DEBUGPR(msg) \
521 do if (debug_flag) { print_spaces (depth); printf (msg, file->name); \
522 fflush (stdout); } while (0)
525 # ifndef EXIT_FAILURE
526 # define EXIT_FAILURE 3
528 # ifndef EXIT_SUCCESS
529 # define EXIT_SUCCESS 1
531 # ifndef EXIT_TROUBLE
532 # define EXIT_TROUBLE 2
535 # ifndef EXIT_FAILURE
536 # define EXIT_FAILURE 2
538 # ifndef EXIT_SUCCESS
539 # define EXIT_SUCCESS 0
541 # ifndef EXIT_TROUBLE
542 # define EXIT_TROUBLE 1
546 /* Set up heap debugging library dmalloc. */
548 #ifdef HAVE_DMALLOC_H