| 1 | /* Miscellaneous global declarations and portability cruft for GNU Make.
|
|---|
| 2 | Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
|
|---|
| 3 | 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
|
|---|
| 4 | Foundation, Inc.
|
|---|
| 5 | This file is part of GNU Make.
|
|---|
| 6 |
|
|---|
| 7 | GNU Make is free software; you can redistribute it and/or modify it under the
|
|---|
| 8 | terms of the GNU General Public License as published by the Free Software
|
|---|
| 9 | Foundation; either version 2, or (at your option) any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|---|
| 13 | A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License along with
|
|---|
| 16 | GNU Make; see the file COPYING. If not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
|
|---|
| 18 |
|
|---|
| 19 | /* We use <config.h> instead of "config.h" so that a compilation
|
|---|
| 20 | using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
|
|---|
| 21 | (which it would do because make.h was found in $srcdir). */
|
|---|
| 22 | #include <config.h>
|
|---|
| 23 | #undef HAVE_CONFIG_H
|
|---|
| 24 | #define HAVE_CONFIG_H 1
|
|---|
| 25 |
|
|---|
| 26 | /* AIX requires this to be the first thing in the file. */
|
|---|
| 27 | #ifndef __GNUC__
|
|---|
| 28 | # if HAVE_ALLOCA_H
|
|---|
| 29 | # include <alloca.h>
|
|---|
| 30 | # else
|
|---|
| 31 | # ifdef _AIX
|
|---|
| 32 | #pragma alloca
|
|---|
| 33 | # else
|
|---|
| 34 | # ifndef alloca /* predefined by HP cc +Olibcalls */
|
|---|
| 35 | char *alloca ();
|
|---|
| 36 | # endif
|
|---|
| 37 | # endif
|
|---|
| 38 | # endif
|
|---|
| 39 | #endif
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | /* Use prototypes if available. */
|
|---|
| 43 | #if defined (__cplusplus) || defined (__STDC__) || defined WINDOWS32 /* bird: protos on windows */
|
|---|
| 44 | # undef PARAMS
|
|---|
| 45 | # define PARAMS(protos) protos
|
|---|
| 46 | #else /* Not C++ or ANSI C. */
|
|---|
| 47 | # undef PARAMS
|
|---|
| 48 | # define PARAMS(protos) ()
|
|---|
| 49 | #endif /* C++ or ANSI C. */
|
|---|
| 50 |
|
|---|
| 51 | /* Specify we want GNU source code. This must be defined before any
|
|---|
| 52 | system headers are included. */
|
|---|
| 53 |
|
|---|
| 54 | #define _GNU_SOURCE 1
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | #ifdef CRAY
|
|---|
| 58 | /* This must happen before #include <signal.h> so
|
|---|
| 59 | that the declaration therein is changed. */
|
|---|
| 60 | # define signal bsdsignal
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 | /* If we're compiling for the dmalloc debugger, turn off string inlining. */
|
|---|
| 64 | #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
|
|---|
| 65 | # define __NO_STRING_INLINES
|
|---|
| 66 | #endif
|
|---|
| 67 |
|
|---|
| 68 | #include <sys/types.h>
|
|---|
| 69 | #include <sys/stat.h>
|
|---|
| 70 | #include <signal.h>
|
|---|
| 71 | #include <stdio.h>
|
|---|
| 72 | #include <ctype.h>
|
|---|
| 73 | #ifdef HAVE_SYS_TIMEB_H
|
|---|
| 74 | /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
|
|---|
| 75 | unless <sys/timeb.h> has been included first. Does every system have a
|
|---|
| 76 | <sys/timeb.h>? If any does not, configure should check for it. */
|
|---|
| 77 | # include <sys/timeb.h>
|
|---|
| 78 | #endif
|
|---|
| 79 |
|
|---|
| 80 | #if TIME_WITH_SYS_TIME
|
|---|
| 81 | # include <sys/time.h>
|
|---|
| 82 | # include <time.h>
|
|---|
| 83 | #else
|
|---|
| 84 | # if HAVE_SYS_TIME_H
|
|---|
| 85 | # include <sys/time.h>
|
|---|
| 86 | # else
|
|---|
| 87 | # include <time.h>
|
|---|
| 88 | # endif
|
|---|
| 89 | #endif
|
|---|
| 90 |
|
|---|
| 91 | #include <errno.h>
|
|---|
| 92 |
|
|---|
| 93 | #ifndef errno
|
|---|
| 94 | extern int errno;
|
|---|
| 95 | #endif
|
|---|
| 96 |
|
|---|
| 97 | #ifndef isblank
|
|---|
| 98 | # define isblank(c) ((c) == ' ' || (c) == '\t')
|
|---|
| 99 | #endif
|
|---|
| 100 |
|
|---|
| 101 | #ifdef HAVE_UNISTD_H
|
|---|
| 102 | # include <unistd.h>
|
|---|
| 103 | /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
|
|---|
| 104 | POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
|
|---|
| 105 | # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
|
|---|
| 106 | # define POSIX 1
|
|---|
| 107 | # endif
|
|---|
| 108 | #endif
|
|---|
| 109 |
|
|---|
| 110 | /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
|
|---|
| 111 | #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
|
|---|
| 112 | # undef POSIX
|
|---|
| 113 | #endif
|
|---|
| 114 |
|
|---|
| 115 | #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
|
|---|
| 116 | # define POSIX 1
|
|---|
| 117 | #endif
|
|---|
| 118 |
|
|---|
| 119 | #ifndef RETSIGTYPE
|
|---|
| 120 | # define RETSIGTYPE void
|
|---|
| 121 | #endif
|
|---|
| 122 |
|
|---|
| 123 | #ifndef sigmask
|
|---|
| 124 | # define sigmask(sig) (1 << ((sig) - 1))
|
|---|
| 125 | #endif
|
|---|
| 126 |
|
|---|
| 127 | #ifndef HAVE_SA_RESTART
|
|---|
| 128 | # define SA_RESTART 0
|
|---|
| 129 | #endif
|
|---|
| 130 |
|
|---|
| 131 | #ifdef HAVE_LIMITS_H
|
|---|
| 132 | # include <limits.h>
|
|---|
| 133 | #endif
|
|---|
| 134 | #ifdef HAVE_SYS_PARAM_H
|
|---|
| 135 | # include <sys/param.h>
|
|---|
| 136 | #endif
|
|---|
| 137 |
|
|---|
| 138 | #ifndef PATH_MAX
|
|---|
| 139 | # ifndef POSIX
|
|---|
| 140 | # define PATH_MAX MAXPATHLEN
|
|---|
| 141 | # endif
|
|---|
| 142 | #endif
|
|---|
| 143 | #ifndef MAXPATHLEN
|
|---|
| 144 | # define MAXPATHLEN 1024
|
|---|
| 145 | #endif
|
|---|
| 146 |
|
|---|
| 147 | #ifdef PATH_MAX
|
|---|
| 148 | # define GET_PATH_MAX PATH_MAX
|
|---|
| 149 | # define PATH_VAR(var) char var[PATH_MAX]
|
|---|
| 150 | #else
|
|---|
| 151 | # define NEED_GET_PATH_MAX 1
|
|---|
| 152 | # define GET_PATH_MAX (get_path_max ())
|
|---|
| 153 | # define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
|
|---|
| 154 | extern unsigned int get_path_max PARAMS ((void));
|
|---|
| 155 | #endif
|
|---|
| 156 |
|
|---|
| 157 | #ifndef CHAR_BIT
|
|---|
| 158 | # define CHAR_BIT 8
|
|---|
| 159 | #endif
|
|---|
| 160 |
|
|---|
| 161 | /* Nonzero if the integer type T is signed. */
|
|---|
| 162 | #define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
|
|---|
| 163 |
|
|---|
| 164 | /* The minimum and maximum values for the integer type T.
|
|---|
| 165 | Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
|
|---|
| 166 | #define INTEGER_TYPE_MINIMUM(t) \
|
|---|
| 167 | (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
|
|---|
| 168 | #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
|
|---|
| 169 |
|
|---|
| 170 | #ifndef CHAR_MAX
|
|---|
| 171 | # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
|
|---|
| 172 | #endif
|
|---|
| 173 |
|
|---|
| 174 | #ifdef STAT_MACROS_BROKEN
|
|---|
| 175 | # ifdef S_ISREG
|
|---|
| 176 | # undef S_ISREG
|
|---|
| 177 | # endif
|
|---|
| 178 | # ifdef S_ISDIR
|
|---|
| 179 | # undef S_ISDIR
|
|---|
| 180 | # endif
|
|---|
| 181 | #endif /* STAT_MACROS_BROKEN. */
|
|---|
| 182 |
|
|---|
| 183 | #ifndef S_ISREG
|
|---|
| 184 | # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
|---|
| 185 | #endif
|
|---|
| 186 | #ifndef S_ISDIR
|
|---|
| 187 | # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
|---|
| 188 | #endif
|
|---|
| 189 |
|
|---|
| 190 | #ifdef VMS
|
|---|
| 191 | # include <types.h>
|
|---|
| 192 | # include <unixlib.h>
|
|---|
| 193 | # include <unixio.h>
|
|---|
| 194 | # include <perror.h>
|
|---|
| 195 | /* Needed to use alloca on VMS. */
|
|---|
| 196 | # include <builtins.h>
|
|---|
| 197 | #endif
|
|---|
| 198 |
|
|---|
| 199 | #ifndef __attribute__
|
|---|
| 200 | /* This feature is available in gcc versions 2.5 and later. */
|
|---|
| 201 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
|
|---|
| 202 | # define __attribute__(x)
|
|---|
| 203 | # endif
|
|---|
| 204 | /* The __-protected variants of `format' and `printf' attributes
|
|---|
| 205 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
|---|
| 206 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
|---|
| 207 | # define __format__ format
|
|---|
| 208 | # define __printf__ printf
|
|---|
| 209 | # endif
|
|---|
| 210 | #endif
|
|---|
| 211 | #define UNUSED __attribute__ ((unused))
|
|---|
| 212 |
|
|---|
| 213 | #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
|
|---|
| 214 | # include <stdlib.h>
|
|---|
| 215 | # include <string.h>
|
|---|
| 216 | # define ANSI_STRING 1
|
|---|
| 217 | #else /* No standard headers. */
|
|---|
| 218 | # ifdef HAVE_STRING_H
|
|---|
| 219 | # include <string.h>
|
|---|
| 220 | # define ANSI_STRING 1
|
|---|
| 221 | # else
|
|---|
| 222 | # include <strings.h>
|
|---|
| 223 | # endif
|
|---|
| 224 | # ifdef HAVE_MEMORY_H
|
|---|
| 225 | # include <memory.h>
|
|---|
| 226 | # endif
|
|---|
| 227 | # ifdef HAVE_STDLIB_H
|
|---|
| 228 | # include <stdlib.h>
|
|---|
| 229 | # else
|
|---|
| 230 | extern char *malloc PARAMS ((int));
|
|---|
| 231 | extern char *realloc PARAMS ((char *, int));
|
|---|
| 232 | extern void free PARAMS ((char *));
|
|---|
| 233 |
|
|---|
| 234 | extern void abort PARAMS ((void)) __attribute__ ((noreturn));
|
|---|
| 235 | extern void exit PARAMS ((int)) __attribute__ ((noreturn));
|
|---|
| 236 | # endif /* HAVE_STDLIB_H. */
|
|---|
| 237 |
|
|---|
| 238 | #endif /* Standard headers. */
|
|---|
| 239 |
|
|---|
| 240 | /* These should be in stdlib.h. Make sure we have them. */
|
|---|
| 241 | #ifndef EXIT_SUCCESS
|
|---|
| 242 | # define EXIT_SUCCESS 0
|
|---|
| 243 | #endif
|
|---|
| 244 | #ifndef EXIT_FAILURE
|
|---|
| 245 | # define EXIT_FAILURE 0
|
|---|
| 246 | #endif
|
|---|
| 247 |
|
|---|
| 248 | #ifdef ANSI_STRING
|
|---|
| 249 |
|
|---|
| 250 | # ifndef bcmp
|
|---|
| 251 | # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
|
|---|
| 252 | # endif
|
|---|
| 253 | # ifndef bzero
|
|---|
| 254 | # define bzero(s, n) memset ((s), 0, (n))
|
|---|
| 255 | # endif
|
|---|
| 256 | # if defined(HAVE_MEMMOVE) && !defined(bcopy)
|
|---|
| 257 | # define bcopy(s, d, n) memmove ((d), (s), (n))
|
|---|
| 258 | # endif
|
|---|
| 259 |
|
|---|
| 260 | #else /* Not ANSI_STRING. */
|
|---|
| 261 |
|
|---|
| 262 | # ifndef HAVE_STRCHR
|
|---|
| 263 | # define strchr(s, c) index((s), (c))
|
|---|
| 264 | # define strrchr(s, c) rindex((s), (c))
|
|---|
| 265 | # endif
|
|---|
| 266 |
|
|---|
| 267 | # ifndef bcmp
|
|---|
| 268 | extern int bcmp PARAMS ((const char *, const char *, int));
|
|---|
| 269 | # endif
|
|---|
| 270 | # ifndef bzero
|
|---|
| 271 | extern void bzero PARAMS ((char *, int));
|
|---|
| 272 | #endif
|
|---|
| 273 | # ifndef bcopy
|
|---|
| 274 | extern void bcopy PARAMS ((const char *b1, char *b2, int));
|
|---|
| 275 | # endif
|
|---|
| 276 |
|
|---|
| 277 | /* SCO Xenix has a buggy macro definition in <string.h>. */
|
|---|
| 278 | #undef strerror
|
|---|
| 279 | #if !defined(__DECC)
|
|---|
| 280 | extern char *strerror PARAMS ((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 | #define FILE_TIMESTAMP uintmax_t
|
|---|
| 290 |
|
|---|
| 291 | #if !defined(HAVE_STRSIGNAL)
|
|---|
| 292 | extern char *strsignal PARAMS ((int signum));
|
|---|
| 293 | #endif
|
|---|
| 294 |
|
|---|
| 295 | /* ISDIGIT offers the following features:
|
|---|
| 296 | - Its arg may be any int or unsigned int; it need not be an unsigned char.
|
|---|
| 297 | - It's guaranteed to evaluate its argument exactly once.
|
|---|
| 298 | NOTE! Make relies on this behavior, don't change it!
|
|---|
| 299 | - It's typically faster.
|
|---|
| 300 | POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
|
|---|
| 301 | only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
|
|---|
| 302 | it's important to use the locale's definition of `digit' even when the
|
|---|
| 303 | host does not conform to POSIX. */
|
|---|
| 304 | #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
|
|---|
| 305 |
|
|---|
| 306 | #ifndef iAPX286
|
|---|
| 307 | # define streq(a, b) \
|
|---|
| 308 | ((a) == (b) || \
|
|---|
| 309 | (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
|
|---|
| 310 | # ifdef HAVE_CASE_INSENSITIVE_FS
|
|---|
| 311 | /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
|
|---|
| 312 | # define strieq(a, b) \
|
|---|
| 313 | ((a) == (b) \
|
|---|
| 314 | || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
|
|---|
| 315 | && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
|
|---|
| 316 | # else
|
|---|
| 317 | # define strieq(a, b) streq(a, b)
|
|---|
| 318 | # endif
|
|---|
| 319 | #else
|
|---|
| 320 | /* Buggy compiler can't handle this. */
|
|---|
| 321 | # define streq(a, b) (strcmp ((a), (b)) == 0)
|
|---|
| 322 | # define strieq(a, b) (strcmp ((a), (b)) == 0)
|
|---|
| 323 | #endif
|
|---|
| 324 | #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
|
|---|
| 325 | #ifdef VMS
|
|---|
| 326 | extern int strcmpi (const char *,const char *);
|
|---|
| 327 | #endif
|
|---|
| 328 |
|
|---|
| 329 | #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
|
|---|
| 330 | # define ENUM_BITFIELD(bits) :bits
|
|---|
| 331 | #else
|
|---|
| 332 | # define ENUM_BITFIELD(bits)
|
|---|
| 333 | #endif
|
|---|
| 334 |
|
|---|
| 335 | /* Handle gettext and locales. */
|
|---|
| 336 |
|
|---|
| 337 | #if HAVE_LOCALE_H
|
|---|
| 338 | # include <locale.h>
|
|---|
| 339 | #else
|
|---|
| 340 | # define setlocale(category, locale)
|
|---|
| 341 | #endif
|
|---|
| 342 |
|
|---|
| 343 | #include <gettext.h>
|
|---|
| 344 |
|
|---|
| 345 | #define _(msgid) gettext (msgid)
|
|---|
| 346 | #define N_(msgid) gettext_noop (msgid)
|
|---|
| 347 | #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
|
|---|
| 348 |
|
|---|
| 349 | /* Handle other OSs. */
|
|---|
| 350 | #if defined(HAVE_DOS_PATHS)
|
|---|
| 351 | # define PATH_SEPARATOR_CHAR ';'
|
|---|
| 352 | #elif defined(VMS)
|
|---|
| 353 | # define PATH_SEPARATOR_CHAR ','
|
|---|
| 354 | #else
|
|---|
| 355 | # define PATH_SEPARATOR_CHAR ':'
|
|---|
| 356 | #endif
|
|---|
| 357 |
|
|---|
| 358 | /* This is needed for getcwd() and chdir(). */
|
|---|
| 359 | #if defined(_MSC_VER) || defined(__BORLANDC__)
|
|---|
| 360 | # include <direct.h>
|
|---|
| 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 |
|
|---|
| 369 | extern void sync_Path_environment(void);
|
|---|
| 370 | extern int kill(int pid, int sig);
|
|---|
| 371 | extern char *end_of_token_w32(char *s, char stopchar);
|
|---|
| 372 | extern int find_and_set_default_shell(char *token);
|
|---|
| 373 |
|
|---|
| 374 | /* indicates whether or not we have Bourne shell */
|
|---|
| 375 | extern int no_default_sh_exe;
|
|---|
| 376 |
|
|---|
| 377 | /* is default_shell unixy? */
|
|---|
| 378 | extern int unixy_shell;
|
|---|
| 379 | #endif /* WINDOWS32 */
|
|---|
| 380 |
|
|---|
| 381 | struct floc
|
|---|
| 382 | {
|
|---|
| 383 | const char *filenm;
|
|---|
| 384 | unsigned long lineno;
|
|---|
| 385 | };
|
|---|
| 386 | #define NILF ((struct floc *)0)
|
|---|
| 387 |
|
|---|
| 388 | #define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
|
|---|
| 389 |
|
|---|
| 390 | |
|---|
| 391 |
|
|---|
| 392 | /* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
|
|---|
| 393 | variadic versions of these functions. */
|
|---|
| 394 |
|
|---|
| 395 | #if HAVE_STDARG_H || HAVE_VARARGS_H
|
|---|
| 396 | # if HAVE_VPRINTF || HAVE_DOPRNT
|
|---|
| 397 | # define USE_VARIADIC 1
|
|---|
| 398 | # endif
|
|---|
| 399 | #endif
|
|---|
| 400 |
|
|---|
| 401 | #if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
|
|---|
| 402 | extern void message (int prefix, const char *fmt, ...)
|
|---|
| 403 | __attribute__ ((__format__ (__printf__, 2, 3)));
|
|---|
| 404 | extern void error (const struct floc *flocp, const char *fmt, ...)
|
|---|
| 405 | __attribute__ ((__format__ (__printf__, 2, 3)));
|
|---|
| 406 | extern void fatal (const struct floc *flocp, const char *fmt, ...)
|
|---|
| 407 | __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
|
|---|
| 408 | #else
|
|---|
| 409 | extern void message ();
|
|---|
| 410 | extern void error ();
|
|---|
| 411 | extern void fatal ();
|
|---|
| 412 | #endif
|
|---|
| 413 |
|
|---|
| 414 | extern void die PARAMS ((int)) __attribute__ ((noreturn));
|
|---|
| 415 | extern void log_working_directory PARAMS ((int));
|
|---|
| 416 | extern void pfatal_with_name PARAMS ((const char *)) __attribute__ ((noreturn));
|
|---|
| 417 | extern void perror_with_name PARAMS ((const char *, const char *));
|
|---|
| 418 | extern char *savestring PARAMS ((const char *, unsigned int));
|
|---|
| 419 | extern char *concat PARAMS ((const char *, const char *, const char *));
|
|---|
| 420 | extern char *xmalloc PARAMS ((unsigned int));
|
|---|
| 421 | extern char *xrealloc PARAMS ((char *, unsigned int));
|
|---|
| 422 | extern char *xstrdup PARAMS ((const char *));
|
|---|
| 423 | extern char *find_next_token PARAMS ((char **, unsigned int *));
|
|---|
| 424 | extern char *next_token PARAMS ((const char *));
|
|---|
| 425 | extern char *end_of_token PARAMS ((const char *));
|
|---|
| 426 | extern void collapse_continuations PARAMS ((char *));
|
|---|
| 427 | #ifdef CONFIG_WITH_OPTIMIZATION_HACKS /* memchr is usually compiler intrinsic, thus faster. */
|
|---|
| 428 | #define lindex(s, limit, c) ((char *)memchr((s), (c), (limit) - (s)))
|
|---|
| 429 | #else
|
|---|
| 430 | extern char *lindex PARAMS ((const char *, const char *, int));
|
|---|
| 431 | #endif
|
|---|
| 432 | extern int alpha_compare PARAMS ((const void *, const void *));
|
|---|
| 433 | extern void print_spaces PARAMS ((unsigned int));
|
|---|
| 434 | extern char *find_percent PARAMS ((char *));
|
|---|
| 435 | extern FILE *open_tmpfile PARAMS ((char **, const char *));
|
|---|
| 436 |
|
|---|
| 437 | #ifndef NO_ARCHIVES
|
|---|
| 438 | extern int ar_name PARAMS ((char *));
|
|---|
| 439 | extern void ar_parse_name PARAMS ((char *, char **, char **));
|
|---|
| 440 | extern int ar_touch PARAMS ((char *));
|
|---|
| 441 | extern time_t ar_member_date PARAMS ((char *));
|
|---|
| 442 | #endif
|
|---|
| 443 |
|
|---|
| 444 | extern int dir_file_exists_p PARAMS ((char *, char *));
|
|---|
| 445 | extern int file_exists_p PARAMS ((char *));
|
|---|
| 446 | extern int file_impossible_p PARAMS ((char *));
|
|---|
| 447 | extern void file_impossible PARAMS ((char *));
|
|---|
| 448 | extern char *dir_name PARAMS ((char *));
|
|---|
| 449 | extern void hash_init_directories PARAMS ((void));
|
|---|
| 450 |
|
|---|
| 451 | extern void define_default_variables PARAMS ((void));
|
|---|
| 452 | extern void set_default_suffixes PARAMS ((void));
|
|---|
| 453 | extern void install_default_suffix_rules PARAMS ((void));
|
|---|
| 454 | extern void install_default_implicit_rules PARAMS ((void));
|
|---|
| 455 |
|
|---|
| 456 | extern void build_vpath_lists PARAMS ((void));
|
|---|
| 457 | extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath));
|
|---|
| 458 | extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr));
|
|---|
| 459 | extern int gpath_search PARAMS ((char *file, unsigned int len));
|
|---|
| 460 |
|
|---|
| 461 | extern void construct_include_path PARAMS ((char **arg_dirs));
|
|---|
| 462 |
|
|---|
| 463 | extern void user_access PARAMS ((void));
|
|---|
| 464 | extern void make_access PARAMS ((void));
|
|---|
| 465 | extern void child_access PARAMS ((void));
|
|---|
| 466 |
|
|---|
| 467 | extern void close_stdout PARAMS ((void));
|
|---|
| 468 |
|
|---|
| 469 | extern char *strip_whitespace PARAMS ((const char **begpp, const char **endpp));
|
|---|
| 470 |
|
|---|
| 471 | /* String caching */
|
|---|
| 472 | extern void strcache_init PARAMS ((void));
|
|---|
| 473 | extern void strcache_print_stats PARAMS ((const char *prefix));
|
|---|
| 474 | extern int strcache_iscached PARAMS ((const char *str));
|
|---|
| 475 | extern const char *strcache_add PARAMS ((const char *str));
|
|---|
| 476 | extern const char *strcache_add_len PARAMS ((const char *str, int len));
|
|---|
| 477 | extern int strcache_setbufsize PARAMS ((int size));
|
|---|
| 478 |
|
|---|
| 479 | #ifdef HAVE_VFORK_H
|
|---|
| 480 | # include <vfork.h>
|
|---|
| 481 | #endif
|
|---|
| 482 |
|
|---|
| 483 | /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
|
|---|
| 484 | because such systems often declare them in header files anyway. */
|
|---|
| 485 |
|
|---|
| 486 | #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
|
|---|
| 487 |
|
|---|
| 488 | extern long int atol ();
|
|---|
| 489 | # ifndef VMS
|
|---|
| 490 | extern long int lseek ();
|
|---|
| 491 | # endif
|
|---|
| 492 |
|
|---|
| 493 | #endif /* Not GNU C library or POSIX. */
|
|---|
| 494 |
|
|---|
| 495 | #ifdef HAVE_GETCWD
|
|---|
| 496 | # if !defined(VMS) && !defined(__DECC)
|
|---|
| 497 | extern char *getcwd ();
|
|---|
| 498 | # endif
|
|---|
| 499 | #else
|
|---|
| 500 | extern char *getwd ();
|
|---|
| 501 | # define getcwd(buf, len) getwd (buf)
|
|---|
| 502 | #endif
|
|---|
| 503 |
|
|---|
| 504 | extern const struct floc *reading_file;
|
|---|
| 505 | extern const struct floc **expanding_var;
|
|---|
| 506 |
|
|---|
| 507 | extern char **environ;
|
|---|
| 508 |
|
|---|
| 509 | extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
|
|---|
| 510 | extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
|
|---|
| 511 | extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
|
|---|
| 512 | extern int print_version_flag, print_directory_flag, check_symlink_flag;
|
|---|
| 513 | extern int warn_undefined_variables_flag, posix_pedantic, not_parallel;
|
|---|
| 514 | extern int second_expansion, clock_skew_detected, rebuilding_makefiles;
|
|---|
| 515 | #ifdef CONFIG_PRETTY_COMMAND_PRINTING
|
|---|
| 516 | extern int pretty_command_printing;
|
|---|
| 517 | #endif
|
|---|
| 518 |
|
|---|
| 519 | /* can we run commands via 'sh -c xxx' or must we use batch files? */
|
|---|
| 520 | extern int batch_mode_shell;
|
|---|
| 521 |
|
|---|
| 522 | extern unsigned int job_slots;
|
|---|
| 523 | extern int job_fds[2];
|
|---|
| 524 | extern int job_rfd;
|
|---|
| 525 | #ifndef NO_FLOAT
|
|---|
| 526 | extern double max_load_average;
|
|---|
| 527 | #else
|
|---|
| 528 | extern int max_load_average;
|
|---|
| 529 | #endif
|
|---|
| 530 |
|
|---|
| 531 | extern char *program;
|
|---|
| 532 | extern char *starting_directory;
|
|---|
| 533 | extern unsigned int makelevel;
|
|---|
| 534 | extern char *version_string, *remote_description, *make_host;
|
|---|
| 535 |
|
|---|
| 536 | extern unsigned int commands_started;
|
|---|
| 537 |
|
|---|
| 538 | extern int handling_fatal_signal;
|
|---|
| 539 |
|
|---|
| 540 |
|
|---|
| 541 | #ifndef MIN
|
|---|
| 542 | #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
|
|---|
| 543 | #endif
|
|---|
| 544 | #ifndef MAX
|
|---|
| 545 | #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
|
|---|
| 546 | #endif
|
|---|
| 547 |
|
|---|
| 548 | #ifdef VMS
|
|---|
| 549 | # define MAKE_SUCCESS 1
|
|---|
| 550 | # define MAKE_TROUBLE 2
|
|---|
| 551 | # define MAKE_FAILURE 3
|
|---|
| 552 | #else
|
|---|
| 553 | # define MAKE_SUCCESS 0
|
|---|
| 554 | # define MAKE_TROUBLE 1
|
|---|
| 555 | # define MAKE_FAILURE 2
|
|---|
| 556 | #endif
|
|---|
| 557 |
|
|---|
| 558 | /* Set up heap debugging library dmalloc. */
|
|---|
| 559 |
|
|---|
| 560 | #ifdef HAVE_DMALLOC_H
|
|---|
| 561 | #include <dmalloc.h>
|
|---|
| 562 | #endif
|
|---|
| 563 |
|
|---|
| 564 | #ifndef initialize_main
|
|---|
| 565 | # ifdef __EMX__
|
|---|
| 566 | # define initialize_main(pargc, pargv) \
|
|---|
| 567 | { _wildcard(pargc, pargv); _response(pargc, pargv); }
|
|---|
| 568 | # else
|
|---|
| 569 | # define initialize_main(pargc, pargv)
|
|---|
| 570 | # endif
|
|---|
| 571 | #endif
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 | #ifdef __EMX__
|
|---|
| 575 | # if !HAVE_STRCASECMP
|
|---|
| 576 | # define strcasecmp stricmp
|
|---|
| 577 | # endif
|
|---|
| 578 |
|
|---|
| 579 | # if !defined chdir
|
|---|
| 580 | # define chdir _chdir2
|
|---|
| 581 | # endif
|
|---|
| 582 | # if !defined getcwd
|
|---|
| 583 | # define getcwd _getcwd2
|
|---|
| 584 | # endif
|
|---|
| 585 |
|
|---|
| 586 | /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
|
|---|
| 587 | chdir() and getcwd(). This avoids some error messages for the
|
|---|
| 588 | make testsuite but restricts the drive letter support. */
|
|---|
| 589 | # ifdef NO_CHDIR2
|
|---|
| 590 | # warning NO_CHDIR2: usage of drive letters restricted
|
|---|
| 591 | # undef chdir
|
|---|
| 592 | # undef getcwd
|
|---|
| 593 | # endif
|
|---|
| 594 | #endif
|
|---|
| 595 |
|
|---|
| 596 | #ifndef initialize_main
|
|---|
| 597 | # define initialize_main(pargc, pargv)
|
|---|
| 598 | #endif
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 | /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
|
|---|
| 602 | properly according to POSIX. So, we try to wrap common system calls with
|
|---|
| 603 | checks for EINTR. Note that there are still plenty of system calls that
|
|---|
| 604 | can fail with EINTR but this, reportedly, gets the vast majority of
|
|---|
| 605 | failure cases. If you still experience failures you'll need to either get
|
|---|
| 606 | a system where SA_RESTART works, or you need to avoid -j. */
|
|---|
| 607 |
|
|---|
| 608 | #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
|
|---|
| 609 |
|
|---|
| 610 | /* While system calls that return integers are pretty consistent about
|
|---|
| 611 | returning -1 on failure and setting errno in that case, functions that
|
|---|
| 612 | return pointers are not always so well behaved. Sometimes they return
|
|---|
| 613 | NULL for expected behavior: one good example is readdir() which returns
|
|---|
| 614 | NULL at the end of the directory--and _doesn't_ reset errno. So, we have
|
|---|
| 615 | to do it ourselves here. */
|
|---|
| 616 |
|
|---|
| 617 | #define ENULLLOOP(_v,_c) do{ errno = 0; \
|
|---|
| 618 | while (((_v)=_c)==0 && errno==EINTR); }while(0)
|
|---|
| 619 |
|
|---|
| 620 | #if defined(__EMX__) && defined(CONFIG_WITH_OPTIMIZATION_HACKS) /* bird: saves 40-100ms on libc. */
|
|---|
| 621 | static inline void *__my_rawmemchr (const void *__s, int __c);
|
|---|
| 622 | #undef strchr
|
|---|
| 623 | #define strchr(s, c) \
|
|---|
| 624 | (__extension__ (__builtin_constant_p (c) \
|
|---|
| 625 | ? ((c) == '\0' \
|
|---|
| 626 | ? (char *) __my_rawmemchr ((s), (c)) \
|
|---|
| 627 | : __my_strchr_c ((s), ((c) & 0xff) << 8)) \
|
|---|
| 628 | : __my_strchr_g ((s), (c))))
|
|---|
| 629 | static inline char *__my_strchr_c (const char *__s, int __c)
|
|---|
| 630 | {
|
|---|
| 631 | register unsigned long int __d0;
|
|---|
| 632 | register char *__res;
|
|---|
| 633 | __asm__ __volatile__
|
|---|
| 634 | ("1:\n\t"
|
|---|
| 635 | "movb (%0),%%al\n\t"
|
|---|
| 636 | "cmpb %%ah,%%al\n\t"
|
|---|
| 637 | "je 2f\n\t"
|
|---|
| 638 | "leal 1(%0),%0\n\t"
|
|---|
| 639 | "testb %%al,%%al\n\t"
|
|---|
| 640 | "jne 1b\n\t"
|
|---|
| 641 | "xorl %0,%0\n"
|
|---|
| 642 | "2:"
|
|---|
| 643 | : "=r" (__res), "=&a" (__d0)
|
|---|
| 644 | : "0" (__s), "1" (__c),
|
|---|
| 645 | "m" ( *(struct { char __x[0xfffffff]; } *)__s)
|
|---|
| 646 | : "cc");
|
|---|
| 647 | return __res;
|
|---|
| 648 | }
|
|---|
| 649 |
|
|---|
| 650 | static inline char *__my_strchr_g (__const char *__s, int __c)
|
|---|
| 651 | {
|
|---|
| 652 | register unsigned long int __d0;
|
|---|
| 653 | register char *__res;
|
|---|
| 654 | __asm__ __volatile__
|
|---|
| 655 | ("movb %%al,%%ah\n"
|
|---|
| 656 | "1:\n\t"
|
|---|
| 657 | "movb (%0),%%al\n\t"
|
|---|
| 658 | "cmpb %%ah,%%al\n\t"
|
|---|
| 659 | "je 2f\n\t"
|
|---|
| 660 | "leal 1(%0),%0\n\t"
|
|---|
| 661 | "testb %%al,%%al\n\t"
|
|---|
| 662 | "jne 1b\n\t"
|
|---|
| 663 | "xorl %0,%0\n"
|
|---|
| 664 | "2:"
|
|---|
| 665 | : "=r" (__res), "=&a" (__d0)
|
|---|
| 666 | : "0" (__s), "1" (__c),
|
|---|
| 667 | "m" ( *(struct { char __x[0xfffffff]; } *)__s)
|
|---|
| 668 | : "cc");
|
|---|
| 669 | return __res;
|
|---|
| 670 | }
|
|---|
| 671 |
|
|---|
| 672 | static inline void *__my_rawmemchr (const void *__s, int __c)
|
|---|
| 673 | {
|
|---|
| 674 | register unsigned long int __d0;
|
|---|
| 675 | register unsigned char *__res;
|
|---|
| 676 | __asm__ __volatile__
|
|---|
| 677 | ("cld\n\t"
|
|---|
| 678 | "repne; scasb\n\t"
|
|---|
| 679 | : "=D" (__res), "=&c" (__d0)
|
|---|
| 680 | : "a" (__c), "0" (__s), "1" (0xffffffff),
|
|---|
| 681 | "m" ( *(struct { char __x[0xfffffff]; } *)__s)
|
|---|
| 682 | : "cc");
|
|---|
| 683 | return __res - 1;
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 | #undef memchr
|
|---|
| 687 | #define memchr(a,b,c) __my_memchr((a),(b),(c))
|
|---|
| 688 | static inline void *__my_memchr (__const void *__s, int __c, size_t __n)
|
|---|
| 689 | {
|
|---|
| 690 | register unsigned long int __d0;
|
|---|
| 691 | register unsigned char *__res;
|
|---|
| 692 | if (__n == 0)
|
|---|
| 693 | return NULL;
|
|---|
| 694 | __asm__ __volatile__
|
|---|
| 695 | ("repne; scasb\n\t"
|
|---|
| 696 | "je 1f\n\t"
|
|---|
| 697 | "movl $1,%0\n"
|
|---|
| 698 | "1:"
|
|---|
| 699 | : "=D" (__res), "=&c" (__d0)
|
|---|
| 700 | : "a" (__c), "0" (__s), "1" (__n),
|
|---|
| 701 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
|
|---|
| 702 | : "cc");
|
|---|
| 703 | return __res - 1;
|
|---|
| 704 | }
|
|---|
| 705 |
|
|---|
| 706 | #endif /* __EMX__ (bird) */
|
|---|