OSDN Git Service

* configure.in: Kill tm.h. Include the files in the $tm_file
[pf3gnuchains/gcc-fork.git] / gcc / system.h
1 /* Get common system includes and various definitions and declarations based
2    on autoconf macros.
3    Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 #ifndef __GCC_SYSTEM_H__
24 #define __GCC_SYSTEM_H__
25
26 /* This is the location of the online document giving information how
27    to report bugs. If you change this string, also check for strings
28    not under control of the preprocessor.  */
29 #define GCCBUGURL "<URL:http://www.gnu.org/software/gcc/bugs.html>"
30
31 /* We must include stdarg.h/varargs.h before stdio.h. */
32 #ifdef ANSI_PROTOTYPES
33 #include <stdarg.h>
34 #else
35 #include <varargs.h>
36 #endif
37
38 #ifndef va_copy
39 # ifdef __va_copy
40 #   define va_copy(d,s)  __va_copy((d),(s))
41 # else
42 #   define va_copy(d,s)  ((d) = (s))
43 # endif
44 #endif
45
46 #ifdef HAVE_STDDEF_H
47 # include <stddef.h>
48 #endif
49
50 #include <stdio.h>
51
52 /* Define a generic NULL if one hasn't already been defined.  */
53 #ifndef NULL
54 #define NULL 0
55 #endif
56
57 /* The compiler is not a multi-threaded application and therefore we
58    do not have to use the locking functions.
59
60    HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the IO
61    code is multi-thread safe by default.  If it is set to 0, then do
62    not worry about using the _unlocked functions.
63    
64    fputs_unlocked is an extension and needs to be prototyped specially.  */
65
66 #if defined HAVE_PUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
67 # undef putc
68 # define putc(C, Stream) putc_unlocked (C, Stream)
69 #endif
70 #if defined HAVE_FPUTC_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
71 # undef fputc
72 # define fputc(C, Stream) fputc_unlocked (C, Stream)
73 #endif
74 #if defined HAVE_FPUTS_UNLOCKED && (defined (HAVE_DECL_PUTC_UNLOCKED) && HAVE_DECL_PUTC_UNLOCKED)
75 # undef fputs
76 # define fputs(String, Stream) fputs_unlocked (String, Stream)
77 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
78 extern int fputs_unlocked PARAMS ((const char *, FILE *));
79 # endif
80 #endif
81
82 /* There are an extraordinary number of issues with <ctype.h>.
83    The last straw is that it varies with the locale.  Use libiberty's
84    replacement instead.  */
85 #include <safe-ctype.h>
86
87 /* Define a default escape character; it's different for EBCDIC.  */
88 #ifndef TARGET_ESC
89 #define TARGET_ESC 033
90 #endif
91
92 #include <sys/types.h>
93
94 #include <errno.h>
95
96 #ifndef errno
97 extern int errno;
98 #endif
99
100 #ifdef STRING_WITH_STRINGS
101 # include <string.h>
102 # include <strings.h>
103 #else
104 # ifdef HAVE_STRING_H
105 #  include <string.h>
106 # else
107 #  ifdef HAVE_STRINGS_H
108 #   include <strings.h>
109 #  endif
110 # endif
111 #endif
112
113 #ifdef HAVE_STDLIB_H
114 # include <stdlib.h>
115 # ifdef USE_C_ALLOCA
116 /* Note that systems that use glibc have a <stdlib.h> that includes
117    <alloca.h> that defines alloca, so let USE_C_ALLOCA override this. */
118 # undef alloca
119 #endif
120 #endif
121
122 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and
123    FATAL_EXIT_CODE to EXIT_SUCCESS and EXIT_FAILURE respectively,
124    or 0 and 1 if those macros are not defined.  */
125 #ifndef SUCCESS_EXIT_CODE
126 # ifdef EXIT_SUCCESS
127 #  define SUCCESS_EXIT_CODE EXIT_SUCCESS
128 # else
129 #  define SUCCESS_EXIT_CODE 0
130 # endif
131 #endif
132
133 #ifndef FATAL_EXIT_CODE
134 # ifdef EXIT_FAILURE
135 #  define FATAL_EXIT_CODE EXIT_FAILURE
136 # else
137 #  define FATAL_EXIT_CODE 1
138 # endif
139 #endif
140
141 #ifdef HAVE_UNISTD_H
142 # include <unistd.h>
143 #endif
144
145 #ifdef HAVE_SYS_PARAM_H
146 # include <sys/param.h>
147 #endif
148
149 #if HAVE_LIMITS_H
150 # include <limits.h>
151 #endif
152
153 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
154    It will be the largest integer mode supported by the host which may
155    (or may not) be larger than HOST_WIDE_INT.  This must appear after
156    <limits.h> since we only use `long long' if its bigger than a
157    `long' and also if it is supported by macros in limits.h.  For old
158    hosts which don't have a limits.h (and thus won't include it in
159    stage2 cause we don't rerun configure) we assume gcc supports long
160    long.)  Note, you won't get these defined if you don't include
161    {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
162
163 #ifndef HOST_WIDEST_INT
164 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
165 #  if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
166 #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
167 #   define HOST_WIDEST_INT long long
168 #   define HOST_WIDEST_INT_PRINT_DEC "%lld"
169 #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
170 #   define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
171 #  else
172 #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
173 #   define HOST_WIDEST_INT long
174 #   define HOST_WIDEST_INT_PRINT_DEC "%ld"
175 #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
176 #   define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
177 #  endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
178 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
179 #endif /* ! HOST_WIDEST_INT */
180
181 /* Infrastructure for defining missing _MAX and _MIN macros.  Note that
182    macros defined with these cannot be used in #if.  */
183
184 /* The extra casts work around common compiler bugs.  */
185 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
186 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
187    It is necessary at least when t == time_t.  */
188 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
189                              ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
190 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
191
192 /* Use that infrastructure to provide a few constants.  */
193 #ifndef UCHAR_MAX
194 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
195 #endif
196
197 #ifdef TIME_WITH_SYS_TIME
198 # include <sys/time.h>
199 # include <time.h>
200 #else
201 # if HAVE_SYS_TIME_H
202 #  include <sys/time.h>
203 # else
204 #  ifdef HAVE_TIME_H
205 #   include <time.h>
206 #  endif
207 # endif
208 #endif
209
210 #ifdef HAVE_FCNTL_H
211 # include <fcntl.h>
212 #else
213 # ifdef HAVE_SYS_FILE_H
214 #  include <sys/file.h>
215 # endif
216 #endif
217
218 #ifndef SEEK_SET
219 # define SEEK_SET 0
220 # define SEEK_CUR 1
221 # define SEEK_END 2
222 #endif
223 #ifndef F_OK
224 # define F_OK 0
225 # define X_OK 1
226 # define W_OK 2
227 # define R_OK 4
228 #endif
229 #ifndef O_RDONLY
230 # define O_RDONLY 0
231 #endif
232 #ifndef O_WRONLY
233 # define O_WRONLY 1
234 #endif
235
236 /* Some systems define these in, e.g., param.h.  We undefine these names
237    here to avoid the warnings.  We prefer to use our definitions since we
238    know they are correct.  */
239
240 #undef MIN
241 #undef MAX
242 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
243 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
244
245 /* Returns the least number N such that N * Y >= X.  */
246 #define CEIL(x,y) (((x) + (y) - 1) / (y))
247
248 #ifdef HAVE_SYS_WAIT_H
249 #include <sys/wait.h>
250 #endif
251
252 #ifndef WIFSIGNALED
253 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
254 #endif
255 #ifndef WTERMSIG
256 #define WTERMSIG(S) ((S) & 0x7f)
257 #endif
258 #ifndef WIFEXITED
259 #define WIFEXITED(S) (((S) & 0xff) == 0)
260 #endif
261 #ifndef WEXITSTATUS
262 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
263 #endif
264 #ifndef WSTOPSIG
265 #define WSTOPSIG WEXITSTATUS
266 #endif
267
268 /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1.  If they
269    are defined to 0 then we must provide the relevant declaration
270    here.  These checks will be in the undefined state while configure
271    is running so be careful to test "defined (HAVE_DECL_*)".  */
272
273 #ifndef bcopy
274 # ifdef HAVE_BCOPY
275 #  if defined (HAVE_DECL_BCOPY) && !HAVE_DECL_BCOPY
276 extern void bcopy PARAMS ((const PTR, PTR, size_t));
277 #  endif
278 # else /* ! HAVE_BCOPY */
279 #  define bcopy(src,dst,len) memmove((dst),(src),(len))
280 # endif
281 #endif
282
283 #if defined (HAVE_DECL_ATOF) && !HAVE_DECL_ATOF
284 extern double atof PARAMS ((const char *));
285 #endif
286
287 #if defined (HAVE_DECL_ATOL) && !HAVE_DECL_ATOL
288 extern long atol PARAMS ((const char *));
289 #endif
290
291 #if defined (HAVE_DECL_FREE) && !HAVE_DECL_FREE
292 extern void free PARAMS ((PTR));
293 #endif
294
295 #if defined (HAVE_DECL_GETCWD) && !HAVE_DECL_GETCWD
296 extern char *getcwd PARAMS ((char *, size_t));
297 #endif
298
299 #if defined (HAVE_DECL_GETENV) && !HAVE_DECL_GETENV
300 extern char *getenv PARAMS ((const char *));
301 #endif
302
303 #if defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT
304 extern int getopt PARAMS ((int, char * const *, const char *));
305 #endif
306
307 #if defined (HAVE_DECL_GETWD) && !HAVE_DECL_GETWD
308 extern char *getwd PARAMS ((char *));
309 #endif
310
311 #if defined (HAVE_DECL_SBRK) && !HAVE_DECL_SBRK
312 extern PTR sbrk PARAMS ((int));
313 #endif
314
315 #if defined (HAVE_DECL_STRSTR) && !HAVE_DECL_STRSTR
316 extern char *strstr PARAMS ((const char *, const char *));
317 #endif
318
319 #ifdef HAVE_MALLOC_H
320 #include <malloc.h>
321 #endif
322
323 #if defined (HAVE_DECL_MALLOC) && !HAVE_DECL_MALLOC
324 extern PTR malloc PARAMS ((size_t));
325 #endif
326
327 #if defined (HAVE_DECL_CALLOC) && !HAVE_DECL_CALLOC
328 extern PTR calloc PARAMS ((size_t, size_t));
329 #endif
330
331 #if defined (HAVE_DECL_REALLOC) && !HAVE_DECL_REALLOC
332 extern PTR realloc PARAMS ((PTR, size_t));
333 #endif
334
335 /* If the system doesn't provide strsignal, we get it defined in
336    libiberty but no declaration is supplied. */
337 #ifndef HAVE_STRSIGNAL
338 # ifndef strsignal
339 extern const char *strsignal PARAMS ((int));
340 # endif
341 #endif
342
343 #ifdef HAVE_GETRLIMIT
344 # if defined (HAVE_DECL_GETRLIMIT) && !HAVE_DECL_GETRLIMIT
345 #  ifndef getrlimit
346 #   ifdef ANSI_PROTOTYPES
347 struct rlimit;
348 #   endif
349 extern int getrlimit PARAMS ((int, struct rlimit *));
350 #  endif
351 # endif
352 #endif
353
354 #ifdef HAVE_SETRLIMIT
355 # if defined (HAVE_DECL_SETRLIMIT) && !HAVE_DECL_SETRLIMIT
356 #  ifndef setrlimit
357 #   ifdef ANSI_PROTOTYPES
358 struct rlimit;
359 #   endif
360 extern int setrlimit PARAMS ((int, const struct rlimit *));
361 #  endif
362 # endif
363 #endif
364
365 /* HAVE_VOLATILE only refers to the stage1 compiler.  We also check
366    __STDC__ and assume gcc sets it and has volatile in stage >=2. */
367 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
368 #define volatile
369 #endif
370
371 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
372 extern void abort PARAMS ((void));
373 #endif
374
375 /* 1 if we have C99 designated initializers.  */
376 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
377 #define HAVE_DESIGNATED_INITIALIZERS \
378   ((GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L))
379 #endif
380
381 /* 1 if we have _Bool.  */
382 #ifndef HAVE__BOOL
383 # define HAVE__BOOL \
384    ((GCC_VERSION >= 3000) || (__STDC_VERSION__ >= 199901L))
385 #endif
386
387
388
389 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
390    Note: if the argument passed to STRINGIFY is itself a macro, eg
391    #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
392    Although the __STDC__ case could be made to expand this via a layer
393    of indirection, the traditional C case can not do so.  Therefore
394    this behavior is not supported. */
395 #ifndef STRINGIFY
396 # ifdef HAVE_STRINGIZE
397 #  define STRINGIFY(STRING) #STRING
398 # else
399 #  define STRINGIFY(STRING) "STRING"
400 # endif
401 #endif /* ! STRINGIFY */
402
403 #if HAVE_SYS_STAT_H
404 # include <sys/stat.h>
405 #endif
406
407 /* Test if something is a normal file.  */
408 #ifndef S_ISREG
409 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
410 #endif
411
412 /* Test if something is a directory.  */
413 #ifndef S_ISDIR
414 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
415 #endif
416
417 /* Test if something is a character special file.  */
418 #ifndef S_ISCHR
419 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
420 #endif
421
422 /* Test if something is a block special file.  */
423 #ifndef S_ISBLK
424 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
425 #endif
426
427 /* Test if something is a socket.  */
428 #ifndef S_ISSOCK
429 # ifdef S_IFSOCK
430 #   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
431 # else
432 #   define S_ISSOCK(m) 0
433 # endif
434 #endif
435
436 /* Test if something is a FIFO.  */
437 #ifndef S_ISFIFO
438 # ifdef S_IFIFO
439 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
440 # else
441 #  define S_ISFIFO(m) 0
442 # endif
443 #endif
444
445 /* Approximate O_NONBLOCK.  */
446 #ifndef O_NONBLOCK
447 #define O_NONBLOCK O_NDELAY
448 #endif
449
450 /* Approximate O_NOCTTY.  */
451 #ifndef O_NOCTTY
452 #define O_NOCTTY 0
453 #endif
454
455 /* Define well known filenos if the system does not define them.  */
456 #ifndef STDIN_FILENO
457 # define STDIN_FILENO   0
458 #endif
459 #ifndef STDOUT_FILENO
460 # define STDOUT_FILENO  1
461 #endif
462 #ifndef STDERR_FILENO
463 # define STDERR_FILENO  2
464 #endif
465
466 /* Some systems have mkdir that takes a single argument. */
467 #ifdef MKDIR_TAKES_ONE_ARG
468 # define mkdir(a,b) mkdir(a)
469 #endif
470
471 /* Provide a way to print an address via printf.  */
472 #ifndef HOST_PTR_PRINTF
473 # ifdef HAVE_PRINTF_PTR
474 #  define HOST_PTR_PRINTF "%p"
475 # else
476 #  define HOST_PTR_PRINTF \
477     (sizeof (int) == sizeof (char *) ? "%x" \
478      : sizeof (long) == sizeof (char *) ? "%lx" : "%llx")
479 # endif
480 #endif /* ! HOST_PTR_PRINTF */
481
482 /* By default, colon separates directories in a path.  */
483 #ifndef PATH_SEPARATOR
484 #define PATH_SEPARATOR ':'
485 #endif
486
487 #ifndef DIR_SEPARATOR
488 #define DIR_SEPARATOR '/'
489 #endif
490
491 /* Define IS_DIR_SEPARATOR.  */
492 #ifndef DIR_SEPARATOR_2
493 # define IS_DIR_SEPARATOR(CH) ((CH) == DIR_SEPARATOR)
494 #else /* DIR_SEPARATOR_2 */
495 # define IS_DIR_SEPARATOR(CH) \
496         (((CH) == DIR_SEPARATOR) || ((CH) == DIR_SEPARATOR_2))
497 #endif /* DIR_SEPARATOR_2 */
498
499 /* Say how to test for an absolute pathname.  On Unix systems, this is if
500    it starts with a leading slash or a '$', the latter meaning the value of
501    an environment variable is to be used.  On machien with DOS-based
502    file systems, it is also absolute if it starts with a drive identifier.  */
503 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
504 #define IS_ABSOLUTE_PATHNAME(STR) \
505   (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$' \
506    || ((STR)[0] != '\0' && (STR)[1] == ':' && IS_DIR_SEPARATOR ((STR)[2])))
507 #else
508 #define IS_ABSOLUTE_PATHNAME(STR) \
509   (IS_DIR_SEPARATOR ((STR)[0]) || (STR)[0] == '$')
510 #endif
511
512 /* Get libiberty declarations. */
513 #include "libiberty.h"
514
515 /* Make sure that ONLY_INT_FIELDS has an integral value.  */
516 #ifdef ONLY_INT_FIELDS
517 #undef ONLY_INT_FIELDS
518 #define ONLY_INT_FIELDS 1
519 #else
520 #define ONLY_INT_FIELDS 0
521 #endif 
522
523 /* Provide a default for the HOST_BIT_BUCKET.
524    This suffices for POSIX-like hosts.  */
525
526 #ifndef HOST_BIT_BUCKET
527 #define HOST_BIT_BUCKET "/dev/null"
528 #endif
529
530 /* Enumerated bitfields are safe to use unless we've been explictly told
531    otherwise or if they are signed. */
532  
533 #define USE_ENUM_BITFIELDS (__GNUC__ || (!ONLY_INT_FIELDS && ENUM_BITFIELDS_ARE_UNSIGNED))
534
535 #if USE_ENUM_BITFIELDS
536 #define ENUM_BITFIELD(TYPE) enum TYPE
537 #else
538 #define ENUM_BITFIELD(TYPE) unsigned int
539 #endif
540
541 #ifndef offsetof
542 #define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *)0)->MEMBER)
543 #endif
544
545 /* Traditional C cannot initialize union members of structs.  Provide
546    a macro which expands appropriately to handle it.  This only works
547    if you intend to initalize the union member to zero since it relies
548    on default initialization to zero in the traditional C case.  */
549 #ifdef __STDC__
550 #define UNION_INIT_ZERO , {0}
551 #else
552 #define UNION_INIT_ZERO
553 #endif
554
555 /* GCC now gives implicit declaration warnings for undeclared builtins.  */
556 #if defined(__GNUC__) && defined (__SIZE_TYPE__)
557 extern void *alloca (__SIZE_TYPE__);
558 #endif
559
560 /* Various error reporting routines want to use __FUNCTION__.  */
561 #if (GCC_VERSION < 2007)
562 #ifndef __FUNCTION__
563 #define __FUNCTION__ "?"
564 #endif /* ! __FUNCTION__ */
565 #endif
566
567 /* Provide some sort of boolean type.  We use stdbool.h if it's
568   available.  This is dead last because various system headers might
569   mess us up.  */
570 #undef bool
571 #undef true
572 #undef false
573 #undef TRUE
574 #undef FALSE
575
576 #ifdef HAVE_STDBOOL_H
577 # include <stdbool.h>
578 #else
579 # if !HAVE__BOOL
580 typedef char _Bool;
581 # endif
582 # define bool _Bool
583 # define true 1
584 # define false 0
585 #endif
586
587 #define TRUE true
588 #define FALSE false
589
590 #endif /* __GCC_SYSTEM_H__ */