OSDN Git Service

* Makefile.in (pexecute.o): Use pexecute.c from libiberty. Provide
[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     eval IMPORTED=\$$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 int/_G_ullong/g
292                 s/long long int/_G_llong/g
293                 s/unsigned long long/_G_ullong/g
294                 s/long long/_G_llong/g
295                 /.*typedef  *\\(.*[^ ]\\)  *X*$t *;.*/{s||\1|;p;q;}
296                 /.*typedef  *\\(.*[^ a-zA-Z0-9_]\\)X*$t *;.*/{s||\1|;p;q;}
297             "
298             t=`${SED} -n "$sed_script" <dummy.out`
299             case "$t" in
300               '')
301                 break;;
302               *)
303                 # Found a type $t; save it in VALUE.
304                 VALUE=$t
305                 # If it won't cause problems in matching,
306                 # look for a typedef for it in turn.
307                 case "$VALUE" in
308                   *.* | */* | *\ * | *\** | *\[* | *\\*) break;;
309                 esac;;
310             esac
311         done
312
313         case "$VALUE" in
314           ?*) eval "$TYPE=\"$VALUE\""
315         esac
316     fi
317 done
318
319 # Look for some standard macros.
320 for NAME in BUFSIZ FOPEN_MAX FILENAME_MAX NULL; do
321     eval IMPORTED=\$$NAME
322     if [ -n "${IMPORTED}" ] ; then
323         eval "$NAME='$IMPORTED /* specified */'"
324     else
325         rm -f TMP
326         ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\(.*\);|\1|w TMP" \
327           <dummy.out>/dev/null
328         # Now select the first definition.
329         if [ -s TMP ]; then
330             eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
331         fi
332     fi
333 done
334
335 # These macros must be numerical constants; strip any trailing 'L's.
336 for NAME in SHRT_MAX INT_MAX LONG_MAX LONG_LONG_MAX; do
337     eval IMPORTED=\$$NAME
338     if [ -n "${IMPORTED}" ] ; then
339         eval "$NAME='$IMPORTED /* specified */'"
340     else
341         rm -f TMP
342         ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\([0-9]*\)L* *;|\1|w TMP" \
343           <dummy.out>/dev/null
344         # Now select the first definition.
345         if [ -s TMP ]; then
346             eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
347         fi
348     fi
349 done
350
351 # Figure out integral type sizes.
352
353 default_int16='short /* deduction failed */'
354 default_int32='long /* deduction failed */'
355 INT16=32767
356 INT32=2147483647
357
358 if [ "${SHRT_MAX}" = $INT16 ] ; then
359   default_int16='short /* deduced */'
360   if [ "${LONG_MAX}" = $INT32 ] ; then
361     default_int32='long /* deduced */'
362   elif [ "${INT_MAX}" = $INT32 ] ; then
363     default_int32='int /* deduced */'
364   fi
365 fi
366
367 [ -n "$u_int16_t" ] && uint16_t="$u_int16_t"
368 [ -n "$u_int32_t" ] && uint32_t="$u_int32_t"
369
370 [ -z  "$int16_t" ] &&  int16_t="$default_int16"
371 [ -z "$uint16_t" ] && uint16_t="unsigned $int16_t"
372 [ -z  "$int32_t" ] &&  int32_t="$default_int32"
373 [ -z "$uint32_t" ] && uint32_t="unsigned $int32_t"
374
375 cat <<!EOF!
376 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
377 typedef          int   ${macro_prefix}int8_t __attribute__((__mode__(__QI__)));
378 typedef unsigned int  ${macro_prefix}uint8_t __attribute__((__mode__(__QI__)));
379 typedef          int  ${macro_prefix}int16_t __attribute__((__mode__(__HI__)));
380 typedef unsigned int ${macro_prefix}uint16_t __attribute__((__mode__(__HI__)));
381 typedef          int  ${macro_prefix}int32_t __attribute__((__mode__(__SI__)));
382 typedef unsigned int ${macro_prefix}uint32_t __attribute__((__mode__(__SI__)));
383 typedef          int  ${macro_prefix}int64_t __attribute__((__mode__(__DI__)));
384 typedef unsigned int ${macro_prefix}uint64_t __attribute__((__mode__(__DI__)));
385 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 8
386 __extension__ typedef long long ${macro_prefix}llong;
387 __extension__ typedef unsigned long long ${macro_prefix}ullong;
388 #endif
389 #else
390 typedef  $int16_t  ${macro_prefix}int16_t;
391 typedef $uint16_t ${macro_prefix}uint16_t;
392 typedef  $int32_t  ${macro_prefix}int32_t;
393 typedef $uint32_t ${macro_prefix}uint32_t;
394 #endif
395
396 typedef ${clock_t-int /* default */} ${macro_prefix}clock_t;
397 typedef ${dev_t-int /* default */} ${macro_prefix}dev_t;
398 typedef ${fpos_t-long /* default */} ${macro_prefix}fpos_t;
399 typedef ${gid_t-int /* default */} ${macro_prefix}gid_t;
400 typedef ${ino_t-int /* default */} ${macro_prefix}ino_t;
401 typedef ${mode_t-int /* default */} ${macro_prefix}mode_t;
402 typedef ${nlink_t-int /* default */} ${macro_prefix}nlink_t;
403 typedef ${off_t-long /* default */} ${macro_prefix}off_t;
404 typedef ${pid_t-int /* default */} ${macro_prefix}pid_t;
405 #ifndef __PTRDIFF_TYPE__
406 #define __PTRDIFF_TYPE__ ${ptrdiff_t-long int /* default */}
407 #endif
408 typedef __PTRDIFF_TYPE__ ${macro_prefix}ptrdiff_t;
409 typedef ${sigset_t-int /* default */} ${macro_prefix}sigset_t;
410 #ifndef __SIZE_TYPE__
411 #define __SIZE_TYPE__ ${size_t-unsigned long /* default */}
412 #endif
413 typedef __SIZE_TYPE__ ${macro_prefix}size_t;
414 typedef ${time_t-int /* default */} ${macro_prefix}time_t;
415 typedef ${uid_t-int /* default */} ${macro_prefix}uid_t;
416 typedef ${wchar_t-int /* default */} ${macro_prefix}wchar_t;
417
418 #define ${macro_prefix}BUFSIZ ${BUFSIZ-1024 /* default */}
419 #define ${macro_prefix}FOPEN_MAX ${FOPEN_MAX-32 /* default */}
420 #define ${macro_prefix}FILENAME_MAX ${FILENAME_MAX-1024 /* default */}
421 #if defined (__cplusplus) || defined (__STDC__)
422 #define ${macro_prefix}ARGS(ARGLIST) ARGLIST
423 #else
424 #define ${macro_prefix}ARGS(ARGLIST) ()
425 #endif
426 #if !defined (__GNUG__) || defined (__STRICT_ANSI__)
427 #define ${macro_prefix}NO_NRV
428 #endif
429 #if !defined (__GNUG__)
430 #define _G_NO_EXTERN_TEMPLATES
431 #endif
432 !EOF!
433
434 # ssize_t is the signed version of size_t
435 if [ -n "${ssize_t}" ] ; then
436     echo "typedef ${ssize_t} ${macro_prefix}ssize_t;"
437 elif [ -z "${size_t}" ] ; then
438     echo "typedef long ${macro_prefix}ssize_t;"
439 else
440     # Remove "unsigned" from ${size_t} to get ${ssize_t}.
441     tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's|  | |g'`"
442     if [ -z "$tmp" ] ; then
443         tmp=int
444     else
445         # check $tmp doesn't conflict with <unistd.h>
446         echo "#include <unistd.h>
447         extern $tmp read();" >dummy.c
448         ${CC} -c dummy.c >/dev/null 2>&1 || tmp=int
449     fi
450     echo "typedef $tmp /* default */ ${macro_prefix}ssize_t;"
451 fi
452
453 # wint_t is often the integral type to which wchar_t promotes.
454 if [ -z "${wint_t}" ] ; then
455   for TYPE in int 'unsigned int' 'long int' 'long unsigned int'; do
456     cat >dummy.C <<!EOF!
457 #ifndef __WCHAR_TYPE__
458 #define __WCHAR_TYPE__ ${wchar_t-int /* default */}
459 #endif
460 typedef __WCHAR_TYPE__ ${macro_prefix}wchar_t;
461 void foo ($TYPE);
462 void foo (double);
463 void bar (${macro_prefix}wchar_t w)
464 {
465   foo (w);
466 }
467 !EOF!
468     if ${CXX} -c dummy.C >/dev/null 2>&1 ; then  
469       wint_t="$TYPE /* default */"
470       break
471     fi
472   done
473 fi
474 echo "typedef ${wint_t-int /* wchar_t is broken */} ${macro_prefix}wint_t;"
475
476 # va_list can cause problems (e.g. some systems have va_list as a struct).
477 # Check to see if ${va_list-char*} really is compatible with stdarg.h.
478 cat >dummy.C <<!EOF!
479 #define X_va_list ${va_list-char* /* default */}
480 extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
481 extern "C" {
482 #include <stdarg.h>
483 }
484 long foo(X_va_list ap) { return va_arg(ap, long); }
485 long bar(int i, ...)
486 { va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
487 !EOF!
488 if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
489   # Ok: We have something that works.
490   echo "typedef ${va_list-char* /* default */} ${macro_prefix}va_list;"
491 else
492   echo "#define ${macro_prefix}NEED_STDARG_H"
493   # Check and see if we have __gnuc_va_list, as we might set up define
494   # loops if we use va_list.
495   cat >dummy.C <<!EOF!
496 #include <stdarg.h>
497 long foo(__gnuc_va_list ap) { return va_arg(ap, long); }
498 !EOF!
499   if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
500     echo "#define ${macro_prefix}va_list __gnuc_va_list"
501   else
502     echo "#define ${macro_prefix}va_list va_list"
503   fi
504 fi
505
506 cat >dummy.c <<!EOF!
507 #include <signal.h>
508 extern int (*signal())();
509 extern int dummy (int);
510 main()
511 {
512     int (*oldsig)(int) = signal (1, dummy);
513     (void) signal (2, oldsig);
514     return 0;
515 }
516 !EOF!
517 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
518   echo "#define ${macro_prefix}signal_return_type int"
519 else
520   echo "#define ${macro_prefix}signal_return_type void"
521 fi
522
523 # check sprintf return type
524
525 cat >dummy.c <<!EOF!
526 #include <stdio.h>
527 extern int sprintf(); char buf[100];
528 int main() { return sprintf(buf, "%d", 34); }
529 !EOF!
530 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
531   echo "#define ${macro_prefix}sprintf_return_type int"
532 else
533   echo "#define ${macro_prefix}sprintf_return_type char*"
534 fi
535
536 if test -n "${HAVE_ATEXIT}" ; then
537  echo "#define ${macro_prefix}HAVE_ATEXIT ${HAVE_ATEXIT}"
538 else
539   cat >dummy.c <<!EOF!
540 #include <stdlib.h>
541 int main()
542 {
543   atexit (0);
544 }
545 !EOF!
546   if ${CC} dummy.c >/dev/null 2>&1 ; then
547     echo "#define ${macro_prefix}HAVE_ATEXIT 1"
548   else
549     echo "#define ${macro_prefix}HAVE_ATEXIT 0"
550   fi
551 fi
552
553
554 # *** Check for presence of certain include files ***
555
556 # check for sys/resource.h
557
558 if test -n "${HAVE_SYS_RESOURCE}" ; then
559  echo "#define ${macro_prefix}HAVE_SYS_RESOURCE ${HAVE_SYS_RESOURCE}"
560 else
561   cat >dummy.c <<!EOF!
562 #include <sys/types.h>
563 #include <sys/time.h>
564 #include <sys/resource.h>
565   int main()
566   {
567     struct rusage res;
568     getrusage(RUSAGE_SELF, &res);
569     return (int)(res.ru_utime.tv_sec + (res.ru_utime.tv_usec / 1000000.0));
570   }
571 !EOF!
572   # Note: We link because some systems have sys/resource, but not getrusage().
573   if ${CC} dummy.c >/dev/null 2>&1 ; then
574     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 1"
575   else
576     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 0"
577   fi
578 fi
579
580 # check for struct tms in sys/times.h
581
582 if test -n "${HAVE_SYS_TIMES}" ; then
583  echo "#define ${macro_prefix}HAVE_SYS_TIMES ${HAVE_SYS_TIMES}"
584 else
585  cat >dummy.c <<!EOF!
586 #include <sys/types.h>
587 #include <sys/times.h>
588   int main()
589   {
590     struct tms s;
591     return s.tms_utime;
592   }
593 !EOF!
594   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
595     echo "#define ${macro_prefix}HAVE_SYS_TIMES 1"
596   else
597     echo "#define ${macro_prefix}HAVE_SYS_TIMES 0"
598   fi
599 fi
600
601 # check for sys/socket.h
602
603 if test -n "${HAVE_SYS_SOCKET}" ; then
604  echo "#define ${macro_prefix}HAVE_SYS_SOCKET ${HAVE_SYS_SOCKET}"
605 else
606   echo '#include <sys/types.h>' >dummy.c
607   echo '#include <sys/socket.h>' >>dummy.c
608   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
609     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 1"
610   else
611     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 0"
612   fi
613 fi
614
615 # check for sys/cdefs.h
616
617 if test -n "${HAVE_SYS_CDEFS}" ; then
618  echo "#define ${macro_prefix}HAVE_SYS_CDEFS ${HAVE_SYS_CDEFS}"
619 else
620   echo '#include <sys/cdefs.h>' >dummy.c
621   echo 'extern int myfunc __P((int, int));' >>dummy.c
622   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
623     echo "#define ${macro_prefix}HAVE_SYS_CDEFS 1"
624   else
625     echo "#define ${macro_prefix}HAVE_SYS_CDEFS 0"
626   fi
627 fi
628
629 # Check for a (Posix-compatible) sys/wait.h */
630
631 if test -n "${HAVE_SYS_WAIT}" ; then
632  echo "#define ${macro_prefix}HAVE_SYS_WAIT ${HAVE_SYS_WAIT}"
633 else
634   cat >dummy.c <<!EOF!
635 #include <sys/types.h>
636 #include <sys/wait.h>
637   int f() { int i; wait(&i); return i; }
638 !EOF!
639   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
640     echo "#define ${macro_prefix}HAVE_SYS_WAIT 1"
641   else
642     echo "#define ${macro_prefix}HAVE_SYS_WAIT 0"
643   fi
644 fi
645
646 if test -n "${HAVE_UNISTD}" ; then
647  echo "#define ${macro_prefix}HAVE_UNISTD ${HAVE_UNISTD}"
648 else
649   echo '#include <unistd.h>' >dummy.c
650   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
651     echo "#define ${macro_prefix}HAVE_UNISTD 1"
652   else
653     echo "#define ${macro_prefix}HAVE_UNISTD 0"
654   fi
655 fi
656
657 if test -n "${HAVE_DIRENT}" ; then
658  echo "#define ${macro_prefix}HAVE_DIRENT ${HAVE_DIRENT}"
659 else
660   echo '#include <sys/types.h>
661 #include <dirent.h>' >dummy.c
662   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
663     echo "#define ${macro_prefix}HAVE_DIRENT 1"
664   else
665     echo "#define ${macro_prefix}HAVE_DIRENT 0"
666   fi
667 fi
668
669 if test -n "${HAVE_CURSES}" ; then
670  echo "#define ${macro_prefix}HAVE_CURSES ${HAVE_CURSES}"
671 else
672   echo '#include <curses.h>' >dummy.c
673   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
674     echo "#define ${macro_prefix}HAVE_CURSES 1"
675   else
676     echo "#define ${macro_prefix}HAVE_CURSES 0"
677   fi
678 fi
679
680 # There is no test for this at the moment; it is just set by the
681 # configuration files.
682 if test -n "${MATH_H_INLINES}" ; then
683   echo "#define ${macro_prefix}MATH_H_INLINES ${MATH_H_INLINES}"
684 else
685   echo "#define ${macro_prefix}MATH_H_INLINES 0"
686 fi
687
688 if test -n "${HAVE_BOOL}" ; then
689  echo "#define ${macro_prefix}HAVE_BOOL ${HAVE_BOOL}"
690 else
691   echo 'bool i=true,j=false;' >dummy.C
692   if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
693     echo "#define ${macro_prefix}HAVE_BOOL 1"
694   else
695     echo "#define ${macro_prefix}HAVE_BOOL 0"
696   fi
697 fi
698
699 if test -n "${NO_USE_DTOA}" ; then
700     echo "#define ${macro_prefix}NO_USE_DTOA 1"
701 fi
702 if test -n "${USE_INT32_FLAGS}" ; then
703     echo "#define ${macro_prefix}USE_INT32_FLAGS 1"
704 fi
705
706 # A little test program to check if __printf_fp is available.
707 cat >dummy.c <<EOF
708 int main()
709 {
710     return __printf_fp ();
711 }
712 EOF
713
714 if ${CC} dummy.c >/dev/null 2>&1 ; then
715   echo "#define ${macro_prefix}HAVE_PRINTF_FP 1"
716   echo "#define ${macro_prefix}HAVE_LONG_DOUBLE_IO 1"
717 else
718   echo "#define ${macro_prefix}HAVE_PRINTF_FP 0"
719   echo "#define ${macro_prefix}HAVE_LONG_DOUBLE_IO 0"
720 fi
721
722 # Uncomment the following line if you don't have working templates.
723 # echo "#define ${macro_prefix}NO_TEMPLATES"
724
725 # Override bogus definitions of NULL in system headers.
726 cat <<EOF
727 #undef NULL
728 #define __need_NULL
729 #include <stddef.h>
730 EOF
731
732 rm -f dummy.C dummy.o dummy.c dummy.out TMP core a.out
733
734 echo "#endif /* !${macro_prefix}config_h */"