.
[make.git] / make.h
blob01ead89f4d48d04b33742fc2e9dd7315da3f4574
1 /* Miscellaneous global declarations and portability cruft for GNU Make.
2 Copyright (C) 1988,89,90,91,92,93,94,95,96 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19 /* AIX requires this to be the first thing in the file. */
20 #if defined (_AIX) && !defined (__GNUC__)
21 #pragma alloca
22 #endif
24 /* We use <config.h> instead of "config.h" so that a compilation
25 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
26 (which it would do because make.h was found in $srcdir). */
27 #include <config.h>
28 #undef HAVE_CONFIG_H
29 #define HAVE_CONFIG_H
32 /* Use prototypes if available. */
33 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
34 #undef PARAMS
35 #define PARAMS(protos) protos
36 #else /* Not C++ or ANSI C. */
37 #undef PARAMS
38 #define PARAMS(protos) ()
39 #endif /* C++ or ANSI C. */
42 #ifdef CRAY
43 /* This must happen before #include <signal.h> so
44 that the declaration therein is changed. */
45 #define signal bsdsignal
46 #endif
48 #define _GNU_SOURCE
49 #include <sys/types.h>
50 #include <sys/stat.h>
51 #include <signal.h>
52 #include <stdio.h>
53 #include <ctype.h>
54 #ifdef HAVE_SYS_TIMEB_H
55 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
56 unless <sys/timeb.h> has been included first. Does every system have a
57 <sys/timeb.h>? If any does not, configure should check for it. */
58 #include <sys/timeb.h>
59 #endif
60 #include <time.h>
61 #include <errno.h>
63 #ifndef errno
64 extern int errno;
65 #endif
67 #ifndef isblank
68 #define isblank(c) ((c) == ' ' || (c) == '\t')
69 #endif
71 #ifdef HAVE_UNISTD_H
72 #include <unistd.h>
73 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
74 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
75 #if defined (_POSIX_VERSION) && !defined (ultrix)
76 #define POSIX
77 #endif
78 #endif
80 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
81 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
82 #undef POSIX
83 #endif
85 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
86 #define POSIX
87 #endif
89 #ifdef HAVE_SYS_SIGLIST
90 #ifndef SYS_SIGLIST_DECLARED
91 extern char *sys_siglist[];
92 #endif
93 #else
94 #include "signame.h"
95 #endif
97 /* Some systems do not define NSIG in <signal.h>. */
98 #ifndef NSIG
99 #ifdef _NSIG
100 #define NSIG _NSIG
101 #else
102 #define NSIG 32
103 #endif
104 #endif
106 #ifndef RETSIGTYPE
107 #define RETSIGTYPE void
108 #endif
110 #ifndef sigmask
111 #define sigmask(sig) (1 << ((sig) - 1))
112 #endif
114 #ifdef HAVE_LIMITS_H
115 #include <limits.h>
116 #endif
117 #ifdef HAVE_SYS_PARAM_H
118 #include <sys/param.h>
119 #endif
121 #ifndef PATH_MAX
122 #ifndef POSIX
123 #define PATH_MAX MAXPATHLEN
124 #endif /* Not POSIX. */
125 #endif /* No PATH_MAX. */
126 #ifndef MAXPATHLEN
127 #define MAXPATHLEN 1024
128 #endif /* No MAXPATHLEN. */
130 #ifdef PATH_MAX
131 #define GET_PATH_MAX PATH_MAX
132 #define PATH_VAR(var) char var[PATH_MAX]
133 #else
134 #define NEED_GET_PATH_MAX
135 extern unsigned int get_path_max PARAMS ((void));
136 #define GET_PATH_MAX (get_path_max ())
137 #define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
138 #endif
140 #ifdef STAT_MACROS_BROKEN
141 #ifdef S_ISREG
142 #undef S_ISREG
143 #endif
144 #ifdef S_ISDIR
145 #undef S_ISDIR
146 #endif
147 #endif /* STAT_MACROS_BROKEN. */
149 #ifndef S_ISREG
150 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
151 #endif
152 #ifndef S_ISDIR
153 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
154 #endif
156 #ifdef VMS
157 #include <stdio.h>
158 #include <types.h>
159 #include <unixlib.h>
160 #include <unixio.h>
161 #include <errno.h>
162 #include <perror.h>
163 #endif
165 #if (defined (STDC_HEADERS) || defined (__GNU_LIBRARY__) || defined(VMS))
166 #include <stdlib.h>
167 #include <string.h>
168 #define ANSI_STRING
169 #else /* No standard headers. */
171 #ifdef HAVE_STRING_H
172 #include <string.h>
173 #define ANSI_STRING
174 #else
175 #include <strings.h>
176 #endif
177 #ifdef HAVE_MEMORY_H
178 #include <memory.h>
179 #endif
181 extern char *malloc PARAMS ((int));
182 extern char *realloc PARAMS ((char *, int));
183 extern void free PARAMS ((char *));
185 extern void abort PARAMS ((void));
186 extern void exit PARAMS ((int));
188 #endif /* Standard headers. */
190 #ifdef ANSI_STRING
192 #ifndef index
193 #define index(s, c) strchr((s), (c))
194 #endif
195 #ifndef rindex
196 #define rindex(s, c) strrchr((s), (c))
197 #endif
199 #ifndef bcmp
200 #define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
201 #endif
202 #ifndef bzero
203 #define bzero(s, n) memset ((s), 0, (n))
204 #endif
205 #ifndef bcopy
206 #define bcopy(s, d, n) memcpy ((d), (s), (n))
207 #endif
209 #else /* Not ANSI_STRING. */
211 #ifndef bcmp
212 extern int bcmp ();
213 #endif
214 #ifndef bzero
215 extern void bzero ();
216 #endif
217 #ifndef bcopy
218 extern void bcopy ();
219 #endif
221 #endif /* ANSI_STRING. */
222 #undef ANSI_STRING
224 /* SCO Xenix has a buggy macro definition in <string.h>. */
225 #undef strerror
227 #if !defined(ANSI_STRING) && !defined(__DECC)
228 extern char *strerror PARAMS ((int errnum));
229 #endif
232 #ifdef __GNUC__
233 #undef alloca
234 #define alloca(n) __builtin_alloca (n)
235 #else /* Not GCC. */
236 #ifdef HAVE_ALLOCA_H
237 #include <alloca.h>
238 #else /* Not HAVE_ALLOCA_H. */
239 #ifndef _AIX
240 extern char *alloca ();
241 #endif /* Not AIX. */
242 #endif /* HAVE_ALLOCA_H. */
243 #endif /* GCC. */
245 #ifndef iAPX286
246 #define streq(a, b) \
247 ((a) == (b) || \
248 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
249 #ifdef _AMIGA
250 #define strieq(a, b) \
251 ((a) == (b) || \
252 (tolower(*(a)) == tolower(*(b)) && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
253 #else
254 #define strieq(a, b) \
255 ((a) == (b) || \
256 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
257 #endif
258 #else
259 /* Buggy compiler can't handle this. */
260 #define streq(a, b) (strcmp ((a), (b)) == 0)
261 #define strieq(a, b) (strcmp ((a), (b)) == 0)
262 #endif
264 /* Add to VAR the hashing value of C, one character in a name. */
265 #define HASH(var, c) \
266 ((var += (c)), (var = ((var) << 7) + ((var) >> 20)))
267 #ifdef _AMIGA /* Fold filenames on #amiga */
268 #define HASHI(var, c) \
269 ((var += tolower((c))), (var = ((var) << 7) + ((var) >> 20)))
270 #else
271 #define HASHI(var, c) HASH(var,c)
272 #endif
274 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
275 #define ENUM_BITFIELD(bits) :bits
276 #else
277 #define ENUM_BITFIELD(bits)
278 #endif
280 #if defined(__MSDOS__) || defined(WIN32)
281 #define PATH_SEPARATOR_CHAR ';'
282 #else
283 #define PATH_SEPARATOR_CHAR ':'
284 #endif
286 #ifdef WIN32
287 #include <fcntl.h>
288 #include <malloc.h>
289 #define pipe(p) _pipe(p, 512, O_BINARY)
290 #define kill(pid,sig) w32_kill(pid,sig)
292 extern void sync_Path_environment(void);
293 extern int kill(int pid, int sig);
294 extern int safe_stat(char *file, struct stat *sb);
295 extern char *end_of_token_w32();
296 #endif
298 extern void die ();
299 extern void message ();
300 extern void fatal ();
301 extern void error ();
302 extern void log_working_directory ();
303 extern void makefile_error ();
304 extern void makefile_fatal ();
305 extern void pfatal_with_name ();
306 extern void perror_with_name ();
307 extern char *savestring ();
308 extern char *concat ();
309 extern char *xmalloc ();
310 extern char *xrealloc ();
311 extern char *find_next_token ();
312 extern char *next_token ();
313 extern char *end_of_token ();
314 extern void collapse_continuations ();
315 extern void remove_comments ();
316 extern char *sindex ();
317 extern char *lindex ();
318 extern int alpha_compare ();
319 extern void print_spaces ();
320 extern struct dep *copy_dep_chain ();
321 extern char *find_char_unquote ();
322 extern char *find_percent ();
324 #ifndef NO_ARCHIVES
325 extern int ar_name ();
326 extern void ar_parse_name ();
327 extern int ar_touch ();
328 extern time_t ar_member_date ();
329 #endif
331 extern void dir_load ();
332 extern int dir_file_exists_p ();
333 extern int file_exists_p ();
334 extern int file_impossible_p ();
335 extern void file_impossible ();
336 extern char *dir_name ();
338 extern void define_default_variables ();
339 extern void set_default_suffixes ();
340 extern void install_default_suffix_rules ();
341 extern void install_default_implicit_rules ();
342 extern void count_implicit_rule_limits ();
343 extern void convert_to_pattern ();
344 extern void create_pattern_rule ();
346 extern void build_vpath_lists ();
347 extern void construct_vpath_list ();
348 extern int vpath_search ();
350 extern void construct_include_path ();
351 extern void uniquize_deps ();
353 extern int update_goal_chain ();
354 extern void notice_finished_file ();
356 extern void user_access ();
357 extern void make_access ();
358 extern void child_access ();
360 #ifdef HAVE_VFORK_H
361 #include <vfork.h>
362 #endif
364 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
365 because such systems often declare the in header files anyway. */
367 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WIN32)
369 extern long int atol ();
370 #ifndef VMS
371 extern long int lseek ();
372 #endif
374 #endif /* Not GNU C library or POSIX. */
376 #ifdef HAVE_GETCWD
377 extern char *getcwd ();
378 #ifdef VMS
379 extern char *getwd PARAMS ((char *));
380 #endif
381 #else
382 extern char *getwd ();
383 #define getcwd(buf, len) getwd (buf)
384 #endif
386 extern char **environ;
388 extern char *reading_filename;
389 extern unsigned int *reading_lineno_ptr;
391 extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
392 extern int debug_flag, print_data_base_flag, question_flag, touch_flag;
393 extern int env_overrides, no_builtin_rules_flag, print_version_flag;
394 extern int print_directory_flag, warn_undefined_variables_flag;
395 extern int posix_pedantic;
397 extern unsigned int job_slots;
398 #ifndef NO_FLOAT
399 extern double max_load_average;
400 #else
401 extern int max_load_average;
402 #endif
404 extern char *program;
405 extern char *starting_directory;
406 extern unsigned int makelevel;
407 extern char *version_string, *remote_description;
409 extern unsigned int commands_started;
411 extern int handling_fatal_signal;
414 #define DEBUGPR(msg) \
415 do if (debug_flag) { print_spaces (depth); printf (msg, file->name); \
416 fflush (stdout); } while (0)
418 #ifdef VMS
419 # ifndef EXIT_FAILURE
420 # define EXIT_FAILURE 3
421 # endif
422 # ifndef EXIT_SUCCESS
423 # define EXIT_SUCCESS 1
424 # endif
425 # ifndef EXIT_TROUBLE
426 # define EXIT_TROUBLE 2
427 # endif
428 #else
429 # ifndef EXIT_FAILURE
430 # define EXIT_FAILURE 2
431 # endif
432 # ifndef EXIT_SUCCESS
433 # define EXIT_SUCCESS 0
434 # endif
435 # ifndef EXIT_TROUBLE
436 # define EXIT_TROUBLE 1
437 # endif
438 #endif