VirtualBox

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

Last change on this file since 1973 was 1971, checked in by bird, 16 years ago

Some CONFIG_WITH_ALLOC_CACHE build fixes.

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