Documentation and tests for order-only prerequisites.
[make.git] / make.h
blob5162d8b528c7066a0bb51d48762e724fc0b9dd74
1 /* Miscellaneous global declarations and portability cruft for GNU Make.
2 Copyright (C) 1988,89,90,91,92,93,94,95,96,97,99 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, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* We use <config.h> instead of "config.h" so that a compilation
21 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
22 (which it would do because make.h was found in $srcdir). */
23 #include <config.h>
24 #undef HAVE_CONFIG_H
25 #define HAVE_CONFIG_H 1
27 /* AIX requires this to be the first thing in the file. */
28 #ifndef __GNUC__
29 # if HAVE_ALLOCA_H
30 # include <alloca.h>
31 # else
32 # ifdef _AIX
33 #pragma alloca
34 # else
35 # ifndef alloca /* predefined by HP cc +Olibcalls */
36 char *alloca ();
37 # endif
38 # endif
39 # endif
40 #endif
43 /* Use prototypes if available. */
44 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
45 # undef PARAMS
46 # define PARAMS(protos) protos
47 #else /* Not C++ or ANSI C. */
48 # undef PARAMS
49 # define PARAMS(protos) ()
50 #endif /* C++ or ANSI C. */
52 /* Specify we want GNU source code. This must be defined before any
53 system headers are included. */
55 #define _GNU_SOURCE 1
58 #ifdef CRAY
59 /* This must happen before #include <signal.h> so
60 that the declaration therein is changed. */
61 # define signal bsdsignal
62 #endif
64 /* If we're compiling for the dmalloc debugger, turn off string inlining. */
65 #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
66 # define __NO_STRING_INLINES
67 #endif
69 #include <sys/types.h>
70 #include <sys/stat.h>
71 #include <signal.h>
72 #include <stdio.h>
73 #include <ctype.h>
74 #ifdef HAVE_SYS_TIMEB_H
75 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
76 unless <sys/timeb.h> has been included first. Does every system have a
77 <sys/timeb.h>? If any does not, configure should check for it. */
78 # include <sys/timeb.h>
79 #endif
81 #if TIME_WITH_SYS_TIME
82 # include <sys/time.h>
83 # include <time.h>
84 #else
85 # if HAVE_SYS_TIME_H
86 # include <sys/time.h>
87 # else
88 # include <time.h>
89 # endif
90 #endif
92 #include <errno.h>
94 #ifndef errno
95 extern int errno;
96 #endif
98 #ifndef isblank
99 # define isblank(c) ((c) == ' ' || (c) == '\t')
100 #endif
102 #ifdef HAVE_UNISTD_H
103 # include <unistd.h>
104 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
105 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
106 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
107 # define POSIX 1
108 # endif
109 #endif
111 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
112 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
113 # undef POSIX
114 #endif
116 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
117 # define POSIX 1
118 #endif
120 #ifndef RETSIGTYPE
121 # define RETSIGTYPE void
122 #endif
124 #ifndef sigmask
125 # define sigmask(sig) (1 << ((sig) - 1))
126 #endif
128 #ifndef HAVE_SA_RESTART
129 # define SA_RESTART 0
130 #endif
132 #ifdef HAVE_LIMITS_H
133 # include <limits.h>
134 #endif
135 #ifdef HAVE_SYS_PARAM_H
136 # include <sys/param.h>
137 #endif
139 #ifndef PATH_MAX
140 # ifndef POSIX
141 # define PATH_MAX MAXPATHLEN
142 # endif
143 #endif
144 #ifndef MAXPATHLEN
145 # define MAXPATHLEN 1024
146 #endif
148 #ifdef PATH_MAX
149 # define GET_PATH_MAX PATH_MAX
150 # define PATH_VAR(var) char var[PATH_MAX]
151 #else
152 # define NEED_GET_PATH_MAX 1
153 # define GET_PATH_MAX (get_path_max ())
154 # define PATH_VAR(var) char *var = (char *) alloca (GET_PATH_MAX)
155 extern unsigned int get_path_max PARAMS ((void));
156 #endif
158 #ifndef CHAR_BIT
159 # define CHAR_BIT 8
160 #endif
162 /* Nonzero if the integer type T is signed. */
163 #define INTEGER_TYPE_SIGNED(t) ((t) -1 < 0)
165 /* The minimum and maximum values for the integer type T.
166 Use ~ (t) 0, not -1, for portability to 1's complement hosts. */
167 #define INTEGER_TYPE_MINIMUM(t) \
168 (! INTEGER_TYPE_SIGNED (t) ? (t) 0 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))
169 #define INTEGER_TYPE_MAXIMUM(t) (~ (t) 0 - INTEGER_TYPE_MINIMUM (t))
171 #ifndef CHAR_MAX
172 # define CHAR_MAX INTEGER_TYPE_MAXIMUM (char)
173 #endif
175 #ifdef STAT_MACROS_BROKEN
176 # ifdef S_ISREG
177 # undef S_ISREG
178 # endif
179 # ifdef S_ISDIR
180 # undef S_ISDIR
181 # endif
182 #endif /* STAT_MACROS_BROKEN. */
184 #ifndef S_ISREG
185 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
186 #endif
187 #ifndef S_ISDIR
188 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
189 #endif
191 #ifdef VMS
192 # include <types.h>
193 # include <unixlib.h>
194 # include <unixio.h>
195 # include <perror.h>
196 #endif
198 #ifndef __attribute__
199 /* This feature is available in gcc versions 2.5 and later. */
200 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
201 # define __attribute__(x)
202 # endif
203 /* The __-protected variants of `format' and `printf' attributes
204 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
205 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
206 # define __format__ format
207 # define __printf__ printf
208 # endif
209 #endif
211 #if defined (STDC_HEADERS) || defined (__GNU_LIBRARY__)
212 # include <stdlib.h>
213 # include <string.h>
214 # define ANSI_STRING 1
215 #else /* No standard headers. */
216 # ifdef HAVE_STRING_H
217 # include <string.h>
218 # define ANSI_STRING 1
219 # else
220 # include <strings.h>
221 # endif
222 # ifdef HAVE_MEMORY_H
223 # include <memory.h>
224 # endif
225 # ifdef HAVE_STDLIB_H
226 # include <stdlib.h>
227 # else
228 extern char *malloc PARAMS ((int));
229 extern char *realloc PARAMS ((char *, int));
230 extern void free PARAMS ((char *));
232 extern void abort PARAMS ((void)) __attribute__ ((noreturn));
233 extern void exit PARAMS ((int)) __attribute__ ((noreturn));
234 # endif /* HAVE_STDLIB_H. */
236 #endif /* Standard headers. */
238 /* These should be in stdlib.h. Make sure we have them. */
239 #ifndef EXIT_SUCCESS
240 # define EXIT_SUCCESS 0
241 #endif
242 #ifndef EXIT_FAILURE
243 # define EXIT_FAILURE 0
244 #endif
246 #ifdef ANSI_STRING
248 # ifndef bcmp
249 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
250 # endif
251 # ifndef bzero
252 # define bzero(s, n) memset ((s), 0, (n))
253 # endif
254 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
255 # define bcopy(s, d, n) memmove ((d), (s), (n))
256 # endif
258 #else /* Not ANSI_STRING. */
260 # ifndef HAVE_STRCHR
261 # define strchr(s, c) index((s), (c))
262 # define strrchr(s, c) rindex((s), (c))
263 # endif
265 # ifndef bcmp
266 extern int bcmp PARAMS ((const char *, const char *, int));
267 # endif
268 # ifndef bzero
269 extern void bzero PARAMS ((char *, int));
270 #endif
271 # ifndef bcopy
272 extern void bcopy PARAMS ((const char *b1, char *b2, int));
273 # endif
275 #endif /* ANSI_STRING. */
276 #undef ANSI_STRING
278 /* SCO Xenix has a buggy macro definition in <string.h>. */
279 #undef strerror
281 #if !defined(ANSI_STRING) && !defined(__DECC)
282 extern char *strerror PARAMS ((int errnum));
283 #endif
285 #if HAVE_INTTYPES_H
286 # include <inttypes.h>
287 #endif
288 #define FILE_TIMESTAMP uintmax_t
290 #if !defined(HAVE_STRSIGNAL)
291 extern char *strsignal PARAMS ((int signum));
292 #endif
294 /* ISDIGIT offers the following features:
295 - Its arg may be any int or unsigned int; it need not be an unsigned char.
296 - It's guaranteed to evaluate its argument exactly once.
297 NOTE! Make relies on this behavior, don't change it!
298 - It's typically faster.
299 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
300 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
301 it's important to use the locale's definition of `digit' even when the
302 host does not conform to Posix. */
303 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
305 #ifndef iAPX286
306 # define streq(a, b) \
307 ((a) == (b) || \
308 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
309 # ifdef HAVE_CASE_INSENSITIVE_FS
310 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
311 # define strieq(a, b) \
312 ((a) == (b) \
313 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
314 && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
315 # else
316 # define strieq(a, b) streq(a, b)
317 # endif
318 #else
319 /* Buggy compiler can't handle this. */
320 # define streq(a, b) (strcmp ((a), (b)) == 0)
321 # define strieq(a, b) (strcmp ((a), (b)) == 0)
322 #endif
323 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
324 #ifdef VMS
325 extern int strcmpi (const char *,const char *);
326 #endif
328 /* Add to VAR the hashing value of C, one character in a name. */
329 #define HASH(var, c) \
330 ((var += (c)), (var = ((var) << 7) + ((var) >> 20)))
331 #ifdef HAVE_CASE_INSENSITIVE_FS /* Fold filenames */
332 # define HASHI(var, c) \
333 ((var += tolower((unsigned char)(c))), (var = ((var) << 7) + ((var) >> 20)))
334 #else
335 # define HASHI(var, c) HASH(var,c)
336 #endif
338 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
339 # define ENUM_BITFIELD(bits) :bits
340 #else
341 # define ENUM_BITFIELD(bits)
342 #endif
344 /* Handle gettext and locales. */
346 #if HAVE_LOCALE_H
347 # include <locale.h>
348 #else
349 # define setlocale(category, locale)
350 #endif
352 #include <gettext.h>
354 #define _(msgid) gettext (msgid)
355 #define N_(msgid) gettext_noop (msgid)
356 #define S_(msg1,msg2,num) ngettext (msg1,msg2,num)
358 /* Handle other OSs. */
360 #if defined(__MSDOS__) || defined(WINDOWS32)
361 # define PATH_SEPARATOR_CHAR ';'
362 #else
363 # if defined(VMS)
364 # define PATH_SEPARATOR_CHAR ','
365 # else
366 # define PATH_SEPARATOR_CHAR ':'
367 # endif
368 #endif
370 #ifdef WINDOWS32
371 # include <fcntl.h>
372 # include <malloc.h>
373 # define pipe(p) _pipe(p, 512, O_BINARY)
374 # define kill(pid,sig) w32_kill(pid,sig)
376 extern void sync_Path_environment(void);
377 extern int kill(int pid, int sig);
378 extern int safe_stat(char *file, struct stat *sb);
379 extern char *end_of_token_w32(char *s, char stopchar);
380 extern int find_and_set_default_shell(char *token);
382 /* indicates whether or not we have Bourne shell */
383 extern int no_default_sh_exe;
385 /* is default_shell unixy? */
386 extern int unixy_shell;
387 #endif /* WINDOWS32 */
389 struct floc
391 char *filenm;
392 unsigned long lineno;
394 #define NILF ((struct floc *)0)
396 #define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
399 /* Fancy processing for variadic functions in both ANSI and pre-ANSI
400 compilers. */
401 #if defined __STDC__ && __STDC__
402 extern void message (int prefix, const char *fmt, ...)
403 __attribute__ ((__format__ (__printf__, 2, 3)));
404 extern void error (const struct floc *flocp, const char *fmt, ...)
405 __attribute__ ((__format__ (__printf__, 2, 3)));
406 extern void fatal (const struct floc *flocp, const char *fmt, ...)
407 __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
408 #else
409 extern void message ();
410 extern void error ();
411 extern void fatal ();
412 #endif
414 extern void die PARAMS ((int)) __attribute__ ((noreturn));
415 extern void log_working_directory PARAMS ((int));
416 extern void pfatal_with_name PARAMS ((const char *)) __attribute__ ((noreturn));
417 extern void perror_with_name PARAMS ((const char *, const char *));
418 extern char *savestring PARAMS ((const char *, unsigned int));
419 extern char *concat PARAMS ((const char *, const char *, const char *));
420 extern char *xmalloc PARAMS ((unsigned int));
421 extern char *xrealloc PARAMS ((char *, unsigned int));
422 extern char *xstrdup PARAMS ((const char *));
423 extern char *find_next_token PARAMS ((char **, unsigned int *));
424 extern char *next_token PARAMS ((const char *));
425 extern char *end_of_token PARAMS ((char *));
426 extern void collapse_continuations PARAMS ((char *));
427 extern void remove_comments PARAMS((char *));
428 extern char *sindex PARAMS ((const char *, unsigned int, \
429 const char *, unsigned int));
430 extern char *lindex PARAMS ((const char *, const char *, int));
431 extern int alpha_compare PARAMS ((const void *, const void *));
432 extern void print_spaces PARAMS ((unsigned int));
433 extern char *find_char_unquote PARAMS ((char *, char *, int));
434 extern char *find_percent PARAMS ((char *));
435 extern FILE *open_tmpfile PARAMS ((char **, const char *));
437 #ifndef NO_ARCHIVES
438 extern int ar_name PARAMS ((char *));
439 extern void ar_parse_name PARAMS ((char *, char **, char **));
440 extern int ar_touch PARAMS ((char *));
441 extern time_t ar_member_date PARAMS ((char *));
442 #endif
444 extern int dir_file_exists_p PARAMS ((char *, char *));
445 extern int file_exists_p PARAMS ((char *));
446 extern int file_impossible_p PARAMS ((char *));
447 extern void file_impossible PARAMS ((char *));
448 extern char *dir_name PARAMS ((char *));
450 extern void define_default_variables PARAMS ((void));
451 extern void set_default_suffixes PARAMS ((void));
452 extern void install_default_suffix_rules PARAMS ((void));
453 extern void install_default_implicit_rules PARAMS ((void));
455 extern void build_vpath_lists PARAMS ((void));
456 extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath));
457 extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr));
458 extern int gpath_search PARAMS ((char *file, int len));
460 extern void construct_include_path PARAMS ((char **arg_dirs));
462 extern void user_access PARAMS ((void));
463 extern void make_access PARAMS ((void));
464 extern void child_access PARAMS ((void));
466 #ifdef HAVE_VFORK_H
467 # include <vfork.h>
468 #endif
470 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
471 because such systems often declare them in header files anyway. */
473 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
475 extern long int atol ();
476 # ifndef VMS
477 extern long int lseek ();
478 # endif
480 #endif /* Not GNU C library or POSIX. */
482 #ifdef HAVE_GETCWD
483 # if !defined(VMS) && !defined(__DECC)
484 extern char *getcwd ();
485 #endif
486 #else
487 extern char *getwd ();
488 # define getcwd(buf, len) getwd (buf)
489 #endif
491 extern const struct floc *reading_file;
493 extern char **environ;
495 extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
496 extern int print_data_base_flag, question_flag, touch_flag;
497 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
498 extern int print_version_flag, print_directory_flag;
499 extern int warn_undefined_variables_flag, posix_pedantic, not_parallel;
500 extern int clock_skew_detected;
502 /* can we run commands via 'sh -c xxx' or must we use batch files? */
503 extern int batch_mode_shell;
505 extern unsigned int job_slots;
506 extern int job_fds[2];
507 extern int job_rfd;
508 #ifndef NO_FLOAT
509 extern double max_load_average;
510 #else
511 extern int max_load_average;
512 #endif
514 extern char *program;
515 extern char *starting_directory;
516 extern unsigned int makelevel;
517 extern char *version_string, *remote_description;
519 extern unsigned int commands_started;
521 extern int handling_fatal_signal;
524 #ifndef MIN
525 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
526 #endif
527 #ifndef MAX
528 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
529 #endif
531 #ifdef VMS
532 # define MAKE_SUCCESS 1
533 # define MAKE_TROUBLE 2
534 # define MAKE_FAILURE 3
535 #else
536 # define MAKE_SUCCESS 0
537 # define MAKE_TROUBLE 1
538 # define MAKE_FAILURE 2
539 #endif
541 /* Set up heap debugging library dmalloc. */
543 #ifdef HAVE_DMALLOC_H
544 #include <dmalloc.h>
545 #endif