home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / libg++-2.7.1-base.tgz / libg++-2.7.1-src.tar / fsf / libg++ / libio / gen-params < prev    next >
Text File  |  1995-11-03  |  21KB  |  682 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 this library; see the file COPYING.  If not, write to the Free
  14. # Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 cc ; 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.       if [ -n "`${SED} -n -e 's/ virtual table/nope/p' <TMP`" ] ; then
  109.     ${CONFIG_NM} --no-cplus dummy.o >TMP 2>/dev/null ||
  110.       ${CONFIG_NM} --no-demangle dummy.o >TMP 2>/dev/null ||
  111.       ${CONFIG_NM} dummy.o >TMP 2>/dev/null
  112.       fi
  113.       # First we look for a pattern that matches historical output from g++.
  114.       # We surround the actual label name by <> to separate it from
  115.       # other nm junk. 
  116.       ${SED} -n -e 's/_*vt[$_.]7*filebuf/<&>/p' <TMP >dummy.out
  117.       # For paranoia's sake (e.g. if we're using some other C++ compiler)
  118.       # we try a more general pattern, and append the result.
  119.       grep -v foo <TMP \
  120.     | ${SED} -n -e 's/[a-zA-Z0-9_.$]*filebuf[a-zA-Z0-9_.$]*/<&>/p' \
  121.     >>dummy.out
  122.       # Now we get rid of the <>, and any other junk on the nm output line.
  123.       # (We get rid of <filebuf> in case nm included debugging output for
  124.       # class filebuf itself.)  Finally, we select the first line of
  125.       # the result, and hope that's what we wanted!
  126.       vtab_name=`${SED} -n -e '/<filebuf>/d' -e 's/^.*<\(.*\)>.*$/\1/p' \
  127.         <dummy.out | ${SED} -n -e '1p'`
  128.       case "${vtab_name}" in
  129.         *7filebuf) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 1" ;;
  130.         *) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 0" ;;
  131.       esac
  132.       VTABLE_LABEL_PREFIX=`echo $vtab_name | ${SED} -e 's/7*filebuf//'`
  133.     fi
  134.     echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX" '"'"${VTABLE_LABEL_PREFIX}"'"'
  135.     if [ "${VTABLE_LABEL_PREFIX}" = "__vt_" -o \
  136.         "${VTABLE_LABEL_PREFIX}" = "___vt_" ] ; then
  137.       echo "#define ${macro_prefix}USING_THUNKS"
  138.     fi
  139.  
  140.     # VTABLE_LABEL_PREFIX_ID is the same as VTABLE_LABEL_PREFIX,
  141.     # but the former is a C identifier, while the latter is a quoted
  142.     # st
  143.     if [ -z ""`echo ${VTABLE_LABEL_PREFIX} | ${SED} -e 's/[a-zA-Z0-9_]//g'` ] ; then
  144.       if [ "${NAMES_HAVE_UNDERSCORE}" = "1" ] ; then
  145.     VTABLE_LABEL_PREFIX=`echo ${VTABLE_LABEL_PREFIX} | ${SED} -e 's/^_//'`
  146.       fi
  147.       echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX_ID ${VTABLE_LABEL_PREFIX}"
  148.     fi
  149.  
  150. #    if test -n "${DOLLAR_IN_LABEL}" ; then
  151. #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL ${DOLLAR_IN_LABEL}"
  152. #    elif test "`${CONFIG_NM} dummy.o | grep 'vt[$$]7filebuf'`" != ""; then
  153. #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 1"
  154. #    elif test "`${CONFIG_NM} dummy.o | grep 'vt[.]7filebuf'`" != ""; then
  155. #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
  156. #    elif test "`${CONFIG_NM} dummy.o | grep 'vtbl__7filebuf'`" != ""; then
  157. #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
  158. #    else
  159. #      echo "gen-params: ${CONFIG_NM} failed to find vt[.\$]filebuf in dummy.o!" 1>&2; exit 1
  160. #    fi
  161.   else
  162.     # The compile failed for some reason (no C++?)
  163.     echo "gen-params: could not compile dummy.C with ${CXX}" 1>&2; exit 1;
  164.   fi
  165. fi
  166.  
  167. # A little test program to check if struct stat has st_blksize.
  168. cat >dummy.c <<!EOF!
  169. #include <sys/types.h>
  170. #include <sys/stat.h>
  171. int BLKSIZE(struct stat *st)
  172. {
  173.     return st->st_blksize;
  174. }
  175. !EOF!
  176.  
  177. if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  178.   echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 1"
  179. else
  180.   echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 0"
  181. fi
  182.  
  183. # Next, generate definitions for the standard types (such as mode_t)
  184. # compatible with those in the standard C header files.
  185. # It works by a dummy program through the C pre-processor, and then
  186. # using sed to search for typedefs in the output.
  187.  
  188. for hdr in wchar wctype; do
  189.   eval $hdr=0
  190.   cat >dummy.c <<EOF
  191. #include <${hdr}.h>
  192. EOF
  193.   if ${CPP} dummy.c >/dev/null 2>&1 ; then eval $hdr=1; fi
  194. done
  195.  
  196. cat >dummy.c <<!EOF!
  197. #include <sys/types.h>
  198. #include <stddef.h>
  199. #ifdef __STDC__
  200. #include <stdarg.h>
  201. #else /* !__STDC__ */
  202. #include <varargs.h>
  203. #endif /* __STDC__ */
  204. #include <stdio.h>
  205. #include <time.h>
  206. #include <signal.h>
  207. #ifdef __STDC__
  208. #include <limits.h>
  209. #endif
  210. #if WCHAR == 1
  211. #include <wchar.h>
  212. #endif
  213. #if WCTYPE == 1
  214. #include <wctype.h>
  215. #endif
  216. #ifdef size_t
  217. typedef size_t Xsize_t;
  218. #elif defined(__SIZE_TYPE__)
  219. typedef __SIZE_TYPE__ Xsize_t;
  220. #endif
  221. #ifdef ptrdiff_t
  222. typedef ptrdiff_t Xptrdiff_t;
  223. #elif defined(__PTRDIFF_TYPE__)
  224. typedef __PTRDIFF_TYPE__ Xptrdiff_t;
  225. #endif
  226. #ifdef wchar_t
  227. typedef wchar_t Xwchar_t;
  228. #elif defined(__WCHAR_TYPE__)
  229. typedef __WCHAR_TYPE__ Xwchar_t;
  230. #endif
  231. #ifdef va_list
  232. typedef va_list XXXva_list;
  233. #endif
  234. #ifdef BUFSIZ
  235. long XBUFSIZ=BUFSIZ;
  236. #endif
  237. #ifdef FOPEN_MAX
  238. long XFOPEN_MAX=FOPEN_MAX;
  239. #endif
  240. #ifdef FILENAME_MAX
  241. long XFILENAME_MAX=FILENAME_MAX;
  242. #endif
  243. #ifdef SHRT_MAX
  244. long XSHRT_MAX=SHRT_MAX;
  245. #endif
  246. #ifdef INT_MAX
  247. long XINT_MAX=INT_MAX;
  248. #endif
  249. #ifdef LONG_MAX
  250. long XLONG_MAX=LONG_MAX;
  251. #endif
  252. #ifdef LONG_LONG_MAX
  253. long XLONG_LONG_MAX=LONG_LONG_MAX;
  254. #endif
  255. !EOF!
  256.  
  257. if ${CPP} dummy.c -DWCHAR=$wchar -DWCTYPE=$wctype >TMP ; then true
  258. else
  259.   echo "gen-params: could not invoke ${CPP} on dummy.c" 1>&2 ; exit 1
  260. fi
  261. tr '    ' ' ' <TMP >dummy.out
  262.  
  263. 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
  264.     IMPORTED=`eval 'echo $'"$TYPE"`
  265.     if [ -n "${IMPORTED}" ] ; then
  266.     eval "$TYPE='$IMPORTED'"
  267.     else
  268.     t=$TYPE
  269.     VALUE=''
  270.  
  271.     # Follow `typedef VALUE TYPE' chains, but don't loop indefinitely.
  272.     for iteration in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
  273.         # Search dummy.out for a typedef for X*$t.
  274.         sed_script="
  275.         /.*typedef  *\\(.*[^ ]\\)  *X*$t *;.*/{s||\1|;p;q;}
  276.         /.*typedef  *\\(.*[^ a-zA-Z0-9_]\\)X*$t *;.*/{s||\1|;p;q;}
  277.         "
  278.         t=`${SED} -n "$sed_script" <dummy.out`
  279.         case "$t" in
  280.           '')
  281.         break;;
  282.           *)
  283.         # Found a type $t; save it in VALUE.
  284.         VALUE=$t
  285.         # If it won't cause problems in matching,
  286.         # look for a typedef for it in turn.
  287.         case "$VALUE" in
  288.           *.* | */* | *\ * | *\** | *\[* | *\\*) break;;
  289.         esac;;
  290.         esac
  291.     done
  292.  
  293.     case "$VALUE" in
  294.       ?*) eval "$TYPE=\"$VALUE\""
  295.     esac
  296.     fi
  297. done
  298.  
  299. cat <<!EOF!
  300. typedef ${clock_t-int /* default */} ${macro_prefix}clock_t;
  301. typedef ${dev_t-int /* default */} ${macro_prefix}dev_t;
  302. typedef ${fpos_t-long /* default */} ${macro_prefix}fpos_t;
  303. typedef ${gid_t-int /* default */} ${macro_prefix}gid_t;
  304. typedef ${ino_t-int /* default */} ${macro_prefix}ino_t;
  305. typedef ${mode_t-int /* default */} ${macro_prefix}mode_t;
  306. typedef ${nlink_t-int /* default */} ${macro_prefix}nlink_t;
  307. typedef ${off_t-long /* default */} ${macro_prefix}off_t;
  308. typedef ${pid_t-int /* default */} ${macro_prefix}pid_t;
  309. #ifndef __PTRDIFF_TYPE__
  310. #define __PTRDIFF_TYPE__ ${ptrdiff_t-long int /* default */}
  311. #endif
  312. typedef __PTRDIFF_TYPE__ ${macro_prefix}ptrdiff_t;
  313. typedef ${sigset_t-int /* default */} ${macro_prefix}sigset_t;
  314. #ifndef __SIZE_TYPE__
  315. #define __SIZE_TYPE__ ${size_t-unsigned long /* default */}
  316. #endif
  317. typedef __SIZE_TYPE__ ${macro_prefix}size_t;
  318. typedef ${time_t-int /* default */} ${macro_prefix}time_t;
  319. typedef ${uid_t-int /* default */} ${macro_prefix}uid_t;
  320. typedef ${wchar_t-int /* default */} ${macro_prefix}wchar_t;
  321. !EOF!
  322.  
  323.  
  324. # ssize_t is the signed version of size_t
  325. if [ -n "${ssize_t}" ] ; then
  326.     echo "typedef ${ssize_t} ${macro_prefix}ssize_t;"
  327. elif [ -z "${size_t}" ] ; then
  328.     echo "typedef long ${macro_prefix}ssize_t;"
  329. else
  330.     # Remove "unsigned" from ${size_t} to get ${ssize_t}.
  331.     tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's|  | |g'`"
  332.     if [ -z "$tmp" ] ; then
  333.     tmp=int
  334.     else
  335.     # check $tmp doesn't conflict with <unistd.h>
  336.     echo "#include <unistd.h>
  337.     extern $tmp read();" >dummy.c
  338.     ${CC} -c dummy.c >/dev/null 2>&1 || tmp=int
  339.     fi
  340.     echo "typedef $tmp /* default */ ${macro_prefix}ssize_t;"
  341. fi
  342.  
  343. # wint_t is often the integral type to which wchar_t promotes.
  344. if [ -z "${wint_t}" ] ; then
  345.   for TYPE in int 'unsigned int' 'long int' 'long unsigned int'; do
  346.     cat >dummy.C <<!EOF!
  347. #ifndef __WCHAR_TYPE__
  348. #define __WCHAR_TYPE__ ${wchar_t-int /* default */}
  349. #endif
  350. typedef __WCHAR_TYPE__ ${macro_prefix}wchar_t;
  351. void foo ($TYPE);
  352. void foo (double);
  353. void bar (${macro_prefix}wchar_t w)
  354. {
  355.   foo (w);
  356. }
  357. !EOF!
  358.     if ${CXX} -c dummy.C >/dev/null 2>&1 ; then  
  359.       wint_t="$TYPE /* default */"
  360.       break
  361.     fi
  362.   done
  363. fi
  364. echo "typedef ${wint_t-int /* wchar_t is broken */} ${macro_prefix}wint_t;"
  365.  
  366. # va_list can cause problems (e.g. some systems have va_list as a struct).
  367. # Check to see if ${va_list-char*} really is compatible with stdarg.h.
  368. cat >dummy.C <<!EOF!
  369. #define X_va_list ${va_list-char* /* default */}
  370. extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
  371. extern "C" {
  372. #include <stdarg.h>
  373. }
  374. long foo(X_va_list ap) { return va_arg(ap, long); }
  375. long bar(int i, ...)
  376. { va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
  377. !EOF!
  378. if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
  379.   # Ok: We have something that works.
  380.   echo "typedef ${va_list-char* /* default */} ${macro_prefix}va_list;"
  381. else
  382.   # No, it breaks.  Indicate that <stdarg.h> must be included.
  383.   echo "#define ${macro_prefix}NEED_STDARG_H
  384. #define ${macro_prefix}va_list va_list"
  385. fi
  386.  
  387. cat >dummy.c <<!EOF!
  388. #include <signal.h>
  389. extern int (*signal())();
  390. extern int dummy (int);
  391. main()
  392. {
  393.     int (*oldsig)(int) = signal (1, dummy);
  394.     (void) signal (2, oldsig);
  395.     return 0;
  396. }
  397. !EOF!
  398. if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  399.   echo "#define ${macro_prefix}signal_return_type int"
  400. else
  401.   echo "#define ${macro_prefix}signal_return_type void"
  402. fi
  403.  
  404. # check sprintf return type
  405.  
  406. cat >dummy.c <<!EOF!
  407. #include <stdio.h>
  408. extern int sprintf(); char buf[100];
  409. int main() { return sprintf(buf, "%d", 34); }
  410. !EOF!
  411. if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  412.   echo "#define ${macro_prefix}sprintf_return_type int"
  413. else
  414.   echo "#define ${macro_prefix}sprintf_return_type char*"
  415. fi
  416.  
  417. # Look for some standard macros.
  418. for NAME in BUFSIZ FOPEN_MAX FILENAME_MAX NULL; do
  419.     IMPORTED=`eval 'echo $'"$NAME"`
  420.     if [ -n "${IMPORTED}" ] ; then
  421.     eval "$NAME='$IMPORTED /* specified */"
  422.     else
  423.     rm -f TMP
  424.     ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\(.*\);|\1|w TMP" \
  425.       <dummy.out>/dev/null
  426.     # Now select the first definition.
  427.     if [ -s TMP ]; then
  428.         eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
  429.     fi
  430.     fi
  431. done
  432.  
  433. # These macros must be numerical constants; strip any trailing 'L's.
  434. for NAME in SHRT_MAX INT_MAX LONG_MAX LONG_LONG_MAX; do
  435.     IMPORTED=`eval 'echo $'"$NAME"`
  436.     if [ -n "${IMPORTED}" ] ; then
  437.     eval "$NAME='$IMPORTED /* specified */"
  438.     else
  439.     rm -f TMP
  440.     ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\([0-9]*\)L* *;|\1|w TMP" \
  441.       <dummy.out>/dev/null
  442.     # Now select the first definition.
  443.     if [ -s TMP ]; then
  444.         eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
  445.     fi
  446.     fi
  447. done
  448.  
  449. # Figure out integral type sizes.
  450.  
  451. default_int16='short /* deduction failed */'
  452. default_int32='long /* deduction failed */'
  453. INT16=32767
  454. INT32=2147483647
  455.  
  456. if [ "${SHRT_MAX}" = $INT16 ] ; then
  457.   default_int16='short /* deduced */'
  458.   if [ "${LONG_MAX}" = $INT32 ] ; then
  459.     default_int32='long /* deduced */'
  460.   elif [ "${INT_MAX}" = $INT32 ] ; then
  461.     default_int32='int /* deduced */'
  462.   fi
  463. fi
  464.  
  465. [ -n "$u_int16_t" ] && uint16_t="$u_int16_t"
  466. [ -n "$u_int32_t" ] && uint32_t="$u_int32_t"
  467.  
  468. [ -z  "$int16_t" ] &&  int16_t="$default_int16"
  469. [ -z "$uint16_t" ] && uint16_t="unsigned $int16_t"
  470. [ -z  "$int32_t" ] &&  int32_t="$default_int32"
  471. [ -z "$uint32_t" ] && uint32_t="unsigned $int32_t"
  472.  
  473. cat <<!EOF!
  474.  
  475. #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
  476. typedef          int   ${macro_prefix}int8_t __attribute__((__mode__(__QI__)));
  477. typedef unsigned int  ${macro_prefix}uint8_t __attribute__((__mode__(__QI__)));
  478. typedef          int  ${macro_prefix}int16_t __attribute__((__mode__(__HI__)));
  479. typedef unsigned int ${macro_prefix}uint16_t __attribute__((__mode__(__HI__)));
  480. typedef          int  ${macro_prefix}int32_t __attribute__((__mode__(__SI__)));
  481. typedef unsigned int ${macro_prefix}uint32_t __attribute__((__mode__(__SI__)));
  482. typedef          int  ${macro_prefix}int64_t __attribute__((__mode__(__DI__)));
  483. typedef unsigned int ${macro_prefix}uint64_t __attribute__((__mode__(__DI__)));
  484. #else
  485. typedef  $int16_t  ${macro_prefix}int16_t;
  486. typedef $uint16_t ${macro_prefix}uint16_t;
  487. typedef  $int32_t  ${macro_prefix}int32_t;
  488. typedef $uint32_t ${macro_prefix}uint32_t;
  489. #endif
  490.  
  491. #define ${macro_prefix}BUFSIZ ${BUFSIZ-1024 /* default */}
  492. #define ${macro_prefix}FOPEN_MAX ${FOPEN_MAX-32 /* default */}
  493. #define ${macro_prefix}FILENAME_MAX ${FILENAME_MAX-1024 /* default */}
  494. #define ${macro_prefix}NULL ${NULL-0 /* default */}
  495. #if defined (__cplusplus) || defined (__STDC__)
  496. #define ${macro_prefix}ARGS(ARGLIST) ARGLIST
  497. #else
  498. #define ${macro_prefix}ARGS(ARGLIST) ()
  499. #endif
  500. #if !defined (__GNUG__) || defined (__STRICT_ANSI__)
  501. #define ${macro_prefix}NO_NRV
  502. #endif
  503. #if !defined (__GNUG__)
  504. #define _G_NO_EXTERN_TEMPLATES
  505. #endif
  506. !EOF!
  507.  
  508. rm -f dummy.c dummy.o dummy.h
  509.  
  510. if test -n "${HAVE_ATEXIT}" ; then
  511.  echo "#define ${macro_prefix}HAVE_ATEXIT ${HAVE_ATEXIT}"
  512. else
  513.   cat >dummy.c <<!EOF!
  514. #include <stdlib.h>
  515. int main()
  516. {
  517.   atexit (0);
  518. }
  519. !EOF!
  520.   if ${CC} dummy.c >/dev/null 2>&1 ; then
  521.     echo "#define ${macro_prefix}HAVE_ATEXIT 1"
  522.   else
  523.     echo "#define ${macro_prefix}HAVE_ATEXIT 0"
  524.   fi
  525. fi
  526.  
  527.  
  528. # *** Check for presence of certain include files ***
  529.  
  530. # check for sys/resource.h
  531.  
  532. if test -n "${HAVE_SYS_RESOURCE}" ; then
  533.  echo "#define ${macro_prefix}HAVE_SYS_RESOURCE ${HAVE_SYS_RESOURCE}"
  534. else
  535.   cat >dummy.c <<!EOF!
  536. #include <sys/types.h>
  537. #include <sys/time.h>
  538. #include <sys/resource.h>
  539.   int main()
  540.   {
  541.     struct rusage res;
  542.     getrusage(RUSAGE_SELF, &res);
  543.     return (int)(res.ru_utime.tv_sec + (res.ru_utime.tv_usec / 1000000.0));
  544.   }
  545. !EOF!
  546.   # Note: We link because some systems have sys/resource, but not getrusage().
  547.   if ${CC} dummy.c >/dev/null 2>&1 ; then
  548.     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 1"
  549.   else
  550.     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 0"
  551.   fi
  552. fi
  553.  
  554. # check for struct tms in sys/times.h
  555.  
  556. if test -n "${HAVE_SYS_TIMES}" ; then
  557.  echo "#define ${macro_prefix}HAVE_SYS_TIMES ${HAVE_SYS_TIMES}"
  558. else
  559.  cat >dummy.c <<!EOF!
  560. #include <sys/types.h>
  561. #include <sys/times.h>
  562.   int main()
  563.   {
  564.     struct tms s;
  565.     return s.tms_utime;
  566.   }
  567. !EOF!
  568.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  569.     echo "#define ${macro_prefix}HAVE_SYS_TIMES 1"
  570.   else
  571.     echo "#define ${macro_prefix}HAVE_SYS_TIMES 0"
  572.   fi
  573. fi
  574.  
  575. # check for sys/socket.h
  576.  
  577. if test -n "${HAVE_SYS_SOCKET}" ; then
  578.  echo "#define ${macro_prefix}HAVE_SYS_SOCKET ${HAVE_SYS_SOCKET}"
  579. else
  580.   echo '#include <sys/types.h>' >dummy.c
  581.   echo '#include <sys/socket.h>' >>dummy.c
  582.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  583.     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 1"
  584.   else
  585.     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 0"
  586.   fi
  587. fi
  588.  
  589. # check for sys/cdefs.h
  590.  
  591. if test -n "${HAVE_SYS_CDEFS}" ; then
  592.  echo "#define ${macro_prefix}HAVE_SYS_CDEFS ${HAVE_SYS_CDEFS}"
  593. else
  594.   echo '#include <sys/cdefs.h>' >dummy.c
  595.   echo 'extern int myfunc __P((int, int));' >>dummy.c
  596.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  597.     echo "#define ${macro_prefix}HAVE_SYS_CDEFS 1"
  598.   else
  599.     echo "#define ${macro_prefix}HAVE_SYS_CDEFS 0"
  600.   fi
  601. fi
  602.  
  603. # Check for a (Posix-compatible) sys/wait.h */
  604.  
  605. if test -n "${HAVE_SYS_WAIT}" ; then
  606.  echo "#define ${macro_prefix}HAVE_SYS_WAIT ${HAVE_SYS_WAIT}"
  607. else
  608.   cat >dummy.c <<!EOF!
  609. #include <sys/types.h>
  610. #include <sys/wait.h>
  611.   int f() { int i; wait(&i); return i; }
  612. !EOF!
  613.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  614.     echo "#define ${macro_prefix}HAVE_SYS_WAIT 1"
  615.   else
  616.     echo "#define ${macro_prefix}HAVE_SYS_WAIT 0"
  617.   fi
  618. fi
  619.  
  620. if test -n "${HAVE_UNISTD}" ; then
  621.  echo "#define ${macro_prefix}HAVE_UNISTD ${HAVE_UNISTD}"
  622. else
  623.   echo '#include <unistd.h>' >dummy.c
  624.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  625.     echo "#define ${macro_prefix}HAVE_UNISTD 1"
  626.   else
  627.     echo "#define ${macro_prefix}HAVE_UNISTD 0"
  628.   fi
  629. fi
  630.  
  631. if test -n "${HAVE_DIRENT}" ; then
  632.  echo "#define ${macro_prefix}HAVE_DIRENT ${HAVE_DIRENT}"
  633. else
  634.   echo '#include <sys/types.h>
  635. #include <dirent.h>' >dummy.c
  636.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  637.     echo "#define ${macro_prefix}HAVE_DIRENT 1"
  638.   else
  639.     echo "#define ${macro_prefix}HAVE_DIRENT 0"
  640.   fi
  641. fi
  642.  
  643. if test -n "${HAVE_CURSES}" ; then
  644.  echo "#define ${macro_prefix}HAVE_CURSES ${HAVE_CURSES}"
  645. else
  646.   echo '#include <curses.h>' >dummy.c
  647.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  648.     echo "#define ${macro_prefix}HAVE_CURSES 1"
  649.   else
  650.     echo "#define ${macro_prefix}HAVE_CURSES 0"
  651.   fi
  652. fi
  653.  
  654. # There is no test for this at the moment; it is just set by the
  655. # configuration files.
  656. if test -n "${MATH_H_INLINES}" ; then
  657.   echo "#define ${macro_prefix}MATH_H_INLINES ${MATH_H_INLINES}"
  658. else
  659.   echo "#define ${macro_prefix}MATH_H_INLINES 0"
  660. fi
  661.  
  662. if test -n "${HAVE_BOOL}" ; then
  663.  echo "#define ${macro_prefix}HAVE_BOOL ${HAVE_BOOL}"
  664. else
  665.   echo 'bool i=true,j=false;' >dummy.C
  666.   if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
  667.     echo "#define ${macro_prefix}HAVE_BOOL 1"
  668.   else
  669.     echo "#define ${macro_prefix}HAVE_BOOL 0"
  670.   fi
  671. fi
  672.  
  673. # Uncomment the following line if you don't have working templates.
  674. # echo "#define ${macro_prefix}NO_TEMPLATES"
  675.  
  676. rm -f dummy.C dummy.o dummy.c dummy.out TMP core a.out
  677.  
  678. echo "#endif /* !${macro_prefix}config_h */"
  679.