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