1 /* Miscellaneous global declarations and portability cruft for GNU Make. 2 Copyright (C) 1988-2020 Free Software Foundation, Inc. 3 This file is part of GNU Make. 4 5 GNU Make is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3 of the License, or (at your option) any later 8 version. 9 10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along with 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 /* We use <config.h> instead of "config.h" so that a compilation 18 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h 19 (which it would do because makeint.h was found in $srcdir). */ 20 #include <config.h> 21 #undef HAVE_CONFIG_H 22 #define HAVE_CONFIG_H 1 23 24 /* Specify we want GNU source code. This must be defined before any 25 system headers are included. */ 26 27 #define _GNU_SOURCE 1 28 29 /* AIX requires this to be the first thing in the file. */ 30 #if HAVE_ALLOCA_H 31 # include <alloca.h> 32 #else 33 # ifdef _AIX 34 #pragma alloca 35 # else 36 # if !defined(__GNUC__) && !defined(WINDOWS32) 37 # ifndef alloca /* predefined by HP cc +Olibcalls */ 38 char *alloca (); 39 # endif 40 # endif 41 # endif 42 #endif 43 44 /* Disable assert() unless we're a maintainer. 45 Some asserts are compute-intensive. */ 46 #ifndef MAKE_MAINTAINER_MODE 47 # define NDEBUG 1 48 #endif 49 50 /* Include the externally-visible content. 51 Be sure to use the local one, and not one installed on the system. 52 Define GMK_BUILDING_MAKE for proper selection of dllexport/dllimport 53 declarations for MS-Windows. */ 54 #ifdef WINDOWS32 55 # define GMK_BUILDING_MAKE 56 #endif 57 #include "gnumake.h" 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 <stddef.h> 71 #include <sys/types.h> 72 #include <sys/stat.h> 73 #include <signal.h> 74 #include <stdio.h> 75 #include <ctype.h> 76 77 #ifdef HAVE_SYS_TIMEB_H 78 /* SCO 3.2 "devsys 4.2" has a prototype for 'ftime' in <time.h> that bombs 79 unless <sys/timeb.h> has been included first. */ 80 # include <sys/timeb.h> 81 #endif 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 96 extern int errno; 97 #endif 98 99 #ifdef __VMS 100 /* In strict ANSI mode, VMS compilers should not be defining the 101 VMS macro. Define it here instead of a bulk edit for the correct code. 102 */ 103 # ifndef VMS 104 # define VMS 105 # endif 106 #endif 107 108 #ifdef HAVE_UNISTD_H 109 # include <unistd.h> 110 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get 111 POSIX.1 behavior with 'cc -YPOSIX', which predefines POSIX itself! */ 112 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS) 113 # define POSIX 1 114 # endif 115 #endif 116 117 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */ 118 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386))) 119 #endif 120 121 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE) 122 # define POSIX 1 123 #endif 124 125 #ifndef RETSIGTYPE 126 # define RETSIGTYPE void 127 #endif 128 129 #ifndef sigmask 130 # define sigmask(sig) (1 << ((sig) - 1)) 131 #endif 132 133 #ifndef HAVE_SA_RESTART 134 # define SA_RESTART 0 135 #endif 136 137 #ifdef HAVE_VFORK_H 138 # include <vfork.h> 139 #endif 140 141 #ifdef HAVE_LIMITS_H 142 # include <limits.h> 143 #endif 144 #ifdef HAVE_SYS_PARAM_H 145 # include <sys/param.h> 146 #endif 147 148 #ifndef PATH_MAX 149 # ifndef POSIX 150 # define PATH_MAX MAXPATHLEN 151 # endif 152 #endif 153 #ifndef MAXPATHLEN 154 # define MAXPATHLEN 1024 155 #endif 156 157 #ifdef PATH_MAX 158 # define GET_PATH_MAX PATH_MAX 159 # define PATH_VAR(var) char var[PATH_MAX+1] 160 #else 161 # define NEED_GET_PATH_MAX 1 162 # define GET_PATH_MAX (get_path_max ()) 163 # define PATH_VAR(var) char *var = alloca (GET_PATH_MAX+1) 164 unsigned int get_path_max (void); 165 #endif 166 167 #ifndef CHAR_BIT 168 # define CHAR_BIT 8 169 #endif 170 171 #ifndef USHRT_MAX 172 # define USHRT_MAX 65535 173 #endif 174 175 /* Nonzero if the integer type T is signed. 176 Use <= to avoid GCC warnings about always-false expressions. */ 177 #define INTEGER_TYPE_SIGNED(t) ((t) -1 <= 0) 178 179 /* The minimum and maximum values for the integer type T. 180 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */ 181 #define INTEGER_TYPE_MINIMUM(t) \ 182 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)) 183 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t)) 184 185 #ifndef CHAR_MAX 186 # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char) 187 #endif 188 189 #ifdef STAT_MACROS_BROKEN 190 # ifdef S_ISREG 191 # undef S_ISREG 192 # endif 193 # ifdef S_ISDIR 194 # undef S_ISDIR 195 # endif 196 #endif /* STAT_MACROS_BROKEN. */ 197 198 #ifndef S_ISREG 199 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 200 #endif 201 #ifndef S_ISDIR 202 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 203 #endif 204 205 #ifdef VMS 206 # include <fcntl.h> 207 # include <types.h> 208 # include <unixlib.h> 209 # include <unixio.h> 210 # include <perror.h> 211 /* Needed to use alloca on VMS. */ 212 # include <builtins.h> 213 214 extern int vms_use_mcr_command; 215 extern int vms_always_use_cmd_file; 216 extern int vms_gnv_shell; 217 extern int vms_comma_separator; 218 extern int vms_legacy_behavior; 219 extern int vms_unix_simulation; 220 #endif 221 222 #if !defined(__attribute__) && (__GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__) 223 /* Don't use __attribute__ if it's not supported. */ 224 # define ATTRIBUTE(x) 225 #else 226 # define ATTRIBUTE(x) __attribute__ (x) 227 #endif 228 229 /* The __-protected variants of 'format' and 'printf' attributes 230 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ 231 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 232 # define __format__ format 233 # define __printf__ printf 234 #endif 235 236 #define UNUSED ATTRIBUTE ((unused)) 237 #define NORETURN ATTRIBUTE ((noreturn)) 238 239 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__) 240 # include <stdlib.h> 241 # include <string.h> 242 # define ANSI_STRING 1 243 #else /* No standard headers. */ 244 # ifdef HAVE_STRING_H 245 # include <string.h> 246 # define ANSI_STRING 1 247 # else 248 # include <strings.h> 249 # endif 250 # ifdef HAVE_MEMORY_H 251 # include <memory.h> 252 # endif 253 # ifdef HAVE_STDLIB_H 254 # include <stdlib.h> 255 # else 256 void *malloc (int); 257 void *realloc (void *, int); 258 void free (void *); 259 260 void abort (void) NORETURN; 261 void exit (int) NORETURN; 262 # endif /* HAVE_STDLIB_H. */ 263 264 #endif /* Standard headers. */ 265 266 /* These should be in stdlib.h. Make sure we have them. */ 267 #ifndef EXIT_SUCCESS 268 # define EXIT_SUCCESS 0 269 #endif 270 #ifndef EXIT_FAILURE 271 # define EXIT_FAILURE 1 272 #endif 273 274 #ifndef ANSI_STRING 275 276 /* SCO Xenix has a buggy macro definition in <string.h>. */ 277 #undef strerror 278 #if !defined(__DECC) 279 char *strerror (int errnum); 280 #endif 281 282 #endif /* !ANSI_STRING. */ 283 #undef ANSI_STRING 284 285 #if HAVE_INTTYPES_H 286 # include <inttypes.h> 287 #endif 288 #if HAVE_STDINT_H 289 # include <stdint.h> 290 #endif 291 #define FILE_TIMESTAMP uintmax_t 292 293 #if !defined(HAVE_STRSIGNAL) 294 char *strsignal (int signum); 295 #endif 296 297 #if !defined(HAVE_UMASK) 298 typedef int mode_t; 299 extern mode_t umask (mode_t); 300 #endif 301 302 /* ISDIGIT offers the following features: 303 - Its arg may be any int or unsigned int; it need not be an unsigned char. 304 - It's guaranteed to evaluate its argument exactly once. 305 NOTE! Make relies on this behavior, don't change it! 306 - It's typically faster. 307 POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that 308 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless 309 it's important to use the locale's definition of 'digit' even when the 310 host does not conform to POSIX. */ 311 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) 312 313 /* Test if two strings are equal. Is this worthwhile? Should be profiled. */ 314 #define streq(a, b) \ 315 ((a) == (b) || \ 316 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1)))) 317 318 /* Test if two strings are equal, but match case-insensitively on systems 319 which have case-insensitive filesystems. Should only be used for 320 filenames! */ 321 #ifdef HAVE_CASE_INSENSITIVE_FS 322 # define patheq(a, b) \ 323 ((a) == (b) \ 324 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \ 325 && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1)))) 326 #else 327 # define patheq(a, b) streq(a, b) 328 #endif 329 330 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0) 331 332 #if defined(ENUM_BITFIELDS) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) 333 # define ENUM_BITFIELD(bits) :bits 334 #else 335 # define ENUM_BITFIELD(bits) 336 #endif 337 338 /* Handle gettext and locales. */ 339 340 #if HAVE_LOCALE_H 341 # include <locale.h> 342 #else 343 # define setlocale(category, locale) 344 #endif 345 346 #include <gettext.h> 347 348 #define _(msgid) gettext (msgid) 349 #define N_(msgid) gettext_noop (msgid) 350 #define S_(msg1,msg2,num) ngettext (msg1,msg2,num) 351 352 /* This is needed for getcwd() and chdir(), on some W32 systems. */ 353 #if defined(HAVE_DIRECT_H) 354 # include <direct.h> 355 #endif 356 357 #ifdef WINDOWS32 358 # include <fcntl.h> 359 # include <malloc.h> 360 # define pipe(_p) _pipe((_p), 512, O_BINARY) 361 # define kill(_pid,_sig) w32_kill((_pid),(_sig)) 362 /* MSVC and Watcom C don't have ftruncate. */ 363 # if defined(_MSC_VER) || defined(__WATCOMC__) 364 # define ftruncate(_fd,_len) _chsize(_fd,_len) 365 # endif 366 /* MinGW64 doesn't have _S_ISDIR. */ 367 # ifndef _S_ISDIR 368 # define _S_ISDIR(m) S_ISDIR(m) 369 # endif 370 371 void sync_Path_environment (void); 372 int w32_kill (pid_t pid, int sig); 373 int find_and_set_default_shell (const char *token); 374 375 /* indicates whether or not we have Bourne shell */ 376 extern int no_default_sh_exe; 377 378 /* is default_shell unixy? */ 379 extern int unixy_shell; 380 381 /* We don't have a preferred fixed value for LOCALEDIR. */ 382 # ifndef LOCALEDIR 383 # define LOCALEDIR NULL 384 # endif 385 386 /* Include only the minimal stuff from windows.h. */ 387 # define WIN32_LEAN_AND_MEAN 388 #endif /* WINDOWS32 */ 389 390 #define ANY_SET(_v,_m) (((_v)&(_m)) != 0) 391 #define NONE_SET(_v,_m) (! ANY_SET ((_v),(_m))) 392 393 #define MAP_NUL 0x0001 394 #define MAP_BLANK 0x0002 395 #define MAP_NEWLINE 0x0004 396 #define MAP_COMMENT 0x0008 397 #define MAP_SEMI 0x0010 398 #define MAP_EQUALS 0x0020 399 #define MAP_COLON 0x0040 400 #define MAP_VARSEP 0x0080 401 #define MAP_PIPE 0x0100 402 #define MAP_DOT 0x0200 403 #define MAP_COMMA 0x0400 404 405 /* These are the valid characters for a user-defined function. */ 406 #define MAP_USERFUNC 0x2000 407 /* This means not only a '$', but skip the variable reference. */ 408 #define MAP_VARIABLE 0x4000 409 /* The set of characters which are directory separators is OS-specific. */ 410 #define MAP_DIRSEP 0x8000 411 412 #ifdef VMS 413 # define MAP_VMSCOMMA MAP_COMMA 414 #else 415 # define MAP_VMSCOMMA 0x0000 416 #endif 417 418 #define MAP_SPACE (MAP_BLANK|MAP_NEWLINE) 419 420 /* Handle other OSs. 421 To overcome an issue parsing paths in a DOS/Windows environment when 422 built in a unix based environment, override the PATH_SEPARATOR_CHAR 423 definition unless being built for Cygwin. */ 424 #if defined(HAVE_DOS_PATHS) && !defined(__CYGWIN__) 425 # undef PATH_SEPARATOR_CHAR 426 # define PATH_SEPARATOR_CHAR ';' 427 # define MAP_PATHSEP MAP_SEMI 428 #elif !defined(PATH_SEPARATOR_CHAR) 429 # if defined (VMS) 430 # define PATH_SEPARATOR_CHAR (vms_comma_separator ? ',' : ':') 431 # define MAP_PATHSEP (vms_comma_separator ? MAP_COMMA : MAP_SEMI) 432 # else 433 # define PATH_SEPARATOR_CHAR ':' 434 # define MAP_PATHSEP MAP_COLON 435 # endif 436 #elif PATH_SEPARATOR_CHAR == ':' 437 # define MAP_PATHSEP MAP_COLON 438 #elif PATH_SEPARATOR_CHAR == ';' 439 # define MAP_PATHSEP MAP_SEMI 440 #elif PATH_SEPARATOR_CHAR == ',' 441 # define MAP_PATHSEP MAP_COMMA 442 #else 443 # error "Unknown PATH_SEPARATOR_CHAR" 444 #endif 445 446 #define STOP_SET(_v,_m) ANY_SET(stopchar_map[(unsigned char)(_v)],(_m)) 447 448 #define ISBLANK(c) STOP_SET((c),MAP_BLANK) 449 #define ISSPACE(c) STOP_SET((c),MAP_SPACE) 450 #define NEXT_TOKEN(s) while (ISSPACE (*(s))) ++(s) 451 #define END_OF_TOKEN(s) while (! STOP_SET (*(s), MAP_SPACE|MAP_NUL)) ++(s) 452 453 /* We can't run setrlimit when using posix_spawn. */ 454 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) && !defined(USE_POSIX_SPAWN) 455 # define SET_STACK_SIZE 456 #endif 457 #ifdef SET_STACK_SIZE 458 # include <sys/resource.h> 459 extern struct rlimit stack_limit; 460 #endif 461 462 #include <glob.h> 463 464 #define NILF ((floc *)0) 465 466 #define CSTRLEN(_s) (sizeof (_s)-1) 467 #define STRING_SIZE_TUPLE(_s) (_s), CSTRLEN(_s) 468 469 /* The number of bytes needed to represent the largest integer as a string. */ 470 #define INTSTR_LENGTH CSTRLEN ("18446744073709551616") 471 472 #define DEFAULT_TTYNAME "true" 473 #ifdef HAVE_TTYNAME 474 # define TTYNAME(_f) ttyname (_f) 475 #else 476 # define TTYNAME(_f) DEFAULT_TTYNAME 477 #endif 478 479 480 481 /* Specify the location of elements read from makefiles. */ 482 typedef struct 483 { 484 const char *filenm; 485 unsigned long lineno; 486 unsigned long offset; 487 } floc; 488 489 const char *concat (unsigned int, ...); 490 void message (int prefix, size_t length, const char *fmt, ...) 491 ATTRIBUTE ((__format__ (__printf__, 3, 4))); 492 void error (const floc *flocp, size_t length, const char *fmt, ...) 493 ATTRIBUTE ((__format__ (__printf__, 3, 4))); 494 void fatal (const floc *flocp, size_t length, const char *fmt, ...) 495 ATTRIBUTE ((noreturn, __format__ (__printf__, 3, 4))); 496 void out_of_memory () NORETURN; 497 498 /* When adding macros to this list be sure to update the value of 499 XGETTEXT_OPTIONS in the po/Makevars file. */ 500 #define O(_t,_a,_f) _t((_a), 0, (_f)) 501 #define OS(_t,_a,_f,_s) _t((_a), strlen (_s), (_f), (_s)) 502 #define OSS(_t,_a,_f,_s1,_s2) _t((_a), strlen (_s1) + strlen (_s2), \ 503 (_f), (_s1), (_s2)) 504 #define OSSS(_t,_a,_f,_s1,_s2,_s3) _t((_a), strlen (_s1) + strlen (_s2) + strlen (_s3), \ 505 (_f), (_s1), (_s2), (_s3)) 506 #define ON(_t,_a,_f,_n) _t((_a), INTSTR_LENGTH, (_f), (_n)) 507 #define ONN(_t,_a,_f,_n1,_n2) _t((_a), INTSTR_LENGTH*2, (_f), (_n1), (_n2)) 508 509 #define OSN(_t,_a,_f,_s,_n) _t((_a), strlen (_s) + INTSTR_LENGTH, \ 510 (_f), (_s), (_n)) 511 #define ONS(_t,_a,_f,_n,_s) _t((_a), INTSTR_LENGTH + strlen (_s), \ 512 (_f), (_n), (_s)) 513 514 void die (int) NORETURN; 515 void pfatal_with_name (const char *) NORETURN; 516 void perror_with_name (const char *, const char *); 517 #define xstrlen(_s) ((_s)==NULL ? 0 : strlen (_s)) 518 void *xmalloc (size_t); 519 void *xcalloc (size_t); 520 void *xrealloc (void *, size_t); 521 char *xstrdup (const char *); 522 char *xstrndup (const char *, size_t); 523 char *find_next_token (const char **, size_t *); 524 char *next_token (const char *); 525 char *end_of_token (const char *); 526 void collapse_continuations (char *); 527 char *lindex (const char *, const char *, int); 528 int alpha_compare (const void *, const void *); 529 void print_spaces (unsigned int); 530 char *find_percent (char *); 531 const char *find_percent_cached (const char **); 532 FILE *get_tmpfile (char **, const char *); 533 ssize_t writebuf (int, const void *, size_t); 534 ssize_t readbuf (int, void *, size_t); 535 536 #ifndef HAVE_MEMRCHR 537 void *memrchr(const void *, int, size_t); 538 #endif 539 540 #ifndef NO_ARCHIVES 541 int ar_name (const char *); 542 void ar_parse_name (const char *, char **, char **); 543 int ar_touch (const char *); 544 time_t ar_member_date (const char *); 545 546 typedef long int (*ar_member_func_t) (int desc, const char *mem, int truncated, 547 long int hdrpos, long int datapos, 548 long int size, long int date, int uid, 549 int gid, unsigned int mode, 550 const void *arg); 551 552 long int ar_scan (const char *archive, ar_member_func_t function, const void *arg); 553 int ar_name_equal (const char *name, const char *mem, int truncated); 554 #ifndef VMS 555 int ar_member_touch (const char *arname, const char *memname); 556 #endif 557 #endif 558 559 int dir_file_exists_p (const char *, const char *); 560 int file_exists_p (const char *); 561 int file_impossible_p (const char *); 562 void file_impossible (const char *); 563 const char *dir_name (const char *); 564 void print_dir_data_base (void); 565 void dir_setup_glob (glob_t *); 566 void hash_init_directories (void); 567 568 void define_default_variables (void); 569 void undefine_default_variables (void); 570 void set_default_suffixes (void); 571 void install_default_suffix_rules (void); 572 void install_default_implicit_rules (void); 573 574 void build_vpath_lists (void); 575 void construct_vpath_list (char *pattern, char *dirpath); 576 const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr, 577 unsigned int* vpath_index, unsigned int* path_index); 578 int gpath_search (const char *file, size_t len); 579 580 void construct_include_path (const char **arg_dirs); 581 582 void user_access (void); 583 void make_access (void); 584 void child_access (void); 585 586 char *strip_whitespace (const char **begpp, const char **endpp); 587 588 void show_goal_error (void); 589 590 /* String caching */ 591 void strcache_init (void); 592 void strcache_print_stats (const char *prefix); 593 int strcache_iscached (const char *str); 594 const char *strcache_add (const char *str); 595 const char *strcache_add_len (const char *str, size_t len); 596 597 /* Guile support */ 598 int guile_gmake_setup (const floc *flocp); 599 600 /* Loadable object support. Sets to the strcached name of the loaded file. */ 601 typedef int (*load_func_t)(const floc *flocp); 602 int load_file (const floc *flocp, const char **filename, int noerror); 603 void unload_file (const char *name); 604 605 /* Maintainer mode support */ 606 #ifdef MAKE_MAINTAINER_MODE 607 # define SPIN(_s) spin (_s) 608 void spin (const char* suffix); 609 #else 610 # define SPIN(_s) 611 #endif 612 613 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION, 614 because such systems often declare them in header files anyway. */ 615 616 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32) 617 618 long int atol (); 619 # ifndef VMS 620 long int lseek (); 621 # endif 622 623 # ifdef HAVE_GETCWD 624 # if !defined(VMS) && !defined(__DECC) 625 char *getcwd (); 626 # endif 627 # else 628 char *getwd (); 629 # define getcwd(buf, len) getwd (buf) 630 # endif 631 632 #endif /* Not GNU C library or POSIX. */ 633 634 #if !HAVE_STRCASECMP 635 # if HAVE_STRICMP 636 # define strcasecmp stricmp 637 # elif HAVE_STRCMPI 638 # define strcasecmp strcmpi 639 # else 640 /* Create our own, in misc.c */ 641 int strcasecmp (const char *s1, const char *s2); 642 # endif 643 #endif 644 645 #if !HAVE_STRNCASECMP 646 # if HAVE_STRNICMP 647 # define strncasecmp strnicmp 648 # elif HAVE_STRNCMPI 649 # define strncasecmp strncmpi 650 # else 651 /* Create our own, in misc.c */ 652 int strncasecmp (const char *s1, const char *s2, int n); 653 # endif 654 #endif 655 656 #define OUTPUT_SYNC_NONE 0 657 #define OUTPUT_SYNC_LINE 1 658 #define OUTPUT_SYNC_TARGET 2 659 #define OUTPUT_SYNC_RECURSE 3 660 661 /* Non-GNU systems may not declare this in unistd.h. */ 662 extern char **environ; 663 664 extern const floc *reading_file; 665 extern const floc **expanding_var; 666 667 extern unsigned short stopchar_map[]; 668 669 extern int just_print_flag, run_silent, ignore_errors_flag, keep_going_flag; 670 extern int print_data_base_flag, question_flag, touch_flag, always_make_flag; 671 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag; 672 extern int print_version_flag, print_directory_flag, check_symlink_flag; 673 extern int warn_undefined_variables_flag, trace_flag, posix_pedantic; 674 extern int not_parallel, second_expansion, clock_skew_detected; 675 extern int rebuilding_makefiles, one_shell, output_sync, verify_flag; 676 677 extern const char *default_shell; 678 679 /* can we run commands via 'sh -c xxx' or must we use batch files? */ 680 extern int batch_mode_shell; 681 682 /* Resetting the command script introduction prefix character. */ 683 #define RECIPEPREFIX_NAME ".RECIPEPREFIX" 684 #define RECIPEPREFIX_DEFAULT '\t' 685 extern char cmd_prefix; 686 687 extern unsigned int job_slots; 688 extern double max_load_average; 689 690 extern const char *program; 691 692 #ifdef VMS 693 const char *vms_command (const char *argv0); 694 const char *vms_progname (const char *argv0); 695 696 void vms_exit (int); 697 # define _exit(foo) vms_exit(foo) 698 # define exit(foo) vms_exit(foo) 699 700 extern char *program_name; 701 702 void 703 set_program_name (const char *arv0); 704 705 int 706 need_vms_symbol (void); 707 708 int 709 create_foreign_command (const char *command, const char *image); 710 711 int 712 vms_export_dcl_symbol (const char *name, const char *value); 713 714 int 715 vms_putenv_symbol (const char *string); 716 717 void 718 vms_restore_symbol (const char *string); 719 720 #endif 721 722 void remote_setup (void); 723 void remote_cleanup (void); 724 int start_remote_job_p (int); 725 int start_remote_job (char **, char **, int, int *, pid_t *, int *); 726 int remote_status (int *, int *, int *, int); 727 void block_remote_children (void); 728 void unblock_remote_children (void); 729 int remote_kill (pid_t id, int sig); 730 void print_variable_data_base (void); 731 void print_vpath_data_base (void); 732 733 extern char *starting_directory; 734 extern unsigned int makelevel; 735 extern char *version_string, *remote_description, *make_host; 736 737 extern unsigned int commands_started; 738 739 extern int handling_fatal_signal; 740 741 #ifndef MIN 742 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b)) 743 #endif 744 #ifndef MAX 745 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b)) 746 #endif 747 748 #define MAKE_SUCCESS 0 749 #define MAKE_TROUBLE 1 750 #define MAKE_FAILURE 2 751 752 /* Set up heap debugging library dmalloc. */ 753 754 #ifdef HAVE_DMALLOC_H 755 #include <dmalloc.h> 756 #endif 757 758 #ifndef initialize_main 759 # ifdef __EMX__ 760 # define initialize_main(pargc, pargv) \ 761 { _wildcard(pargc, pargv); _response(pargc, pargv); } 762 # else 763 # define initialize_main(pargc, pargv) 764 # endif 765 #endif 766 767 #ifdef __EMX__ 768 # if !defined chdir 769 # define chdir _chdir2 770 # endif 771 # if !defined getcwd 772 # define getcwd _getcwd2 773 # endif 774 775 /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of 776 chdir() and getcwd(). This avoids some error messages for the 777 make testsuite but restricts the drive letter support. */ 778 # ifdef NO_CHDIR2 779 # warning NO_CHDIR2: usage of drive letters restricted 780 # undef chdir 781 # undef getcwd 782 # endif 783 #endif 784 785 #ifndef initialize_main 786 # define initialize_main(pargc, pargv) 787 #endif 788 789 790 /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag 791 properly according to POSIX. So, we try to wrap common system calls with 792 checks for EINTR. Note that there are still plenty of system calls that 793 can fail with EINTR but this, reportedly, gets the vast majority of 794 failure cases. If you still experience failures you'll need to either get 795 a system where SA_RESTART works, or you need to avoid -j. */ 796 797 #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR) 798 799 /* While system calls that return integers are pretty consistent about 800 returning -1 on failure and setting errno in that case, functions that 801 return pointers are not always so well behaved. Sometimes they return 802 NULL for expected behavior: one good example is readdir() which returns 803 NULL at the end of the directory--and _doesn't_ reset errno. So, we have 804 to do it ourselves here. */ 805 806 #define ENULLLOOP(_v,_c) do { errno = 0; (_v) = _c; } \ 807 while((_v)==0 && errno==EINTR) 808