1 /* Miscellaneous global declarations and portability cruft for GNU Make.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
5 This file is part of GNU Make.
7 GNU Make is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 2, or (at your option) any later version.
11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with
16 GNU Make; see the file COPYING. If not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
19 /* We use <config.h> instead of "config.h" so that a compilation
20 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
21 (which it would do because make.h was found in $srcdir). */
24 #define HAVE_CONFIG_H 1
26 /* AIX requires this to be the first thing in the file. */
34 # ifndef alloca /* predefined by HP cc +Olibcalls */
42 /* Use prototypes if available. */
43 #if defined (__cplusplus) || defined (__STDC__)
45 # define PARAMS(protos) protos
46 #else /* Not C++ or ANSI C. */
48 # define PARAMS(protos) ()
49 #endif /* C++ or ANSI C. */
51 /* Specify we want GNU source code. This must be defined before any
52 system headers are included. */
58 /* This must happen before #include <signal.h> so
59 that the declaration therein is changed. */
60 # define signal bsdsignal
63 /* If we're compiling for the dmalloc debugger, turn off string inlining. */
64 #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
65 # define __NO_STRING_INLINES
68 #include <sys/types.h>
73 #ifdef HAVE_SYS_TIMEB_H
74 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
75 unless <sys/timeb.h> has been included first. Does every system have a
76 <sys/timeb.h>? If any does not, configure should check for it. */
77 # include <sys/timeb.h>
80 #if TIME_WITH_SYS_TIME
81 # include <sys/time.h>
85 # include <sys/time.h>
98 # define isblank(c) ((c) == ' ' || (c) == '\t')
103 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
104 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
105 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
110 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
111 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
115 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
120 # define RETSIGTYPE void
124 # define sigmask(sig) (1 << ((sig) - 1))
127 #ifndef HAVE_SA_RESTART
128 # define SA_RESTART 0
134 #ifdef HAVE_SYS_PARAM_H
135 # include <sys/param.h>
140 # define PATH_MAX MAXPATHLEN
144 # define MAXPATHLEN 1024
148 # define GET_PATH_MAX PATH_MAX
149 # define PATH_VAR(var) char var[PATH_MAX]
151 # define NEED_GET_PATH_MAX 1
152 # define GET_PATH_MAX (get_path_max ())
153 # define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
154 extern unsigned int get_path_max
PARAMS ((void));
161 /* Nonzero if the integer type T is signed. */
162 #define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
164 /* The minimum and maximum values for the integer type T.
165 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
166 #define INTEGER_TYPE_MINIMUM(t) \
167 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
168 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
171 # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
174 #ifdef STAT_MACROS_BROKEN
181 #endif /* STAT_MACROS_BROKEN. */
184 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
187 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
192 # include <unixlib.h>
195 /* Needed to use alloca on VMS. */
196 # include <builtins.h>
199 #ifndef __attribute__
200 /* This feature is available in gcc versions 2.5 and later. */
201 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
202 # define __attribute__(x)
204 /* The __-protected variants of `format' and `printf' attributes
205 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
206 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
207 # define __format__ format
208 # define __printf__ printf
211 #define UNUSED __attribute__ ((unused))
213 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
216 # define ANSI_STRING 1
217 #else /* No standard headers. */
218 # ifdef HAVE_STRING_H
220 # define ANSI_STRING 1
222 # include <strings.h>
224 # ifdef HAVE_MEMORY_H
227 # ifdef HAVE_STDLIB_H
230 extern char *malloc
PARAMS ((int));
231 extern char *realloc
PARAMS ((char *, int));
232 extern void free
PARAMS ((char *));
234 extern void abort
PARAMS ((void)) __attribute__ ((noreturn
));
235 extern void exit
PARAMS ((int)) __attribute__ ((noreturn
));
236 # endif /* HAVE_STDLIB_H. */
238 #endif /* Standard headers. */
240 /* These should be in stdlib.h. Make sure we have them. */
242 # define EXIT_SUCCESS 0
245 # define EXIT_FAILURE 0
251 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
254 # define bzero(s, n) memset ((s), 0, (n))
256 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
257 # define bcopy(s, d, n) memmove ((d), (s), (n))
260 #else /* Not ANSI_STRING. */
263 # define strchr(s, c) index((s), (c))
264 # define strrchr(s, c) rindex((s), (c))
268 extern int bcmp
PARAMS ((const char *, const char *, int));
271 extern void bzero
PARAMS ((char *, int));
274 extern void bcopy
PARAMS ((const char *b1
, char *b2
, int));
277 /* SCO Xenix has a buggy macro definition in <string.h>. */
280 extern char *strerror
PARAMS ((int errnum
));
283 #endif /* !ANSI_STRING. */
287 # include <inttypes.h>
289 #define FILE_TIMESTAMP uintmax_t
291 #if !defined(HAVE_STRSIGNAL)
292 extern char *strsignal
PARAMS ((int signum
));
295 /* ISDIGIT offers the following features:
296 - Its arg may be any int or unsigned int; it need not be an unsigned char.
297 - It's guaranteed to evaluate its argument exactly once.
298 NOTE! Make relies on this behavior, don't change it!
299 - It's typically faster.
300 POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
301 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
302 it's important to use the locale's definition of `digit' even when the
303 host does not conform to POSIX. */
304 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
307 # define streq(a, b) \
309 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
310 # ifdef HAVE_CASE_INSENSITIVE_FS
311 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
312 # define strieq(a, b) \
314 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
315 && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
317 # define strieq(a, b) streq(a, b)
320 /* Buggy compiler can't handle this. */
321 # define streq(a, b) (strcmp ((a), (b)) == 0)
322 # define strieq(a, b) (strcmp ((a), (b)) == 0)
324 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
326 extern int strcmpi (const char *,const char *);
329 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
330 # define ENUM_BITFIELD(bits) :bits
332 # define ENUM_BITFIELD(bits)
335 /* Handle gettext and locales. */
340 # define setlocale(category, locale)
345 #define _(msgid) gettext (msgid)
346 #define N_(msgid) gettext_noop (msgid)
347 #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
349 /* Handle other OSs. */
350 #if defined(HAVE_DOS_PATHS)
351 # define PATH_SEPARATOR_CHAR ';'
353 # define PATH_SEPARATOR_CHAR ','
355 # define PATH_SEPARATOR_CHAR ':'
358 /* This is needed for getcwd() and chdir(). */
359 #if defined(_MSC_VER) || defined(__BORLANDC__)
366 # define pipe(p) _pipe(p, 512, O_BINARY)
367 # define kill(pid,sig) w32_kill(pid,sig)
369 extern void sync_Path_environment(void);
370 extern int kill(int pid
, int sig
);
371 extern char *end_of_token_w32(char *s
, char stopchar
);
372 extern int find_and_set_default_shell(char *token
);
374 /* indicates whether or not we have Bourne shell */
375 extern int no_default_sh_exe
;
377 /* is default_shell unixy? */
378 extern int unixy_shell
;
379 #endif /* WINDOWS32 */
384 unsigned long lineno
;
386 #define NILF ((struct floc *)0)
388 #define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
391 /* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
392 variadic versions of these functions. */
394 #if HAVE_STDARG_H || HAVE_VARARGS_H
395 # if HAVE_VPRINTF || HAVE_DOPRNT
396 # define USE_VARIADIC 1
400 #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
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)));
408 extern void message ();
409 extern void error ();
410 extern void fatal ();
413 extern void die
PARAMS ((int)) __attribute__ ((noreturn
));
414 extern void log_working_directory
PARAMS ((int));
415 extern void pfatal_with_name
PARAMS ((const char *)) __attribute__ ((noreturn
));
416 extern void perror_with_name
PARAMS ((const char *, const char *));
417 extern char *savestring
PARAMS ((const char *, unsigned int));
418 extern char *concat
PARAMS ((const char *, const char *, const 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 ((const char *));
424 extern char *end_of_token
PARAMS ((const char *));
425 extern void collapse_continuations
PARAMS ((char *));
426 extern char *lindex
PARAMS ((const char *, const char *, int));
427 extern int alpha_compare
PARAMS ((const void *, const void *));
428 extern void print_spaces
PARAMS ((unsigned int));
429 extern char *find_percent
PARAMS ((char *));
430 extern FILE *open_tmpfile
PARAMS ((char **, const char *));
433 extern int ar_name
PARAMS ((char *));
434 extern void ar_parse_name
PARAMS ((char *, char **, char **));
435 extern int ar_touch
PARAMS ((char *));
436 extern time_t ar_member_date
PARAMS ((char *));
439 extern int dir_file_exists_p
PARAMS ((char *, char *));
440 extern int file_exists_p
PARAMS ((char *));
441 extern int file_impossible_p
PARAMS ((char *));
442 extern void file_impossible
PARAMS ((char *));
443 extern char *dir_name
PARAMS ((char *));
444 extern void hash_init_directories
PARAMS ((void));
446 extern void define_default_variables
PARAMS ((void));
447 extern void set_default_suffixes
PARAMS ((void));
448 extern void install_default_suffix_rules
PARAMS ((void));
449 extern void install_default_implicit_rules
PARAMS ((void));
451 extern void build_vpath_lists
PARAMS ((void));
452 extern void construct_vpath_list
PARAMS ((char *pattern
, char *dirpath
));
453 extern int vpath_search
PARAMS ((char **file
, FILE_TIMESTAMP
*mtime_ptr
));
454 extern int gpath_search
PARAMS ((char *file
, unsigned int len
));
456 extern void construct_include_path
PARAMS ((char **arg_dirs
));
458 extern void user_access
PARAMS ((void));
459 extern void make_access
PARAMS ((void));
460 extern void child_access
PARAMS ((void));
462 extern void close_stdout
PARAMS ((void));
464 extern char *strip_whitespace
PARAMS ((const char **begpp
, const char **endpp
));
467 extern void strcache_init
PARAMS ((void));
468 extern void strcache_print_stats
PARAMS ((const char *prefix
));
469 extern int strcache_iscached
PARAMS ((const char *str
));
470 extern const char *strcache_add
PARAMS ((const char *str
));
471 extern const char *strcache_add_len
PARAMS ((const char *str
, int len
));
472 extern int strcache_setbufsize
PARAMS ((int size
));
478 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
479 because such systems often declare them in header files anyway. */
481 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
483 extern long int atol ();
485 extern long int lseek ();
488 #endif /* Not GNU C library or POSIX. */
491 # if !defined(VMS) && !defined(__DECC)
492 extern char *getcwd ();
495 extern char *getwd ();
496 # define getcwd(buf, len) getwd (buf)
499 extern const struct floc
*reading_file
;
501 extern char **environ
;
503 extern int just_print_flag
, silent_flag
, ignore_errors_flag
, keep_going_flag
;
504 extern int print_data_base_flag
, question_flag
, touch_flag
, always_make_flag
;
505 extern int env_overrides
, no_builtin_rules_flag
, no_builtin_variables_flag
;
506 extern int print_version_flag
, print_directory_flag
, check_symlink_flag
;
507 extern int warn_undefined_variables_flag
, posix_pedantic
, not_parallel
;
508 extern int second_expansion
, clock_skew_detected
, rebuilding_makefiles
;
510 /* can we run commands via 'sh -c xxx' or must we use batch files? */
511 extern int batch_mode_shell
;
513 extern unsigned int job_slots
;
514 extern int job_fds
[2];
517 extern double max_load_average
;
519 extern int max_load_average
;
522 extern char *program
;
523 extern char *starting_directory
;
524 extern unsigned int makelevel
;
525 extern char *version_string
, *remote_description
, *make_host
;
527 extern unsigned int commands_started
;
529 extern int handling_fatal_signal
;
533 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
536 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
540 # define MAKE_SUCCESS 1
541 # define MAKE_TROUBLE 2
542 # define MAKE_FAILURE 3
544 # define MAKE_SUCCESS 0
545 # define MAKE_TROUBLE 1
546 # define MAKE_FAILURE 2
549 /* Set up heap debugging library dmalloc. */
551 #ifdef HAVE_DMALLOC_H
555 #ifndef initialize_main
557 # define initialize_main(pargc, pargv) \
558 { _wildcard(pargc, pargv); _response(pargc, pargv); }
560 # define initialize_main(pargc, pargv)
566 # if !HAVE_STRCASECMP
567 # define strcasecmp stricmp
571 # define chdir _chdir2
574 # define getcwd _getcwd2
577 /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
578 chdir() and getcwd(). This avoids some error messages for the
579 make testsuite but restricts the drive letter support. */
581 # warning NO_CHDIR2: usage of drive letters restricted
587 #ifndef initialize_main
588 # define initialize_main(pargc, pargv)
592 /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
593 properly according to POSIX. So, we try to wrap common system calls with
594 checks for EINTR. Note that there are still plenty of system calls that
595 can fail with EINTR but this, reportedly, gets the vast majority of
596 failure cases. If you still experience failures you'll need to either get
597 a system where SA_RESTART works, or you need to avoid -j. */
599 #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
601 /* While system calls that return integers are pretty consistent about
602 returning -1 on failure and setting errno in that case, functions that
603 return pointers are not always so well behaved. Sometimes they return
604 NULL for expected behavior: one good example is readdir() which returns
605 NULL at the end of the directory--and _doesn't_ reset errno. So, we have
606 to do it ourselves here. */
608 #define ENULLLOOP(_v,_c) do{ errno = 0; \
609 while (((_v)=_c)==0 && errno==EINTR); }while(0)