VirtualBox

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

Last change on this file since 2665 was 2633, checked in by bird, 12 years ago

kmk: CONFIG_WITH_ALLOCCACHE_DEBUG - for optionally turning the allocations over to the heap where they can be checked and fenced in.

  • Property svn:eol-style set to native
File size: 27.1 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_good_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#define COMMA ,
241#ifdef CONFIG_WITH_VALUE_LENGTH
242# define IF_WITH_VALUE_LENGTH(a_Expr) a_Expr
243# define IF_WITH_VALUE_LENGTH_PARAM(a_Expr) , a_Expr
244#else
245# define IF_WITH_VALUE_LENGTH(a_Expr)
246# define IF_WITH_VALUE_LENGTH_PARAM(a_Expr)
247#endif
248
249#ifdef CONFIG_WITH_ALLOC_CACHES
250# define IF_WITH_ALLOC_CACHES(a_Expr) a_Expr
251# define IF_WITH_ALLOC_CACHES_PARAM(a_Expr) , a_Expr
252#else
253# define IF_WITH_ALLOC_CACHES(a_Expr)
254# define IF_WITH_ALLOC_CACHES_PARAM(a_Expr)
255#endif
256
257#ifdef CONFIG_WITH_COMMANDS_FUNC
258# define IF_WITH_COMMANDS_FUNC(a_Expr) a_Expr
259# define IF_WITH_COMMANDS_FUNC_PARAM(a_Expr) , a_Expr
260#else
261# define IF_WITH_COMMANDS_FUNC(a_Expr)
262# define IF_WITH_COMMANDS_FUNC_PARAM(a_Expr)
263#endif
264
265/* bird - end */
266
267
268#ifndef CHAR_BIT
269# define CHAR_BIT 8
270#endif
271
272/* Nonzero if the integer type T is signed. */
273#define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
274
275/* The minimum and maximum values for the integer type T.
276 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
277#define INTEGER_TYPE_MINIMUM(t) \
278 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
279#define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
280
281#ifndef CHAR_MAX
282# define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
283#endif
284
285#ifdef STAT_MACROS_BROKEN
286# ifdef S_ISREG
287# undef S_ISREG
288# endif
289# ifdef S_ISDIR
290# undef S_ISDIR
291# endif
292#endif /* STAT_MACROS_BROKEN. */
293
294#ifndef S_ISREG
295# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
296#endif
297#ifndef S_ISDIR
298# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
299#endif
300
301#ifdef VMS
302# include <types.h>
303# include <unixlib.h>
304# include <unixio.h>
305# include <perror.h>
306/* Needed to use alloca on VMS. */
307# include <builtins.h>
308#endif
309
310#ifndef __attribute__
311/* This feature is available in gcc versions 2.5 and later. */
312# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
313# define __attribute__(x)
314# endif
315/* The __-protected variants of `format' and `printf' attributes
316 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
317# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
318# define __format__ format
319# define __printf__ printf
320# endif
321#endif
322#define UNUSED __attribute__ ((unused))
323
324#if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
325# include <stdlib.h>
326# include <string.h>
327# define ANSI_STRING 1
328#else /* No standard headers. */
329# ifdef HAVE_STRING_H
330# include <string.h>
331# define ANSI_STRING 1
332# else
333# include <strings.h>
334# endif
335# ifdef HAVE_MEMORY_H
336# include <memory.h>
337# endif
338# ifdef HAVE_STDLIB_H
339# include <stdlib.h>
340# else
341void *malloc (int);
342void *realloc (void *, int);
343void free (void *);
344
345void abort (void) __attribute__ ((noreturn));
346void exit (int) __attribute__ ((noreturn));
347# endif /* HAVE_STDLIB_H. */
348
349#endif /* Standard headers. */
350
351/* These should be in stdlib.h. Make sure we have them. */
352#ifndef EXIT_SUCCESS
353# define EXIT_SUCCESS 0
354#endif
355#ifndef EXIT_FAILURE
356# define EXIT_FAILURE 1
357#endif
358
359#ifndef ANSI_STRING
360
361/* SCO Xenix has a buggy macro definition in <string.h>. */
362#undef strerror
363#if !defined(__DECC)
364char *strerror (int errnum);
365#endif
366
367#endif /* !ANSI_STRING. */
368#undef ANSI_STRING
369
370#if HAVE_INTTYPES_H
371# include <inttypes.h>
372#endif
373#define FILE_TIMESTAMP uintmax_t
374
375#if !defined(HAVE_STRSIGNAL)
376char *strsignal (int signum);
377#endif
378
379/* ISDIGIT offers the following features:
380 - Its arg may be any int or unsigned int; it need not be an unsigned char.
381 - It's guaranteed to evaluate its argument exactly once.
382 NOTE! Make relies on this behavior, don't change it!
383 - It's typically faster.
384 POSIX 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
385 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
386 it's important to use the locale's definition of `digit' even when the
387 host does not conform to POSIX. */
388#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
389
390/* Test if two strings are equal. Is this worthwhile? Should be profiled. */
391#define streq(a, b) \
392 ((a) == (b) || \
393 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
394
395/* Test if two strings are equal, but match case-insensitively on systems
396 which have case-insensitive filesystems. Should only be used for
397 filenames! */
398#ifdef HAVE_CASE_INSENSITIVE_FS
399# define patheq(a, b) \
400 ((a) == (b) \
401 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
402 && (*(a) == '\0' || !strcasecmp ((a) + 1, (b) + 1))))
403#else
404# define patheq(a, b) streq(a, b)
405#endif
406
407#define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
408
409#if (defined(__GNUC__) || defined(ENUM_BITFIELDS)) && !defined(NO_ENUM_BITFIELDS)
410# define ENUM_BITFIELD(bits) :bits
411#else
412# define ENUM_BITFIELD(bits)
413#endif
414
415/* Handle gettext and locales. */
416
417#if HAVE_LOCALE_H
418# include <locale.h>
419#else
420# define setlocale(category, locale)
421#endif
422
423#include <gettext.h>
424
425#define _(msgid) gettext (msgid)
426#define N_(msgid) gettext_noop (msgid)
427#define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
428
429/* Handle other OSs. */
430#ifndef PATH_SEPARATOR_CHAR
431# if defined(HAVE_DOS_PATHS)
432# define PATH_SEPARATOR_CHAR ';'
433# elif defined(VMS)
434# define PATH_SEPARATOR_CHAR ','
435# else
436# define PATH_SEPARATOR_CHAR ':'
437# endif
438#endif
439
440/* This is needed for getcwd() and chdir(), on some W32 systems. */
441#if defined(HAVE_DIRECT_H)
442# include <direct.h>
443#endif
444
445#ifdef WINDOWS32
446# include <fcntl.h>
447# include <malloc.h>
448# define pipe(_p) _pipe((_p), 512, O_BINARY)
449# define kill(_pid,_sig) w32_kill((_pid),(_sig))
450
451void sync_Path_environment (void);
452int w32_kill (pid_t pid, int sig);
453char *end_of_token_w32 (const char *s, char stopchar);
454int find_and_set_default_shell (const char *token);
455
456/* indicates whether or not we have Bourne shell */
457extern int no_default_sh_exe;
458
459/* is default_shell unixy? */
460extern int unixy_shell;
461#endif /* WINDOWS32 */
462
463#if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
464# define SET_STACK_SIZE
465#endif
466#ifdef SET_STACK_SIZE
467# include <sys/resource.h>
468struct rlimit stack_limit;
469#endif
470
471struct floc
472 {
473 const char *filenm;
474 unsigned long lineno;
475 };
476#define NILF ((struct floc *)0)
477
478#define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
479
480#if defined (CONFIG_WITH_MATH) \
481 || defined (CONFIG_WITH_NANOTS) \
482 || defined (CONFIG_WITH_FILE_SIZE) \
483 || defined (CONFIG_WITH_PRINT_TIME_SWITCH) /* bird */
484# ifdef _MSC_VER
485typedef __int64 big_int;
486# define BIG_INT_C(c) (c ## LL)
487typedef unsigned __int64 big_uint;
488# define BIG_UINT_C(c) (c ## ULL)
489# else
490# include <stdint.h>
491typedef int64_t big_int;
492# define BIG_INT_C(c) INT64_C(c)
493typedef uint64_t big_uint;
494# define BIG_UINT_C(c) UINT64_C(c)
495# endif
496#endif
497
498
499
500/* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
501 variadic versions of these functions. */
502
503#if HAVE_STDARG_H || HAVE_VARARGS_H
504# if HAVE_VPRINTF || HAVE_DOPRNT
505# define USE_VARIADIC 1
506# endif
507#endif
508
509#if HAVE_ANSI_COMPILER && USE_VARIADIC && HAVE_STDARG_H
510const char *concat (unsigned int, ...);
511void message (int prefix, const char *fmt, ...)
512 __attribute__ ((__format__ (__printf__, 2, 3)));
513void error (const struct floc *flocp, const char *fmt, ...)
514 __attribute__ ((__format__ (__printf__, 2, 3)));
515void fatal (const struct floc *flocp, const char *fmt, ...)
516 __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
517#else
518const char *concat ();
519void message ();
520void error ();
521void fatal ();
522#endif
523
524void die (int) __attribute__ ((noreturn));
525void log_working_directory (int);
526void pfatal_with_name (const char *) __attribute__ ((noreturn));
527void perror_with_name (const char *, const char *);
528void *xmalloc (unsigned int);
529void *xcalloc (unsigned int);
530void *xrealloc (void *, unsigned int);
531char *xstrdup (const char *);
532char *xstrndup (const char *, unsigned int);
533#ifdef CONFIG_WITH_PRINT_STATS_SWITCH
534void print_heap_stats (void);
535#endif
536char *find_next_token (const char **, unsigned int *);
537char *next_token (const char *);
538char *end_of_token (const char *);
539#ifdef KMK
540char *find_next_token_eos (const char **ptr, const char *eos, unsigned int *lengthptr);
541#endif
542#ifndef CONFIG_WITH_VALUE_LENGTH
543void collapse_continuations (char *);
544#else
545char *collapse_continuations (char *, unsigned int);
546#endif
547#ifdef CONFIG_WITH_OPTIMIZATION_HACKS /* memchr is usually compiler intrinsic, thus faster. */
548# define lindex(s, limit, c) ((char *)memchr((s), (c), (limit) - (s)))
549#else
550char *lindex (const char *, const char *, int);
551#endif
552int alpha_compare (const void *, const void *);
553void print_spaces (unsigned int);
554char *find_percent (char *);
555const char *find_percent_cached (const char **);
556FILE *open_tmpfile (char **, const char *);
557
558#ifndef NO_ARCHIVES
559int ar_name (const char *);
560void ar_parse_name (const char *, char **, char **);
561int ar_touch (const char *);
562time_t ar_member_date (const char *);
563
564typedef long int (*ar_member_func_t) (int desc, const char *mem, int truncated,
565 long int hdrpos, long int datapos,
566 long int size, long int date, int uid,
567 int gid, int mode, const void *arg);
568
569long int ar_scan (const char *archive, ar_member_func_t function, const void *arg);
570int ar_name_equal (const char *name, const char *mem, int truncated);
571#ifndef VMS
572int ar_member_touch (const char *arname, const char *memname);
573#endif
574#endif
575
576int dir_file_exists_p (const char *, const char *);
577int file_exists_p (const char *);
578int file_impossible_p (const char *);
579void file_impossible (const char *);
580const char *dir_name (const char *);
581void hash_init_directories (void);
582
583void define_default_variables (void);
584void set_default_suffixes (void);
585void install_default_suffix_rules (void);
586void install_default_implicit_rules (void);
587
588void build_vpath_lists (void);
589void construct_vpath_list (char *pattern, char *dirpath);
590const char *vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr,
591 unsigned int* vpath_index, unsigned int* path_index);
592int gpath_search (const char *file, unsigned int len);
593
594void construct_include_path (const char **arg_dirs);
595
596void user_access (void);
597void make_access (void);
598void child_access (void);
599
600void close_stdout (void);
601
602char *strip_whitespace (const char **begpp, const char **endpp);
603
604#ifdef CONFIG_WITH_ALLOC_CACHES
605/* alloccache (misc.c) */
606
607struct alloccache_free_ent
608{
609 struct alloccache_free_ent *next;
610};
611
612struct alloccache
613{
614 char *free_start;
615 char *free_end;
616 struct alloccache_free_ent *free_head;
617 unsigned int size;
618 unsigned int total_count;
619 unsigned long alloc_count;
620 unsigned long free_count;
621 const char *name;
622 struct alloccache *next;
623 void *grow_arg;
624 void *(*grow_alloc)(void *grow_arg, unsigned int size);
625};
626
627void alloccache_init (struct alloccache *cache, unsigned int size, const char *name,
628 void *(*grow_alloc)(void *grow_arg, unsigned int size), void *grow_arg);
629void alloccache_term (struct alloccache *cache,
630 void (*term_free)(void *term_arg, void *ptr, unsigned int size), void *term_arg);
631void alloccache_join (struct alloccache *cache, struct alloccache *eat);
632void alloccache_print (struct alloccache *cache);
633void alloccache_print_all (void);
634struct alloccache_free_ent *alloccache_alloc_grow (struct alloccache *cache);
635void alloccache_free (struct alloccache *cache, void *item);
636
637/* Allocate an item. */
638MY_INLINE void *
639alloccache_alloc (struct alloccache *cache)
640{
641 struct alloccache_free_ent *f;
642# ifndef CONFIG_WITH_ALLOCCACHE_DEBUG
643 f = cache->free_head;
644 if (f)
645 cache->free_head = f->next;
646 else if (cache->free_start != cache->free_end)
647 {
648 f = (struct alloccache_free_ent *)cache->free_start;
649 cache->free_start += cache->size;
650 }
651 else
652# endif
653 f = alloccache_alloc_grow (cache);
654 MAKE_STATS(cache->alloc_count++;);
655 return f;
656}
657
658/* Allocate a cleared item. */
659MY_INLINE void *
660alloccache_calloc (struct alloccache *cache)
661{
662 void *item = alloccache_alloc (cache);
663 memset (item, '\0', cache->size);
664 return item;
665}
666
667
668/* the alloc caches */
669extern struct alloccache dep_cache;
670extern struct alloccache file_cache;
671extern struct alloccache commands_cache;
672extern struct alloccache nameseq_cache;
673extern struct alloccache variable_cache;
674extern struct alloccache variable_set_cache;
675extern struct alloccache variable_set_list_cache;
676
677#endif /* CONFIG_WITH_ALLOC_CACHES */
678
679
680/* String caching */
681void strcache_init (void);
682void strcache_print_stats (const char *prefix);
683#ifndef CONFIG_WITH_STRCACHE2
684int strcache_iscached (const char *str);
685const char *strcache_add (const char *str);
686const char *strcache_add_len (const char *str, int len);
687int strcache_setbufsize (int size);
688#else /* CONFIG_WITH_STRCACHE2 */
689
690# include "strcache2.h"
691extern struct strcache2 file_strcache;
692extern const char *suffixes_strcached;
693
694# define strcache_iscached(str) strcache2_is_cached(&file_strcache, str)
695# define strcache_add(str) strcache2_add_file(&file_strcache, str, strlen (str))
696# define strcache_add_len(str, len) strcache2_add_file(&file_strcache, str, len)
697# define strcache_get_len(str) strcache2_get_len(&file_strcache, str) /* FIXME: replace this and related checks ... */
698
699#endif /* CONFIG_WITH_STRCACHE2 */
700
701#ifdef HAVE_VFORK_H
702# include <vfork.h>
703#endif
704
705/* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
706 because such systems often declare them in header files anyway. */
707
708#if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
709
710long int atol ();
711# ifndef VMS
712long int lseek ();
713# endif
714
715#endif /* Not GNU C library or POSIX. */
716
717#ifdef HAVE_GETCWD
718# if !defined(VMS) && !defined(__DECC) && !defined(_MSC_VER) /* bird: MSC */
719char *getcwd ();
720# endif
721#else
722char *getwd ();
723# define getcwd(buf, len) getwd (buf)
724#endif
725
726#if !HAVE_STRCASECMP
727# if HAVE_STRICMP
728# define strcasecmp stricmp
729# elif HAVE_STRCMPI
730# define strcasecmp strcmpi
731# else
732/* Create our own, in misc.c */
733int strcasecmp (const char *s1, const char *s2);
734# endif
735#endif
736
737#if !HAVE_STRNCASECMP
738# if HAVE_STRNICMP
739# define strncasecmp strnicmp
740# elif HAVE_STRNCMPI
741# define strncasecmp strncmpi
742# else
743/* Create our own, in misc.c */
744int strncasecmp (const char *s1, const char *s2, int n);
745# endif
746#endif
747
748extern const struct floc *reading_file;
749extern const struct floc **expanding_var;
750
751#if !defined(_MSC_VER) /* bird */
752extern char **environ;
753#endif
754
755extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
756extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
757extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
758extern int print_version_flag, print_directory_flag, check_symlink_flag;
759extern int warn_undefined_variables_flag, posix_pedantic, not_parallel;
760extern int second_expansion, clock_skew_detected, rebuilding_makefiles;
761extern int one_shell;
762
763#ifdef CONFIG_WITH_2ND_TARGET_EXPANSION
764extern int second_target_expansion;
765#endif
766#ifdef CONFIG_PRETTY_COMMAND_PRINTING
767extern int pretty_command_printing;
768#endif
769#ifdef CONFIG_WITH_PRINT_TIME_SWITCH
770extern int print_time_min, print_time_width;
771#endif
772#if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
773extern int make_expensive_statistics;
774#endif
775
776
777/* can we run commands via 'sh -c xxx' or must we use batch files? */
778extern int batch_mode_shell;
779
780/* Resetting the command script introduction prefix character. */
781#define RECIPEPREFIX_NAME ".RECIPEPREFIX"
782#define RECIPEPREFIX_DEFAULT '\t'
783extern char cmd_prefix;
784
785extern unsigned int job_slots;
786extern int job_fds[2];
787extern int job_rfd;
788#ifndef NO_FLOAT
789extern double max_load_average;
790#else
791extern int max_load_average;
792#endif
793
794extern char *program;
795extern char *starting_directory;
796extern unsigned int makelevel;
797extern char *version_string, *remote_description, *make_host;
798
799extern unsigned int commands_started;
800
801extern int handling_fatal_signal;
802
803
804#ifndef MIN
805#define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
806#endif
807#ifndef MAX
808#define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
809#endif
810
811#ifdef VMS
812# define MAKE_SUCCESS 1
813# define MAKE_TROUBLE 2
814# define MAKE_FAILURE 3
815#else
816# define MAKE_SUCCESS 0
817# define MAKE_TROUBLE 1
818# define MAKE_FAILURE 2
819#endif
820
821/* Set up heap debugging library dmalloc. */
822
823#ifdef HAVE_DMALLOC_H
824#include <dmalloc.h>
825#endif
826
827#ifndef initialize_main
828# ifdef __EMX__
829# define initialize_main(pargc, pargv) \
830 { _wildcard(pargc, pargv); _response(pargc, pargv); }
831# else
832# define initialize_main(pargc, pargv)
833# endif
834#endif
835
836#ifdef __EMX__
837# if !defined chdir
838# define chdir _chdir2
839# endif
840# if !defined getcwd
841# define getcwd _getcwd2
842# endif
843
844/* NO_CHDIR2 causes make not to use _chdir2() and _getcwd2() instead of
845 chdir() and getcwd(). This avoids some error messages for the
846 make testsuite but restricts the drive letter support. */
847# ifdef NO_CHDIR2
848# warning NO_CHDIR2: usage of drive letters restricted
849# undef chdir
850# undef getcwd
851# endif
852#endif
853
854#ifndef initialize_main
855# define initialize_main(pargc, pargv)
856#endif
857
858
859/* Some systems (like Solaris, PTX, etc.) do not support the SA_RESTART flag
860 properly according to POSIX. So, we try to wrap common system calls with
861 checks for EINTR. Note that there are still plenty of system calls that
862 can fail with EINTR but this, reportedly, gets the vast majority of
863 failure cases. If you still experience failures you'll need to either get
864 a system where SA_RESTART works, or you need to avoid -j. */
865
866#define EINTRLOOP(_v,_c) while (((_v)=_c)==-1 && errno==EINTR)
867
868/* While system calls that return integers are pretty consistent about
869 returning -1 on failure and setting errno in that case, functions that
870 return pointers are not always so well behaved. Sometimes they return
871 NULL for expected behavior: one good example is readdir() which returns
872 NULL at the end of the directory--and _doesn't_ reset errno. So, we have
873 to do it ourselves here. */
874
875#define ENULLLOOP(_v,_c) do { errno = 0; (_v) = _c; } \
876 while((_v)==0 && errno==EINTR)
877
878
879#if defined(__EMX__) && defined(CONFIG_WITH_OPTIMIZATION_HACKS) /* bird: saves 40-100ms on libc. */
880static inline void *__my_rawmemchr (const void *__s, int __c);
881#undef strchr
882#define strchr(s, c) \
883 (__extension__ (__builtin_constant_p (c) \
884 ? ((c) == '\0' \
885 ? (char *) __my_rawmemchr ((s), (c)) \
886 : __my_strchr_c ((s), ((c) & 0xff) << 8)) \
887 : __my_strchr_g ((s), (c))))
888static inline char *__my_strchr_c (const char *__s, int __c)
889{
890 register unsigned long int __d0;
891 register char *__res;
892 __asm__ __volatile__
893 ("1:\n\t"
894 "movb (%0),%%al\n\t"
895 "cmpb %%ah,%%al\n\t"
896 "je 2f\n\t"
897 "leal 1(%0),%0\n\t"
898 "testb %%al,%%al\n\t"
899 "jne 1b\n\t"
900 "xorl %0,%0\n"
901 "2:"
902 : "=r" (__res), "=&a" (__d0)
903 : "0" (__s), "1" (__c),
904 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
905 : "cc");
906 return __res;
907}
908
909static inline char *__my_strchr_g (__const char *__s, int __c)
910{
911 register unsigned long int __d0;
912 register char *__res;
913 __asm__ __volatile__
914 ("movb %%al,%%ah\n"
915 "1:\n\t"
916 "movb (%0),%%al\n\t"
917 "cmpb %%ah,%%al\n\t"
918 "je 2f\n\t"
919 "leal 1(%0),%0\n\t"
920 "testb %%al,%%al\n\t"
921 "jne 1b\n\t"
922 "xorl %0,%0\n"
923 "2:"
924 : "=r" (__res), "=&a" (__d0)
925 : "0" (__s), "1" (__c),
926 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
927 : "cc");
928 return __res;
929}
930
931static inline void *__my_rawmemchr (const void *__s, int __c)
932{
933 register unsigned long int __d0;
934 register unsigned char *__res;
935 __asm__ __volatile__
936 ("cld\n\t"
937 "repne; scasb\n\t"
938 : "=D" (__res), "=&c" (__d0)
939 : "a" (__c), "0" (__s), "1" (0xffffffff),
940 "m" ( *(struct { char __x[0xfffffff]; } *)__s)
941 : "cc");
942 return __res - 1;
943}
944
945#undef memchr
946#define memchr(a,b,c) __my_memchr((a),(b),(c))
947static inline void *__my_memchr (__const void *__s, int __c, size_t __n)
948{
949 register unsigned long int __d0;
950 register unsigned char *__res;
951 if (__n == 0)
952 return NULL;
953 __asm__ __volatile__
954 ("repne; scasb\n\t"
955 "je 1f\n\t"
956 "movl $1,%0\n"
957 "1:"
958 : "=D" (__res), "=&c" (__d0)
959 : "a" (__c), "0" (__s), "1" (__n),
960 "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
961 : "cc");
962 return __res - 1;
963}
964
965#endif /* __EMX__ (bird) */
966
967#ifdef CONFIG_WITH_IF_CONDITIONALS
968extern int expr_eval_if_conditionals(const char *line, const struct floc *flocp);
969extern char *expr_eval_to_string(char *o, const char *expr);
970#endif
971
972#ifdef KMK
973extern char *abspath(const char *name, char *apath);
974extern char *func_breakpoint(char *o, char **argv, const char *funcname);
975#endif
976
977#if defined (CONFIG_WITH_NANOTS) || defined (CONFIG_WITH_PRINT_TIME_SWITCH)
978/* misc.c */
979extern big_int nano_timestamp (void);
980extern int format_elapsed_nano (char *buf, size_t size, big_int ts);
981#endif
982
Note: See TracBrowser for help on using the repository browser.

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