Do not report -Wnested-extern errors for __FUNCTION__/__PRETTY_FUNCTION__.
[official-gcc.git] / gcc / scan-types.sh
blobbe02123a6e2f11cc1b482d9416629a2b6e8569fd
1 #! /bin/sh
2 # Deduce values of standard ANSI and POSIX types (e.g. size_t, pid_t).
3 # Emits macros definitions for these, and some other types.
4 # Intended to be used to massage the sys-protos.h file.
6 CC=${CC-./xgcc}
7 CPP=${CPP-`echo ${CC} -E`}
8 SED=sed
10 # Generate definitions for the standard types (such as mode_t)
11 # compatible with those in the standard C header files.
12 # It works by a dummy program through the C pre-processor, and then
13 # using sed to search for typedefs in the output.
15 cat >dummy.c <<!EOF!
16 #include <sys/types.h>
17 #include <stddef.h>
18 #include <stdarg.h>
19 #include <stdio.h>
20 #include <time.h>
21 #include <signal.h>
22 #ifdef size_t
23 typedef size_t Xsize_t;
24 #elif defined(__SIZE_TYPE__)
25 typedef __SIZE_TYPE__ Xsize_t;
26 #endif
27 #ifdef ptrdiff_t
28 typedef ptrdiff_t Xptrdiff_t;
29 #elif defined(__PTRDIFF_TYPE__)
30 typedef __PTRDIFF_TYPE__ Xptrdiff_t;
31 #endif
32 #ifdef wchar_t
33 typedef wchar_t Xwchar_t;
34 #elif defined(__WCHAR_TYPE__)
35 typedef __WCHAR_TYPE__ Xwchar_t;
36 #endif
37 #ifdef va_list
38 typedef va_list XXXva_list;
39 #endif
40 !EOF!
42 if ${CPP} dummy.c >TMP ; then true
43 else
44 echo "gen-params: could not invoke ${CPP} on dummy.c" 1>&2 ; exit 1
46 tr ' ' ' ' <TMP >dummy.out
48 for TYPE in dev_t clock_t fpos_t gid_t ino_t mode_t nlink_t off_t pid_t ptrdiff_t sigset_t size_t ssize_t time_t uid_t va_list wchar_t int32_t uint_32_t ; do
49 IMPORTED=`eval 'echo $'"$TYPE"`
50 if [ -n "${IMPORTED}" ] ; then
51 eval "$TYPE='$IMPORTED"
52 else
53 # Search dummy.out for a typedef for $TYPE, and write it out
54 # to TMP in #define syntax.
55 rm -f TMP
56 ${SED} -n -e "s|.*typedef *\(.*\) X*$TYPE *;.*|\1|w TMP" <dummy.out>/dev/null
57 # Now select the first definition.
58 if [ -s TMP ]; then
59 # VALUE is now the typedef'd definition of $TYPE.
60 eval "VALUE='`${SED} -e 's| *$||' -e '2,$d' <TMP`'"
61 # Unless VALUE contains a blank, look for a typedef for it
62 # in turn (this could be a loop, but that would be over-kill).
63 if echo $VALUE | grep " " >/dev/null ; then true
64 else
65 rm -f TMP
66 ${SED} -n -e "s|.*typedef[ ][ ]*\(.*[^a-zA-Z0-9_]\)${VALUE}[ ]*;.*|\1|w TMP" <dummy.out>/dev/null
67 if [ -s TMP ]; then
68 eval "VALUE='`${SED} -e '2,$d' -e 's|[ ]*$||' <TMP`'"
71 eval "$TYPE='$VALUE'"
74 done
76 cat <<!EOF!
77 #define ${macro_prefix}clock_t ${clock_t-int /* default */}
78 #define ${macro_prefix}dev_t ${dev_t-int /* default */}
79 #define ${macro_prefix}fpos_t ${fpos_t-long /* default */}
80 #define ${macro_prefix}gid_t ${gid_t-int /* default */}
81 #define ${macro_prefix}ino_t ${ino_t-int /* default */}
82 #define ${macro_prefix}mode_t ${mode_t-int /* default */}
83 #define ${macro_prefix}nlink_t ${nlink_t-int /* default */}
84 #define ${macro_prefix}off_t ${off_t-long /* default */}
85 #define ${macro_prefix}pid_t ${pid_t-int /* default */}
86 #define ${macro_prefix}ptrdiff_t ${ptrdiff_t-long int /* default */}
87 #define ${macro_prefix}sigset_t ${sigset_t-int /* default */}
88 #define ${macro_prefix}size_t ${size_t-unsigned long /* default */}
89 #define ${macro_prefix}time_t ${time_t-int /* default */}
90 #define ${macro_prefix}uid_t ${uid_t-int /* default */}
91 #define ${macro_prefix}wchar_t ${wchar_t-int /* default */}
92 #define ${macro_prefix}int32_t ${int32_t-int /* default */}
93 #define ${macro_prefix}uint32_t ${uint32_t-unsigned int /* default */}
94 !EOF!
96 # (wait_arg_t*) should be (int*), according to Posix, but
97 # BSD traditionally used (union wait*). Use (void*) to allow either usage.
98 echo "#define ${macro_prefix}wait_arg_t void"
100 # ssize_t is the signed version of size_t
101 if [ -n "${ssize_t}" ] ; then
102 echo "#define ${macro_prefix}ssize_t ${ssize_t}"
103 elif [ -z "${size_t}" ] ; then
104 echo "#define ${macro_prefix}ssize_t long"
105 else
106 # Remove "unsigned" from ${size_t} to get ${ssize_t}.
107 tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's| | |g'`"
108 if [ -z "$tmp" ] ; then
109 tmp=int
110 else
111 # check $tmp doesn't conflict with <unistd.h>
112 echo "#include <unistd.h>
113 extern $tmp read();" >dummy.c
114 ${CC} -c dummy.c >/dev/null 2>&1 || tmp=int
116 echo "#define ${macro_prefix}ssize_t $tmp /* default */"
119 # va_list can cause problems (e.g. some systems have va_list as a struct).
120 # Check to see if ${va_list-char*} really is compatible with stdarg.h.
121 cat >dummy.c <<!EOF!
122 #define X_va_list ${va_list-char* /* default */}
123 extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
124 #include <stdarg.h>
125 long foo(X_va_list ap) { return va_arg(ap, long); }
126 long bar(int i, ...)
127 { va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
128 !EOF!
129 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
130 # Ok: We have something that works.
131 echo "#define ${macro_prefix}va_list ${va_list-char* /* default */}"
132 else
133 # No, it breaks. Indicate that <stdarg.h> must be included.
134 echo "#define ${macro_prefix}NEED_STDARG_H
135 #define ${macro_prefix}va_list va_list"
138 # stuff needed for curses.h
140 # This isn't correct for SVR4 (for example). However, we only
141 # use this when adding a missing prototype, so it shouldn't matter.
142 echo "#define chtype int"
143 # sys-protos.h uses non-standard names (due to the CHTYPE argument problem).
144 echo "#define box32 box"
145 echo "#define initscr32 initscr"
146 echo "#define w32addch waddch"
147 echo "#define w32insch winsch"
149 rm -f dummy.c dummy.o TMP dummy.out