[53] | 1 | /* Miscellaneous global declarations and portability cruft for GNU Make.
|
---|
[3140] | 2 | Copyright (C) 1988-2016 Free Software Foundation, Inc.
|
---|
[53] | 3 | This file is part of GNU Make.
|
---|
| 4 |
|
---|
[503] | 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
|
---|
[1993] | 7 | Foundation; either version 3 of the License, or (at your option) any later
|
---|
| 8 | version.
|
---|
[53] | 9 |
|
---|
[503] | 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.
|
---|
[53] | 13 |
|
---|
[503] | 14 | You should have received a copy of the GNU General Public License along with
|
---|
[1993] | 15 | this program. If not, see <http://www.gnu.org/licenses/>. */
|
---|
[53] | 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
|
---|
[3140] | 19 | (which it would do because makeint.h was found in $srcdir). */
|
---|
[53] | 20 | #include <config.h>
|
---|
| 21 | #undef HAVE_CONFIG_H
|
---|
| 22 | #define HAVE_CONFIG_H 1
|
---|
| 23 |
|
---|
[3140] | 24 | #include <k/kDefs.h> /* bird */
|
---|
| 25 |
|
---|
[2591] | 26 | /* Specify we want GNU source code. This must be defined before any
|
---|
| 27 | system headers are included. */
|
---|
| 28 |
|
---|
| 29 | #define _GNU_SOURCE 1
|
---|
| 30 |
|
---|
[53] | 31 | /* AIX requires this to be the first thing in the file. */
|
---|
[2591] | 32 | #if HAVE_ALLOCA_H
|
---|
| 33 | # include <alloca.h>
|
---|
| 34 | #else
|
---|
| 35 | # ifdef _AIX
|
---|
| 36 | #pragma alloca
|
---|
[53] | 37 | # else
|
---|
[2591] | 38 | # if !defined(__GNUC__) && !defined(WINDOWS32)
|
---|
[53] | 39 | # ifndef alloca /* predefined by HP cc +Olibcalls */
|
---|
| 40 | char *alloca ();
|
---|
| 41 | # endif
|
---|
| 42 | # endif
|
---|
| 43 | # endif
|
---|
| 44 | #endif
|
---|
| 45 |
|
---|
[3140] | 46 | /* Disable assert() unless we're a maintainer.
|
---|
| 47 | Some asserts are compute-intensive. */
|
---|
| 48 | #ifndef MAKE_MAINTAINER_MODE
|
---|
| 49 | # define NDEBUG 1
|
---|
| 50 | #endif
|
---|
[53] | 51 |
|
---|
[3140] | 52 | /* Include the externally-visible content.
|
---|
| 53 | Be sure to use the local one, and not one installed on the system.
|
---|
| 54 | Define GMK_BUILDING_MAKE for proper selection of dllexport/dllimport
|
---|
| 55 | declarations for MS-Windows. */
|
---|
| 56 | #ifdef WINDOWS32
|
---|
| 57 | # define GMK_BUILDING_MAKE
|
---|
| 58 | #endif
|
---|
| 59 | #include "gnumake.h"
|
---|
| 60 |
|
---|
[53] | 61 | #ifdef CRAY
|
---|
| 62 | /* This must happen before #include <signal.h> so
|
---|
| 63 | that the declaration therein is changed. */
|
---|
| 64 | # define signal bsdsignal
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 | /* If we're compiling for the dmalloc debugger, turn off string inlining. */
|
---|
| 68 | #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
|
---|
| 69 | # define __NO_STRING_INLINES
|
---|
| 70 | #endif
|
---|
| 71 |
|
---|
| 72 | #include <sys/types.h>
|
---|
| 73 | #include <sys/stat.h>
|
---|
| 74 | #include <signal.h>
|
---|
| 75 | #include <stdio.h>
|
---|
| 76 | #include <ctype.h>
|
---|
[3140] | 77 |
|
---|
[53] | 78 | #ifdef HAVE_SYS_TIMEB_H
|
---|
[3140] | 79 | /* SCO 3.2 "devsys 4.2" has a prototype for 'ftime' in <time.h> that bombs
|
---|
| 80 | unless <sys/timeb.h> has been included first. */
|
---|
[53] | 81 | # include <sys/timeb.h>
|
---|
| 82 | #endif
|
---|
| 83 | #if TIME_WITH_SYS_TIME
|
---|
| 84 | # include <sys/time.h>
|
---|
| 85 | # include <time.h>
|
---|
| 86 | #else
|
---|
| 87 | # if HAVE_SYS_TIME_H
|
---|
| 88 | # include <sys/time.h>
|
---|
| 89 | # else
|
---|
| 90 | # include <time.h>
|
---|
| 91 | # endif
|
---|
| 92 | #endif
|
---|
| 93 |
|
---|
| 94 | #include <errno.h>
|
---|
| 95 |
|
---|
| 96 | #ifndef errno
|
---|
| 97 | extern int errno;
|
---|
| 98 | #endif
|
---|
| 99 |
|
---|
[3140] | 100 | #ifdef __VMS
|
---|
| 101 | /* In strict ANSI mode, VMS compilers should not be defining the
|
---|
| 102 | VMS macro. Define it here instead of a bulk edit for the correct code.
|
---|
| 103 | */
|
---|
| 104 | # ifndef VMS
|
---|
| 105 | # define VMS
|
---|
| 106 | # endif
|
---|
[53] | 107 | #endif
|
---|
| 108 |
|
---|
| 109 | #ifdef HAVE_UNISTD_H
|
---|
| 110 | # include <unistd.h>
|
---|
| 111 | /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
|
---|
[3140] | 112 | POSIX.1 behavior with 'cc -YPOSIX', which predefines POSIX itself! */
|
---|
[53] | 113 | # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
|
---|
| 114 | # define POSIX 1
|
---|
| 115 | # endif
|
---|
| 116 | #endif
|
---|
| 117 |
|
---|
| 118 | /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
|
---|
| 119 | #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
|
---|
| 120 | # undef POSIX
|
---|
| 121 | #endif
|
---|
| 122 |
|
---|
| 123 | #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
|
---|
| 124 | # define POSIX 1
|
---|
| 125 | #endif
|
---|
| 126 |
|
---|
| 127 | #ifndef RETSIGTYPE
|
---|
| 128 | # define RETSIGTYPE void
|
---|
| 129 | #endif
|
---|
| 130 |
|
---|
| 131 | #ifndef sigmask
|
---|
| 132 | # define sigmask(sig) (1 << ((sig) - 1))
|
---|
| 133 | #endif
|
---|
| 134 |
|
---|
| 135 | #ifndef HAVE_SA_RESTART
|
---|
| 136 | # define SA_RESTART 0
|
---|
| 137 | #endif
|
---|
| 138 |
|
---|
[3140] | 139 | #ifdef HAVE_VFORK_H
|
---|
| 140 | # include <vfork.h>
|
---|
| 141 | #endif
|
---|
| 142 |
|
---|
[53] | 143 | #ifdef HAVE_LIMITS_H
|
---|
| 144 | # include <limits.h>
|
---|
| 145 | #endif
|
---|
| 146 | #ifdef HAVE_SYS_PARAM_H
|
---|
| 147 | # include <sys/param.h>
|
---|
| 148 | #endif
|
---|
| 149 |
|
---|
| 150 | #ifndef PATH_MAX
|
---|
| 151 | # ifndef POSIX
|
---|
| 152 | # define PATH_MAX MAXPATHLEN
|
---|
| 153 | # endif
|
---|
| 154 | #endif
|
---|
| 155 | #ifndef MAXPATHLEN
|
---|
| 156 | # define MAXPATHLEN 1024
|
---|
| 157 | #endif
|
---|
| 158 |
|
---|
| 159 | #ifdef PATH_MAX
|
---|
| 160 | # define GET_PATH_MAX PATH_MAX
|
---|
| 161 | # define PATH_VAR(var) char var[PATH_MAX]
|
---|
| 162 | #else
|
---|
| 163 | # define NEED_GET_PATH_MAX 1
|
---|
| 164 | # define GET_PATH_MAX (get_path_max ())
|
---|
[903] | 165 | # define PATH_VAR(var) char *var = alloca (GET_PATH_MAX)
|
---|
| 166 | unsigned int get_path_max (void);
|
---|
[53] | 167 | #endif
|
---|
| 168 |
|
---|
[1971] | 169 | #if defined (KMK) || defined (CONFIG_WITH_VALUE_LENGTH) \
|
---|
[1976] | 170 | || defined (CONFIG_WITH_ALLOC_CACHES) \
|
---|
| 171 | || defined (CONFIG_WITH_STRCACHE2)
|
---|
[1834] | 172 | # ifdef _MSC_VER
|
---|
[1835] | 173 | # define MY_INLINE _inline static
|
---|
[1971] | 174 | # elif defined(__GNUC__)
|
---|
| 175 | # define MY_INLINE static __inline__
|
---|
| 176 | # else
|
---|
| 177 | # define MY_INLINE static
|
---|
| 178 | # endif
|
---|
| 179 |
|
---|
| 180 | # ifdef __GNUC__
|
---|
| 181 | # define MY_PREDICT_TRUE(expr) __builtin_expect(!!(expr), 1)
|
---|
| 182 | # define MY_PREDICT_FALSE(expr) __builtin_expect(!!(expr), 0)
|
---|
| 183 | # else
|
---|
| 184 | # define MY_PREDICT_TRUE(expr) (expr)
|
---|
| 185 | # define MY_PREDICT_FALSE(expr) (expr)
|
---|
| 186 | # endif
|
---|
| 187 | #endif
|
---|
| 188 |
|
---|
[1975] | 189 | #if defined (KMK) || defined (CONFIG_WITH_VALUE_LENGTH) \
|
---|
| 190 | || defined (CONFIG_WITH_STRCACHE2)
|
---|
[1971] | 191 | # ifdef _MSC_VER
|
---|
[1835] | 192 | # define MY_DBGBREAK __debugbreak()
|
---|
[1834] | 193 | # elif defined(__GNUC__)
|
---|
[1835] | 194 | # if defined(__i386__) || defined(__x86_64__)
|
---|
| 195 | # define MY_DBGBREAK __asm__ __volatile__ ("int3")
|
---|
[1971] | 196 | # else
|
---|
[1835] | 197 | # define MY_DBGBREAK assert(0)
|
---|
| 198 | # endif
|
---|
[1834] | 199 | # else
|
---|
[1971] | 200 | # define MY_DBGBREAK assert(0)
|
---|
[1834] | 201 | # endif
|
---|
| 202 | # ifndef NDEBUG
|
---|
| 203 | # define MY_ASSERT_MSG(expr, printfargs) \
|
---|
[1835] | 204 | do { if (!(expr)) { printf printfargs; MY_DBGBREAK; } } while (0)
|
---|
[1834] | 205 | # else
|
---|
| 206 | # define MY_ASSERT_MSG(expr, printfargs) do { } while (0)
|
---|
| 207 | # endif
|
---|
| 208 | #endif
|
---|
| 209 |
|
---|
[1842] | 210 | #ifdef KMK
|
---|
[3140] | 211 | /** @todo measure performance diff here! */
|
---|
| 212 | # if 0 /* See if this speeds things up (Windows is doing this anyway, so,
|
---|
[1842] | 213 | we might as well try be consistent in speed + features). */
|
---|
[3140] | 214 | # define MY_IS_BLANK(ch) ((ch) == ' ' || (ch) == '\t')
|
---|
| 215 | # define MY_IS_BLANK_OR_EOS(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\0')
|
---|
[1842] | 216 | # else
|
---|
[3140] | 217 | # define MY_IS_BLANK(ch) ISBLANK ((ch))
|
---|
| 218 | # define MY_IS_BLANK_OR_EOS(ch) (ISBLANK ((ch)) || (ch) == '\0')
|
---|
[1842] | 219 | # endif
|
---|
| 220 | #endif
|
---|
| 221 |
|
---|
[1925] | 222 | #ifdef CONFIG_WITH_MAKE_STATS
|
---|
| 223 | extern long make_stats_allocations;
|
---|
[1986] | 224 | extern long make_stats_reallocations;
|
---|
[1925] | 225 | extern unsigned long make_stats_allocated;
|
---|
| 226 | extern unsigned long make_stats_ht_lookups;
|
---|
| 227 | extern unsigned long make_stats_ht_collisions;
|
---|
| 228 |
|
---|
| 229 | # ifdef __APPLE__
|
---|
| 230 | # include <malloc/malloc.h>
|
---|
[2745] | 231 | # define SIZE_OF_HEAP_BLOCK(ptr) malloc_size(ptr)
|
---|
[1925] | 232 |
|
---|
| 233 | # elif defined(__linux__) /* glibc */
|
---|
| 234 | # include <malloc.h>
|
---|
| 235 | # define SIZE_OF_HEAP_BLOCK(ptr) malloc_usable_size(ptr)
|
---|
| 236 |
|
---|
| 237 | # elif defined(_MSC_VER) || defined(__OS2__)
|
---|
| 238 | # define SIZE_OF_HEAP_BLOCK(ptr) _msize(ptr)
|
---|
| 239 |
|
---|
| 240 | # else
|
---|
| 241 | # include <stdlib.h>
|
---|
| 242 | # define SIZE_OF_HEAP_BLOCK(ptr) 0
|
---|
| 243 | #endif
|
---|
| 244 |
|
---|
| 245 | # define MAKE_STATS_3(expr) do { expr; } while (0)
|
---|
| 246 | # define MAKE_STATS_2(expr) do { expr; } while (0)
|
---|
| 247 | # define MAKE_STATS(expr) do { expr; } while (0)
|
---|
| 248 | #else
|
---|
| 249 | # define MAKE_STATS_3(expr) do { } while (0)
|
---|
| 250 | # define MAKE_STATS_2(expr) do { } while (0)
|
---|
| 251 | # define MAKE_STATS(expr) do { } while (0)
|
---|
| 252 | #endif
|
---|
| 253 |
|
---|
[2591] | 254 | /* bird - start */
|
---|
[2758] | 255 | #ifdef _MSC_VER
|
---|
| 256 | # include <intrin.h>
|
---|
| 257 | # define CURRENT_CLOCK_TICK() __rdtsc()
|
---|
| 258 | #else
|
---|
| 259 | # define CURRENT_CLOCK_TICK() 0
|
---|
| 260 | #endif
|
---|
| 261 |
|
---|
[2591] | 262 | #define COMMA ,
|
---|
| 263 | #ifdef CONFIG_WITH_VALUE_LENGTH
|
---|
| 264 | # define IF_WITH_VALUE_LENGTH(a_Expr) a_Expr
|
---|
| 265 | # define IF_WITH_VALUE_LENGTH_PARAM(a_Expr) , a_Expr
|
---|
| 266 | #else
|
---|
| 267 | # define IF_WITH_VALUE_LENGTH(a_Expr)
|
---|
| 268 | # define IF_WITH_VALUE_LENGTH_PARAM(a_Expr)
|
---|
| 269 | #endif
|
---|
[1925] | 270 |
|
---|
[2591] | 271 | #ifdef CONFIG_WITH_ALLOC_CACHES
|
---|
| 272 | # define IF_WITH_ALLOC_CACHES(a_Expr) a_Expr
|
---|
| 273 | # define IF_WITH_ALLOC_CACHES_PARAM(a_Expr) , a_Expr
|
---|
| 274 | #else
|
---|
| 275 | # define IF_WITH_ALLOC_CACHES(a_Expr)
|
---|
| 276 | # define IF_WITH_ALLOC_CACHES_PARAM(a_Expr)
|
---|
| 277 | #endif
|
---|
| 278 |
|
---|
| 279 | #ifdef CONFIG_WITH_COMMANDS_FUNC
|
---|
| 280 | # define IF_WITH_COMMANDS_FUNC(a_Expr) a_Expr
|
---|
| 281 | # define IF_WITH_COMMANDS_FUNC_PARAM(a_Expr) , a_Expr
|
---|
| 282 | #else
|
---|
| 283 | # define IF_WITH_COMMANDS_FUNC(a_Expr)
|
---|
| 284 | # define IF_WITH_COMMANDS_FUNC_PARAM(a_Expr)
|
---|
| 285 | #endif
|
---|
| 286 |
|
---|
| 287 | /* bird - end */
|
---|
| 288 |
|
---|
| 289 |
|
---|
[1896] | 290 | #ifndef CHAR_BIT
|
---|
| 291 | # define CHAR_BIT 8
|
---|
| 292 | #endif
|
---|
| 293 |
|
---|
[3140] | 294 | #ifndef USHRT_MAX
|
---|
| 295 | # define USHRT_MAX 65535
|
---|
| 296 | #endif
|
---|
[53] | 297 |
|
---|
[3140] | 298 | /* Nonzero if the integer type T is signed.
|
---|
| 299 | Use <= to avoid GCC warnings about always-false expressions. */
|
---|
| 300 | #define INTEGER_TYPE_SIGNED(t) ((t) -1 <= 0)
|
---|
| 301 |
|
---|
[53] | 302 | /* The minimum and maximum values for the integer type T.
|
---|
| 303 | Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
|
---|
| 304 | #define INTEGER_TYPE_MINIMUM(t) \
|
---|
| 305 | (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
|
---|
| 306 | #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
|
---|
| 307 |
|
---|
| 308 | #ifndef CHAR_MAX
|
---|
| 309 | # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
|
---|
| 310 | #endif
|
---|
| 311 |
|
---|
| 312 | #ifdef STAT_MACROS_BROKEN
|
---|
| 313 | # ifdef S_ISREG
|
---|
| 314 | # undef S_ISREG
|
---|
| 315 | # endif
|
---|
| 316 | # ifdef S_ISDIR
|
---|
| 317 | # undef S_ISDIR
|
---|
| 318 | # endif
|
---|
| 319 | #endif /* STAT_MACROS_BROKEN. */
|
---|
| 320 |
|
---|
| 321 | #ifndef S_ISREG
|
---|
| 322 | # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
|
---|
| 323 | #endif
|
---|
| 324 | #ifndef S_ISDIR
|
---|
| 325 | # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
---|
| 326 | #endif
|
---|
| 327 |
|
---|
| 328 | #ifdef VMS
|
---|
[3140] | 329 | # include <fcntl.h>
|
---|
[53] | 330 | # include <types.h>
|
---|
| 331 | # include <unixlib.h>
|
---|
| 332 | # include <unixio.h>
|
---|
| 333 | # include <perror.h>
|
---|
| 334 | /* Needed to use alloca on VMS. */
|
---|
| 335 | # include <builtins.h>
|
---|
[3140] | 336 |
|
---|
| 337 | extern int vms_use_mcr_command;
|
---|
| 338 | extern int vms_always_use_cmd_file;
|
---|
| 339 | extern int vms_gnv_shell;
|
---|
| 340 | extern int vms_comma_separator;
|
---|
| 341 | extern int vms_legacy_behavior;
|
---|
| 342 | extern int vms_unix_simulation;
|
---|
[53] | 343 | #endif
|
---|
| 344 |
|
---|
| 345 | #ifndef __attribute__
|
---|
| 346 | /* This feature is available in gcc versions 2.5 and later. */
|
---|
| 347 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
|
---|
| 348 | # define __attribute__(x)
|
---|
| 349 | # endif
|
---|
[3140] | 350 | /* The __-protected variants of 'format' and 'printf' attributes
|
---|
[53] | 351 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
---|
| 352 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
---|
| 353 | # define __format__ format
|
---|
| 354 | # define __printf__ printf
|
---|
| 355 | # endif
|
---|
| 356 | #endif
|
---|
[153] | 357 | #define UNUSED __attribute__ ((unused))
|
---|
[53] | 358 |
|
---|
| 359 | #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
|
---|
| 360 | # include <stdlib.h>
|
---|
| 361 | # include <string.h>
|
---|
| 362 | # define ANSI_STRING 1
|
---|
| 363 | #else /* No standard headers. */
|
---|
| 364 | # ifdef HAVE_STRING_H
|
---|
| 365 | # include <string.h>
|
---|
| 366 | # define ANSI_STRING 1
|
---|
| 367 | # else
|
---|
| 368 | # include <strings.h>
|
---|
| 369 | # endif
|
---|
| 370 | # ifdef HAVE_MEMORY_H
|
---|
| 371 | # include <memory.h>
|
---|
| 372 | # endif
|
---|
| 373 | # ifdef HAVE_STDLIB_H
|
---|
| 374 | # include <stdlib.h>
|
---|
| 375 | # else
|
---|
[903] | 376 | void *malloc (int);
|
---|
| 377 | void *realloc (void *, int);
|
---|
| 378 | void free (void *);
|
---|
[53] | 379 |
|
---|
[903] | 380 | void abort (void) __attribute__ ((noreturn));
|
---|
| 381 | void exit (int) __attribute__ ((noreturn));
|
---|
[53] | 382 | # endif /* HAVE_STDLIB_H. */
|
---|
| 383 |
|
---|
| 384 | #endif /* Standard headers. */
|
---|
| 385 |
|
---|
| 386 | /* These should be in stdlib.h. Make sure we have them. */
|
---|
| 387 | #ifndef EXIT_SUCCESS
|
---|
| 388 | # define EXIT_SUCCESS 0
|
---|
| 389 | #endif
|
---|
| 390 | #ifndef EXIT_FAILURE
|
---|
[903] | 391 | # define EXIT_FAILURE 1
|
---|
[53] | 392 | #endif
|
---|
| 393 |
|
---|
[903] | 394 | #ifndef ANSI_STRING
|
---|
[53] | 395 |
|
---|
| 396 | /* SCO Xenix has a buggy macro definition in <string.h>. */
|
---|
| 397 | #undef strerror
|
---|
[503] | 398 | #if !defined(__DECC)
|
---|
[903] | 399 | char *strerror (int errnum);
|
---|
[53] | 400 | #endif
|
---|
| 401 |
|
---|
[503] | 402 | #endif /* !ANSI_STRING. */
|
---|
| 403 | #undef ANSI_STRING
|
---|
| 404 |
|
---|
[53] | 405 | #if HAVE_INTTYPES_H
|
---|
| 406 | # include <inttypes.h>
|
---|
| 407 | #endif
|
---|
[3140] | 408 | #if HAVE_STDINT_H
|
---|
| 409 | # include <stdint.h>
|
---|
| 410 | #endif
|
---|
[53] | 411 | #define FILE_TIMESTAMP uintmax_t
|
---|
| 412 |
|
---|
| 413 | #if !defined(HAVE_STRSIGNAL)
|
---|
[903] | 414 | char *strsignal (int signum);
|
---|
[53] | 415 | #endif
|
---|
| 416 |
|
---|
| 417 | /* ISDIGIT offers the following features:
|
---|
| 418 | - Its arg may be any int or unsigned int; it need not be an unsigned char.
|
---|
| 419 | - It's guaranteed to evaluate its argument exactly once.
|
---|
| 420 | NOTE! Make relies on this behavior, don't change it!
|
---|
| 421 | - It's typically faster.
|
---|
| 422 | POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
|
---|
| 423 | only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
|
---|
[3140] | 424 | it's important to use the locale's definition of 'digit' even when the
|
---|
[53] | 425 | host does not conform to POSIX. */
|
---|
| 426 | #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
|
---|
| 427 |
|
---|
[2591] | 428 | /* Test if two strings are equal. Is this worthwhile? Should be profiled. */
|
---|
| 429 | #define streq(a, b) \
|
---|
[53] | 430 | ((a) == (b) || \
|
---|
| 431 | (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
|
---|
[2591] | 432 |
|
---|
| 433 | /* Test if two strings are equal, but match case-insensitively on systems
|
---|
| 434 | which have case-insensitive filesystems. Should only be used for
|
---|
| 435 | filenames! */
|
---|
| 436 | #ifdef HAVE_CASE_INSENSITIVE_FS
|
---|
| 437 | # define patheq(a, b) \
|
---|
[53] | 438 | ((a) == (b) \
|
---|
| 439 | || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
|
---|
[903] | 440 | && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1))))
|
---|
[53] | 441 | #else
|
---|
[2591] | 442 | # define patheq(a, b) streq(a, b)
|
---|
[53] | 443 | #endif
|
---|
[2591] | 444 |
|
---|
[53] | 445 | #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
|
---|
| 446 |
|
---|
[3140] | 447 | #if (defined(__GNUC__) || defined(ENUM_BITFIELDS)) && !defined(NO_ENUM_BITFIELDS) /* bird: NO_ENUM_BITFIELDS */
|
---|
[53] | 448 | # define ENUM_BITFIELD(bits) :bits
|
---|
| 449 | #else
|
---|
| 450 | # define ENUM_BITFIELD(bits)
|
---|
| 451 | #endif
|
---|
| 452 |
|
---|
| 453 | /* Handle gettext and locales. */
|
---|
| 454 |
|
---|
| 455 | #if HAVE_LOCALE_H
|
---|
| 456 | # include <locale.h>
|
---|
| 457 | #else
|
---|
| 458 | # define setlocale(category, locale)
|
---|
| 459 | #endif
|
---|
| 460 |
|
---|
| 461 | #include <gettext.h>
|
---|
| 462 |
|
---|
| 463 | #define _(msgid) gettext (msgid)
|
---|
| 464 | #define N_(msgid) gettext_noop (msgid)
|
---|
| 465 | #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
|
---|
| 466 |
|
---|
[903] | 467 | /* This is needed for getcwd() and chdir(), on some W32 systems. */
|
---|
| 468 | #if defined(HAVE_DIRECT_H)
|
---|
[503] | 469 | # include <direct.h>
|
---|
| 470 | #endif
|
---|
| 471 |
|
---|
[53] | 472 | #ifdef WINDOWS32
|
---|
| 473 | # include <fcntl.h>
|
---|
| 474 | # include <malloc.h>
|
---|
[903] | 475 | # define pipe(_p) _pipe((_p), 512, O_BINARY)
|
---|
[3156] | 476 | # ifndef CONFIG_NEW_WIN_CHILDREN /* (only used by commands.c) */
|
---|
[903] | 477 | # define kill(_pid,_sig) w32_kill((_pid),(_sig))
|
---|
[3156] | 478 | # endif
|
---|
[3140] | 479 | /* MSVC and Watcom C don't have ftruncate. */
|
---|
| 480 | # if defined(_MSC_VER) || defined(__WATCOMC__)
|
---|
| 481 | # define ftruncate(_fd,_len) _chsize(_fd,_len)
|
---|
| 482 | # endif
|
---|
| 483 | /* MinGW64 doesn't have _S_ISDIR. */
|
---|
| 484 | # ifndef _S_ISDIR
|
---|
| 485 | # define _S_ISDIR(m) S_ISDIR(m)
|
---|
| 486 | # endif
|
---|
[53] | 487 |
|
---|
[903] | 488 | void sync_Path_environment (void);
|
---|
[3156] | 489 | # ifndef CONFIG_NEW_WIN_CHILDREN /* (only used by commands.c) */
|
---|
[2591] | 490 | int w32_kill (pid_t pid, int sig);
|
---|
[3156] | 491 | # endif
|
---|
[903] | 492 | int find_and_set_default_shell (const char *token);
|
---|
[53] | 493 |
|
---|
| 494 | /* indicates whether or not we have Bourne shell */
|
---|
| 495 | extern int no_default_sh_exe;
|
---|
| 496 |
|
---|
| 497 | /* is default_shell unixy? */
|
---|
| 498 | extern int unixy_shell;
|
---|
[3140] | 499 |
|
---|
| 500 | /* We don't have a preferred fixed value for LOCALEDIR. */
|
---|
| 501 | # ifndef LOCALEDIR
|
---|
| 502 | # define LOCALEDIR NULL
|
---|
| 503 | # endif
|
---|
| 504 |
|
---|
| 505 | /* Include only the minimal stuff from windows.h. */
|
---|
| 506 | # define WIN32_LEAN_AND_MEAN
|
---|
[53] | 507 | #endif /* WINDOWS32 */
|
---|
| 508 |
|
---|
[3140] | 509 | #define ANY_SET(_v,_m) (((_v)&(_m)) != 0)
|
---|
| 510 | #define NONE_SET(_v,_m) (! ANY_SET ((_v),(_m)))
|
---|
| 511 |
|
---|
| 512 | #define MAP_NUL 0x0001
|
---|
| 513 | #define MAP_BLANK 0x0002
|
---|
| 514 | #define MAP_NEWLINE 0x0004
|
---|
| 515 | #define MAP_COMMENT 0x0008
|
---|
| 516 | #define MAP_SEMI 0x0010
|
---|
| 517 | #define MAP_EQUALS 0x0020
|
---|
| 518 | #define MAP_COLON 0x0040
|
---|
| 519 | #define MAP_PERCENT 0x0080
|
---|
| 520 | #define MAP_PIPE 0x0100
|
---|
| 521 | #define MAP_DOT 0x0200
|
---|
| 522 | #define MAP_COMMA 0x0400
|
---|
| 523 |
|
---|
| 524 | /* These are the valid characters for a user-defined function. */
|
---|
| 525 | #define MAP_USERFUNC 0x2000
|
---|
| 526 | /* This means not only a '$', but skip the variable reference. */
|
---|
| 527 | #define MAP_VARIABLE 0x4000
|
---|
| 528 | /* The set of characters which are directory separators is OS-specific. */
|
---|
| 529 | #define MAP_DIRSEP 0x8000
|
---|
| 530 |
|
---|
| 531 | #ifdef VMS
|
---|
| 532 | # define MAP_VMSCOMMA MAP_COMMA
|
---|
| 533 | #else
|
---|
| 534 | # define MAP_VMSCOMMA 0x0000
|
---|
| 535 | #endif
|
---|
| 536 |
|
---|
| 537 | #define MAP_SPACE (MAP_BLANK|MAP_NEWLINE)
|
---|
| 538 |
|
---|
| 539 | /* Handle other OSs.
|
---|
| 540 | To overcome an issue parsing paths in a DOS/Windows environment when
|
---|
| 541 | built in a unix based environment, override the PATH_SEPARATOR_CHAR
|
---|
| 542 | definition unless being built for Cygwin. */
|
---|
| 543 | #if defined(HAVE_DOS_PATHS) && !defined(__CYGWIN__)
|
---|
| 544 | # undef PATH_SEPARATOR_CHAR
|
---|
| 545 | # define PATH_SEPARATOR_CHAR ';'
|
---|
| 546 | # define MAP_PATHSEP MAP_SEMI
|
---|
| 547 | #elif !defined(PATH_SEPARATOR_CHAR)
|
---|
| 548 | # if defined (VMS)
|
---|
| 549 | # define PATH_SEPARATOR_CHAR (vms_comma_separator ? ',' : ':')
|
---|
| 550 | # define MAP_PATHSEP (vms_comma_separator ? MAP_COMMA : MAP_SEMI)
|
---|
| 551 | # else
|
---|
| 552 | # define PATH_SEPARATOR_CHAR ':'
|
---|
| 553 | # define MAP_PATHSEP MAP_COLON
|
---|
| 554 | # endif
|
---|
| 555 | #elif PATH_SEPARATOR_CHAR == ':'
|
---|
| 556 | # define MAP_PATHSEP MAP_COLON
|
---|
| 557 | #elif PATH_SEPARATOR_CHAR == ';'
|
---|
| 558 | # define MAP_PATHSEP MAP_SEMI
|
---|
| 559 | #elif PATH_SEPARATOR_CHAR == ','
|
---|
| 560 | # define MAP_PATHSEP MAP_COMMA
|
---|
| 561 | #else
|
---|
| 562 | # error "Unknown PATH_SEPARATOR_CHAR"
|
---|
| 563 | #endif
|
---|
| 564 |
|
---|
| 565 | #define STOP_SET(_v,_m) ANY_SET(stopchar_map[(unsigned char)(_v)],(_m))
|
---|
| 566 |
|
---|
| 567 | #define ISBLANK(c) STOP_SET((c),MAP_BLANK)
|
---|
| 568 | #define ISSPACE(c) STOP_SET((c),MAP_SPACE)
|
---|
| 569 | #define NEXT_TOKEN(s) while (ISSPACE (*(s))) ++(s)
|
---|
| 570 | #define END_OF_TOKEN(s) while (! STOP_SET (*(s), MAP_SPACE|MAP_NUL)) ++(s)
|
---|
| 571 |
|
---|
[2591] | 572 | #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
|
---|
| 573 | # define SET_STACK_SIZE
|
---|
| 574 | #endif
|
---|
| 575 | #ifdef SET_STACK_SIZE
|
---|
| 576 | # include <sys/resource.h>
|
---|
[3140] | 577 | extern struct rlimit stack_limit;
|
---|
[2591] | 578 | #endif
|
---|
| 579 |
|
---|
[3140] | 580 | #include "glob.h" /* bird double quotes */
|
---|
| 581 |
|
---|
| 582 | #define NILF ((floc *)0)
|
---|
| 583 |
|
---|
| 584 | #define CSTRLEN(_s) (sizeof (_s)-1)
|
---|
| 585 | #define STRING_SIZE_TUPLE(_s) (_s), CSTRLEN(_s) /* The number of bytes needed to represent the largest integer as a string. */
|
---|
| 586 | #define INTSTR_LENGTH CSTRLEN ("18446744073709551616")
|
---|
| 587 |
|
---|
| 588 | #define DEFAULT_TTYNAME "true"
|
---|
| 589 | #ifdef HAVE_TTYNAME
|
---|
| 590 | # define TTYNAME(_f) ttyname (_f)
|
---|
| 591 | #else
|
---|
| 592 | # define TTYNAME(_f) DEFAULT_TTYNAME
|
---|
| 593 | #endif
|
---|
| 594 |
|
---|
| 595 | |
---|
| 596 |
|
---|
| 597 |
|
---|
| 598 | /* Specify the location of elements read from makefiles. */
|
---|
[53] | 599 | typedef struct
|
---|
[503] | 600 | {
|
---|
[53] | 601 | const char *filenm;
|
---|
[3140] | 602 | unsigned long lineno;
|
---|
| 603 | unsigned long offset;
|
---|
[53] | 604 | } floc;
|
---|
[3140] | 605 |
|
---|
[2101] | 606 | #if defined (CONFIG_WITH_MATH) /* bird start */ \
|
---|
| 607 | || defined (CONFIG_WITH_NANOTS) \
|
---|
[3140] | 608 | || defined (CONFIG_WITH_FILE_SIZE) \
|
---|
[2101] | 609 | || defined (CONFIG_WITH_PRINT_TIME_SWITCH)
|
---|
| 610 | # ifdef _MSC_VER
|
---|
| 611 | typedef __int64 big_int;
|
---|
| 612 | # define BIG_INT_C(c) (c ## LL)
|
---|
| 613 | typedef unsigned __int64 big_uint;
|
---|
| 614 | # define BIG_UINT_C(c) (c ## ULL)
|
---|
| 615 | # else
|
---|
| 616 | # include <stdint.h>
|
---|
| 617 | typedef int64_t big_int;
|
---|
| 618 | # define BIG_INT_C(c) INT64_C(c)
|
---|
| 619 | typedef uint64_t big_uint;
|
---|
| 620 | # define BIG_UINT_C(c) UINT64_C(c)
|
---|
[3140] | 621 | # endif
|
---|
[2101] | 622 | #endif /* bird end */
|
---|
[3140] | 623 |
|
---|
| 624 | const char *concat (unsigned int, ...);
|
---|
| 625 | void message (int prefix, size_t length, const char *fmt, ...)
|
---|
| 626 | __attribute__ ((__format__ (__printf__, 3, 4)));
|
---|
| 627 | void error (const floc *flocp, size_t length, const char *fmt, ...)
|
---|
| 628 | __attribute__ ((__format__ (__printf__, 3, 4)));
|
---|
| 629 | void fatal (const floc *flocp, size_t length, const char *fmt, ...)
|
---|
[153] | 630 | __attribute__ ((noreturn, __format__ (__printf__, 3, 4)));
|
---|
[3140] | 631 |
|
---|
| 632 | #define O(_t,_a,_f) _t((_a), 0, (_f))
|
---|
| 633 | #define OS(_t,_a,_f,_s) _t((_a), strlen (_s), (_f), (_s))
|
---|
| 634 | #define OSS(_t,_a,_f,_s1,_s2) _t((_a), strlen (_s1) + strlen (_s2), \
|
---|
| 635 | (_f), (_s1), (_s2))
|
---|
| 636 | #define OSSS(_t,_a,_f,_s1,_s2,_s3) _t((_a), strlen (_s1) + strlen (_s2) + strlen (_s3), \
|
---|
| 637 | (_f), (_s1), (_s2), (_s3))
|
---|
| 638 | #define ON(_t,_a,_f,_n) _t((_a), INTSTR_LENGTH, (_f), (_n))
|
---|
[153] | 639 | #define ONN(_t,_a,_f,_n1,_n2) _t((_a), INTSTR_LENGTH*2, (_f), (_n1), (_n2))
|
---|
[3140] | 640 |
|
---|
| 641 | #define OSN(_t,_a,_f,_s,_n) _t((_a), strlen (_s) + INTSTR_LENGTH, \
|
---|
| 642 | (_f), (_s), (_n))
|
---|
| 643 | #define ONS(_t,_a,_f,_n,_s) _t((_a), INTSTR_LENGTH + strlen (_s), \
|
---|
[53] | 644 | (_f), (_n), (_s))
|
---|
[3140] | 645 |
|
---|
| 646 | /* bird: more wrappers */
|
---|
| 647 | #define OSNN(_t,_a,_f,_s,_n1,_n2) _t((_a), strlen (_s) + INTSTR_LENGTH + INTSTR_LENGTH, \
|
---|
| 648 | (_f), (_s), (_n1), (_n2)) /* bird */
|
---|
| 649 | #define OSNS(_t,_a,_f,_s1,_n,_s2) _t((_a), strlen (_s1) + strlen (_s2) + INTSTR_LENGTH, \
|
---|
| 650 | (_f), (_s1), (_n), (_s2)) /* bird */
|
---|
| 651 | #define OSSSS(_t,_a,_f,_s1,_s2,_s3,_s4) _t((_a), strlen (_s1) + strlen (_s2) + strlen (_s3) + strlen (_s4), \
|
---|
[3273] | 652 | (_f), (_s1), (_s2), (_s3), (_s4)) /* bird */
|
---|
| 653 | #define OSSN(_t,_a,_f,_s1,_s2,_n) _t((_a), strlen (_s1) + strlen (_s2) + INTSTR_LENGTH, \
|
---|
[3140] | 654 | (_f), (_s1), (_s2), (_n)) /* bird */
|
---|
| 655 | #define OSSNS(_t,_a,_f,_s1,_s2,_n,_s3) _t((_a), strlen (_s1) + strlen (_s2) + strlen (_s3) + INTSTR_LENGTH, \
|
---|
[3162] | 656 | (_f), (_s1), (_s2), (_n), (_s3)) /* bird */
|
---|
| 657 | #define ONNS(_t,_a,_f,_n1,_n2,_s1) _t((_a), INTSTR_LENGTH * 2 + strlen (_s1), \
|
---|
| 658 | (_f), (_n1), (_n2), (_s1)) /* bird */
|
---|
| 659 | #define ONNNS(_t,_a,_f,_n1,_n2,_n3,_s1) _t((_a), INTSTR_LENGTH * 3 + strlen (_s1), \
|
---|
[3140] | 660 | (_f), (_n1), (_n2), (_n3), (_s1)) /* bird */
|
---|
| 661 |
|
---|
| 662 | #define OUT_OF_MEM() O (fatal, NILF, _("virtual memory exhausted"))
|
---|
[903] | 663 |
|
---|
| 664 | void die (int) __attribute__ ((noreturn));
|
---|
| 665 | void pfatal_with_name (const char *) __attribute__ ((noreturn));
|
---|
[3140] | 666 | void perror_with_name (const char *, const char *);
|
---|
[903] | 667 | #define xstrlen(_s) ((_s)==NULL ? 0 : strlen (_s))
|
---|
[2591] | 668 | void *xmalloc (unsigned int);
|
---|
[903] | 669 | void *xcalloc (unsigned int);
|
---|
| 670 | void *xrealloc (void *, unsigned int);
|
---|
[2591] | 671 | char *xstrdup (const char *);
|
---|
[1918] | 672 | char *xstrndup (const char *, unsigned int);
|
---|
| 673 | #ifdef CONFIG_WITH_PRINT_STATS_SWITCH
|
---|
| 674 | void print_heap_stats (void);
|
---|
[903] | 675 | #endif
|
---|
| 676 | char *find_next_token (const char **, unsigned int *);
|
---|
| 677 | char *next_token (const char *);
|
---|
[2548] | 678 | char *end_of_token (const char *);
|
---|
| 679 | #ifdef KMK
|
---|
[3322] | 680 | char *find_next_token_eos (const char **ptr, const char *eos, unsigned int *lengthptr);
|
---|
[2548] | 681 | char *find_next_file_token (const char **ptr, const char *eos, unsigned int *lengthptr);
|
---|
[1811] | 682 | #endif
|
---|
[903] | 683 | #ifndef CONFIG_WITH_VALUE_LENGTH
|
---|
[1811] | 684 | void collapse_continuations (char *);
|
---|
| 685 | #else
|
---|
| 686 | char *collapse_continuations (char *, unsigned int);
|
---|
[527] | 687 | #endif
|
---|
[903] | 688 | #ifdef CONFIG_WITH_OPTIMIZATION_HACKS /* memchr is usually compiler intrinsic, thus faster. */
|
---|
[429] | 689 | # define lindex(s, limit, c) ((char *)memchr((s), (c), (limit) - (s)))
|
---|
[903] | 690 | #else
|
---|
[429] | 691 | char *lindex (const char *, const char *, int);
|
---|
[903] | 692 | #endif
|
---|
| 693 | int alpha_compare (const void *, const void *);
|
---|
| 694 | void print_spaces (unsigned int);
|
---|
| 695 | char *find_percent (char *);
|
---|
[53] | 696 | const char *find_percent_cached (const char **);
|
---|
| 697 |
|
---|
[903] | 698 | #ifndef NO_ARCHIVES
|
---|
| 699 | int ar_name (const char *);
|
---|
| 700 | void ar_parse_name (const char *, char **, char **);
|
---|
| 701 | int ar_touch (const char *);
|
---|
| 702 | time_t ar_member_date (const char *);
|
---|
| 703 |
|
---|
[3140] | 704 | typedef long int (*ar_member_func_t) (int desc, const char *mem, int truncated,
|
---|
| 705 | long int hdrpos, long int datapos,
|
---|
| 706 | long int size, long int date, int uid,
|
---|
| 707 | int gid, unsigned int mode,
|
---|
[903] | 708 | const void *arg);
|
---|
| 709 |
|
---|
| 710 | long int ar_scan (const char *archive, ar_member_func_t function, const void *arg);
|
---|
| 711 | int ar_name_equal (const char *name, const char *mem, int truncated);
|
---|
| 712 | #ifndef VMS
|
---|
[53] | 713 | int ar_member_touch (const char *arname, const char *memname);
|
---|
[903] | 714 | #endif
|
---|
[53] | 715 | #endif
|
---|
[903] | 716 |
|
---|
| 717 | int dir_file_exists_p (const char *, const char *);
|
---|
| 718 | int file_exists_p (const char *);
|
---|
| 719 | int file_impossible_p (const char *);
|
---|
| 720 | void file_impossible (const char *);
|
---|
[3140] | 721 | const char *dir_name (const char *);
|
---|
| 722 | void print_dir_data_base (void);
|
---|
[903] | 723 | void dir_setup_glob (glob_t *);
|
---|
[3184] | 724 | void hash_init_directories (void);
|
---|
| 725 | #if defined (KMK) && defined (KBUILD_OS_WINDOWS)
|
---|
| 726 | int utf16_regular_file_p(const wchar_t *pwszPath);
|
---|
[53] | 727 | #endif
|
---|
[903] | 728 |
|
---|
[3140] | 729 | void define_default_variables (void);
|
---|
[903] | 730 | void undefine_default_variables (void);
|
---|
| 731 | void set_default_suffixes (void);
|
---|
| 732 | void install_default_suffix_rules (void);
|
---|
[53] | 733 | void install_default_implicit_rules (void);
|
---|
[903] | 734 |
|
---|
| 735 | void build_vpath_lists (void);
|
---|
[2591] | 736 | void construct_vpath_list (char *pattern, char *dirpath);
|
---|
| 737 | const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr,
|
---|
[903] | 738 | unsigned int* vpath_index, unsigned int* path_index);
|
---|
[53] | 739 | int gpath_search (const char *file, unsigned int len);
|
---|
[903] | 740 |
|
---|
[53] | 741 | void construct_include_path (const char **arg_dirs);
|
---|
[903] | 742 |
|
---|
| 743 | void user_access (void);
|
---|
| 744 | void make_access (void);
|
---|
[53] | 745 | void child_access (void);
|
---|
[903] | 746 |
|
---|
[280] | 747 | char *strip_whitespace (const char **begpp, const char **endpp);
|
---|
[3140] | 748 |
|
---|
| 749 | void show_goal_error (void);
|
---|
| 750 |
|
---|
| 751 |
|
---|
[1863] | 752 | #ifdef CONFIG_WITH_ALLOC_CACHES /* bird start */
|
---|
| 753 | /* alloccache (misc.c) */
|
---|
| 754 |
|
---|
| 755 | struct alloccache_free_ent
|
---|
| 756 | {
|
---|
| 757 | struct alloccache_free_ent *next;
|
---|
| 758 | };
|
---|
| 759 |
|
---|
| 760 | struct alloccache
|
---|
| 761 | {
|
---|
| 762 | char *free_start;
|
---|
| 763 | char *free_end;
|
---|
| 764 | struct alloccache_free_ent *free_head;
|
---|
| 765 | unsigned int size;
|
---|
[1925] | 766 | unsigned int total_count;
|
---|
| 767 | unsigned long alloc_count;
|
---|
[1863] | 768 | unsigned long free_count;
|
---|
| 769 | const char *name;
|
---|
| 770 | struct alloccache *next;
|
---|
| 771 | void *grow_arg;
|
---|
| 772 | void *(*grow_alloc)(void *grow_arg, unsigned int size);
|
---|
| 773 | };
|
---|
| 774 |
|
---|
| 775 | void alloccache_init (struct alloccache *cache, unsigned int size, const char *name,
|
---|
[1872] | 776 | void *(*grow_alloc)(void *grow_arg, unsigned int size), void *grow_arg);
|
---|
| 777 | void alloccache_term (struct alloccache *cache,
|
---|
[1863] | 778 | void (*term_free)(void *term_arg, void *ptr, unsigned int size), void *term_arg);
|
---|
| 779 | void alloccache_join (struct alloccache *cache, struct alloccache *eat);
|
---|
| 780 | void alloccache_print (struct alloccache *cache);
|
---|
| 781 | void alloccache_print_all (void);
|
---|
[2050] | 782 | struct alloccache_free_ent *alloccache_alloc_grow (struct alloccache *cache);
|
---|
[1863] | 783 | void alloccache_free (struct alloccache *cache, void *item);
|
---|
| 784 |
|
---|
| 785 | /* Allocate an item. */
|
---|
| 786 | MY_INLINE void *
|
---|
| 787 | alloccache_alloc (struct alloccache *cache)
|
---|
[2633] | 788 | {
|
---|
| 789 | struct alloccache_free_ent *f;
|
---|
| 790 | # ifndef CONFIG_WITH_ALLOCCACHE_DEBUG
|
---|
[1863] | 791 | f = cache->free_head;
|
---|
| 792 | if (f)
|
---|
| 793 | cache->free_head = f->next;
|
---|
| 794 | else if (cache->free_start != cache->free_end)
|
---|
| 795 | {
|
---|
| 796 | f = (struct alloccache_free_ent *)cache->free_start;
|
---|
| 797 | cache->free_start += cache->size;
|
---|
| 798 | }
|
---|
[2633] | 799 | else
|
---|
[1863] | 800 | # endif
|
---|
[1925] | 801 | f = alloccache_alloc_grow (cache);
|
---|
[1863] | 802 | MAKE_STATS(cache->alloc_count++;);
|
---|
| 803 | return f;
|
---|
| 804 | }
|
---|
| 805 |
|
---|
| 806 | /* Allocate a cleared item. */
|
---|
| 807 | MY_INLINE void *
|
---|
| 808 | alloccache_calloc (struct alloccache *cache)
|
---|
| 809 | {
|
---|
| 810 | void *item = alloccache_alloc (cache);
|
---|
| 811 | memset (item, '\0', cache->size);
|
---|
| 812 | return item;
|
---|
| 813 | }
|
---|
| 814 |
|
---|
| 815 |
|
---|
| 816 | /* the alloc caches */
|
---|
[3140] | 817 | extern struct alloccache dep_cache;
|
---|
| 818 | extern struct alloccache goaldep_cache;
|
---|
[1867] | 819 | extern struct alloccache nameseq_cache;
|
---|
| 820 | extern struct alloccache file_cache;
|
---|
[1863] | 821 | extern struct alloccache commands_cache;
|
---|
[1864] | 822 | extern struct alloccache variable_cache;
|
---|
| 823 | extern struct alloccache variable_set_cache;
|
---|
[1863] | 824 | extern struct alloccache variable_set_list_cache;
|
---|
[3140] | 825 |
|
---|
[1863] | 826 | #endif /* CONFIG_WITH_ALLOC_CACHES - bird end*/
|
---|
| 827 |
|
---|
[503] | 828 |
|
---|
[903] | 829 | /* String caching */
|
---|
| 830 | void strcache_init (void);
|
---|
[3140] | 831 | void strcache_print_stats (const char *prefix);
|
---|
[903] | 832 | #ifndef CONFIG_WITH_STRCACHE2 /* bird */
|
---|
| 833 | int strcache_iscached (const char *str);
|
---|
[3140] | 834 | const char *strcache_add (const char *str);
|
---|
[1870] | 835 | const char *strcache_add_len (const char *str, unsigned int len);
|
---|
| 836 | #else /* CONFIG_WITH_STRCACHE2 */
|
---|
| 837 |
|
---|
| 838 | # include "strcache2.h"
|
---|
[1933] | 839 | extern struct strcache2 file_strcache;
|
---|
[1870] | 840 | extern const char *suffixes_strcached;
|
---|
| 841 |
|
---|
[1885] | 842 | # define strcache_iscached(str) strcache2_is_cached(&file_strcache, str)
|
---|
| 843 | # define strcache_add(str) strcache2_add_file(&file_strcache, str, strlen (str))
|
---|
[1897] | 844 | # define strcache_add_len(str, len) strcache2_add_file(&file_strcache, str, len)
|
---|
[1870] | 845 | # define strcache_get_len(str) strcache2_get_len(&file_strcache, str) /* FIXME: replace this and related checks ... */
|
---|
| 846 |
|
---|
| 847 | #endif /* CONFIG_WITH_STRCACHE2 */
|
---|
[3140] | 848 |
|
---|
| 849 | /* Guile support */
|
---|
[53] | 850 | int guile_gmake_setup (const floc *flocp);
|
---|
[3140] | 851 |
|
---|
| 852 | /* Loadable object support. Sets to the strcached name of the loaded file. */
|
---|
| 853 | typedef int (*load_func_t)(const floc *flocp);
|
---|
| 854 | int load_file (const floc *flocp, const char **filename, int noerror);
|
---|
| 855 | void unload_file (const char *name);
|
---|
[53] | 856 |
|
---|
| 857 | /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
|
---|
| 858 | because such systems often declare them in header files anyway. */
|
---|
| 859 |
|
---|
| 860 | #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
|
---|
[903] | 861 |
|
---|
[53] | 862 | long int atol ();
|
---|
[903] | 863 | # ifndef VMS
|
---|
[53] | 864 | long int lseek ();
|
---|
| 865 | # endif
|
---|
[3140] | 866 |
|
---|
| 867 | # ifdef HAVE_GETCWD
|
---|
[903] | 868 | # if !defined(VMS) && !defined(__DECC) && !defined(_MSC_VER) /* bird: MSC */
|
---|
[3140] | 869 | char *getcwd ();
|
---|
| 870 | # endif
|
---|
| 871 | # else
|
---|
| 872 | char *getwd ();
|
---|
[503] | 873 | # define getcwd(buf, len) getwd (buf)
|
---|
[53] | 874 | # endif
|
---|
[3140] | 875 |
|
---|
| 876 | #endif /* Not GNU C library or POSIX. */
|
---|
[903] | 877 |
|
---|
| 878 | #if !HAVE_STRCASECMP
|
---|
| 879 | # if HAVE_STRICMP
|
---|
| 880 | # define strcasecmp stricmp
|
---|
| 881 | # elif HAVE_STRCMPI
|
---|
| 882 | # define strcasecmp strcmpi
|
---|
| 883 | # else
|
---|
| 884 | /* Create our own, in misc.c */
|
---|
| 885 | int strcasecmp (const char *s1, const char *s2);
|
---|
| 886 | # endif
|
---|
| 887 | #endif
|
---|
[2591] | 888 |
|
---|
| 889 | #if !HAVE_STRNCASECMP
|
---|
| 890 | # if HAVE_STRNICMP
|
---|
| 891 | # define strncasecmp strnicmp
|
---|
| 892 | # elif HAVE_STRNCMPI
|
---|
| 893 | # define strncasecmp strncmpi
|
---|
| 894 | # else
|
---|
| 895 | /* Create our own, in misc.c */
|
---|
| 896 | int strncasecmp (const char *s1, const char *s2, int n);
|
---|
| 897 | # endif
|
---|
| 898 | #endif
|
---|
[3140] | 899 |
|
---|
| 900 | #define OUTPUT_SYNC_NONE 0
|
---|
| 901 | #define OUTPUT_SYNC_LINE 1
|
---|
| 902 | #define OUTPUT_SYNC_TARGET 2
|
---|
[53] | 903 | #define OUTPUT_SYNC_RECURSE 3
|
---|
[903] | 904 |
|
---|
[3140] | 905 | #if !defined(_MSC_VER) /* bird */
|
---|
[53] | 906 | /* Non-GNU systems may not declare this in unistd.h. */
|
---|
[803] | 907 | extern char **environ;
|
---|
[53] | 908 | #endif
|
---|
[3140] | 909 |
|
---|
| 910 | extern const floc *reading_file;
|
---|
| 911 | extern const floc **expanding_var;
|
---|
| 912 |
|
---|
| 913 | extern unsigned short stopchar_map[];
|
---|
[53] | 914 |
|
---|
| 915 | extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
|
---|
| 916 | extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
|
---|
[280] | 917 | extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
|
---|
[3140] | 918 | extern int print_version_flag, print_directory_flag, check_symlink_flag;
|
---|
| 919 | extern int warn_undefined_variables_flag, trace_flag, posix_pedantic;
|
---|
| 920 | extern int not_parallel, second_expansion, clock_skew_detected;
|
---|
[2591] | 921 | extern int rebuilding_makefiles, one_shell, output_sync, verify_flag;
|
---|
[3140] | 922 |
|
---|
[1701] | 923 | #ifdef CONFIG_WITH_2ND_TARGET_EXPANSION /* bird start */
|
---|
| 924 | extern int second_target_expansion;
|
---|
[591] | 925 | #endif
|
---|
| 926 | #ifdef CONFIG_PRETTY_COMMAND_PRINTING
|
---|
| 927 | extern int pretty_command_printing;
|
---|
[2101] | 928 | #endif
|
---|
| 929 | #ifdef CONFIG_WITH_PRINT_TIME_SWITCH
|
---|
| 930 | extern int print_time_min, print_time_width;
|
---|
[1915] | 931 | #endif
|
---|
[1535] | 932 | #if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
|
---|
[3140] | 933 | extern int make_expensive_statistics;
|
---|
[53] | 934 | #endif /* bird end */
|
---|
[3140] | 935 |
|
---|
[1535] | 936 | extern const char *default_shell;
|
---|
[53] | 937 |
|
---|
| 938 | /* can we run commands via 'sh -c xxx' or must we use batch files? */
|
---|
| 939 | extern int batch_mode_shell;
|
---|
[1993] | 940 |
|
---|
| 941 | /* Resetting the command script introduction prefix character. */
|
---|
| 942 | #define RECIPEPREFIX_NAME ".RECIPEPREFIX"
|
---|
[903] | 943 | #define RECIPEPREFIX_DEFAULT '\t'
|
---|
| 944 | extern char cmd_prefix;
|
---|
[53] | 945 |
|
---|
| 946 | extern unsigned int job_slots;
|
---|
| 947 | #ifndef NO_FLOAT
|
---|
| 948 | extern double max_load_average;
|
---|
| 949 | #else
|
---|
| 950 | extern int max_load_average;
|
---|
| 951 | #endif
|
---|
[3140] | 952 |
|
---|
[53] | 953 | #ifdef WINDOWS32
|
---|
[3140] | 954 | extern char *program;
|
---|
| 955 | #else
|
---|
| 956 | extern const char *program;
|
---|
| 957 | #endif
|
---|
| 958 |
|
---|
| 959 | #ifdef VMS
|
---|
| 960 | const char *vms_command (const char *argv0);
|
---|
| 961 | const char *vms_progname (const char *argv0);
|
---|
| 962 |
|
---|
| 963 | void vms_exit (int);
|
---|
| 964 | # define _exit(foo) vms_exit(foo)
|
---|
| 965 | # define exit(foo) vms_exit(foo)
|
---|
| 966 |
|
---|
| 967 | extern char *program_name;
|
---|
| 968 |
|
---|
| 969 | void
|
---|
| 970 | set_program_name (const char *arv0);
|
---|
| 971 |
|
---|
| 972 | int
|
---|
| 973 | need_vms_symbol (void);
|
---|
| 974 |
|
---|
| 975 | int
|
---|
| 976 | create_foreign_command (const char *command, const char *image);
|
---|
| 977 |
|
---|
| 978 | int
|
---|
| 979 | vms_export_dcl_symbol (const char *name, const char *value);
|
---|
| 980 |
|
---|
| 981 | int
|
---|
| 982 | vms_putenv_symbol (const char *string);
|
---|
| 983 |
|
---|
| 984 | void
|
---|
| 985 | vms_restore_symbol (const char *string);
|
---|
| 986 |
|
---|
| 987 | #endif
|
---|
| 988 |
|
---|
| 989 | void remote_setup (void);
|
---|
| 990 | void remote_cleanup (void);
|
---|
| 991 | int start_remote_job_p (int);
|
---|
| 992 | int start_remote_job (char **, char **, int, int *, int *, int *);
|
---|
| 993 | int remote_status (int *, int *, int *, int);
|
---|
| 994 | void block_remote_children (void);
|
---|
| 995 | void unblock_remote_children (void);
|
---|
| 996 | int remote_kill (int id, int sig);
|
---|
| 997 | void print_variable_data_base (void);
|
---|
| 998 | void print_vpath_data_base (void);
|
---|
[53] | 999 |
|
---|
| 1000 | extern char *starting_directory;
|
---|
| 1001 | extern unsigned int makelevel;
|
---|
| 1002 | extern char *version_string, *remote_description, *make_host;
|
---|
| 1003 |
|
---|
| 1004 | extern unsigned int commands_started;
|
---|
| 1005 |
|
---|
| 1006 | extern int handling_fatal_signal;
|
---|
| 1007 |
|
---|
| 1008 |
|
---|
| 1009 | #ifndef MIN
|
---|
| 1010 | #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
|
---|
| 1011 | #endif
|
---|
| 1012 | #ifndef MAX
|
---|
| 1013 | #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
|
---|
| 1014 | #endif
|
---|
| 1015 |
|
---|
[3140] | 1016 |
|
---|
| 1017 | #define MAKE_SUCCESS 0
|
---|
| 1018 | #define MAKE_TROUBLE 1
|
---|
| 1019 | #define MAKE_FAILURE 2
|
---|
[53] | 1020 |
|
---|
| 1021 | /* Set up heap debugging library dmalloc. */
|
---|
| 1022 |
|
---|
| 1023 | #ifdef HAVE_DMALLOC_H
|
---|
| 1024 | #include <dmalloc.h>
|
---|
| 1025 | #endif
|
---|
| 1026 |
|
---|
| 1027 | #ifndef initialize_main
|
---|
| 1028 | # ifdef __EMX__
|
---|
| 1029 | # define initialize_main(pargc, pargv) \
|
---|
| 1030 | { _wildcard(pargc, pargv); _response(pargc, pargv); }
|
---|
| 1031 | # else
|
---|
| 1032 | # define initialize_main(pargc, pargv)
|
---|
| 1033 | # endif
|
---|
| 1034 | #endif
|
---|
| 1035 |
|
---|
| 1036 | #ifdef __EMX__
|
---|
| 1037 | # if !defined chdir
|
---|
| 1038 | # define chdir _chdir2
|
---|
| 1039 | # endif
|
---|
| 1040 | # if !defined getcwd
|
---|
| 1041 | # define getcwd _getcwd2
|
---|
| 1042 | # endif
|
---|
| 1043 |
|
---|
| 1044 | /* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
|
---|
| 1045 | chdir() and getcwd(). This avoids some error messages for the
|
---|
| 1046 | make testsuite but restricts the drive letter support. */
|
---|
| 1047 | # ifdef NO_CHDIR2
|
---|
| 1048 | # warning NO_CHDIR2: usage of drive letters restricted
|
---|
| 1049 | # undef chdir
|
---|
| 1050 | # undef getcwd
|
---|
| 1051 | # endif
|
---|
| 1052 | #endif
|
---|
| 1053 |
|
---|
| 1054 | #ifndef initialize_main
|
---|
| 1055 | # define initialize_main(pargc, pargv)
|
---|
| 1056 | #endif
|
---|
| 1057 |
|
---|
| 1058 |
|
---|
| 1059 | /* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
|
---|
| 1060 | properly according to POSIX. So, we try to wrap common system calls with
|
---|
| 1061 | checks for EINTR. Note that there are still plenty of system calls that
|
---|
| 1062 | can fail with EINTR but this, reportedly, gets the vast majority of
|
---|
| 1063 | failure cases. If you still experience failures you'll need to either get
|
---|
| 1064 | a system where SA_RESTART works, or you need to avoid -j. */
|
---|
| 1065 |
|
---|
| 1066 | #define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
|
---|
| 1067 |
|
---|
| 1068 | /* While system calls that return integers are pretty consistent about
|
---|
| 1069 | returning -1 on failure and setting errno in that case, functions that
|
---|
| 1070 | return pointers are not always so well behaved. Sometimes they return
|
---|
| 1071 | NULL for expected behavior: one good example is readdir() which returns
|
---|
| 1072 | NULL at the end of the directory--and _doesn't_ reset errno. So, we have
|
---|
| 1073 | to do it ourselves here. */
|
---|
[903] | 1074 |
|
---|
| 1075 | #define ENULLLOOP(_v,_c) do { errno = 0; (_v) = _c; } \
|
---|
[53] | 1076 | while((_v)==0 && errno==EINTR)
|
---|
[903] | 1077 |
|
---|
[527] | 1078 |
|
---|
[549] | 1079 | #if defined(__EMX__) && defined(CONFIG_WITH_OPTIMIZATION_HACKS) /* bird: saves 40-100ms on libc. */
|
---|
[430] | 1080 | static inline void *__my_rawmemchr (const void *__s, int __c);
|
---|
| 1081 | #undef strchr
|
---|
| 1082 | #define strchr(s, c) \
|
---|
| 1083 | (__extension__ (__builtin_constant_p (c) \
|
---|
[549] | 1084 | ? ((c) == '\0' \
|
---|
| 1085 | ? (char *) __my_rawmemchr ((s), (c)) \
|
---|
| 1086 | : __my_strchr_c ((s), ((c) & 0xff) << 8)) \
|
---|
| 1087 | : __my_strchr_g ((s), (c))))
|
---|
[430] | 1088 | static inline char *__my_strchr_c (const char *__s, int __c)
|
---|
| 1089 | {
|
---|
| 1090 | register unsigned long int __d0;
|
---|
| 1091 | register char *__res;
|
---|
| 1092 | __asm__ __volatile__
|
---|
| 1093 | ("1:\n\t"
|
---|
| 1094 | "movb (%0),%%al\n\t"
|
---|
| 1095 | "cmpb %%ah,%%al\n\t"
|
---|
| 1096 | "je 2f\n\t"
|
---|
| 1097 | "leal 1(%0),%0\n\t"
|
---|
| 1098 | "testb %%al,%%al\n\t"
|
---|
| 1099 | "jne 1b\n\t"
|
---|
| 1100 | "xorl %0,%0\n"
|
---|
| 1101 | "2:"
|
---|
| 1102 | : "=r" (__res), "=&a" (__d0)
|
---|
| 1103 | : "0" (__s), "1" (__c),
|
---|
| 1104 | "m" ( *(struct { char __x[0xfffffff]; } *)__s)
|
---|
| 1105 | : "cc");
|
---|
| 1106 | return __res;
|
---|
| 1107 | }
|
---|
[549] | 1108 |
|
---|
[430] | 1109 | static inline char *__my_strchr_g (__const char *__s, int __c)
|
---|
| 1110 | {
|
---|
| 1111 | register unsigned long int __d0;
|
---|
| 1112 | register char *__res;
|
---|
| 1113 | __asm__ __volatile__
|
---|
| 1114 | ("movb %%al,%%ah\n"
|
---|
| 1115 | "1:\n\t"
|
---|
| 1116 | "movb (%0),%%al\n\t"
|
---|
| 1117 | "cmpb %%ah,%%al\n\t"
|
---|
| 1118 | "je 2f\n\t"
|
---|
| 1119 | "leal 1(%0),%0\n\t"
|
---|
| 1120 | "testb %%al,%%al\n\t"
|
---|
| 1121 | "jne 1b\n\t"
|
---|
| 1122 | "xorl %0,%0\n"
|
---|
| 1123 | "2:"
|
---|
| 1124 | : "=r" (__res), "=&a" (__d0)
|
---|
| 1125 | : "0" (__s), "1" (__c),
|
---|
| 1126 | "m" ( *(struct { char __x[0xfffffff]; } *)__s)
|
---|
| 1127 | : "cc");
|
---|
| 1128 | return __res;
|
---|
| 1129 | }
|
---|
[549] | 1130 |
|
---|
[430] | 1131 | static inline void *__my_rawmemchr (const void *__s, int __c)
|
---|
| 1132 | {
|
---|
| 1133 | register unsigned long int __d0;
|
---|
| 1134 | register unsigned char *__res;
|
---|
| 1135 | __asm__ __volatile__
|
---|
| 1136 | ("cld\n\t"
|
---|
| 1137 | "repne; scasb\n\t"
|
---|
| 1138 | : "=D" (__res), "=&c" (__d0)
|
---|
| 1139 | : "a" (__c), "0" (__s), "1" (0xffffffff),
|
---|
| 1140 | "m" ( *(struct { char __x[0xfffffff]; } *)__s)
|
---|
| 1141 | : "cc");
|
---|
| 1142 | return __res - 1;
|
---|
| 1143 | }
|
---|
| 1144 |
|
---|
[549] | 1145 | #undef memchr
|
---|
| 1146 | #define memchr(a,b,c) __my_memchr((a),(b),(c))
|
---|
[430] | 1147 | static inline void *__my_memchr (__const void *__s, int __c, size_t __n)
|
---|
| 1148 | {
|
---|
| 1149 | register unsigned long int __d0;
|
---|
| 1150 | register unsigned char *__res;
|
---|
| 1151 | if (__n == 0)
|
---|
| 1152 | return NULL;
|
---|
| 1153 | __asm__ __volatile__
|
---|
| 1154 | ("repne; scasb\n\t"
|
---|
| 1155 | "je 1f\n\t"
|
---|
| 1156 | "movl $1,%0\n"
|
---|
| 1157 | "1:"
|
---|
| 1158 | : "=D" (__res), "=&c" (__d0)
|
---|
| 1159 | : "a" (__c), "0" (__s), "1" (__n),
|
---|
| 1160 | "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
|
---|
| 1161 | : "cc");
|
---|
| 1162 | return __res - 1;
|
---|
| 1163 | }
|
---|
[520] | 1164 |
|
---|
[1438] | 1165 | #endif /* __EMX__ (bird) */
|
---|
[1715] | 1166 |
|
---|
[3140] | 1167 | #ifdef CONFIG_WITH_IF_CONDITIONALS
|
---|
[2161] | 1168 | extern int expr_eval_if_conditionals(const char *line, const floc *flocp);
|
---|
[1715] | 1169 | extern char *expr_eval_to_string(char *o, const char *expr);
|
---|
| 1170 | #endif
|
---|
[1725] | 1171 |
|
---|
| 1172 | #ifdef KMK
|
---|
| 1173 | extern char *abspath(const char *name, char *apath);
|
---|
[2886] | 1174 | extern char *func_breakpoint(char *o, char **argv, const char *funcname);
|
---|
| 1175 | # ifdef KBUILD_OS_WINDOWS
|
---|
| 1176 | extern void dir_cache_invalid_after_job (void);
|
---|
[3359] | 1177 | extern void dir_cache_invalid_all (void);
|
---|
[2886] | 1178 | extern void dir_cache_invalid_all_and_close_dirs (int including_root);
|
---|
| 1179 | extern void dir_cache_invalid_missing (void);
|
---|
[2912] | 1180 | extern int dir_cache_volatile_dir (const char *dir);
|
---|
[2886] | 1181 | extern int dir_cache_deleted_directory(const char *pszDir);
|
---|
[1793] | 1182 | # endif
|
---|
[2101] | 1183 | #endif
|
---|
[3170] | 1184 |
|
---|
[2101] | 1185 | #if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH) || defined(CONFIG_WITH_KMK_BUILTIN_STATS)
|
---|
| 1186 | /* misc.c */
|
---|
| 1187 | extern big_int nano_timestamp (void);
|
---|
| 1188 | extern int format_elapsed_nano (char *buf, size_t size, big_int ts);
|
---|
| 1189 | #endif
|
---|
| 1190 |
|
---|