home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / src / amiga / libg++-2.6.2-src.lha / libg++-2.6.2 / libio / gen-params < prev    next >
Encoding:
Text File  |  1994-12-18  |  19.2 KB  |  639 lines

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