VirtualBox

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

最後變更 在這個檔案從2548是 2548,由 bird 提交於 13 年 前

kmk: hacking on a new kmk/kBuild language extension.

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

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