source: trunk/src/kmk/makeint.h@ 3651

Last change on this file since 3651 was 3651, checked in by bird, 9 months ago

kmk: debug win.arm64 build fix

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