OSDN Git Service

Uli's libio/libstdc++ patches.
[pf3gnuchains/gcc-fork.git] / libio / gen-params
1 #!/bin/sh
2 # Copyright (C) 1992, 1993, 1994 Free Software Foundation
3
4 # This file is part of the GNU IO Library.  This library is free
5 # software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9
10 # This library 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.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this library; see the file COPYING.  If not, write to the Free
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 #    Written by Per Bothner (bothner@cygnus.com)
20
21 # This is a shell-script that figures out various things about a
22 # system, and writes (to stdout) a C-style include files with
23 # suitable definitions, including all the standard Posix types.
24 # It works by compiling various test programs -- some are run through
25 # the C pre-processor, and the output examined.
26 # The test programs are only compiled, not executed, so the script
27 # should even if you're cross-compiling.
28 # It uses $CC (which defaults to cc) to compile C programs (extension .c),
29 # and $CXX (which defaults to gcc) to compile C++ programs (extension .C).
30 # The shell-script is written for libg++.a.
31
32 # Usage: gen-params [NAME1=name1 ...]
33 # - where an assignment (such as size_t="unsigned int" means to
34 # use that value, instead of trying to figure it out.
35
36 # Uncomment following line for debugging
37 # set -x
38
39 SED=sed
40
41 # Evaluate the arguments (which should be assignments):
42 for arg in "$@"; do
43   # Quote arg (i.e. FOO=bar => FOO='bar'), then eval it.
44   eval `echo "$arg" | ${SED} -e "s|^\(.*\)=\(.*\)|\1='\2'|"`
45 done
46
47 macro_prefix=${macro_prefix-"_G_"}
48 rootdir=`pwd`/..
49 gccdir=${gccdir-${rootdir}/gcc}
50 binutilsdir=${binutilsdir-${rootdir}/binutils}
51 CC=${CC-`if [ -f ${gccdir}/xgcc ] ; \
52         then echo ${gccdir}/xgcc -B${gccdir}/ ; \
53         else echo cc ; fi`}
54 CXX=${CXX-`if [ -f ${gccdir}/xgcc ] ; \
55         then echo ${gccdir}/xgcc -B${gccdir}/ ; \
56         else echo gcc ; fi`}
57 CPP=${CPP-`echo ${CC} -E`}
58 CONFIG_NM=${CONFIG_NM-`if [ -f ${binutilsdir}/nm.new ] ; \
59         then echo ${binutilsdir}/nm.new ; \
60         else echo nm ; fi`}
61
62 cat <<!EOF!
63 /* AUTOMATICALLY GENERATED; DO NOT EDIT! */ 
64 #ifndef ${macro_prefix}config_h
65 #define ${macro_prefix}config_h
66 !EOF!
67
68 if [ x"${LIB_VERSION}" != "x" ] ; then
69   echo "#define ${macro_prefix}LIB_VERSION" '"'${LIB_VERSION}'"'
70 fi
71
72 # This program is used to test if the compiler prepends '_' before identifiers.
73 # It is also used to check the g++ uses '$' or '.' various places.
74
75 if test -z "${NAMES_HAVE_UNDERSCORE}" -o -z "${DOLLAR_IN_LABEL}" \
76     -o -z "${VTABLE_LABEL_PREFIX}"; then
77   cat >dummy.h <<!EOF!
78 #ifdef __GNUG__
79 #pragma interface
80 #endif
81   struct filebuf {
82       virtual int foo();
83   };
84 !EOF!
85   cat >dummy.C <<!EOF!
86 #ifdef __GNUG__
87 #pragma implementation
88 #endif
89 #include "dummy.h"
90   int filebuf::foo() { return 0; }
91   extern "C" int FUNC(int);
92   int FUNC(int i) { return i+10; }
93 !EOF!
94
95   if ${CXX} -O -c dummy.C ; then
96     if test -z "${NAMES_HAVE_UNDERSCORE}" ; then
97       if test "`${CONFIG_NM} dummy.o | grep _FUNC`" != ""; then
98         NAMES_HAVE_UNDERSCORE=1
99       elif test "`${CONFIG_NM} dummy.o | grep FUNC`" != ""; then
100         NAMES_HAVE_UNDERSCORE=0
101       else
102         echo "${CONFIG_NM} failed to find FUNC in dummy.o!" 1>&2; exit -1;
103       fi
104     fi
105     echo "#define ${macro_prefix}NAMES_HAVE_UNDERSCORE ${NAMES_HAVE_UNDERSCORE}"
106
107     if test -z "${VTABLE_LABEL_PREFIX}" ; then
108       # Determine how virtual function tables are named.  This is fragile,
109       # because different nm's produce output in different formats.
110       ${CONFIG_NM} dummy.o >TMP
111       if [ -n "`${SED} -n -e 's/ virtual table/nope/p' <TMP`" ] ; then
112         ${CONFIG_NM} --no-cplus dummy.o >TMP 2>/dev/null ||
113           ${CONFIG_NM} --no-demangle dummy.o >TMP 2>/dev/null ||
114           ${CONFIG_NM} dummy.o >TMP 2>/dev/null
115       fi
116       # First we look for a pattern that matches historical output from g++.
117       # We surround the actual label name by <> to separate it from
118       # other nm junk. 
119       ${SED} -n -e 's/_*vt[$_.]7*filebuf/<&>/p' <TMP >dummy.out
120       # For paranoia's sake (e.g. if we're using some other C++ compiler)
121       # we try a more general pattern, and append the result.
122       grep -v foo <TMP \
123         | ${SED} -n -e 's/[a-zA-Z0-9_.$]*filebuf[a-zA-Z0-9_.$]*/<&>/p' \
124         >>dummy.out
125       # Now we get rid of the <>, and any other junk on the nm output line.
126       # (We get rid of <filebuf> in case nm included debugging output for
127       # class filebuf itself.)  Finally, we select the first line of
128       # the result, and hope that's what we wanted!
129       vtab_name=`${SED} -n -e '/<filebuf>/d' -e 's/^.*<\(.*\)>.*$/\1/p' \
130         <dummy.out | ${SED} -n -e '1p'`
131       case "${vtab_name}" in
132         *7filebuf) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 1" ;;
133         *) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 0" ;;
134       esac
135       VTABLE_LABEL_PREFIX=`echo $vtab_name | ${SED} -e 's/7*filebuf//'`
136     fi
137     echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX" '"'"${VTABLE_LABEL_PREFIX}"'"'
138     if [ "${VTABLE_LABEL_PREFIX}" = "__vt_" -o \
139         "${VTABLE_LABEL_PREFIX}" = "___vt_" ] ; then
140       echo "#define ${macro_prefix}USING_THUNKS"
141     fi
142
143     # VTABLE_LABEL_PREFIX_ID is the same as VTABLE_LABEL_PREFIX,
144     # but the former is a C identifier, while the latter is a quoted
145     # st
146     if [ -z ""`echo ${VTABLE_LABEL_PREFIX} | ${SED} -e 's/[a-zA-Z0-9_]//g'` ] ; then
147       if [ "${NAMES_HAVE_UNDERSCORE}" = "1" ] ; then
148         VTABLE_LABEL_PREFIX=`echo ${VTABLE_LABEL_PREFIX} | ${SED} -e 's/^_//'`
149       fi
150       echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX_ID ${VTABLE_LABEL_PREFIX}"
151     fi
152
153 #    if test -n "${DOLLAR_IN_LABEL}" ; then
154 #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL ${DOLLAR_IN_LABEL}"
155 #    elif test "`${CONFIG_NM} dummy.o | grep 'vt[$$]7filebuf'`" != ""; then
156 #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 1"
157 #    elif test "`${CONFIG_NM} dummy.o | grep 'vt[.]7filebuf'`" != ""; then
158 #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
159 #    elif test "`${CONFIG_NM} dummy.o | grep 'vtbl__7filebuf'`" != ""; then
160 #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
161 #    else
162 #      echo "gen-params: ${CONFIG_NM} failed to find vt[.\$]filebuf in dummy.o!" 1>&2; exit 1
163 #    fi
164   else
165     # The compile failed for some reason (no C++?)
166     echo "gen-params: could not compile dummy.C with ${CXX}" 1>&2; exit 1;
167   fi
168 fi
169
170 # A little test program to check if struct stat has st_blksize.
171 cat >dummy.c <<!EOF!
172 #include <sys/types.h>
173 #include <sys/stat.h>
174 int BLKSIZE(struct stat *st)
175 {
176     return st->st_blksize;
177 }
178 !EOF!
179
180 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
181   echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 1"
182 else
183   echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 0"
184 fi
185
186 # A little test program to check if the name 'clog' is defined in libm,
187 # as it is under DEC UNIX.
188 cat >dummy.c <<!EOF!
189 int clog;
190 main () {}
191 !EOF!
192
193 if ${CC} dummy.c -lm 2>&1 >/dev/null | grep clog >/dev/null; then
194   echo "#define ${macro_prefix}CLOG_CONFLICT 1"
195 fi
196
197 echo ""
198
199 # Next, generate definitions for the standard types (such as mode_t)
200 # compatible with those in the standard C header files.
201 # It works by a dummy program through the C pre-processor, and then
202 # using sed to search for typedefs in the output.
203
204 for hdr in wchar wctype; do
205   eval $hdr=0
206   cat >dummy.c <<EOF
207 #include <${hdr}.h>
208 EOF
209   if ${CPP} dummy.c >/dev/null 2>&1 ; then eval $hdr=1; fi
210 done
211
212 cat >dummy.c <<!EOF!
213 #include <sys/types.h>
214 #include <stddef.h>
215 #ifdef __STDC__
216 #include <stdarg.h>
217 #else /* !__STDC__ */
218 #include <varargs.h>
219 #endif /* __STDC__ */
220 #include <stdio.h>
221 #include <time.h>
222 #include <signal.h>
223 #ifdef __STDC__
224 #include <limits.h>
225 #endif
226 #if WCHAR == 1
227 #include <wchar.h>
228 #endif
229 #if WCTYPE == 1
230 #include <wctype.h>
231 #endif
232 #ifdef size_t
233 typedef size_t Xsize_t;
234 #elif defined(__SIZE_TYPE__)
235 typedef __SIZE_TYPE__ Xsize_t;
236 #endif
237 #ifdef ptrdiff_t
238 typedef ptrdiff_t Xptrdiff_t;
239 #elif defined(__PTRDIFF_TYPE__)
240 typedef __PTRDIFF_TYPE__ Xptrdiff_t;
241 #endif
242 #ifdef wchar_t
243 typedef wchar_t Xwchar_t;
244 #elif defined(__WCHAR_TYPE__)
245 typedef __WCHAR_TYPE__ Xwchar_t;
246 #endif
247 #ifdef va_list
248 typedef va_list XXXva_list;
249 #endif
250 #ifdef BUFSIZ
251 long XBUFSIZ=BUFSIZ;
252 #endif
253 #ifdef FOPEN_MAX
254 long XFOPEN_MAX=FOPEN_MAX;
255 #endif
256 #ifdef FILENAME_MAX
257 long XFILENAME_MAX=FILENAME_MAX;
258 #endif
259 #ifdef SHRT_MAX
260 long XSHRT_MAX=SHRT_MAX;
261 #endif
262 #ifdef INT_MAX
263 long XINT_MAX=INT_MAX;
264 #endif
265 #ifdef LONG_MAX
266 long XLONG_MAX=LONG_MAX;
267 #endif
268 #ifdef LONG_LONG_MAX
269 long XLONG_LONG_MAX=LONG_LONG_MAX;
270 #endif
271 !EOF!
272
273 if ${CPP} dummy.c -DWCHAR=$wchar -DWCTYPE=$wctype >TMP ; then true
274 else
275   echo "gen-params: could not invoke ${CPP} on dummy.c" 1>&2 ; exit 1
276 fi
277 tr '    ' ' ' <TMP >dummy.out
278
279 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 wint_t int16_t uint16_t int32_t uint_32_t u_int16_t u_int32_t; do
280     IMPORTED=`eval 'echo $'"$TYPE"`
281     if [ -n "${IMPORTED}" ] ; then
282         eval "$TYPE='$IMPORTED'"
283     else
284         t=$TYPE
285         VALUE=''
286
287         # Follow `typedef VALUE TYPE' chains, but don't loop indefinitely.
288         for iteration in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
289             # Search dummy.out for a typedef for X*$t.
290             sed_script="
291                 s/unsigned long long/_G_ullong/g
292                 s/long long/_G_llong/g
293                 /.*typedef  *\\(.*[^ ]\\)  *X*$t *;.*/{s||\1|;p;q;}
294                 /.*typedef  *\\(.*[^ a-zA-Z0-9_]\\)X*$t *;.*/{s||\1|;p;q;}
295             "
296             t=`${SED} -n "$sed_script" <dummy.out`
297             case "$t" in
298               '')
299                 break;;
300               *)
301                 # Found a type $t; save it in VALUE.
302                 VALUE=$t
303                 # If it won't cause problems in matching,
304                 # look for a typedef for it in turn.
305                 case "$VALUE" in
306                   *.* | */* | *\ * | *\** | *\[* | *\\*) break;;
307                 esac;;
308             esac
309         done
310
311         case "$VALUE" in
312           ?*) eval "$TYPE=\"$VALUE\""
313         esac
314     fi
315 done
316
317 # Look for some standard macros.
318 for NAME in BUFSIZ FOPEN_MAX FILENAME_MAX NULL; do
319     IMPORTED=`eval 'echo $'"$NAME"`
320     if [ -n "${IMPORTED}" ] ; then
321         eval "$NAME='$IMPORTED /* specified */"
322     else
323         rm -f TMP
324         ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\(.*\);|\1|w TMP" \
325           <dummy.out>/dev/null
326         # Now select the first definition.
327         if [ -s TMP ]; then
328             eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
329         fi
330     fi
331 done
332
333 # These macros must be numerical constants; strip any trailing 'L's.
334 for NAME in SHRT_MAX INT_MAX LONG_MAX LONG_LONG_MAX; do
335     IMPORTED=`eval 'echo $'"$NAME"`
336     if [ -n "${IMPORTED}" ] ; then
337         eval "$NAME='$IMPORTED /* specified */"
338     else
339         rm -f TMP
340         ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\([0-9]*\)L* *;|\1|w TMP" \
341           <dummy.out>/dev/null
342         # Now select the first definition.
343         if [ -s TMP ]; then
344             eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
345         fi
346     fi
347 done
348
349 # Figure out integral type sizes.
350
351 default_int16='short /* deduction failed */'
352 default_int32='long /* deduction failed */'
353 INT16=32767
354 INT32=2147483647
355
356 if [ "${SHRT_MAX}" = $INT16 ] ; then
357   default_int16='short /* deduced */'
358   if [ "${LONG_MAX}" = $INT32 ] ; then
359     default_int32='long /* deduced */'
360   elif [ "${INT_MAX}" = $INT32 ] ; then
361     default_int32='int /* deduced */'
362   fi
363 fi
364
365 [ -n "$u_int16_t" ] && uint16_t="$u_int16_t"
366 [ -n "$u_int32_t" ] && uint32_t="$u_int32_t"
367
368 [ -z  "$int16_t" ] &&  int16_t="$default_int16"
369 [ -z "$uint16_t" ] && uint16_t="unsigned $int16_t"
370 [ -z  "$int32_t" ] &&  int32_t="$default_int32"
371 [ -z "$uint32_t" ] && uint32_t="unsigned $int32_t"
372
373 cat <<!EOF!
374 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
375 typedef          int   ${macro_prefix}int8_t __attribute__((__mode__(__QI__)));
376 typedef unsigned int  ${macro_prefix}uint8_t __attribute__((__mode__(__QI__)));
377 typedef          int  ${macro_prefix}int16_t __attribute__((__mode__(__HI__)));
378 typedef unsigned int ${macro_prefix}uint16_t __attribute__((__mode__(__HI__)));
379 typedef          int  ${macro_prefix}int32_t __attribute__((__mode__(__SI__)));
380 typedef unsigned int ${macro_prefix}uint32_t __attribute__((__mode__(__SI__)));
381 typedef          int  ${macro_prefix}int64_t __attribute__((__mode__(__DI__)));
382 typedef unsigned int ${macro_prefix}uint64_t __attribute__((__mode__(__DI__)));
383 __extension__ typedef long long ${macro_prefix}llong;
384 __extension__ typedef unsigned long long ${macro_prefix}ullong;
385 #else
386 typedef  $int16_t  ${macro_prefix}int16_t;
387 typedef $uint16_t ${macro_prefix}uint16_t;
388 typedef  $int32_t  ${macro_prefix}int32_t;
389 typedef $uint32_t ${macro_prefix}uint32_t;
390 #endif
391
392 typedef ${clock_t-int /* default */} ${macro_prefix}clock_t;
393 typedef ${dev_t-int /* default */} ${macro_prefix}dev_t;
394 typedef ${fpos_t-long /* default */} ${macro_prefix}fpos_t;
395 typedef ${gid_t-int /* default */} ${macro_prefix}gid_t;
396 typedef ${ino_t-int /* default */} ${macro_prefix}ino_t;
397 typedef ${mode_t-int /* default */} ${macro_prefix}mode_t;
398 typedef ${nlink_t-int /* default */} ${macro_prefix}nlink_t;
399 typedef ${off_t-long /* default */} ${macro_prefix}off_t;
400 typedef ${pid_t-int /* default */} ${macro_prefix}pid_t;
401 #ifndef __PTRDIFF_TYPE__
402 #define __PTRDIFF_TYPE__ ${ptrdiff_t-long int /* default */}
403 #endif
404 typedef __PTRDIFF_TYPE__ ${macro_prefix}ptrdiff_t;
405 typedef ${sigset_t-int /* default */} ${macro_prefix}sigset_t;
406 #ifndef __SIZE_TYPE__
407 #define __SIZE_TYPE__ ${size_t-unsigned long /* default */}
408 #endif
409 typedef __SIZE_TYPE__ ${macro_prefix}size_t;
410 typedef ${time_t-int /* default */} ${macro_prefix}time_t;
411 typedef ${uid_t-int /* default */} ${macro_prefix}uid_t;
412 typedef ${wchar_t-int /* default */} ${macro_prefix}wchar_t;
413
414 #define ${macro_prefix}BUFSIZ ${BUFSIZ-1024 /* default */}
415 #define ${macro_prefix}FOPEN_MAX ${FOPEN_MAX-32 /* default */}
416 #define ${macro_prefix}FILENAME_MAX ${FILENAME_MAX-1024 /* default */}
417 #if defined (__cplusplus) || defined (__STDC__)
418 #define ${macro_prefix}ARGS(ARGLIST) ARGLIST
419 #else
420 #define ${macro_prefix}ARGS(ARGLIST) ()
421 #endif
422 #if !defined (__GNUG__) || defined (__STRICT_ANSI__)
423 #define ${macro_prefix}NO_NRV
424 #endif
425 #if !defined (__GNUG__)
426 #define _G_NO_EXTERN_TEMPLATES
427 #endif
428 !EOF!
429
430 # ssize_t is the signed version of size_t
431 if [ -n "${ssize_t}" ] ; then
432     echo "typedef ${ssize_t} ${macro_prefix}ssize_t;"
433 elif [ -z "${size_t}" ] ; then
434     echo "typedef long ${macro_prefix}ssize_t;"
435 else
436     # Remove "unsigned" from ${size_t} to get ${ssize_t}.
437     tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's|  | |g'`"
438     if [ -z "$tmp" ] ; then
439         tmp=int
440     else
441         # check $tmp doesn't conflict with <unistd.h>
442         echo "#include <unistd.h>
443         extern $tmp read();" >dummy.c
444         ${CC} -c dummy.c >/dev/null 2>&1 || tmp=int
445     fi
446     echo "typedef $tmp /* default */ ${macro_prefix}ssize_t;"
447 fi
448
449 # wint_t is often the integral type to which wchar_t promotes.
450 if [ -z "${wint_t}" ] ; then
451   for TYPE in int 'unsigned int' 'long int' 'long unsigned int'; do
452     cat >dummy.C <<!EOF!
453 #ifndef __WCHAR_TYPE__
454 #define __WCHAR_TYPE__ ${wchar_t-int /* default */}
455 #endif
456 typedef __WCHAR_TYPE__ ${macro_prefix}wchar_t;
457 void foo ($TYPE);
458 void foo (double);
459 void bar (${macro_prefix}wchar_t w)
460 {
461   foo (w);
462 }
463 !EOF!
464     if ${CXX} -c dummy.C >/dev/null 2>&1 ; then  
465       wint_t="$TYPE /* default */"
466       break
467     fi
468   done
469 fi
470 echo "typedef ${wint_t-int /* wchar_t is broken */} ${macro_prefix}wint_t;"
471
472 # va_list can cause problems (e.g. some systems have va_list as a struct).
473 # Check to see if ${va_list-char*} really is compatible with stdarg.h.
474 cat >dummy.C <<!EOF!
475 #define X_va_list ${va_list-char* /* default */}
476 extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
477 extern "C" {
478 #include <stdarg.h>
479 }
480 long foo(X_va_list ap) { return va_arg(ap, long); }
481 long bar(int i, ...)
482 { va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
483 !EOF!
484 if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
485   # Ok: We have something that works.
486   echo "typedef ${va_list-char* /* default */} ${macro_prefix}va_list;"
487 else
488   # No, it breaks.  Indicate that <stdarg.h> must be included.
489   echo "#define ${macro_prefix}NEED_STDARG_H
490 #define ${macro_prefix}va_list va_list"
491 fi
492
493 cat >dummy.c <<!EOF!
494 #include <signal.h>
495 extern int (*signal())();
496 extern int dummy (int);
497 main()
498 {
499     int (*oldsig)(int) = signal (1, dummy);
500     (void) signal (2, oldsig);
501     return 0;
502 }
503 !EOF!
504 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
505   echo "#define ${macro_prefix}signal_return_type int"
506 else
507   echo "#define ${macro_prefix}signal_return_type void"
508 fi
509
510 # check sprintf return type
511
512 cat >dummy.c <<!EOF!
513 #include <stdio.h>
514 extern int sprintf(); char buf[100];
515 int main() { return sprintf(buf, "%d", 34); }
516 !EOF!
517 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
518   echo "#define ${macro_prefix}sprintf_return_type int"
519 else
520   echo "#define ${macro_prefix}sprintf_return_type char*"
521 fi
522
523 if test -n "${HAVE_ATEXIT}" ; then
524  echo "#define ${macro_prefix}HAVE_ATEXIT ${HAVE_ATEXIT}"
525 else
526   cat >dummy.c <<!EOF!
527 #include <stdlib.h>
528 int main()
529 {
530   atexit (0);
531 }
532 !EOF!
533   if ${CC} dummy.c >/dev/null 2>&1 ; then
534     echo "#define ${macro_prefix}HAVE_ATEXIT 1"
535   else
536     echo "#define ${macro_prefix}HAVE_ATEXIT 0"
537   fi
538 fi
539
540
541 # *** Check for presence of certain include files ***
542
543 # check for sys/resource.h
544
545 if test -n "${HAVE_SYS_RESOURCE}" ; then
546  echo "#define ${macro_prefix}HAVE_SYS_RESOURCE ${HAVE_SYS_RESOURCE}"
547 else
548   cat >dummy.c <<!EOF!
549 #include <sys/types.h>
550 #include <sys/time.h>
551 #include <sys/resource.h>
552   int main()
553   {
554     struct rusage res;
555     getrusage(RUSAGE_SELF, &res);
556     return (int)(res.ru_utime.tv_sec + (res.ru_utime.tv_usec / 1000000.0));
557   }
558 !EOF!
559   # Note: We link because some systems have sys/resource, but not getrusage().
560   if ${CC} dummy.c >/dev/null 2>&1 ; then
561     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 1"
562   else
563     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 0"
564   fi
565 fi
566
567 # check for struct tms in sys/times.h
568
569 if test -n "${HAVE_SYS_TIMES}" ; then
570  echo "#define ${macro_prefix}HAVE_SYS_TIMES ${HAVE_SYS_TIMES}"
571 else
572  cat >dummy.c <<!EOF!
573 #include <sys/types.h>
574 #include <sys/times.h>
575   int main()
576   {
577     struct tms s;
578     return s.tms_utime;
579   }
580 !EOF!
581   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
582     echo "#define ${macro_prefix}HAVE_SYS_TIMES 1"
583   else
584     echo "#define ${macro_prefix}HAVE_SYS_TIMES 0"
585   fi
586 fi
587
588 # check for sys/socket.h
589
590 if test -n "${HAVE_SYS_SOCKET}" ; then
591  echo "#define ${macro_prefix}HAVE_SYS_SOCKET ${HAVE_SYS_SOCKET}"
592 else
593   echo '#include <sys/types.h>' >dummy.c
594   echo '#include <sys/socket.h>' >>dummy.c
595   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
596     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 1"
597   else
598     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 0"
599   fi
600 fi
601
602 # check for sys/cdefs.h
603
604 if test -n "${HAVE_SYS_CDEFS}" ; then
605  echo "#define ${macro_prefix}HAVE_SYS_CDEFS ${HAVE_SYS_CDEFS}"
606 else
607   echo '#include <sys/cdefs.h>' >dummy.c
608   echo 'extern int myfunc __P((int, int));' >>dummy.c
609   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
610     echo "#define ${macro_prefix}HAVE_SYS_CDEFS 1"
611   else
612     echo "#define ${macro_prefix}HAVE_SYS_CDEFS 0"
613   fi
614 fi
615
616 # Check for a (Posix-compatible) sys/wait.h */
617
618 if test -n "${HAVE_SYS_WAIT}" ; then
619  echo "#define ${macro_prefix}HAVE_SYS_WAIT ${HAVE_SYS_WAIT}"
620 else
621   cat >dummy.c <<!EOF!
622 #include <sys/types.h>
623 #include <sys/wait.h>
624   int f() { int i; wait(&i); return i; }
625 !EOF!
626   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
627     echo "#define ${macro_prefix}HAVE_SYS_WAIT 1"
628   else
629     echo "#define ${macro_prefix}HAVE_SYS_WAIT 0"
630   fi
631 fi
632
633 if test -n "${HAVE_UNISTD}" ; then
634  echo "#define ${macro_prefix}HAVE_UNISTD ${HAVE_UNISTD}"
635 else
636   echo '#include <unistd.h>' >dummy.c
637   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
638     echo "#define ${macro_prefix}HAVE_UNISTD 1"
639   else
640     echo "#define ${macro_prefix}HAVE_UNISTD 0"
641   fi
642 fi
643
644 if test -n "${HAVE_DIRENT}" ; then
645  echo "#define ${macro_prefix}HAVE_DIRENT ${HAVE_DIRENT}"
646 else
647   echo '#include <sys/types.h>
648 #include <dirent.h>' >dummy.c
649   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
650     echo "#define ${macro_prefix}HAVE_DIRENT 1"
651   else
652     echo "#define ${macro_prefix}HAVE_DIRENT 0"
653   fi
654 fi
655
656 if test -n "${HAVE_CURSES}" ; then
657  echo "#define ${macro_prefix}HAVE_CURSES ${HAVE_CURSES}"
658 else
659   echo '#include <curses.h>' >dummy.c
660   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
661     echo "#define ${macro_prefix}HAVE_CURSES 1"
662   else
663     echo "#define ${macro_prefix}HAVE_CURSES 0"
664   fi
665 fi
666
667 # There is no test for this at the moment; it is just set by the
668 # configuration files.
669 if test -n "${MATH_H_INLINES}" ; then
670   echo "#define ${macro_prefix}MATH_H_INLINES ${MATH_H_INLINES}"
671 else
672   echo "#define ${macro_prefix}MATH_H_INLINES 0"
673 fi
674
675 if test -n "${HAVE_BOOL}" ; then
676  echo "#define ${macro_prefix}HAVE_BOOL ${HAVE_BOOL}"
677 else
678   echo 'bool i=true,j=false;' >dummy.C
679   if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
680     echo "#define ${macro_prefix}HAVE_BOOL 1"
681   else
682     echo "#define ${macro_prefix}HAVE_BOOL 0"
683   fi
684 fi
685
686 if test -n "${NO_USE_DTOA}" ; then
687     echo "#define ${macro_prefix}NO_USE_DTOA 1"
688 fi
689 if test -n "${USE_INT32_FLAGS}" ; then
690     echo "#define ${macro_prefix}USE_INT32_FLAGS 1"
691 fi
692
693 # Uncomment the following line if you don't have working templates.
694 # echo "#define ${macro_prefix}NO_TEMPLATES"
695
696 rm -f dummy.C dummy.o dummy.c dummy.out TMP core a.out
697
698 echo "#endif /* !${macro_prefix}config_h */"