* Implement GNU gettext internationalization support in GNU make.
[make.git] / make.h
blobd2176320431109a56966a32b7686d3bea2e9ce92
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 /* AIX requires this to be the first thing in the file. */
21 #if defined (_AIX) && !defined (__GNUC__)
22 #pragma alloca
23 #endif
25 /* We use <config.h> instead of "config.h" so that a compilation
26 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
27 (which it would do because make.h was found in $srcdir). */
28 #include <config.h>
29 #undef HAVE_CONFIG_H
30 #define HAVE_CONFIG_H 1
33 /* Use prototypes if available. */
34 #if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
35 # undef PARAMS
36 # define PARAMS(protos) protos
37 #else /* Not C++ or ANSI C. */
38 # undef PARAMS
39 # define PARAMS(protos) ()
40 #endif /* C++ or ANSI C. */
43 #if HAVE_LOCALE_H
44 # include <locale.h>
45 #endif
46 #if !HAVE_SETLOCALE
47 # define setlocale(Category, Locale) /* empty */
48 #endif
50 #if ENABLE_NLS
51 # include <libintl.h>
52 # define _(Text) gettext (Text)
53 #else
54 # undef bindtextdomain
55 # define bindtextdomain(Domain, Directory) /* empty */
56 # undef textdomain
57 # define textdomain(Domain) /* empty */
58 # define _(Text) Text
59 # define gettext(Text) Text
60 #endif
61 #define N_(Text) Text
64 #ifdef CRAY
65 /* This must happen before #include <signal.h> so
66 that the declaration therein is changed. */
67 # define signal bsdsignal
68 #endif
70 /* If we're compiling for the dmalloc debugger, turn off string inlining. */
71 #if defined(HAVE_DMALLOC_H) && defined(__GNUC__)
72 # define __NO_STRING_INLINES
73 #endif
75 #define _GNU_SOURCE 1
76 #include <sys/types.h>
77 #include <sys/stat.h>
78 #include <signal.h>
79 #include <stdio.h>
80 #include <ctype.h>
81 #ifdef HAVE_SYS_TIMEB_H
82 /* SCO 3.2 "devsys 4.2" has a prototype for `ftime' in <time.h> that bombs
83 unless <sys/timeb.h> has been included first. Does every system have a
84 <sys/timeb.h>? If any does not, configure should check for it. */
85 # include <sys/timeb.h>
86 #endif
87 #include <time.h>
88 #include <errno.h>
90 #ifndef errno
91 extern int errno;
92 #endif
94 /* A shortcut for EINTR checking. Note you should be careful when negating
95 this! That might not mean what you want if EINTR is not available. */
96 #ifdef EINTR
97 # define EINTR_SET (errno == EINTR)
98 #else
99 # define EINTR_SET (0)
100 #endif
102 #ifndef isblank
103 # define isblank(c) ((c) == ' ' || (c) == '\t')
104 #endif
106 #ifdef HAVE_UNISTD_H
107 # include <unistd.h>
108 /* Ultrix's unistd.h always defines _POSIX_VERSION, but you only get
109 POSIX.1 behavior with `cc -YPOSIX', which predefines POSIX itself! */
110 # if defined (_POSIX_VERSION) && !defined (ultrix) && !defined (VMS)
111 # define POSIX 1
112 # endif
113 #endif
115 /* Some systems define _POSIX_VERSION but are not really POSIX.1. */
116 #if (defined (butterfly) || defined (__arm) || (defined (__mips) && defined (_SYSTYPE_SVR3)) || (defined (sequent) && defined (i386)))
117 # undef POSIX
118 #endif
120 #if !defined (POSIX) && defined (_AIX) && defined (_POSIX_SOURCE)
121 # define POSIX 1
122 #endif
124 #ifndef RETSIGTYPE
125 # define RETSIGTYPE void
126 #endif
128 #ifndef sigmask
129 # define sigmask(sig) (1 << ((sig) - 1))
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 #ifdef ANSI_STRING
240 # ifndef bcmp
241 # define bcmp(s1, s2, n) memcmp ((s1), (s2), (n))
242 # endif
243 # ifndef bzero
244 # define bzero(s, n) memset ((s), 0, (n))
245 # endif
246 # if defined(HAVE_MEMMOVE) && !defined(bcopy)
247 # define bcopy(s, d, n) memmove ((d), (s), (n))
248 # endif
250 #else /* Not ANSI_STRING. */
252 # ifndef HAVE_STRCHR
253 # define strchr(s, c) index((s), (c))
254 # define strrchr(s, c) rindex((s), (c))
255 # endif
257 # ifndef bcmp
258 extern int bcmp PARAMS ((const char *, const char *, int));
259 # endif
260 # ifndef bzero
261 extern void bzero PARAMS ((char *, int));
262 #endif
263 # ifndef bcopy
264 extern void bcopy PARAMS ((const char *b1, char *b2, int));
265 # endif
267 #endif /* ANSI_STRING. */
268 #undef ANSI_STRING
270 /* SCO Xenix has a buggy macro definition in <string.h>. */
271 #undef strerror
273 #if !defined(ANSI_STRING) && !defined(__DECC)
274 extern char *strerror PARAMS ((int errnum));
275 #endif
277 #ifdef __GNUC__
278 # undef alloca
279 # define alloca(n) __builtin_alloca (n)
280 #else /* Not GCC. */
281 # ifdef HAVE_ALLOCA_H
282 # include <alloca.h>
283 # else /* Not HAVE_ALLOCA_H. */
284 # ifndef _AIX
285 extern char *alloca ();
286 # endif /* Not AIX. */
287 # endif /* HAVE_ALLOCA_H. */
288 #endif /* GCC. */
290 #if ST_MTIM_NSEC
291 # if HAVE_INTTYPES_H
292 # include <inttypes.h>
293 # endif
294 # define FILE_TIMESTAMP uintmax_t
295 #else
296 # define FILE_TIMESTAMP time_t
297 #endif
299 /* ISDIGIT offers the following features:
300 - Its arg may be any int or unsigned int; it need not be an unsigned char.
301 - It's guaranteed to evaluate its argument exactly once.
302 NOTE! Make relies on this behavior, don't change it!
303 - It's typically faster.
304 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
305 only '0' through '9' are digits. Prefer ISDIGIT to isdigit() unless
306 it's important to use the locale's definition of `digit' even when the
307 host does not conform to Posix. */
308 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
310 #ifndef iAPX286
311 # define streq(a, b) \
312 ((a) == (b) || \
313 (*(a) == *(b) && (*(a) == '\0' || !strcmp ((a) + 1, (b) + 1))))
314 # ifdef HAVE_CASE_INSENSITIVE_FS
315 /* This is only used on Windows/DOS platforms, so we assume strcmpi(). */
316 # define strieq(a, b) \
317 ((a) == (b) \
318 || (tolower((unsigned char)*(a)) == tolower((unsigned char)*(b)) \
319 && (*(a) == '\0' || !strcmpi ((a) + 1, (b) + 1))))
320 # else
321 # define strieq(a, b) streq(a, b)
322 # endif
323 #else
324 /* Buggy compiler can't handle this. */
325 # define streq(a, b) (strcmp ((a), (b)) == 0)
326 # define strieq(a, b) (strcmp ((a), (b)) == 0)
327 #endif
328 #define strneq(a, b, l) (strncmp ((a), (b), (l)) == 0)
329 #ifdef VMS
330 extern int strcmpi (const char *,const char *);
331 #endif
333 /* Add to VAR the hashing value of C, one character in a name. */
334 #define HASH(var, c) \
335 ((var += (c)), (var = ((var) << 7) + ((var) >> 20)))
336 #ifdef HAVE_CASE_INSENSITIVE_FS /* Fold filenames */
337 # define HASHI(var, c) \
338 ((var += tolower((unsigned char)(c))), (var = ((var) << 7) + ((var) >> 20)))
339 #else
340 # define HASHI(var, c) HASH(var,c)
341 #endif
343 #if defined(__GNUC__) || defined(ENUM_BITFIELDS)
344 # define ENUM_BITFIELD(bits) :bits
345 #else
346 # define ENUM_BITFIELD(bits)
347 #endif
349 #if defined(__MSDOS__) || defined(WINDOWS32)
350 # define PATH_SEPARATOR_CHAR ';'
351 #else
352 # if defined(VMS)
353 # define PATH_SEPARATOR_CHAR ','
354 # else
355 # define PATH_SEPARATOR_CHAR ':'
356 # endif
357 #endif
359 #ifdef WINDOWS32
360 # include <fcntl.h>
361 # include <malloc.h>
362 # define pipe(p) _pipe(p, 512, O_BINARY)
363 # define kill(pid,sig) w32_kill(pid,sig)
365 extern void sync_Path_environment(void);
366 extern int kill(int pid, int sig);
367 extern int safe_stat(char *file, struct stat *sb);
368 extern char *end_of_token_w32(char *s, char stopchar);
369 extern int find_and_set_default_shell(char *token);
371 /* indicates whether or not we have Bourne shell */
372 extern int no_default_sh_exe;
374 /* is default_shell unixy? */
375 extern int unixy_shell;
376 #endif /* WINDOWS32 */
378 struct floc
380 char *filenm;
381 unsigned long lineno;
383 #define NILF ((struct floc *)0)
386 /* Fancy processing for variadic functions in both ANSI and pre-ANSI
387 compilers. */
388 #if defined __STDC__ && __STDC__
389 extern void message (int prefix, const char *fmt, ...)
390 __attribute__ ((__format__ (__printf__, 2, 3)));
391 extern void error (const struct floc *flocp, const char *fmt, ...)
392 __attribute__ ((__format__ (__printf__, 2, 3)));
393 extern void fatal (const struct floc *flocp, const char *fmt, ...)
394 __attribute__ ((noreturn, __format__ (__printf__, 2, 3)));
395 #else
396 extern void message ();
397 extern void error ();
398 extern void fatal ();
399 #endif
401 extern void die PARAMS ((int)) __attribute__ ((noreturn));
402 extern void log_working_directory PARAMS ((int));
403 extern void pfatal_with_name PARAMS ((char *)) __attribute__ ((noreturn));
404 extern void perror_with_name PARAMS ((char *, char *));
405 extern char *savestring PARAMS ((const char *, unsigned int));
406 extern char *concat PARAMS ((char *, char *, char *));
407 extern char *xmalloc PARAMS ((unsigned int));
408 extern char *xrealloc PARAMS ((char *, unsigned int));
409 extern char *xstrdup PARAMS ((const char *));
410 extern char *find_next_token PARAMS ((char **, unsigned int *));
411 extern char *next_token PARAMS ((char *));
412 extern char *end_of_token PARAMS ((char *));
413 extern void collapse_continuations PARAMS ((char *));
414 extern void remove_comments PARAMS((char *));
415 extern char *sindex PARAMS ((const char *, unsigned int, \
416 const char *, unsigned int));
417 extern char *lindex PARAMS ((const char *, const char *, int));
418 extern int alpha_compare PARAMS ((const void *, const void *));
419 extern void print_spaces PARAMS ((unsigned int));
420 extern char *find_char_unquote PARAMS ((char *, char *, int));
421 extern char *find_percent PARAMS ((char *));
423 #ifndef NO_ARCHIVES
424 extern int ar_name PARAMS ((char *));
425 extern void ar_parse_name PARAMS ((char *, char **, char **));
426 extern int ar_touch PARAMS ((char *));
427 extern time_t ar_member_date PARAMS ((char *));
428 #endif
430 extern int dir_file_exists_p PARAMS ((char *, char *));
431 extern int file_exists_p PARAMS ((char *));
432 extern int file_impossible_p PARAMS ((char *));
433 extern void file_impossible PARAMS ((char *));
434 extern char *dir_name PARAMS ((char *));
436 extern void define_default_variables PARAMS ((void));
437 extern void set_default_suffixes PARAMS ((void));
438 extern void install_default_suffix_rules PARAMS ((void));
439 extern void install_default_implicit_rules PARAMS ((void));
441 extern void build_vpath_lists PARAMS ((void));
442 extern void construct_vpath_list PARAMS ((char *pattern, char *dirpath));
443 extern int vpath_search PARAMS ((char **file, FILE_TIMESTAMP *mtime_ptr));
444 extern int gpath_search PARAMS ((char *file, int len));
446 extern void construct_include_path PARAMS ((char **arg_dirs));
448 extern void user_access PARAMS ((void));
449 extern void make_access PARAMS ((void));
450 extern void child_access PARAMS ((void));
452 #ifdef HAVE_VFORK_H
453 # include <vfork.h>
454 #endif
456 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
457 because such systems often declare them in header files anyway. */
459 #if !defined (__GNU_LIBRARY__) && !defined (POSIX) && !defined (_POSIX_VERSION) && !defined(WINDOWS32)
461 extern long int atol ();
462 # ifndef VMS
463 extern long int lseek ();
464 # endif
466 #endif /* Not GNU C library or POSIX. */
468 #ifdef HAVE_GETCWD
469 # if !defined(VMS) && !defined(__DECC)
470 extern char *getcwd ();
471 #endif
472 #else
473 extern char *getwd ();
474 # define getcwd(buf, len) getwd (buf)
475 #endif
477 extern const struct floc *reading_file;
479 extern char **environ;
481 extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
482 extern int print_data_base_flag, question_flag, touch_flag;
483 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
484 extern int print_version_flag, print_directory_flag;
485 extern int warn_undefined_variables_flag, posix_pedantic, not_parallel;
486 extern int clock_skew_detected;
488 /* can we run commands via 'sh -c xxx' or must we use batch files? */
489 extern int batch_mode_shell;
491 extern unsigned int job_slots;
492 extern int job_fds[2];
493 extern int job_rfd;
494 #ifndef NO_FLOAT
495 extern double max_load_average;
496 #else
497 extern int max_load_average;
498 #endif
500 extern char *program;
501 extern char *starting_directory;
502 extern unsigned int makelevel;
503 extern char *version_string, *remote_description;
505 extern unsigned int commands_started;
507 extern int handling_fatal_signal;
510 #ifndef MIN
511 #define MIN(_a,_b) ((_a)<(_b)?(_a):(_b))
512 #endif
513 #ifndef MAX
514 #define MAX(_a,_b) ((_a)>(_b)?(_a):(_b))
515 #endif
517 #ifdef VMS
518 # ifndef EXIT_FAILURE
519 # define EXIT_FAILURE 3
520 # endif
521 # ifndef EXIT_SUCCESS
522 # define EXIT_SUCCESS 1
523 # endif
524 # ifndef EXIT_TROUBLE
525 # define EXIT_TROUBLE 2
526 # endif
527 #else
528 # ifndef EXIT_FAILURE
529 # define EXIT_FAILURE 2
530 # endif
531 # ifndef EXIT_SUCCESS
532 # define EXIT_SUCCESS 0
533 # endif
534 # ifndef EXIT_TROUBLE
535 # define EXIT_TROUBLE 1
536 # endif
537 #endif
539 /* Set up heap debugging library dmalloc. */
541 #ifdef HAVE_DMALLOC_H
542 #include <dmalloc.h>
543 #endif