VirtualBox

source: kBuild/trunk/src/kmk/make.h@ 3068

Last change on this file since 3068 was 2912, checked in by bird, 8 years ago

rewrote kmk_redirect to skip the separate process. Added chache invalidation after directory deletion for addressing kmk rebuild and fetching.

  • Property svn:eol-style set to native
File size: 27.5 KB
Line 
1/* Miscellaneous global declarations and portability cruft for GNU Make.
2Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
31998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
42010 Free Software Foundation, Inc.
5This file is part of GNU Make.
6
7GNU Make is free software; you can redistribute it and/or modify it under the
8terms of the GNU General Public License as published by the Free Software
9Foundation; either version 3 of the License, or (at your option) any later
10version.
11
12GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License along with
17this program. If not, see <http://www.gnu.org/licenses/>. */
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/* 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
47#ifdef CRAY
48/* This must happen before #include <signal.h> so
49 that the declaration therein is changed. */
50# define signal bsdsignal
51#endif
52
53/* If we're compiling for the dmalloc debugger, turn off string inlining. */
54#if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
55# define __NO_STRING_INLINES
56#endif
57
58#include <sys/types.h>
59#include <sys/stat.h>
60#include <signal.h>
61#include <stdio.h>
62#include <ctype.h>
63#ifdef HAVE_SYS_TIMEB_H
64/* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
65 unless <sys/timeb.h> has been included first. Does every system have a
66 <sys/timeb.h>? If any does not, configure should check for it. */
67# include <sys/timeb.h>
68#endif
69
70#if TIME_WITH_SYS_TIME
71# include <sys/time.h>
72# include <time.h>
73#else
74# if HAVE_SYS_TIME_H
75# include <sys/time.h>
76# else
77# include <time.h>
78# endif
79#endif
80
81#include <errno.h>
82
83#ifndef errno
84extern int errno;
85#endif
86
87#ifndef isblank
88# define isblank(c) ((c) == ' ' || (c) == '\t')
89#endif
90
91#ifdef HAVE_UNISTD_H
92# include <unistd.h>
93/* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
94 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
95# if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
96# define POSIX 1
97# endif
98#endif
99
100/* Some systems define _POSIX_VERSION but are not really POSIX.1. */
101#if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
102# undef POSIX
103#endif
104
105#if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
106# define POSIX 1
107#endif
108
109#ifndef RETSIGTYPE
110# define RETSIGTYPE void
111#endif
112
113#ifndef sigmask
114# define sigmask(sig) (1 << ((sig) - 1))
115#endif
116
117#ifndef HAVE_SA_RESTART
118# define SA_RESTART 0
119#endif
120
121#ifdef HAVE_LIMITS_H
122# include <limits.h>
123#endif
124#ifdef HAVE_SYS_PARAM_H
125# include <sys/param.h>
126#endif
127
128#ifndef PATH_MAX
129# ifndef POSIX
130# define PATH_MAX MAXPATHLEN
131# endif
132#endif
133#ifndef MAXPATHLEN
134# define MAXPATHLEN 1024
135#endif
136
137#ifdef PATH_MAX
138# define GET_PATH_MAX PATH_MAX
139# define PATH_VAR(var) char var[PATH_MAX]
140#else
141# define NEED_GET_PATH_MAX 1
142# define GET_PATH_MAX (get_path_max ())
143# define PATH_VAR(var) char *var = alloca (GET_PATH_MAX)
144unsigned int get_path_max (void);
145#endif
146
147#if defined (KMK) || defined (CONFIG_WITH_VALUE_LENGTH) \
148 || defined (CONFIG_WITH_ALLOC_CACHES) \
149 || defined (CONFIG_WITH_STRCACHE2)
150# ifdef _MSC_VER
151# define MY_INLINE _inline static
152# elif defined(__GNUC__)
153# define MY_INLINE static __inline__
154# else
155# define MY_INLINE static
156# endif
157
158# ifdef __GNUC__
159# define MY_PREDICT_TRUE(expr) __builtin_expect(!!(expr), 1)
160# define MY_PREDICT_FALSE(expr) __builtin_expect(!!(expr), 0)
161# else
162# define MY_PREDICT_TRUE(expr) (expr)
163# define MY_PREDICT_FALSE(expr) (expr)
164# endif
165#endif
166
167#if defined (KMK) || defined (CONFIG_WITH_VALUE_LENGTH) \
168 || defined (CONFIG_WITH_STRCACHE2)
169# ifdef _MSC_VER
170# define MY_DBGBREAK __debugbreak()
171# elif defined(__GNUC__)
172# if defined(__i386__) || defined(__x86_64__)
173# define MY_DBGBREAK __asm__ __volatile__ ("int3")
174# else
175# define MY_DBGBREAK assert(0)
176# endif
177# else
178# define MY_DBGBREAK assert(0)
179# endif
180# ifndef NDEBUG
181# define MY_ASSERT_MSG(expr, printfargs) \
182 do { if (!(expr)) { printf printfargs; MY_DBGBREAK; } } while (0)
183# else
184# define MY_ASSERT_MSG(expr, printfargs) do { } while (0)
185# endif
186#endif
187
188#ifdef KMK
189# include <ctype.h>
190# if 1 /* See if this speeds things up (Windows is doing this anyway, so,
191 we might as well try be consistent in speed + features). */
192# if 1
193# define MY_IS_BLANK(ch) ((ch) == ' ' || (ch) == '\t')
194# define MY_IS_BLANK_OR_EOS(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\0')
195# else
196# define MY_IS_BLANK(ch) (((ch) == ' ') | ((ch) == '\t'))
197# define MY_IS_BLANK_OR_EOS(ch) (((ch) == ' ') | ((ch) == '\t') | ((ch) == '\0'))
198# endif
199# undef isblank
200# define isblank(ch) MY_IS_BLANK(ch)
201# else
202# define MY_IS_BLANK(ch) isblank ((unsigned char)(ch))
203# define MY_IS_BLANK_OR_EOS(ch) (isblank ((unsigned char)(ch)) || (ch) == '\0')
204# endif
205#endif
206
207#ifdef CONFIG_WITH_MAKE_STATS
208extern long make_stats_allocations;
209extern long make_stats_reallocations;
210extern unsigned long make_stats_allocated;
211extern unsigned long make_stats_ht_lookups;
212extern unsigned long make_stats_ht_collisions;
213
214# ifdef __APPLE__
215# include <malloc/malloc.h>
216# define SIZE_OF_HEAP_BLOCK(ptr) malloc_size(ptr)
217
218# elif defined(__linux__) /* glibc */
219# include <malloc.h>
220# define SIZE_OF_HEAP_BLOCK(ptr) malloc_usable_size(ptr)
221
222# elif defined(_MSC_VER) || defined(__OS2__)
223# define SIZE_OF_HEAP_BLOCK(ptr) _msize(ptr)
224
225# else
226# include <stdlib.h>
227# define SIZE_OF_HEAP_BLOCK(ptr) 0
228#endif
229
230# define MAKE_STATS_3(expr) do { expr; } while (0)
231# define MAKE_STATS_2(expr) do { expr; } while (0)
232# define MAKE_STATS(expr) do { expr; } while (0)
233#else
234# define MAKE_STATS_3(expr) do { } while (0)
235# define MAKE_STATS_2(expr) do { } while (0)
236# define MAKE_STATS(expr) do { } while (0)
237#endif
238
239/* bird - start */
240#ifdef _MSC_VER
241# include <intrin.h>
242# define CURRENT_CLOCK_TICK() __rdtsc()
243#else
244# define CURRENT_CLOCK_TICK() 0
245#endif
246
247#define COMMA ,
248#ifdef CONFIG_WITH_VALUE_LENGTH
249# define IF_WITH_VALUE_LENGTH(a_Expr) a_Expr
250# define IF_WITH_VALUE_LENGTH_PARAM(a_Expr) , a_Expr
251#else
252# define IF_WITH_VALUE_LENGTH(a_Expr)
253# define IF_WITH_VALUE_LENGTH_PARAM(a_Expr)
254#endif
255
256#ifdef CONFIG_WITH_ALLOC_CACHES
257# define IF_WITH_ALLOC_CACHES(a_Expr) a_Expr
258# define IF_WITH_ALLOC_CACHES_PARAM(a_Expr) , a_Expr
259#else
260# define IF_WITH_ALLOC_CACHES(a_Expr)
261# define IF_WITH_ALLOC_CACHES_PARAM(a_Expr)
262#endif
263
264#ifdef CONFIG_WITH_COMMANDS_FUNC
265# define IF_WITH_COMMANDS_FUNC(a_Expr) a_Expr
266# define IF_WITH_COMMANDS_FUNC_PARAM(a_Expr) , a_Expr
267#else
268# define IF_WITH_COMMANDS_FUNC(a_Expr)
269# define IF_WITH_COMMANDS_FUNC_PARAM(a_Expr)
270#endif
271
272/* bird - end */
273
274
275#ifndef CHAR_BIT
276# define CHAR_BIT 8
277#endif
278
279/* Nonzero if the integer type T is signed. */
280#define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
281
282/* The minimum and maximum values for the integer type T.
283 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
284#define INTEGER_TYPE_MINIMUM(t) \
285 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
286#define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
287
288#ifndef CHAR_MAX
289# define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
290#endif
291
292#ifdef STAT_MACROS_BROKEN
293# ifdef S_ISREG
294# undef S_ISREG
295# endif
296# ifdef S_ISDIR
297# undef S_ISDIR
298# endif
299#endif /* STAT_MACROS_BROKEN. */
300
301#ifndef S_ISREG
302# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
303#endif
304#ifndef S_ISDIR
305# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
306#endif
307
308#ifdef VMS
309# include <types.h>
310# include <unixlib.h>
311# include <unixio.h>
312# include <perror.h>
313/* Needed to use alloca on VMS. */
314# include <builtins.h>
315#endif
316
317#ifndef __attribute__
318/* This feature is available in gcc versions 2.5 and later. */
319# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
320# define __attribute__(x)
321# endif
322/* The __-protected variants of `format' and `printf' attributes
323 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
324# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
325# define __format__ format
326# define __printf__ printf
327# endif
328#endif
329#define UNUSED __attribute__ ((unused))
330
331#if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
332# include <stdlib.h>
333# include <string.h>
334# define ANSI_STRING 1
335#else /* No standard headers. */
336# ifdef HAVE_STRING_H
337# include <string.h>
338# define ANSI_STRING 1
339# else
340# include <strings.h>
341# endif
342# ifdef HAVE_MEMORY_H
343# include <memory.h>
344# endif
345# ifdef HAVE_STDLIB_H
346# include <stdlib.h>
347# else
348void *malloc (int);
349void *realloc (void *, int);
350void free (void *);
351
352void abort (void) __attribute__ ((noreturn));
353void exit (int) __attribute__ ((noreturn));
354# endif /* HAVE_STDLIB_H. */
355
356#endif /* Standard headers. */
357
358/* These should be in stdlib.h. Make sure we have them. */
359#ifndef EXIT_SUCCESS
360# define EXIT_SUCCESS 0
361#endif
362#ifndef EXIT_FAILURE
363# define EXIT_FAILURE 1
364#endif
365
366#ifndef ANSI_STRING
367
368/* SCO Xenix has a buggy macro definition in <string.h>. */
369#undef strerror
370#if !defined(__DECC)
371char *strerror (int errnum);
372#endif
373
374#endif /* !ANSI_STRING. */
375#undef ANSI_STRING
376
377#if HAVE_INTTYPES_H
378# include <inttypes.h>
379#endif
380#define FILE_TIMESTAMP uintmax_t
381
382#if !defined(HAVE_STRSIGNAL)
383char *strsignal (int signum);
384#endif
385
386/* ISDIGIT offers the following features:
387 - Its arg may be any int or unsigned int; it need not be an unsigned char.
388 - It's guaranteed to evaluate its argument exactly once.
389 NOTE! Make relies on this behavior, don't change it!
390 - It's typically faster.
391 POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
392 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
393 it's important to use the locale's definition of `digit' even when the
394 host does not conform to POSIX. */
395#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
396
397/* Test if two strings are equal. Is this worthwhile? Should be profiled. */
398#define streq(a, b) \
399 ((a) == (b) || \
400 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
401
402/* Test if two strings are equal, but match case-insensitively on systems
403 which have case-insensitive filesystems. Should only be used for
404 filenames! */
405#ifdef HAVE_CASE_INSENSITIVE_FS
406# define patheq(a, b) \
407 ((a) == (b) \
408 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
409 && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1))))
410#else
411# define patheq(a, b) streq(a, b)
412#endif
413
414#define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
415
416#if (defined(__GNUC__) || defined(ENUM_BITFIELDS)) && !defined(NO_ENUM_BITFIELDS)
417# define ENUM_BITFIELD(bits) :bits
418#else
419# define ENUM_BITFIELD(bits)
420#endif
421
422/* Handle gettext and locales. */
423
424#if HAVE_LOCALE_H
425# include <locale.h>
426#else
427# define setlocale(category, locale)
428#endif
429
430#include <gettext.h>
431
432#define _(msgid) gettext (msgid)
433#define N_(msgid) gettext_noop (msgid)
434#define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
435
436/* Handle other OSs. */
437#ifndef PATH_SEPARATOR_CHAR
438# if defined(HAVE_DOS_PATHS)
439# define PATH_SEPARATOR_CHAR ';'
440# elif defined(VMS)
441# define PATH_SEPARATOR_CHAR ','
442# else
443# define PATH_SEPARATOR_CHAR ':'
444# endif
445#endif
446
447/* This is needed for getcwd() and chdir(), on some W32 systems. */
448#if defined(HAVE_DIRECT_H)
449# include <direct.h>
450#endif
451
452#ifdef WINDOWS32
453# include <fcntl.h>
454# include <malloc.h>
455# define pipe(_p) _pipe((_p), 512, O_BINARY)
456# define kill(_pid,_sig) w32_kill((_pid),(_sig))
457
458void sync_Path_environment (void);
459int w32_kill (pid_t pid, int sig);
460char *end_of_token_w32 (const char *s, char stopchar);
461int find_and_set_default_shell (const char *token);
462
463/* indicates whether or not we have Bourne shell */
464extern int no_default_sh_exe;
465
466/* is default_shell unixy? */
467extern int unixy_shell;
468#endif /* WINDOWS32 */
469
470#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
471# define SET_STACK_SIZE
472#endif
473#ifdef SET_STACK_SIZE
474# include <sys/resource.h>
475struct rlimit stack_limit;
476#endif
477
478struct floc
479 {
480 const char *filenm;
481 unsigned long lineno;
482 };
483#define NILF ((struct floc *)0)
484
485#define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
486
487#if defined (CONFIG_WITH_MATH) \
488 || defined (CONFIG_WITH_NANOTS) \
489 || defined (CONFIG_WITH_FILE_SIZE) \
490 || defined (CONFIG_WITH_PRINT_TIME_SWITCH) /* bird */
491# ifdef _MSC_VER
492typedef __int64 big_int;
493# define BIG_INT_C(c) (c ## LL)
494typedef unsigned __int64 big_uint;
495# define BIG_UINT_C(c) (c ## ULL)
496# else
497# include <stdint.h>
498typedef int64_t big_int;
499# define BIG_INT_C(c) INT64_C(c)
500typedef uint64_t big_uint;
501# define BIG_UINT_C(c) UINT64_C(c)
502# endif
503#endif
504
505
506
507/* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
508 variadic versions of these functions. */
509
510#if HAVE_STDARG_H || HAVE_VARARGS_H
511# if HAVE_VPRINTF || HAVE_DOPRNT
512# define USE_VARIADIC 1
513# endif
514#endif
515
516#if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
517const char *concat (unsigned int, ...);
518void message (int prefix, const char *fmt, ...)
519 __attribute__ ((__format__ (__printf__, 2, 3)));
520void error (const struct floc *flocp, const char *fmt, ...)
521 __attribute__ ((__format__ (__printf__, 2, 3)));
522void fatal (const struct floc *flocp, const char *fmt, ...)
523 __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
524#else
525const char *concat ();
526void message ();
527void error ();
528void fatal ();
529#endif
530
531void die (int) __attribute__ ((noreturn));
532void log_working_directory (int);
533void pfatal_with_name (const char *) __attribute__ ((noreturn));
534void perror_with_name (const char *, const char *);
535void *xmalloc (unsigned int);
536void *xcalloc (unsigned int);
537void *xrealloc (void *, unsigned int);
538char *xstrdup (const char *);
539char *xstrndup (const char *, unsigned int);
540#ifdef CONFIG_WITH_PRINT_STATS_SWITCH
541void print_heap_stats (void);
542#endif
543char *find_next_token (const char **, unsigned int *);
544char *next_token (const char *);
545char *end_of_token (const char *);
546#ifdef KMK
547char *find_next_token_eos (const char **ptr, const char *eos, unsigned int *lengthptr);
548#endif
549#ifndef CONFIG_WITH_VALUE_LENGTH
550void collapse_continuations (char *);
551#else
552char *collapse_continuations (char *, unsigned int);
553#endif
554#ifdef CONFIG_WITH_OPTIMIZATION_HACKS /* memchr is usually compiler intrinsic, thus faster. */
555# define lindex(s, limit, c) ((char *)memchr((s), (c), (limit) - (s)))
556#else
557char *lindex (const char *, const char *, int);
558#endif
559int alpha_compare (const void *, const void *);
560void print_spaces (unsigned int);
561char *find_percent (char *);
562const char *find_percent_cached (const char **);
563FILE *open_tmpfile (char **, const char *);
564
565#ifndef NO_ARCHIVES
566int ar_name (const char *);
567void ar_parse_name (const char *, char **, char **);
568int ar_touch (const char *);
569time_t ar_member_date (const char *);
570
571typedef long int (*ar_member_func_t) (int desc, const char *mem, int truncated,
572 long int hdrpos, long int datapos,
573 long int size, long int date, int uid,
574 int gid, int mode, const void *arg);
575
576long int ar_scan (const char *archive, ar_member_func_t function, const void *arg);
577int ar_name_equal (const char *name, const char *mem, int truncated);
578#ifndef VMS
579int ar_member_touch (const char *arname, const char *memname);
580#endif
581#endif
582
583int dir_file_exists_p (const char *, const char *);
584int file_exists_p (const char *);
585int file_impossible_p (const char *);
586void file_impossible (const char *);
587const char *dir_name (const char *);
588void hash_init_directories (void);
589
590void define_default_variables (void);
591void set_default_suffixes (void);
592void install_default_suffix_rules (void);
593void install_default_implicit_rules (void);
594
595void build_vpath_lists (void);
596void construct_vpath_list (char *pattern, char *dirpath);
597const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr,
598 unsigned int* vpath_index, unsigned int* path_index);
599int gpath_search (const char *file, unsigned int len);
600
601void construct_include_path (const char **arg_dirs);
602
603void user_access (void);
604void make_access (void);
605void child_access (void);
606
607void close_stdout (void);
608
609char *strip_whitespace (const char **begpp, const char **endpp);
610
611#ifdef CONFIG_WITH_ALLOC_CACHES
612/* alloccache (misc.c) */
613
614struct alloccache_free_ent
615{
616 struct alloccache_free_ent *next;
617};
618
619struct alloccache
620{
621 char *free_start;
622 char *free_end;
623 struct alloccache_free_ent *free_head;
624 unsigned int size;
625 unsigned int total_count;
626 unsigned long alloc_count;
627 unsigned long free_count;
628 const char *name;
629 struct alloccache *next;
630 void *grow_arg;
631 void *(*grow_alloc)(void *grow_arg, unsigned int size);
632};
633
634void alloccache_init (struct alloccache *cache, unsigned int size, const char *name,
635 void *(*grow_alloc)(void *grow_arg, unsigned int size), void *grow_arg);
636void alloccache_term (struct alloccache *cache,
637 void (*term_free)(void *term_arg, void *ptr, unsigned int size), void *term_arg);
638void alloccache_join (struct alloccache *cache, struct alloccache *eat);
639void alloccache_print (struct alloccache *cache);
640void alloccache_print_all (void);
641struct alloccache_free_ent *alloccache_alloc_grow (struct alloccache *cache);
642void alloccache_free (struct alloccache *cache, void *item);
643
644/* Allocate an item. */
645MY_INLINE void *
646alloccache_alloc (struct alloccache *cache)
647{
648 struct alloccache_free_ent *f;
649# ifndef CONFIG_WITH_ALLOCCACHE_DEBUG
650 f = cache->free_head;
651 if (f)
652 cache->free_head = f->next;
653 else if (cache->free_start != cache->free_end)
654 {
655 f = (struct alloccache_free_ent *)cache->free_start;
656 cache->free_start += cache->size;
657 }
658 else
659# endif
660 f = alloccache_alloc_grow (cache);
661 MAKE_STATS(cache->alloc_count++;);
662 return f;
663}
664
665/* Allocate a cleared item. */
666MY_INLINE void *
667alloccache_calloc (struct alloccache *cache)
668{
669 void *item = alloccache_alloc (cache);
670 memset (item, '\0', cache->size);
671 return item;
672}
673
674
675/* the alloc caches */
676extern struct alloccache dep_cache;
677extern struct alloccache file_cache;
678extern struct alloccache commands_cache;
679extern struct alloccache nameseq_cache;
680extern struct alloccache variable_cache;
681extern struct alloccache variable_set_cache;
682extern struct alloccache variable_set_list_cache;
683
684#endif /* CONFIG_WITH_ALLOC_CACHES */
685
686
687/* String caching */
688void strcache_init (void);
689void strcache_print_stats (const char *prefix);
690#ifndef CONFIG_WITH_STRCACHE2
691int strcache_iscached (const char *str);
692const char *strcache_add (const char *str);
693const char *strcache_add_len (const char *str, int len);
694int strcache_setbufsize (int size);
695#else /* CONFIG_WITH_STRCACHE2 */
696
697# include "strcache2.h"
698extern struct strcache2 file_strcache;
699extern const char *suffixes_strcached;
700
701# define strcache_iscached(str) strcache2_is_cached(&file_strcache, str)
702# define strcache_add(str) strcache2_add_file(&file_strcache, str, strlen (str))
703# define strcache_add_len(str, len) strcache2_add_file(&file_strcache, str, len)
704# define strcache_get_len(str) strcache2_get_len(&file_strcache, str) /* FIXME: replace this and related checks ... */
705
706#endif /* CONFIG_WITH_STRCACHE2 */
707
708#ifdef HAVE_VFORK_H
709# include <vfork.h>
710#endif
711
712/* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
713 because such systems often declare them in header files anyway. */
714
715#if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
716
717long int atol ();
718# ifndef VMS
719long int lseek ();
720# endif
721
722#endif /* Not GNU C library or POSIX. */
723
724#ifdef HAVE_GETCWD
725# if !defined(VMS) && !defined(__DECC) && !defined(_MSC_VER) /* bird: MSC */
726char *getcwd ();
727# endif
728#else
729char *getwd ();
730# define getcwd(buf, len) getwd (buf)
731#endif
732
733#if !HAVE_STRCASECMP
734# if HAVE_STRICMP
735# define strcasecmp stricmp
736# elif HAVE_STRCMPI
737# define strcasecmp strcmpi
738# else
739/* Create our own, in misc.c */
740int strcasecmp (const char *s1, const char *s2);
741# endif
742#endif
743
744#if !HAVE_STRNCASECMP
745# if HAVE_STRNICMP
746# define strncasecmp strnicmp
747# elif HAVE_STRNCMPI
748# define strncasecmp strncmpi
749# else
750/* Create our own, in misc.c */
751int strncasecmp (const char *s1, const char *s2, int n);
752# endif
753#endif
754
755extern const struct floc *reading_file;
756extern const struct floc **expanding_var;
757
758#if !defined(_MSC_VER) /* bird */
759extern char **environ;
760#endif
761
762extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
763extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
764extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
765extern int print_version_flag, print_directory_flag, check_symlink_flag;
766extern int warn_undefined_variables_flag, posix_pedantic, not_parallel;
767extern int second_expansion, clock_skew_detected, rebuilding_makefiles;
768extern int one_shell;
769
770#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
771extern int second_target_expansion;
772#endif
773#ifdef CONFIG_PRETTY_COMMAND_PRINTING
774extern int pretty_command_printing;
775#endif
776#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
777extern int print_time_min, print_time_width;
778#endif
779#if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
780extern int make_expensive_statistics;
781#endif
782
783
784/* can we run commands via 'sh -c xxx' or must we use batch files? */
785extern int batch_mode_shell;
786
787/* Resetting the command script introduction prefix character. */
788#define RECIPEPREFIX_NAME ".RECIPEPREFIX"
789#define RECIPEPREFIX_DEFAULT '\t'
790extern char cmd_prefix;
791
792extern unsigned int job_slots;
793extern int job_fds[2];
794extern int job_rfd;
795#ifndef NO_FLOAT
796extern double max_load_average;
797#else
798extern int max_load_average;
799#endif
800
801extern char *program;
802extern char *starting_directory;
803extern unsigned int makelevel;
804extern char *version_string, *remote_description, *make_host;
805
806extern unsigned int commands_started;
807
808extern int handling_fatal_signal;
809
810
811#ifndef MIN
812#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
813#endif
814#ifndef MAX
815#define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
816#endif
817
818#ifdef VMS
819# define MAKE_SUCCESS 1
820# define MAKE_TROUBLE 2
821# define MAKE_FAILURE 3
822#else
823# define MAKE_SUCCESS 0
824# define MAKE_TROUBLE 1
825# define MAKE_FAILURE 2
826#endif
827
828/* Set up heap debugging library dmalloc. */
829
830#ifdef HAVE_DMALLOC_H
831#include <dmalloc.h>
832#endif
833
834#ifndef initialize_main
835# ifdef __EMX__
836# define initialize_main(pargc, pargv) \
837 { _wildcard(pargc, pargv); _response(pargc, pargv); }
838# else
839# define initialize_main(pargc, pargv)
840# endif
841#endif
842
843#ifdef __EMX__
844# if !defined chdir
845# define chdir _chdir2
846# endif
847# if !defined getcwd
848# define getcwd _getcwd2
849# endif
850
851/* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
852 chdir() and getcwd(). This avoids some error messages for the
853 make testsuite but restricts the drive letter support. */
854# ifdef NO_CHDIR2
855# warning NO_CHDIR2: usage of drive letters restricted
856# undef chdir
857# undef getcwd
858# endif
859#endif
860
861#ifndef initialize_main
862# define initialize_main(pargc, pargv)
863#endif
864
865
866/* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
867 properly according to POSIX. So, we try to wrap common system calls with
868 checks for EINTR. Note that there are still plenty of system calls that
869 can fail with EINTR but this, reportedly, gets the vast majority of
870 failure cases. If you still experience failures you'll need to either get
871 a system where SA_RESTART works, or you need to avoid -j. */
872
873#define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
874
875/* While system calls that return integers are pretty consistent about
876 returning -1 on failure and setting errno in that case, functions that
877 return pointers are not always so well behaved. Sometimes they return
878 NULL for expected behavior: one good example is readdir() which returns
879 NULL at the end of the directory--and _doesn't_ reset errno. So, we have
880 to do it ourselves here. */
881
882#define ENULLLOOP(_v,_c) do { errno = 0; (_v) = _c; } \
883 while((_v)==0 && errno==EINTR)
884
885
886#if defined(__EMX__) && defined(CONFIG_WITH_OPTIMIZATION_HACKS) /* bird: saves 40-100ms on libc. */
887static inline void *__my_rawmemchr (const void *__s, int __c);
888#undef strchr
889#define strchr(s, c) \
890 (__extension__ (__builtin_constant_p (c) \
891 ? ((c) == '\0' \
892 ? (char *) __my_rawmemchr ((s), (c)) \
893 : __my_strchr_c ((s), ((c) & 0xff) << 8)) \
894 : __my_strchr_g ((s), (c))))
895static inline char *__my_strchr_c (const char *__s, int __c)
896{
897 register unsigned long int __d0;
898 register char *__res;
899 __asm__ __volatile__
900 ("1:\n\t"
901 "movb (%0),%%al\n\t"
902 "cmpb %%ah,%%al\n\t"
903 "je 2f\n\t"
904 "leal 1(%0),%0\n\t"
905 "testb %%al,%%al\n\t"
906 "jne 1b\n\t"
907 "xorl %0,%0\n"
908 "2:"
909 : "=r" (__res), "=&a" (__d0)
910 : "0" (__s), "1" (__c),
911 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
912 : "cc");
913 return __res;
914}
915
916static inline char *__my_strchr_g (__const char *__s, int __c)
917{
918 register unsigned long int __d0;
919 register char *__res;
920 __asm__ __volatile__
921 ("movb %%al,%%ah\n"
922 "1:\n\t"
923 "movb (%0),%%al\n\t"
924 "cmpb %%ah,%%al\n\t"
925 "je 2f\n\t"
926 "leal 1(%0),%0\n\t"
927 "testb %%al,%%al\n\t"
928 "jne 1b\n\t"
929 "xorl %0,%0\n"
930 "2:"
931 : "=r" (__res), "=&a" (__d0)
932 : "0" (__s), "1" (__c),
933 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
934 : "cc");
935 return __res;
936}
937
938static inline void *__my_rawmemchr (const void *__s, int __c)
939{
940 register unsigned long int __d0;
941 register unsigned char *__res;
942 __asm__ __volatile__
943 ("cld\n\t"
944 "repne; scasb\n\t"
945 : "=D" (__res), "=&c" (__d0)
946 : "a" (__c), "0" (__s), "1" (0xffffffff),
947 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
948 : "cc");
949 return __res - 1;
950}
951
952#undef memchr
953#define memchr(a,b,c) __my_memchr((a),(b),(c))
954static inline void *__my_memchr (__const void *__s, int __c, size_t __n)
955{
956 register unsigned long int __d0;
957 register unsigned char *__res;
958 if (__n == 0)
959 return NULL;
960 __asm__ __volatile__
961 ("repne; scasb\n\t"
962 "je 1f\n\t"
963 "movl $1,%0\n"
964 "1:"
965 : "=D" (__res), "=&c" (__d0)
966 : "a" (__c), "0" (__s), "1" (__n),
967 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
968 : "cc");
969 return __res - 1;
970}
971
972#endif /* __EMX__ (bird) */
973
974#ifdef CONFIG_WITH_IF_CONDITIONALS
975extern int expr_eval_if_conditionals(const char *line, const struct floc *flocp);
976extern char *expr_eval_to_string(char *o, const char *expr);
977#endif
978
979#ifdef KMK
980extern char *abspath(const char *name, char *apath);
981extern char *func_breakpoint(char *o, char **argv, const char *funcname);
982# ifdef KBUILD_OS_WINDOWS
983extern void dir_cache_invalid_after_job (void);
984extern void dir_cache_invalid_all (void);
985extern void dir_cache_invalid_missing (void);
986extern int dir_cache_volatile_dir (const char *dir);
987extern int dir_cache_deleted_directory(const char *pszDir);
988# endif
989#endif
990
991#if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH)
992/* misc.c */
993extern big_int nano_timestamp (void);
994extern int format_elapsed_nano (char *buf, size_t size, big_int ts);
995#endif
996
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette