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