OSDN Git Service

Add comment about duplication of EXTRA_PARTS in EXTRA_MULTILIB_PARTS
[pf3gnuchains/gcc-fork.git] / gcc / system.h
1 /* system.h - Get common system includes and various definitions and
2    declarations based on autoconf macros.
3    Copyright (C) 1998, 1999 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 #ifndef __GCC_SYSTEM_H__
23 #define __GCC_SYSTEM_H__
24
25 /* We must include stdarg.h/varargs.h before stdio.h. */
26 #ifdef ANSI_PROTOTYPES
27 #include <stdarg.h>
28 #else
29 #include <varargs.h>
30 #endif
31
32 #include <stdio.h>
33
34 /* Define a generic NULL if one hasn't already been defined.  */
35 #ifndef NULL
36 #define NULL 0
37 #endif
38
39 /* The compiler is not a multi-threaded application and therefore we
40    do not have to use the locking functions.
41
42    NEED_DECLARATION_PUTC_UNLOCKED actually indicates whether or not
43    the IO code is multi-thread safe by default.  If it is not declared,
44    then do not worry about using the _unlocked functions.
45    
46    fputs_unlocked is an extension and needs to be prototyped specially.  */
47
48 #if defined HAVE_PUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
49 # undef putc
50 # define putc(C, Stream) putc_unlocked (C, Stream)
51 #endif
52 #if defined HAVE_FPUTC_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
53 # undef fputc
54 # define fputc(C, Stream) fputc_unlocked (C, Stream)
55 #endif
56 #if defined HAVE_FPUTS_UNLOCKED && !defined NEED_DECLARATION_PUTC_UNLOCKED
57 # undef fputs
58 # define fputs(String, Stream) fputs_unlocked (String, Stream)
59 # ifdef NEED_DECLARATION_FPUTS_UNLOCKED
60 extern int fputs_unlocked PROTO ((const char *, FILE *));
61 # endif
62 #endif
63
64 #include <ctype.h>
65
66 /* Jim Meyering writes:
67
68    "... Some ctype macros are valid only for character codes that
69    isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
70    using /bin/cc or gcc but without giving an ansi option).  So, all
71    ctype uses should be through macros like ISPRINT...  If
72    STDC_HEADERS is defined, then autoconf has verified that the ctype
73    macros don't need to be guarded with references to isascii. ...
74    Defining isascii to 1 should let any compiler worth its salt
75    eliminate the && through constant folding."
76
77    Bruno Haible adds:
78
79    "... Furthermore, isupper(c) etc. have an undefined result if c is
80    outside the range -1 <= c <= 255. One is tempted to write isupper(c)
81    with c being of type `char', but this is wrong if c is an 8-bit
82    character >= 128 which gets sign-extended to a negative value.
83    The macro ISUPPER protects against this as well."  */
84
85 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
86 # define IN_CTYPE_DOMAIN(c) 1
87 #else
88 # define IN_CTYPE_DOMAIN(c) isascii(c)
89 #endif
90
91 #ifdef isblank
92 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
93 #else
94 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
95 #endif
96 #ifdef isgraph
97 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
98 #else
99 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
100 #endif
101
102 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
103 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
104 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
105 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
106 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
107 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
108 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
109 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
110 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
111 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
112
113 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
114    - Its arg may be any int or unsigned int; it need not be an unsigned char.
115    - It's guaranteed to evaluate its argument exactly once.
116    - It's typically faster.
117    Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
118    only '0' through '9' are digits.  Prefer ISDIGIT to ISDIGIT_LOCALE unless
119    it's important to use the locale's definition of `digit' even when the
120    host does not conform to Posix.  */
121 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
122
123
124 #include <sys/types.h>
125 #include <errno.h>
126
127 #ifndef errno
128 extern int errno;
129 #endif
130
131 #ifdef STRING_WITH_STRINGS
132 # include <string.h>
133 # include <strings.h>
134 #else
135 # ifdef HAVE_STRING_H
136 #  include <string.h>
137 # else
138 #  ifdef HAVE_STRINGS_H
139 #   include <strings.h>
140 #  endif
141 # endif
142 #endif
143
144 #ifdef HAVE_STDLIB_H
145 # include <stdlib.h>
146 #endif
147
148 #ifdef HAVE_UNISTD_H
149 # include <unistd.h>
150 #endif
151
152 #ifdef HAVE_SYS_PARAM_H
153 # include <sys/param.h>
154 #endif
155
156 #if HAVE_LIMITS_H
157 # include <limits.h>
158 #endif
159
160 /* Find HOST_WIDEST_INT and set its bit size, type and print macros.
161    It will be the largest integer mode supported by the host which may
162    (or may not) be larger than HOST_WIDE_INT.  This must appear after
163    <limits.h> since we only use `long long' if its bigger than a
164    `long' and also if it is supported by macros in limits.h.  For old
165    hosts which don't have a limits.h (and thus won't include it in
166    stage2 cause we don't rerun configure) we assume gcc supports long
167    long.)  Note, you won't get these defined if you don't include
168    {ht}config.h before this file to set the HOST_BITS_PER_* macros. */
169
170 #ifndef HOST_WIDEST_INT
171 # if defined (HOST_BITS_PER_LONG) && defined (HOST_BITS_PER_LONGLONG)
172 #  if (HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG) && (defined (LONG_LONG_MAX) || defined (LONGLONG_MAX) || defined (LLONG_MAX) || defined (__GNUC__))
173 #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
174 #   define HOST_WIDEST_INT long long
175 #   define HOST_WIDEST_INT_PRINT_DEC "%lld"
176 #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
177 #   define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
178 #  else
179 #   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
180 #   define HOST_WIDEST_INT long
181 #   define HOST_WIDEST_INT_PRINT_DEC "%ld"
182 #   define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
183 #   define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
184 #  endif /*(long long>long) && (LONG_LONG_MAX||LONGLONG_MAX||LLONG_MAX||GNUC)*/
185 # endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
186 #endif /* ! HOST_WIDEST_INT */
187
188 #ifdef TIME_WITH_SYS_TIME
189 # include <sys/time.h>
190 # include <time.h>
191 #else
192 # if HAVE_SYS_TIME_H
193 #  include <sys/time.h>
194 # else
195 #  ifdef HAVE_TIME_H
196 #   include <time.h>
197 #  endif
198 # endif
199 #endif
200
201 #ifdef HAVE_FCNTL_H
202 # include <fcntl.h>
203 #else
204 # ifdef HAVE_SYS_FILE_H
205 #  include <sys/file.h>
206 # endif
207 #endif
208
209 #ifndef SEEK_SET
210 # define SEEK_SET 0
211 # define SEEK_CUR 1
212 # define SEEK_END 2
213 #endif
214 #ifndef F_OK
215 # define F_OK 0
216 # define X_OK 1
217 # define W_OK 2
218 # define R_OK 4
219 #endif
220 #ifndef O_RDONLY
221 # define O_RDONLY 0
222 #endif
223 #ifndef O_WRONLY
224 # define O_WRONLY 1
225 #endif
226
227 /* Some systems define these in, e.g., param.h.  We undefine these names
228    here to avoid the warnings.  We prefer to use our definitions since we
229    know they are correct.  */
230
231 #undef MIN
232 #undef MAX
233 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
234 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
235
236 #ifdef HAVE_SYS_WAIT_H
237 #include <sys/wait.h>
238 #endif
239
240 #ifndef WIFSIGNALED
241 #define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f)
242 #endif
243 #ifndef WTERMSIG
244 #define WTERMSIG(S) ((S) & 0x7f)
245 #endif
246 #ifndef WIFEXITED
247 #define WIFEXITED(S) (((S) & 0xff) == 0)
248 #endif
249 #ifndef WEXITSTATUS
250 #define WEXITSTATUS(S) (((S) & 0xff00) >> 8)
251 #endif
252
253
254
255 #ifndef bcopy
256 # ifdef HAVE_BCOPY
257 #  ifdef NEED_DECLARATION_BCOPY
258 extern void bcopy ();
259 #  endif
260 # else /* ! HAVE_BCOPY */
261 #  define bcopy(src,dst,len) memmove((dst),(src),(len))
262 # endif
263 #endif
264
265 #ifndef bcmp
266 # ifdef HAVE_BCMP
267 #  ifdef NEED_DECLARATION_BCMP
268 extern int bcmp ();
269 #  endif
270 # else /* ! HAVE_BCMP */
271 #  define bcmp(left,right,len) memcmp ((left),(right),(len))
272 # endif
273 #endif
274
275 #ifndef bzero
276 # ifdef HAVE_BZERO
277 #  ifdef NEED_DECLARATION_BZERO
278 extern void bzero ();
279 #  endif
280 # else /* ! HAVE_BZERO */
281 #  define bzero(dst,len) memset ((dst),0,(len))
282 # endif
283 #endif
284
285 #ifndef index
286 # ifdef HAVE_INDEX
287 #  ifdef NEED_DECLARATION_INDEX
288 extern char *index ();
289 #  endif
290 # else /* ! HAVE_INDEX */
291 #  define index strchr
292 # endif
293 #endif
294
295 #ifndef rindex
296 # ifdef HAVE_RINDEX
297 #  ifdef NEED_DECLARATION_RINDEX
298 extern char *rindex ();
299 #  endif
300 # else /* ! HAVE_RINDEX */
301 #  define rindex strrchr
302 # endif
303 #endif
304
305 #ifdef NEED_DECLARATION_ATOF
306 extern double atof ();
307 #endif
308
309 #ifdef NEED_DECLARATION_ATOL
310 extern long atol();
311 #endif
312
313 #ifdef NEED_DECLARATION_FREE
314 extern void free ();
315 #endif
316
317 #ifdef NEED_DECLARATION_GETCWD
318 extern char *getcwd ();
319 #endif
320
321 #ifdef NEED_DECLARATION_GETENV
322 extern char *getenv ();
323 #endif
324
325 #ifdef NEED_DECLARATION_GETWD
326 extern char *getwd ();
327 #endif
328
329 #ifdef NEED_DECLARATION_SBRK
330 extern char *sbrk ();
331 #endif
332
333 #ifdef HAVE_STRERROR
334 # ifdef NEED_DECLARATION_STRERROR
335 #  ifndef strerror
336 extern char *strerror ();
337 #  endif
338 # endif
339 #else /* ! HAVE_STRERROR */
340 extern int sys_nerr;
341 extern char *sys_errlist[];
342 #endif /* HAVE_STRERROR */
343
344 #ifdef HAVE_STRSIGNAL
345 # ifdef NEED_DECLARATION_STRSIGNAL
346 #  ifndef strsignal
347 extern char * strsignal ();
348 #  endif
349 # endif
350 #else /* ! HAVE_STRSIGNAL */
351 # ifndef SYS_SIGLIST_DECLARED
352 #  ifndef NO_SYS_SIGLIST
353 extern char * sys_siglist[];
354 #  endif
355 # endif
356 #endif /* HAVE_STRSIGNAL */
357
358 #ifdef HAVE_GETRLIMIT
359 # ifdef NEED_DECLARATION_GETRLIMIT
360 #  ifndef getrlimit
361 extern int getrlimit ();
362 #  endif
363 # endif
364 #endif
365
366 #ifdef HAVE_SETRLIMIT
367 # ifdef NEED_DECLARATION_SETRLIMIT
368 #  ifndef setrlimit
369 extern int setrlimit ();
370 #  endif
371 # endif
372 #endif
373
374 /* HAVE_VOLATILE only refers to the stage1 compiler.  We also check
375    __STDC__ and assume gcc sets it and has volatile in stage >=2. */
376 #if !defined(HAVE_VOLATILE) && !defined(__STDC__) && !defined(volatile)
377 #define volatile
378 #endif
379
380 /* Redefine abort to report an internal error w/o coredump, and reporting the
381    location of the error in the source file.  */
382 #ifndef abort
383 #ifndef __STDC__
384 #ifndef __GNUC__
385 #ifndef USE_SYSTEM_ABORT
386 #define USE_SYSTEM_ABORT
387 #endif /* !USE_SYSTEM_ABORT */
388 #endif /* !__GNUC__ */
389 #endif /* !__STDC__ */
390
391 #ifdef USE_SYSTEM_ABORT
392 # ifdef NEED_DECLARATION_ABORT
393 extern void abort ();
394 # endif
395 #else
396 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
397 #define abort()                                                         \
398 (fprintf (stderr,                                                       \
399           "%s:%d: Internal compiler error\n", __FILE__, __LINE__),      \
400  exit (FATAL_EXIT_CODE))
401
402 #else
403 #define abort()                                                         \
404 (fprintf (stderr,                                                       \
405           "%s:%d: Internal compiler error in function %s\n"             \
406           "Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.\n"  \
407           "See <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.\n", \
408           __FILE__, __LINE__, __PRETTY_FUNCTION__),                     \
409  exit (FATAL_EXIT_CODE))
410
411 #endif /* recent gcc */
412 #endif /* USE_SYSTEM_ABORT */
413 #endif /* !abort */
414
415
416 /* Define a STRINGIFY macro that's right for ANSI or traditional C.
417    HAVE_CPP_STRINGIFY only refers to the stage1 compiler.  Assume that
418    (non-traditional) gcc used in stage2 or later has this feature.
419
420    Note: if the argument passed to STRINGIFY is itself a macro, eg
421    #define foo bar, STRINGIFY(foo) will produce "foo", not "bar".
422    Although the __STDC__ case could be made to expand this via a layer
423    of indirection, the traditional C case can not do so.  Therefore
424    this behavior is not supported. */
425 #ifndef STRINGIFY
426 # if defined(HAVE_CPP_STRINGIFY) || (defined(__GNUC__) && defined(__STDC__))
427 #  define STRINGIFY(STRING) #STRING
428 # else
429 #  define STRINGIFY(STRING) "STRING"
430 # endif
431 #endif /* ! STRINGIFY */
432
433 #if HAVE_SYS_STAT_H
434 # include <sys/stat.h>
435 #endif
436
437 /* Test if something is a normal file.  */
438 #ifndef S_ISREG
439 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
440 #endif
441
442 /* Test if something is a directory.  */
443 #ifndef S_ISDIR
444 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
445 #endif
446
447 /* Test if something is a character special file.  */
448 #ifndef S_ISCHR
449 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
450 #endif
451
452 /* Test if something is a socket.  */
453 #ifndef S_ISSOCK
454 # ifdef S_IFSOCK
455 #   define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
456 # else
457 #   define S_ISSOCK(m) 0
458 # endif
459 #endif
460
461 /* Test if something is a FIFO.  */
462 #ifndef S_ISFIFO
463 # ifdef S_IFIFO
464 #  define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
465 # else
466 #  define S_ISFIFO(m) 0
467 # endif
468 #endif
469
470 /* Approximate O_NONBLOCK.  */
471 #ifndef O_NONBLOCK
472 #define O_NONBLOCK O_NDELAY
473 #endif
474
475 /* Approximate O_NOCTTY.  */
476 #ifndef O_NOCTTY
477 #define O_NOCTTY 0
478 #endif
479
480 /* Define well known filenos if the system does not define them.  */
481 #ifndef STDIN_FILENO
482 # define STDIN_FILENO   0
483 #endif
484 #ifndef STDOUT_FILENO
485 # define STDOUT_FILENO  1
486 #endif
487 #ifndef STDOUT_FILENO
488 # define STDERR_FILENO  2
489 #endif
490
491 /* Get libiberty declarations. */
492 #include "libiberty.h"
493
494 #endif /* __GCC_SYSTEM_H__ */