1/* Miscellaneous global declarations and portability cruft for GNU Make. 2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 32002 Free Software Foundation, Inc. 4This file is part of GNU Make. 5 6GNU Make is free software; you can redistribute it and/or modify 7it under the terms of the GNU General Public License as published by 8the Free Software Foundation; either version 2, or (at your option) 9any later version. 10 11GNU Make is distributed in the hope that it will be useful, 12but WITHOUT ANY WARRANTY; without even the implied warranty of 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14GNU General Public License for more details. 15 16You should have received a copy of the GNU General Public License 17along with GNU Make; see the file COPYING. If not, write to 18the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19Boston, MA 02111-1307, USA. */ 20 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). */ 24#include <config.h> 25#undef HAVE_CONFIG_H 26#define HAVE_CONFIG_H 1 27 28/* AIX requires this to be the first thing in the file. */ 29#ifndef __GNUC__ 30# if HAVE_ALLOCA_H 31# include <alloca.h> 32# else 33# ifdef _AIX 34 #pragma alloca 35# else 36# ifndef alloca /* predefined by HP cc +Olibcalls */ 37char *alloca (); 38# endif 39# endif 40# endif 41#endif 42 43 44/* Use prototypes if available. */ 45#if defined (__cplusplus) || (defined (__STDC__) && __STDC__) 46# undef PARAMS 47# define PARAMS(protos) protos 48#else /* Not C++ or ANSI C. */ 49# undef PARAMS 50# define PARAMS(protos) () 51#endif /* C++ or ANSI C. */ 52 53/* Specify we want GNU source code. This must be defined before any 54 system headers are included. */ 55 56#define _GNU_SOURCE 1 57 58 59#ifdef CRAY 60/* This must happen before #include <signal.h> so 61 that the declaration therein is changed. */ 62# define signal bsdsignal 63#endif 64 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 68#endif 69 70#include <sys/types.h> 71#include <sys/stat.h> 72#include <signal.h> 73#include <stdio.h> 74#include <ctype.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> 80#endif 81 82#if TIME_WITH_SYS_TIME 83# include <sys/time.h> 84# include <time.h> 85#else 86# if HAVE_SYS_TIME_H 87# include <sys/time.h> 88# else 89# include <time.h> 90# endif 91#endif 92 93#include <errno.h> 94 95#ifndef errno 96extern int errno; 97#endif 98 99#ifndef isblank 100# define isblank(c) ((c) == ' ' || (c) == '\t') 101#endif 102 103#ifdef HAVE_UNISTD_H 104# include <unistd.h> 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) 108# define POSIX 1 109# endif 110#endif 111 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))) 114# undef POSIX 115#endif 116 117#if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE) 118# define POSIX 1 119#endif 120 121#ifndef RETSIGTYPE 122# define RETSIGTYPE void 123#endif 124 125#ifndef sigmask 126# define sigmask(sig) (1 << ((sig) - 1)) 127#endif 128 129#ifndef HAVE_SA_RESTART 130# define SA_RESTART 0 131#endif 132 133#ifdef HAVE_LIMITS_H 134# include <limits.h> 135#endif 136#ifdef HAVE_SYS_PARAM_H 137# include <sys/param.h> 138#endif 139 140#ifndef PATH_MAX 141# ifndef POSIX 142# define PATH_MAX MAXPATHLEN 143# endif 144#endif 145#ifndef MAXPATHLEN 146# define MAXPATHLEN 1024 147#endif 148 149#ifdef PATH_MAX 150# define GET_PATH_MAX PATH_MAX 151# define PATH_VAR(var) char var[PATH_MAX] 152#else 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) 156extern unsigned int get_path_max PARAMS ((void)); 157#endif 158 159#ifndef CHAR_BIT 160# define CHAR_BIT 8 161#endif 162 163/* Nonzero if the integer type T is signed. */ 164#define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0) 165 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)) 171 172#ifndef CHAR_MAX 173# define CHAR_MAX INTEGER_TYPE_MAXIMUM (char) 174#endif 175 176#ifdef STAT_MACROS_BROKEN 177# ifdef S_ISREG 178# undef S_ISREG 179# endif 180# ifdef S_ISDIR 181# undef S_ISDIR 182# endif 183#endif /* STAT_MACROS_BROKEN. */ 184 185#ifndef S_ISREG 186# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 187#endif 188#ifndef S_ISDIR 189# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 190#endif 191 192#ifdef VMS 193# include <types.h> 194# include <unixlib.h> 195# include <unixio.h> 196# include <perror.h> 197/* Needed to use alloca on VMS. */ 198# include <builtins.h> 199#endif 200 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) 205# endif 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 211# endif 212#endif 213 214#if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__) 215# include <stdlib.h> 216# include <string.h> 217# define ANSI_STRING 1 218#else /* No standard headers. */ 219# ifdef HAVE_STRING_H 220# include <string.h> 221# define ANSI_STRING 1 222# else 223# include <strings.h> 224# endif 225# ifdef HAVE_MEMORY_H 226# include <memory.h> 227# endif 228# ifdef HAVE_STDLIB_H 229# include <stdlib.h> 230# else 231extern char *malloc PARAMS ((int)); 232extern char *realloc PARAMS ((char *, int)); 233extern void free PARAMS ((char *)); 234 235extern void abort PARAMS ((void)) __attribute__ ((noreturn)); 236extern void exit PARAMS ((int)) __attribute__ ((noreturn)); 237# endif /* HAVE_STDLIB_H. */ 238 239#endif /* Standard headers. */ 240 241/* These should be in stdlib.h. Make sure we have them. */ 242#ifndef EXIT_SUCCESS 243# define EXIT_SUCCESS 0 244#endif 245#ifndef EXIT_FAILURE 246# define EXIT_FAILURE 0 247#endif 248 249#ifdef ANSI_STRING 250 251# ifndef bcmp 252# define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) 253# endif 254# ifndef bzero 255# define bzero(s, n) memset ((s), 0, (n)) 256# endif 257# if defined(HAVE_MEMMOVE) && !defined(bcopy) 258# define bcopy(s, d, n) memmove ((d), (s), (n)) 259# endif 260 261#else /* Not ANSI_STRING. */ 262 263# ifndef HAVE_STRCHR 264# define strchr(s, c) index((s), (c)) 265# define strrchr(s, c) rindex((s), (c)) 266# endif 267 268# ifndef bcmp 269extern int bcmp PARAMS ((const char *, const char *, int)); 270# endif 271# ifndef bzero 272extern void bzero PARAMS ((char *, int)); 273#endif 274# ifndef bcopy 275extern void bcopy PARAMS ((const char *b1, char *b2, int)); 276# endif 277 278#endif /* ANSI_STRING. */ 279#undef ANSI_STRING 280 281/* SCO Xenix has a buggy macro definition in <string.h>. */ 282#undef strerror 283 284#if !defined(ANSI_STRING) && !defined(__DECC) 285extern char *strerror PARAMS ((int errnum)); 286#endif 287 288#if HAVE_INTTYPES_H 289# include <inttypes.h> 290#endif 291#define FILE_TIMESTAMP uintmax_t 292 293#if !defined(HAVE_STRSIGNAL) 294extern char *strsignal PARAMS ((int signum)); 295#endif 296 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) 307 308#ifndef iAPX286 309# define streq(a, b) \ 310 ((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) \ 315 ((a) == (b) \ 316 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \ 317 && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1)))) 318# else 319# define strieq(a, b) streq(a, b) 320# endif 321#else 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) 325#endif 326#define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0) 327#ifdef VMS 328extern int strcmpi (const char *,const char *); 329#endif 330 331#if defined(__GNUC__) || defined(ENUM_BITFIELDS) 332# define ENUM_BITFIELD(bits) :bits 333#else 334# define ENUM_BITFIELD(bits) 335#endif 336 337/* Handle gettext and locales. */ 338 339#if HAVE_LOCALE_H 340# include <locale.h> 341#else 342# define setlocale(category, locale) 343#endif 344 345#include <gettext.h> 346 347#define _(msgid) gettext (msgid) 348#define N_(msgid) gettext_noop (msgid) 349#define S_(msg1,msg2,num) ngettext (msg1,msg2,num) 350 351/* Handle other OSs. */ 352 353#if defined(__MSDOS__) || defined(WINDOWS32) 354# define PATH_SEPARATOR_CHAR ';' 355#else 356# if defined(VMS) 357# define PATH_SEPARATOR_CHAR ',' 358# else 359# define PATH_SEPARATOR_CHAR ':' 360# endif 361#endif 362 363#ifdef WINDOWS32 364# include <fcntl.h> 365# include <malloc.h> 366# define pipe(p) _pipe(p, 512, O_BINARY) 367# define kill(pid,sig) w32_kill(pid,sig) 368 369extern void sync_Path_environment(void); 370extern int kill(int pid, int sig); 371extern int safe_stat(char *file, struct stat *sb); 372extern char *end_of_token_w32(char *s, char stopchar); 373extern int find_and_set_default_shell(char *token); 374 375/* indicates whether or not we have Bourne shell */ 376extern int no_default_sh_exe; 377 378/* is default_shell unixy? */ 379extern int unixy_shell; 380#endif /* WINDOWS32 */ 381 382struct floc 383 { 384 char *filenm; 385 unsigned long lineno; 386 }; 387#define NILF ((struct floc *)0) 388 389#define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1) 390 391 392/* Fancy processing for variadic functions in both ANSI and pre-ANSI 393 compilers. */ 394#if defined __STDC__ && __STDC__ 395extern void message (int prefix, const char *fmt, ...) 396 __attribute__ ((__format__ (__printf__, 2, 3))); 397extern void error (const struct floc *flocp, const char *fmt, ...) 398 __attribute__ ((__format__ (__printf__, 2, 3))); 399extern void fatal (const struct floc *flocp, const char *fmt, ...) 400 __attribute__ ((noreturn, __format__ (__printf__, 2, 3))); 401#else 402extern void message (); 403extern void error (); 404extern void fatal (); 405#endif 406 407extern void die PARAMS ((int)) __attribute__ ((noreturn)); 408extern void log_working_directory PARAMS ((int)); 409extern void pfatal_with_name PARAMS ((const char *)) __attribute__ ((noreturn)); 410extern void perror_with_name PARAMS ((const char *, const char *)); 411extern char *savestring PARAMS ((const char *, unsigned int)); 412extern char *concat PARAMS ((const char *, const char *, const char *)); 413extern char *xmalloc PARAMS ((unsigned int)); 414extern char *xrealloc PARAMS ((char *, unsigned int)); 415extern char *xstrdup PARAMS ((const char *)); 416extern char *find_next_token PARAMS ((char **, unsigned int *)); 417extern char *next_token PARAMS ((const char *)); 418extern char *end_of_token PARAMS ((char *)); 419extern void collapse_continuations PARAMS ((char *)); 420extern void remove_comments PARAMS((char *)); 421extern char *sindex PARAMS ((const char *, unsigned int, \ 422 const char *, unsigned int)); 423extern char *lindex PARAMS ((const char *, const char *, int)); 424extern int alpha_compare PARAMS ((const void *, const void *)); 425extern void print_spaces PARAMS ((unsigned int)); 426extern char *find_char_unquote PARAMS ((char *, int, int, int)); 427extern char *find_percent PARAMS ((char *)); 428extern FILE *open_tmpfile PARAMS ((char **, const char *)); 429 430#ifndef NO_ARCHIVES 431extern int ar_name PARAMS ((char *)); 432extern void ar_parse_name PARAMS ((char *, char **, char **)); 433extern int ar_touch PARAMS ((char *)); 434extern time_t ar_member_date PARAMS ((char *)); 435#endif 436 437extern int dir_file_exists_p PARAMS ((char *, char *)); 438extern int file_exists_p PARAMS ((char *)); 439extern int file_impossible_p PARAMS ((char *)); 440extern void file_impossible PARAMS ((char *)); 441extern char *dir_name PARAMS ((char *)); 442extern void hash_init_directories PARAMS ((void)); 443 444extern void define_default_variables PARAMS ((void)); 445extern void set_default_suffixes PARAMS ((void)); 446extern void install_default_suffix_rules PARAMS ((void)); 447extern void install_default_implicit_rules PARAMS ((void)); 448 449extern void build_vpath_lists PARAMS ((void)); 450extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath)); 451extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr)); 452extern int gpath_search PARAMS ((char *file, int len)); 453 454extern void construct_include_path PARAMS ((char **arg_dirs)); 455 456extern void user_access PARAMS ((void)); 457extern void make_access PARAMS ((void)); 458extern void child_access PARAMS ((void)); 459 460#ifdef HAVE_VFORK_H 461# include <vfork.h> 462#endif 463 464/* We omit these declarations on non-POSIX systems which define _POSIX_VERSION, 465 because such systems often declare them in header files anyway. */ 466 467#if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32) 468 469extern long int atol (); 470# ifndef VMS 471extern long int lseek (); 472# endif 473 474#endif /* Not GNU C library or POSIX. */ 475 476#ifdef HAVE_GETCWD 477# if !defined(VMS) && !defined(__DECC) 478extern char *getcwd (); 479#endif 480#else 481extern char *getwd (); 482# define getcwd(buf, len) getwd (buf) 483#endif 484 485extern const struct floc *reading_file; 486 487extern char **environ; 488 489extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag; 490extern int print_data_base_flag, question_flag, touch_flag, always_make_flag; 491extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag; 492extern int print_version_flag, print_directory_flag; 493extern int warn_undefined_variables_flag, posix_pedantic, not_parallel; 494extern int clock_skew_detected; 495 496/* can we run commands via 'sh -c xxx' or must we use batch files? */ 497extern int batch_mode_shell; 498 499extern unsigned int job_slots; 500extern int job_fds[2]; 501extern int job_rfd; 502#ifndef NO_FLOAT 503extern double max_load_average; 504#else 505extern int max_load_average; 506#endif 507 508extern char *program; 509extern char *starting_directory; 510extern unsigned int makelevel; 511extern char *version_string, *remote_description; 512 513extern unsigned int commands_started; 514 515extern int handling_fatal_signal; 516 517 518#ifndef MIN 519#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b)) 520#endif 521#ifndef MAX 522#define MAX(_a,_b) ((_a)>(_b)?(_a):(_b)) 523#endif 524 525#ifdef VMS 526# define MAKE_SUCCESS 1 527# define MAKE_TROUBLE 2 528# define MAKE_FAILURE 3 529#else 530# define MAKE_SUCCESS 0 531# define MAKE_TROUBLE 1 532# define MAKE_FAILURE 2 533#endif 534 535/* Set up heap debugging library dmalloc. */ 536 537#ifdef HAVE_DMALLOC_H 538#include <dmalloc.h> 539#endif 540 541 542/* If we have broken SA_RESTART support, then wrap stat() and readdir() with 543 versions that handle EINTR. Note that there are still plenty of system 544 calls that can fail with EINTR but this, reportedly, gets the vast 545 majority of failure cases. If you still experience failures you'll need 546 to either get a system where SA_RESTART works, or you need to avoid -j. */ 547 548#ifdef HAVE_BROKEN_RESTART 549 550/* Here we make an assumption that a system with a broken SA_RESTART has 551 dirent.h. Right now the only system I know of in this category is PTX, and 552 it does have dirent.h. 553*/ 554#include <dirent.h> 555 556#define stat(_f,_b) atomic_stat ((_f), (_b)) 557#define readdir(_d) atomic_readdir (_d) 558 559extern int atomic_stat PARAMS ((const char *file, struct stat *buf)); 560extern struct dirent *atomic_readdir PARAMS ((DIR *dir)); 561 562#endif 563