1 /* Miscellaneous global declarations and portability cruft for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999,
3 2002 Free Software Foundation, Inc.
4 This file is part of GNU Make.
6 GNU Make is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Make is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Make; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* We use <config.h> instead of "config.h" so that a compilation
22 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
23 (which it would do because make.h was found in $srcdir). */
26 #define HAVE_CONFIG_H 1
28 /* AIX requires this to be the first thing in the file. */
36 # ifndef alloca /* predefined by HP cc +Olibcalls */
44 /* Use prototypes if available. */
45 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
47 # define PARAMS(protos) protos
48 #else /* Not C++ or ANSI C. */
50 # define PARAMS(protos) ()
51 #endif /* C++ or ANSI C. */
53 /* Specify we want GNU source code. This must be defined before any
54 system headers are included. */
60 /* This must happen before #include <signal.h> so
61 that the declaration therein is changed. */
62 # define signal bsdsignal
65 /* If we're compiling for the dmalloc debugger, turn off string inlining. */
66 #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
67 # define __NO_STRING_INLINES
70 #include <sys/types.h>
75 #ifdef HAVE_SYS_TIMEB_H
76 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
77 unless <sys/timeb.h> has been included first. Does every system have a
78 <sys/timeb.h>? If any does not, configure should check for it. */
79 # include <sys/timeb.h>
82 #if TIME_WITH_SYS_TIME
83 # include <sys/time.h>
87 # include <sys/time.h>
100 # define isblank(c) ((c) == ' ' || (c) == '\t')
105 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
106 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
107 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
112 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
113 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
117 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
122 # define RETSIGTYPE void
126 # define sigmask(sig) (1 << ((sig) - 1))
129 #ifndef HAVE_SA_RESTART
130 # define SA_RESTART 0
136 #ifdef HAVE_SYS_PARAM_H
137 # include <sys/param.h>
142 # define PATH_MAX MAXPATHLEN
146 # define MAXPATHLEN 1024
150 # define GET_PATH_MAX PATH_MAX
151 # define PATH_VAR(var) char var[PATH_MAX]
153 # define NEED_GET_PATH_MAX 1
154 # define GET_PATH_MAX (get_path_max ())
155 # define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
156 extern unsigned int get_path_max
PARAMS ((void));
163 /* Nonzero if the integer type T is signed. */
164 #define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
166 /* The minimum and maximum values for the integer type T.
167 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
168 #define INTEGER_TYPE_MINIMUM(t) \
169 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
170 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
173 # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
176 #ifdef STAT_MACROS_BROKEN
183 #endif /* STAT_MACROS_BROKEN. */
186 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
189 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
194 # include <unixlib.h>
197 /* Needed to use alloca on VMS. */
198 # include <builtins.h>
201 #ifndef __attribute__
202 /* This feature is available in gcc versions 2.5 and later. */
203 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
204 # define __attribute__(x)
206 /* The __-protected variants of `format' and `printf' attributes
207 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
208 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
209 # define __format__ format
210 # define __printf__ printf
213 #define UNUSED __attribute__ ((unused))
215 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
218 # define ANSI_STRING 1
219 #else /* No standard headers. */
220 # ifdef HAVE_STRING_H
222 # define ANSI_STRING 1
224 # include <strings.h>
226 # ifdef HAVE_MEMORY_H
229 # ifdef HAVE_STDLIB_H
232 extern char *malloc
PARAMS ((int));
233 extern char *realloc
PARAMS ((char *, int));
234 extern void free
PARAMS ((char *));
236 extern void abort
PARAMS ((void)) __attribute__ ((noreturn
));
237 extern void exit
PARAMS ((int)) __attribute__ ((noreturn
));
238 # endif /* HAVE_STDLIB_H. */
240 #endif /* Standard headers. */
242 /* These should be in stdlib.h. Make sure we have them. */
244 # define EXIT_SUCCESS 0
247 # define EXIT_FAILURE 0
253 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
256 # define bzero(s, n) memset ((s), 0, (n))
258 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
259 # define bcopy(s, d, n) memmove ((d), (s), (n))
262 #else /* Not ANSI_STRING. */
265 # define strchr(s, c) index((s), (c))
266 # define strrchr(s, c) rindex((s), (c))
270 extern int bcmp
PARAMS ((const char *, const char *, int));
273 extern void bzero
PARAMS ((char *, int));
276 extern void bcopy
PARAMS ((const char *b1
, char *b2
, int));
279 /* SCO Xenix has a buggy macro definition in <string.h>. */
282 extern char *strerror
PARAMS ((int errnum
));
285 #endif /* !ANSI_STRING. */
289 # include <inttypes.h>
291 #define FILE_TIMESTAMP uintmax_t
293 #if !defined(HAVE_STRSIGNAL)
294 extern char *strsignal
PARAMS ((int signum
));
297 /* ISDIGIT offers the following features:
298 - Its arg may be any int or unsigned int; it need not be an unsigned char.
299 - It's guaranteed to evaluate its argument exactly once.
300 NOTE! Make relies on this behavior, don't change it!
301 - It's typically faster.
302 POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
303 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
304 it's important to use the locale's definition of `digit' even when the
305 host does not conform to POSIX. */
306 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
309 # define streq(a, b) \
311 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
312 # ifdef HAVE_CASE_INSENSITIVE_FS
313 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
314 # define strieq(a, b) \
316 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
317 && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
319 # define strieq(a, b) streq(a, b)
322 /* Buggy compiler can't handle this. */
323 # define streq(a, b) (strcmp ((a), (b)) == 0)
324 # define strieq(a, b) (strcmp ((a), (b)) == 0)
326 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
328 extern int strcmpi (const char *,const char *);
331 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
332 # define ENUM_BITFIELD(bits) :bits
334 # define ENUM_BITFIELD(bits)
337 /* Handle gettext and locales. */
342 # define setlocale(category, locale)
347 #define _(msgid) gettext (msgid)
348 #define N_(msgid) gettext_noop (msgid)
349 #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
351 /* Handle other OSs. */
352 #if defined(HAVE_DOS_PATHS)
353 # define PATH_SEPARATOR_CHAR ';'
355 # define PATH_SEPARATOR_CHAR ','
357 # define PATH_SEPARATOR_CHAR ':'
360 /* This is needed for getcwd() and chdir(). */
361 #if defined(_MSC_VER) || defined(__BORLANDC__)
368 # define pipe(p) _pipe(p, 512, O_BINARY)
369 # define kill(pid,sig) w32_kill(pid,sig)
371 extern void sync_Path_environment(void);
372 extern int kill(int pid
, int sig
);
373 extern char *end_of_token_w32(char *s
, char stopchar
);
374 extern int find_and_set_default_shell(char *token
);
376 /* indicates whether or not we have Bourne shell */
377 extern int no_default_sh_exe
;
379 /* is default_shell unixy? */
380 extern int unixy_shell
;
381 #endif /* WINDOWS32 */
386 unsigned long lineno
;
388 #define NILF ((struct floc *)0)
390 #define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
393 /* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
394 variadic versions of these functions. */
396 #if HAVE_STDARG_H || HAVE_VARARGS_H
397 # if HAVE_VPRINTF || HAVE_DOPRNT
398 # define USE_VARIADIC 1
402 #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
403 extern void message (int prefix
, const char *fmt
, ...)
404 __attribute__ ((__format__ (__printf__
, 2, 3)));
405 extern void error (const struct floc
*flocp
, const char *fmt
, ...)
406 __attribute__ ((__format__ (__printf__
, 2, 3)));
407 extern void fatal (const struct floc
*flocp
, const char *fmt
, ...)
408 __attribute__ ((noreturn
, __format__ (__printf__
, 2, 3)));
410 extern void message ();
411 extern void error ();
412 extern void fatal ();
415 extern void die
PARAMS ((int)) __attribute__ ((noreturn
));
416 extern void log_working_directory
PARAMS ((int));
417 extern void pfatal_with_name
PARAMS ((const char *)) __attribute__ ((noreturn
));
418 extern void perror_with_name
PARAMS ((const char *, const char *));
419 extern char *savestring
PARAMS ((const char *, unsigned int));
420 extern char *concat
PARAMS ((const char *, const char *, const char *));
421 extern char *xmalloc
PARAMS ((unsigned int));
422 extern char *xrealloc
PARAMS ((char *, unsigned int));
423 extern char *xstrdup
PARAMS ((const char *));
424 extern char *find_next_token
PARAMS ((char **, unsigned int *));
425 extern char *next_token
PARAMS ((const char *));
426 extern char *end_of_token
PARAMS ((const char *));
427 extern void collapse_continuations
PARAMS ((char *));
428 extern char *lindex
PARAMS ((const char *, const char *, int));
429 extern int alpha_compare
PARAMS ((const void *, const void *));
430 extern void print_spaces
PARAMS ((unsigned int));
431 extern char *find_percent
PARAMS ((char *));
432 extern FILE *open_tmpfile
PARAMS ((char **, const char *));
435 extern int ar_name
PARAMS ((char *));
436 extern void ar_parse_name
PARAMS ((char *, char **, char **));
437 extern int ar_touch
PARAMS ((char *));
438 extern time_t ar_member_date
PARAMS ((char *));
441 extern int dir_file_exists_p
PARAMS ((char *, char *));
442 extern int file_exists_p
PARAMS ((char *));
443 extern int file_impossible_p
PARAMS ((char *));
444 extern void file_impossible
PARAMS ((char *));
445 extern char *dir_name
PARAMS ((char *));
446 extern void hash_init_directories
PARAMS ((void));
448 extern void define_default_variables
PARAMS ((void));
449 extern void set_default_suffixes
PARAMS ((void));
450 extern void install_default_suffix_rules
PARAMS ((void));
451 extern void install_default_implicit_rules
PARAMS ((void));
453 extern void build_vpath_lists
PARAMS ((void));
454 extern void construct_vpath_list
PARAMS ((char *pattern
, char *dirpath
));
455 extern int vpath_search
PARAMS ((char **file
, FILE_TIMESTAMP
*mtime_ptr
));
456 extern int gpath_search
PARAMS ((char *file
, unsigned int len
));
458 extern void construct_include_path
PARAMS ((char **arg_dirs
));
460 extern void user_access
PARAMS ((void));
461 extern void make_access
PARAMS ((void));
462 extern void child_access
PARAMS ((void));
464 extern void close_stdout
PARAMS ((void));
466 extern char *strip_whitespace
PARAMS ((const char **begpp
, const char **endpp
));
473 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
474 because such systems often declare them in header files anyway. */
476 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
478 extern long int atol ();
480 extern long int lseek ();
483 #endif /* Not GNU C library or POSIX. */
486 # if !defined(VMS) && !defined(__DECC)
487 extern char *getcwd ();
490 extern char *getwd ();
491 # define getcwd(buf, len) getwd (buf)
494 extern const struct floc
*reading_file
;
496 extern char **environ
;
498 extern int just_print_flag
, silent_flag
, ignore_errors_flag
, keep_going_flag
;
499 extern int print_data_base_flag
, question_flag
, touch_flag
, always_make_flag
;
500 extern int env_overrides
, no_builtin_rules_flag
, no_builtin_variables_flag
;
501 extern int print_version_flag
, print_directory_flag
, check_symlink_flag
;
502 extern int warn_undefined_variables_flag
, posix_pedantic
, not_parallel
;
503 extern int clock_skew_detected
, rebuilding_makefiles
;
505 /* can we run commands via 'sh -c xxx' or must we use batch files? */
506 extern int batch_mode_shell
;
508 extern unsigned int job_slots
;
509 extern int job_fds
[2];
512 extern double max_load_average
;
514 extern int max_load_average
;
517 extern char *program
;
518 extern char *starting_directory
;
519 extern unsigned int makelevel
;
520 extern char *version_string
, *remote_description
, *make_host
;
522 extern unsigned int commands_started
;
524 extern int handling_fatal_signal
;
528 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
531 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
535 # define MAKE_SUCCESS 1
536 # define MAKE_TROUBLE 2
537 # define MAKE_FAILURE 3
539 # define MAKE_SUCCESS 0
540 # define MAKE_TROUBLE 1
541 # define MAKE_FAILURE 2
544 /* Set up heap debugging library dmalloc. */
546 #ifdef HAVE_DMALLOC_H
550 #ifndef initialize_main
552 # define initialize_main(pargc, pargv) \
553 { _wildcard(pargc, pargv); _response(pargc, pargv); }
555 # define initialize_main(pargc, pargv)
561 # if !HAVE_STRCASECMP
562 # define strcasecmp stricmp
566 # define chdir _chdir2
569 # define getcwd _getcwd2
572 /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
573 chdir() and getcwd(). This avoids some error messages for the
574 make testsuite but restricts the drive letter support. */
576 # warning NO_CHDIR2: usage of drive letters restricted
582 #ifndef initialize_main
583 # define initialize_main(pargc, pargv)
587 /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
588 properly according to POSIX. So, we try to wrap common system calls with
589 checks for EINTR. Note that there are still plenty of system calls that
590 can fail with EINTR but this, reportedly, gets the vast majority of
591 failure cases. If you still experience failures you'll need to either get
592 a system where SA_RESTART works, or you need to avoid -j. */
594 #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
596 /* While system calls that return integers are pretty consistent about
597 returning -1 on failure and setting errno in that case, functions that
598 return pointers are not always so well behaved. Sometimes they return
599 NULL for expected behavior: one good example is readdir() which returns
600 NULL at the end of the directory--and _doesn't_ reset errno. So, we have
601 to do it ourselves here. */
603 #define ENULLLOOP(_v,_c) do{ errno = 0; \
604 while (((_v)=_c)==0 && errno==EINTR); }while(0)