* builtins.def (BUILT_IN_LABS, BUILT_IN_LLABS, BUILT_IN_IMAXABS):
[official-gcc.git] / libio / gen-params
blobd83c31b609923e0c4b2cf87c75473a3f4e54d78f
1 #!/bin/sh
2 # Copyright (C) 1992, 1993, 1994, 1997, 1998, 1999, 2000 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.
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.
19 # Written by Per Bothner (bothner@cygnus.com)
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.
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.
36 # Uncomment following line for debugging
37 # set -x
39 SED=sed
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
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`}
62 cat <<!EOF!
63 /* AUTOMATICALLY GENERATED; DO NOT EDIT! */
64 #ifndef ${macro_prefix}config_h
65 #define ${macro_prefix}config_h
66 !EOF!
68 if [ x"${LIB_VERSION}" != "x" ] ; then
69 echo "#define ${macro_prefix}LIB_VERSION" '"'${LIB_VERSION}'"'
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.
75 if test -z "${NAMES_HAVE_UNDERSCORE}" \
76 || test -z "${DOLLAR_IN_LABEL}" \
77 || test -z "${VTABLE_LABEL_PREFIX}"; then
78 cat >dummy.h <<!EOF!
79 #ifdef __GNUG__
80 #pragma interface
81 #endif
82 struct filebuf {
83 virtual int foo();
85 !EOF!
86 cat >dummy.C <<!EOF!
87 #ifdef __GNUG__
88 #pragma implementation
89 #endif
90 #include "dummy.h"
91 int filebuf::foo() { return 0; }
92 extern "C" int FUNC(int);
93 int FUNC(int i) { return i+10; }
94 !EOF!
96 if ${CXX} -O -c dummy.C ; then
97 if test -z "${NAMES_HAVE_UNDERSCORE}" ; then
98 if test "`${CONFIG_NM} dummy.o | grep _FUNC`" != ""; then
99 NAMES_HAVE_UNDERSCORE=1
100 elif test "`${CONFIG_NM} dummy.o | grep FUNC`" != ""; then
101 NAMES_HAVE_UNDERSCORE=0
102 else
103 echo "${CONFIG_NM} failed to find FUNC in dummy.o!" 1>&2; exit -1;
106 echo "#define ${macro_prefix}NAMES_HAVE_UNDERSCORE ${NAMES_HAVE_UNDERSCORE}"
108 if test -z "${VTABLE_LABEL_PREFIX}" ; then
109 # Determine how virtual function tables are named. This is fragile,
110 # because different nm's produce output in different formats.
111 ${CONFIG_NM} dummy.o >TMP
112 if [ -n "`${SED} -n -e 's/ virtual table/nope/p' <TMP`" ] ; then
113 ${CONFIG_NM} --no-cplus dummy.o >TMP 2>/dev/null ||
114 ${CONFIG_NM} --no-demangle dummy.o >TMP 2>/dev/null ||
115 ${CONFIG_NM} dummy.o >TMP 2>/dev/null
117 # First we look for a pattern that matches historical output from g++.
118 # We surround the actual label name by <> to separate it from
119 # other nm junk.
120 ${SED} -n -e 's/_*vt[$_.]7*filebuf/<&>/p' <TMP >dummy.out
121 # For paranoia's sake (e.g. if we're using some other C++ compiler)
122 # we try a more general pattern, and append the result.
123 grep -v foo <TMP \
124 | ${SED} -n -e 's/[a-zA-Z0-9_.$]*filebuf[a-zA-Z0-9_.$]*/<&>/p' \
125 >>dummy.out
126 # Now we get rid of the <>, and any other junk on the nm output line.
127 # (We get rid of <filebuf> in case nm included debugging output for
128 # class filebuf itself.) On windows32, we also need to delete the
129 # unique sections (.data$_vt$*), otherwise we get the wrong result.
130 # Finally, we select the first line of the result, and hope that's
131 # what we wanted!
132 vtab_name=`${SED} -n -e '/<filebuf>/d' \
133 -e '/\.data[$_.]<_vt\$7filebuf>/d' \
134 -e 's/^.*<\(.*\)>.*$/\1/p' \
135 <dummy.out | ${SED} -n -e '1p'`
136 case "${vtab_name}" in
137 *7filebuf) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 1" ;;
138 *) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 0" ;;
139 esac
140 VTABLE_LABEL_PREFIX=`echo $vtab_name | ${SED} -e 's/7*filebuf//'`
142 echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX" '"'"${VTABLE_LABEL_PREFIX}"'"'
143 if [ "${VTABLE_LABEL_PREFIX}" = "__vt_" -o \
144 "${VTABLE_LABEL_PREFIX}" = "___vt_" ] ; then
145 echo "#define ${macro_prefix}USING_THUNKS"
148 # VTABLE_LABEL_PREFIX_ID is the same as VTABLE_LABEL_PREFIX,
149 # but the former is a C identifier, while the latter is a quoted
150 # st
151 if [ -z ""`echo ${VTABLE_LABEL_PREFIX} | ${SED} -e 's/[a-zA-Z0-9_]//g'` ] ; then
152 if [ "${NAMES_HAVE_UNDERSCORE}" = "1" ] ; then
153 VTABLE_LABEL_PREFIX=`echo ${VTABLE_LABEL_PREFIX} | ${SED} -e 's/^_//'`
155 echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX_ID ${VTABLE_LABEL_PREFIX}"
158 # if test -n "${DOLLAR_IN_LABEL}" ; then
159 # echo "#define ${macro_prefix}DOLLAR_IN_LABEL ${DOLLAR_IN_LABEL}"
160 # elif test "`${CONFIG_NM} dummy.o | grep 'vt[$$]7filebuf'`" != ""; then
161 # echo "#define ${macro_prefix}DOLLAR_IN_LABEL 1"
162 # elif test "`${CONFIG_NM} dummy.o | grep 'vt[.]7filebuf'`" != ""; then
163 # echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
164 # elif test "`${CONFIG_NM} dummy.o | grep 'vtbl__7filebuf'`" != ""; then
165 # echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
166 # else
167 # echo "gen-params: ${CONFIG_NM} failed to find vt[.\$]filebuf in dummy.o!" 1>&2; exit 1
168 # fi
169 else
170 # The compile failed for some reason (no C++?)
171 echo "gen-params: could not compile dummy.C with ${CXX}" 1>&2; exit 1;
175 # A little test program to check if struct stat has st_blksize.
176 cat >dummy.c <<!EOF!
177 #include <sys/types.h>
178 #include <sys/stat.h>
179 int BLKSIZE(struct stat *st)
181 return st->st_blksize;
183 !EOF!
185 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
186 echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 1"
187 else
188 echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 0"
191 # A little test program to check if there is an O_APPEND.
192 cat >dummy.c <<!EOF!
193 #include <sys/types.h>
194 #include <sys/stat.h>
195 #include <fcntl.h>
196 int foo()
198 return O_APPEND;
200 !EOF!
202 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
204 else
205 echo "#define O_APPEND 0"
208 # A little test program to check if there is an O_EXCL.
209 cat >dummy.c <<!EOF!
210 #include <sys/types.h>
211 #include <sys/stat.h>
212 #include <fcntl.h>
213 int foo()
215 return O_EXCL;
217 !EOF!
219 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
221 else
222 echo "#define O_EXCL 0"
225 # A little test program to check if the name 'clog' is defined in libm,
226 # as it is under DEC UNIX.
227 cat >dummy.c <<!EOF!
228 int clog;
229 main () {}
230 !EOF!
232 if ${CC} dummy.c -lm 2>&1 >/dev/null | grep clog >/dev/null; then
233 echo "#define ${macro_prefix}CLOG_CONFLICT 1"
236 echo ""
238 # Next, generate definitions for the standard types (such as mode_t)
239 # compatible with those in the standard C header files.
240 # It works by a dummy program through the C pre-processor, and then
241 # using sed to search for typedefs in the output.
243 for hdr in wchar wctype; do
244 eval $hdr=0
245 cat >dummy.c <<EOF
246 #include <${hdr}.h>
248 if ${CPP} dummy.c >/dev/null 2>&1 ; then eval $hdr=1; fi
249 done
251 cat >dummy.c <<!EOF!
252 #include <sys/types.h>
253 #include <stddef.h>
254 #ifdef __STDC__
255 #include <stdarg.h>
256 #else /* !__STDC__ */
257 #include <varargs.h>
258 #endif /* __STDC__ */
259 #include <stdio.h>
260 #include <time.h>
261 #include <signal.h>
262 #ifdef __STDC__
263 #include <limits.h>
264 #endif
265 #if WCHAR == 1
266 #include <wchar.h>
267 #endif
268 #if WCTYPE == 1
269 #include <wctype.h>
270 #endif
271 #ifdef size_t
272 typedef size_t Xsize_t;
273 #elif defined(__SIZE_TYPE__)
274 typedef __SIZE_TYPE__ Xsize_t;
275 #endif
276 #ifdef ptrdiff_t
277 typedef ptrdiff_t Xptrdiff_t;
278 #elif defined(__PTRDIFF_TYPE__)
279 typedef __PTRDIFF_TYPE__ Xptrdiff_t;
280 #endif
281 #ifdef wchar_t
282 typedef wchar_t Xwchar_t;
283 #elif defined(__WCHAR_TYPE__)
284 typedef __WCHAR_TYPE__ Xwchar_t;
285 #endif
286 #ifdef va_list
287 typedef va_list XXXva_list;
288 #endif
289 #ifdef BUFSIZ
290 long XBUFSIZ=BUFSIZ;
291 #endif
292 #ifdef FOPEN_MAX
293 long XFOPEN_MAX=FOPEN_MAX;
294 #endif
295 #ifdef FILENAME_MAX
296 long XFILENAME_MAX=FILENAME_MAX;
297 #endif
298 #ifdef SHRT_MAX
299 long XSHRT_MAX=SHRT_MAX;
300 #endif
301 #ifdef INT_MAX
302 long XINT_MAX=INT_MAX;
303 #endif
304 #ifdef LONG_MAX
305 long XLONG_MAX=LONG_MAX;
306 #endif
307 #ifdef LONG_LONG_MAX
308 long XLONG_LONG_MAX=LONG_LONG_MAX;
309 #endif
310 !EOF!
312 if ${CPP} dummy.c -DWCHAR=$wchar -DWCTYPE=$wctype >TMP ; then true
313 else
314 echo "gen-params: could not invoke ${CPP} on dummy.c" 1>&2 ; exit 1
316 tr ' ' ' ' <TMP >dummy.out
318 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
319 eval IMPORTED=\$$TYPE
320 if [ -n "${IMPORTED}" ] ; then
321 eval "$TYPE='$IMPORTED'"
322 else
323 t=$TYPE
324 VALUE=''
326 # Follow `typedef VALUE TYPE' chains, but don't loop indefinitely.
327 for iteration in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
328 # Search dummy.out for a typedef for X*$t.
329 sed_script="
330 s/unsigned long long int/_G_ullong/g
331 s/long long int /_G_llong /g
332 s/unsigned long long/_G_ullong/g
333 s/long long/_G_llong/g
334 /.*typedef *\\(.*[^ ]\\) *X*$t *;.*/{s||\1|;p;q;}
335 /.*typedef *\\(.*[^ a-zA-Z0-9_]\\)X*$t *;.*/{s||\1|;p;q;}
337 t=`${SED} -n "$sed_script" <dummy.out`
338 case "$t" in
340 break;;
342 # Found a type $t; save it in VALUE.
343 VALUE=$t
344 # If it won't cause problems in matching,
345 # look for a typedef for it in turn.
346 case "$VALUE" in
347 *.* | */* | *\ * | *\** | *\[* | *\\*) break;;
348 esac;;
349 esac
350 done
352 case "$VALUE" in
353 ?*) eval "$TYPE=\"$VALUE\""
354 esac
356 done
358 # Look for some standard macros.
359 for NAME in BUFSIZ FOPEN_MAX FILENAME_MAX NULL; do
360 eval IMPORTED=\$$NAME
361 if [ -n "${IMPORTED}" ] ; then
362 eval "$NAME='$IMPORTED /* specified */'"
363 else
364 rm -f TMP
365 ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\(.*\);|\1|w TMP" \
366 <dummy.out>/dev/null
367 # Now select the first definition.
368 if [ -s TMP ]; then
369 eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
372 done
374 # These macros must be numerical constants; strip any trailing 'L's.
375 for NAME in SHRT_MAX INT_MAX LONG_MAX LONG_LONG_MAX; do
376 eval IMPORTED=\$$NAME
377 if [ -n "${IMPORTED}" ] ; then
378 eval "$NAME='$IMPORTED /* specified */'"
379 else
380 rm -f TMP
381 ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\([0-9]*\)L* *;|\1|w TMP" \
382 <dummy.out>/dev/null
383 # Now select the first definition.
384 if [ -s TMP ]; then
385 eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
388 done
390 # Figure out integral type sizes.
392 default_int16='short /* deduction failed */'
393 default_int32='long /* deduction failed */'
394 INT16=32767
395 INT32=2147483647
397 if [ "${SHRT_MAX}" = $INT16 ] ; then
398 default_int16='short /* deduced */'
399 if [ "${LONG_MAX}" = $INT32 ] ; then
400 default_int32='long /* deduced */'
401 elif [ "${INT_MAX}" = $INT32 ] ; then
402 default_int32='int /* deduced */'
406 [ -n "$u_int16_t" ] && uint16_t="$u_int16_t"
407 [ -n "$u_int32_t" ] && uint32_t="$u_int32_t"
409 [ -z "$int16_t" ] && int16_t="$default_int16"
410 [ -z "$uint16_t" ] && uint16_t="unsigned $int16_t"
411 [ -z "$int32_t" ] && int32_t="$default_int32"
412 [ -z "$uint32_t" ] && uint32_t="unsigned $int32_t"
414 cat <<!EOF!
415 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
416 typedef int ${macro_prefix}int8_t __attribute__((__mode__(__QI__)));
417 typedef unsigned int ${macro_prefix}uint8_t __attribute__((__mode__(__QI__)));
418 typedef int ${macro_prefix}int16_t __attribute__((__mode__(__HI__)));
419 typedef unsigned int ${macro_prefix}uint16_t __attribute__((__mode__(__HI__)));
420 typedef int ${macro_prefix}int32_t __attribute__((__mode__(__SI__)));
421 typedef unsigned int ${macro_prefix}uint32_t __attribute__((__mode__(__SI__)));
422 typedef int ${macro_prefix}int64_t __attribute__((__mode__(__DI__)));
423 typedef unsigned int ${macro_prefix}uint64_t __attribute__((__mode__(__DI__)));
424 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 8
425 __extension__ typedef long long ${macro_prefix}llong;
426 __extension__ typedef unsigned long long ${macro_prefix}ullong;
427 #endif
428 #else
429 typedef $int16_t ${macro_prefix}int16_t;
430 typedef $uint16_t ${macro_prefix}uint16_t;
431 typedef $int32_t ${macro_prefix}int32_t;
432 typedef $uint32_t ${macro_prefix}uint32_t;
433 #endif
435 typedef ${clock_t-int /* default */} ${macro_prefix}clock_t;
436 typedef ${dev_t-int /* default */} ${macro_prefix}dev_t;
437 typedef ${fpos_t-long /* default */} ${macro_prefix}fpos_t;
438 typedef ${gid_t-int /* default */} ${macro_prefix}gid_t;
439 typedef ${ino_t-int /* default */} ${macro_prefix}ino_t;
440 typedef ${mode_t-int /* default */} ${macro_prefix}mode_t;
441 typedef ${nlink_t-int /* default */} ${macro_prefix}nlink_t;
442 typedef ${off_t-long /* default */} ${macro_prefix}off_t;
443 typedef ${pid_t-int /* default */} ${macro_prefix}pid_t;
444 #ifndef __PTRDIFF_TYPE__
445 #define __PTRDIFF_TYPE__ ${ptrdiff_t-long int /* default */}
446 #endif
447 typedef __PTRDIFF_TYPE__ ${macro_prefix}ptrdiff_t;
448 typedef ${sigset_t-int /* default */} ${macro_prefix}sigset_t;
449 #ifndef __SIZE_TYPE__
450 #define __SIZE_TYPE__ ${size_t-unsigned long /* default */}
451 #endif
452 typedef __SIZE_TYPE__ ${macro_prefix}size_t;
453 typedef ${time_t-int /* default */} ${macro_prefix}time_t;
454 typedef ${uid_t-int /* default */} ${macro_prefix}uid_t;
455 typedef ${wchar_t-int /* default */} ${macro_prefix}wchar_t;
457 #define ${macro_prefix}BUFSIZ ${BUFSIZ-1024 /* default */}
458 #define ${macro_prefix}FOPEN_MAX ${FOPEN_MAX-32 /* default */}
459 #define ${macro_prefix}FILENAME_MAX ${FILENAME_MAX-1024 /* default */}
460 #if defined (__cplusplus) || defined (__STDC__)
461 #define ${macro_prefix}ARGS(ARGLIST) ARGLIST
462 #else
463 #define ${macro_prefix}ARGS(ARGLIST) ()
464 #endif
465 #if !defined (__GNUG__) || defined (__STRICT_ANSI__)
466 #define ${macro_prefix}NO_NRV
467 #endif
468 #if !defined (__GNUG__)
469 #define _G_NO_EXTERN_TEMPLATES
470 #endif
471 !EOF!
473 # ssize_t is the signed version of size_t
474 if [ -n "${ssize_t}" ] ; then
475 echo "typedef ${ssize_t} ${macro_prefix}ssize_t;"
476 elif [ -z "${size_t}" ] ; then
477 echo "typedef long ${macro_prefix}ssize_t;"
478 else
479 # Remove "unsigned" from ${size_t} to get ${ssize_t}.
480 tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's| | |g'`"
481 if [ -z "$tmp" ] ; then
482 tmp=int
483 else
484 # check $tmp doesn't conflict with <unistd.h>
485 echo "#include <unistd.h>
486 extern $tmp read();" >dummy.c
487 ${CC} -c dummy.c >/dev/null 2>&1 || tmp=int
489 echo "typedef $tmp /* default */ ${macro_prefix}ssize_t;"
492 # wint_t is often the integral type to which wchar_t promotes.
493 if [ -z "${wint_t}" ] ; then
494 for TYPE in int 'unsigned int' 'long int' 'long unsigned int'; do
495 cat >dummy.C <<!EOF!
496 #ifndef __WCHAR_TYPE__
497 #define __WCHAR_TYPE__ ${wchar_t-int /* default */}
498 #endif
499 typedef __WCHAR_TYPE__ ${macro_prefix}wchar_t;
500 void foo ($TYPE);
501 void foo (double);
502 void bar (${macro_prefix}wchar_t w)
504 foo (w);
506 !EOF!
507 if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
508 wint_t="$TYPE /* default */"
509 break
511 done
513 echo "typedef ${wint_t-int /* wchar_t is broken */} ${macro_prefix}wint_t;"
515 # va_list can cause problems (e.g. some systems have va_list as a struct).
516 # Check to see if ${va_list-char*} really is compatible with stdarg.h.
517 cat >dummy.C <<!EOF!
518 #define X_va_list ${va_list-char* /* default */}
519 extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
520 extern "C" {
521 #include <stdarg.h>
523 long foo(X_va_list ap) { return va_arg(ap, long); }
524 long bar(int i, ...)
525 { va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
526 !EOF!
527 if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
528 # Ok: We have something that works.
529 echo "typedef ${va_list-char* /* default */} ${macro_prefix}va_list;"
530 else
531 echo "#define ${macro_prefix}NEED_STDARG_H"
532 # Check and see if we have __gnuc_va_list, as we might set up define
533 # loops if we use va_list.
534 cat >dummy.C <<!EOF!
535 #include <stdarg.h>
536 long foo(__gnuc_va_list ap) { return va_arg(ap, long); }
537 !EOF!
538 if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
539 echo "#define ${macro_prefix}va_list __gnuc_va_list"
540 else
541 echo "#define ${macro_prefix}va_list va_list"
545 cat >dummy.c <<!EOF!
546 #include <signal.h>
547 extern int (*signal())();
548 extern int dummy (int);
549 main()
551 int (*oldsig)(int) = signal (1, dummy);
552 (void) signal (2, oldsig);
553 return 0;
555 !EOF!
556 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
557 echo "#define ${macro_prefix}signal_return_type int"
558 else
559 echo "#define ${macro_prefix}signal_return_type void"
562 # check sprintf return type
564 cat >dummy.c <<!EOF!
565 #include <stdio.h>
566 extern int sprintf(); char buf[100];
567 int main() { return sprintf(buf, "%d", 34); }
568 !EOF!
569 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
570 echo "#define ${macro_prefix}sprintf_return_type int"
571 else
572 echo "#define ${macro_prefix}sprintf_return_type char*"
575 if test -n "${HAVE_ATEXIT}" ; then
576 echo "#define ${macro_prefix}HAVE_ATEXIT ${HAVE_ATEXIT}"
577 else
578 cat >dummy.c <<!EOF!
579 #include <stdlib.h>
580 int main()
582 atexit (0);
584 !EOF!
585 if ${CC} dummy.c >/dev/null 2>&1 ; then
586 echo "#define ${macro_prefix}HAVE_ATEXIT 1"
587 else
588 echo "#define ${macro_prefix}HAVE_ATEXIT 0"
593 # *** Check for presence of certain include files ***
595 # check for sys/resource.h
597 if test -n "${HAVE_SYS_RESOURCE}" ; then
598 echo "#define ${macro_prefix}HAVE_SYS_RESOURCE ${HAVE_SYS_RESOURCE}"
599 else
600 cat >dummy.c <<!EOF!
601 #include <sys/types.h>
602 #include <sys/time.h>
603 #include <sys/resource.h>
604 int main()
606 struct rusage res;
607 getrusage(RUSAGE_SELF, &res);
608 return (int)(res.ru_utime.tv_sec + (res.ru_utime.tv_usec / 1000000.0));
610 !EOF!
611 # Note: We link because some systems have sys/resource, but not getrusage().
612 if ${CC} dummy.c >/dev/null 2>&1 ; then
613 echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 1"
614 else
615 echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 0"
619 # check for struct tms in sys/times.h
621 if test -n "${HAVE_SYS_TIMES}" ; then
622 echo "#define ${macro_prefix}HAVE_SYS_TIMES ${HAVE_SYS_TIMES}"
623 else
624 cat >dummy.c <<!EOF!
625 #include <sys/types.h>
626 #include <sys/times.h>
627 int main()
629 struct tms s;
630 return s.tms_utime;
632 !EOF!
633 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
634 echo "#define ${macro_prefix}HAVE_SYS_TIMES 1"
635 else
636 echo "#define ${macro_prefix}HAVE_SYS_TIMES 0"
640 # check for sys/socket.h
642 if test -n "${HAVE_SYS_SOCKET}" ; then
643 echo "#define ${macro_prefix}HAVE_SYS_SOCKET ${HAVE_SYS_SOCKET}"
644 else
645 echo '#include <sys/types.h>' >dummy.c
646 echo '#include <sys/socket.h>' >>dummy.c
647 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
648 echo "#define ${macro_prefix}HAVE_SYS_SOCKET 1"
649 else
650 echo "#define ${macro_prefix}HAVE_SYS_SOCKET 0"
654 # check for sys/cdefs.h
656 if test -n "${HAVE_SYS_CDEFS}" ; then
657 echo "#define ${macro_prefix}HAVE_SYS_CDEFS ${HAVE_SYS_CDEFS}"
658 else
659 echo '#include <sys/cdefs.h>' >dummy.c
660 echo 'extern int myfunc __P((int, int));' >>dummy.c
661 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
662 echo "#define ${macro_prefix}HAVE_SYS_CDEFS 1"
663 else
664 echo "#define ${macro_prefix}HAVE_SYS_CDEFS 0"
668 # Check for a (Posix-compatible) sys/wait.h */
670 if test -n "${HAVE_SYS_WAIT}" ; then
671 echo "#define ${macro_prefix}HAVE_SYS_WAIT ${HAVE_SYS_WAIT}"
672 else
673 cat >dummy.c <<!EOF!
674 #include <sys/types.h>
675 #include <sys/wait.h>
676 int f() { int i; wait(&i); return i; }
677 !EOF!
678 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
679 echo "#define ${macro_prefix}HAVE_SYS_WAIT 1"
680 else
681 echo "#define ${macro_prefix}HAVE_SYS_WAIT 0"
685 if test -n "${HAVE_UNISTD}" ; then
686 echo "#define ${macro_prefix}HAVE_UNISTD ${HAVE_UNISTD}"
687 else
688 echo '#include <unistd.h>' >dummy.c
689 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
690 echo "#define ${macro_prefix}HAVE_UNISTD 1"
691 else
692 echo "#define ${macro_prefix}HAVE_UNISTD 0"
696 if test -n "${HAVE_DIRENT}" ; then
697 echo "#define ${macro_prefix}HAVE_DIRENT ${HAVE_DIRENT}"
698 else
699 echo '#include <sys/types.h>
700 #include <dirent.h>' >dummy.c
701 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
702 echo "#define ${macro_prefix}HAVE_DIRENT 1"
703 else
704 echo "#define ${macro_prefix}HAVE_DIRENT 0"
708 if test -n "${HAVE_CURSES}" ; then
709 echo "#define ${macro_prefix}HAVE_CURSES ${HAVE_CURSES}"
710 else
711 echo '#include <curses.h>' >dummy.c
712 if ${CC} -c dummy.c >/dev/null 2>&1 ; then
713 echo "#define ${macro_prefix}HAVE_CURSES 1"
714 else
715 echo "#define ${macro_prefix}HAVE_CURSES 0"
719 # There is no test for this at the moment; it is just set by the
720 # configuration files.
721 if test -n "${MATH_H_INLINES}" ; then
722 echo "#define ${macro_prefix}MATH_H_INLINES ${MATH_H_INLINES}"
723 else
724 echo "#define ${macro_prefix}MATH_H_INLINES 0"
727 if test -n "${HAVE_BOOL}" ; then
728 echo "#define ${macro_prefix}HAVE_BOOL ${HAVE_BOOL}"
729 else
730 echo 'bool i=true,j=false;' >dummy.C
731 if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
732 echo "#define ${macro_prefix}HAVE_BOOL 1"
733 else
734 echo "#define ${macro_prefix}HAVE_BOOL 0"
738 if test -n "${NO_USE_DTOA}" ; then
739 echo "#define ${macro_prefix}NO_USE_DTOA 1"
741 if test -n "${USE_INT32_FLAGS}" ; then
742 echo "#define ${macro_prefix}USE_INT32_FLAGS 1"
745 if test -n "$HAVE_PRINTF_FP"; then
746 echo "#define ${macro_prefix}HAVE_PRINTF_FP $HAVE_PRINTF_FP"
747 echo "#define ${macro_prefix}HAVE_LONG_DOUBLE_IO $HAVE_LONG_DOUBLE_IO"
748 else
749 # A little test program to check if __printf_fp is available.
750 cat >dummy.c <<EOF
751 int main()
753 return __printf_fp ();
757 if ${CC} dummy.c >/dev/null 2>&1 ; then
758 echo "#define ${macro_prefix}HAVE_PRINTF_FP 1"
759 echo "#define ${macro_prefix}HAVE_LONG_DOUBLE_IO 1"
760 else
761 echo "#define ${macro_prefix}HAVE_PRINTF_FP 0"
762 echo "#define ${macro_prefix}HAVE_LONG_DOUBLE_IO 0"
766 # Uncomment the following line if you don't have working templates.
767 # echo "#define ${macro_prefix}NO_TEMPLATES"
769 # Override bogus definitions of NULL in system headers.
770 cat <<EOF
771 #undef NULL
772 #define __need_NULL
773 #include <stddef.h>
776 rm -f dummy.C dummy.o dummy.c dummy.out TMP core a.out
778 echo "#endif /* !${macro_prefix}config_h */"