Annotation of GNUtools/libg++/libio/gen-params, revision 1.1.1.1

1.1       root        1: #!/bin/sh
                      2: # Copyright (C) 1992, 1993 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 GNU CC; see the file COPYING.  If not, write to
                     17: # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
                     18: 
                     19: #    Written by Per Bothner ([email protected])
                     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}/ -I${gccdir}/include ; \
                     53:        else echo cc ; fi`}
                     54: CXX=${CXX-`if [ -f ${gccdir}/xgcc ] ; \
                     55:        then echo ${gccdir}/xgcc -B${gccdir}/ -I${gccdir}/include ; \
                     56:        else echo gcc ; fi`}
                     57: CPP=${CPP-`echo ${CC} -E`}
                     58: CONFIG_NM=${CONFIG_NM-`if [ -f ${binutilsdir}/nm ] ; \
                     59:        then echo ${binutilsdir}/nm ; \
                     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}" ; then
                     76:   cat >dummy.C <<!EOF!
                     77:   struct filebuf {
                     78:       virtual int foo();
                     79:   };
                     80:   filebuf ff;
                     81:   extern "C" int FUNC(int);
                     82:   int FUNC(int i) { return i+10; }
                     83: !EOF!
                     84: 
                     85:   if ${CXX} -c dummy.C ; then
                     86:     if test -n "${NAMES_HAVE_UNDERSCORE}" ; then
                     87:      echo "#define ${macro_prefix}NAMES_HAVE_UNDERSCORE ${NAMES_HAVE_UNDERSCORE}"
                     88:     elif test "`${CONFIG_NM} dummy.o | grep _FUNC`" != ""; then
                     89:       echo "#define ${macro_prefix}NAMES_HAVE_UNDERSCORE 1"
                     90:     elif test "`${CONFIG_NM} dummy.o | grep FUNC`" != ""; then
                     91:       echo "#define ${macro_prefix}NAMES_HAVE_UNDERSCORE 0"
                     92:     else
                     93:       echo "${CONFIG_NM} failed to find FUNC in dummy.o!" 1>&2; exit -1;
                     94:     fi
                     95: 
                     96: #    if test -n "${DOLLAR_IN_LABEL}" ; then
                     97: #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL ${DOLLAR_IN_LABEL}"
                     98: #    elif test "`${CONFIG_NM} dummy.o | grep 'vt[$$]7filebuf'`" != ""; then
                     99: #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 1"
                    100: #    elif test "`${CONFIG_NM} dummy.o | grep 'vt[.]7filebuf'`" != ""; then
                    101: #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
                    102: #    elif test "`${CONFIG_NM} dummy.o | grep 'vtbl__7filebuf'`" != ""; then
                    103: #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
                    104: #    else
                    105: #      echo "gen-params: ${CONFIG_NM} failed to find vt[.\$]filebuf in dummy.o!" 1>&2; exit 1
                    106: #    fi
                    107:   else
                    108:     # The compile failed for some reason (no C++?)
                    109:     echo "gen-params: could not compile dummy.C with ${CXX}" 1>&2; exit 1;
                    110:   fi
                    111: fi
                    112: 
                    113: # A little test program to check if struct stat has st_blksize.
                    114: cat >dummy.c <<!EOF!
                    115: #include <sys/types.h>
                    116: #include <sys/stat.h>
                    117: int BLKSIZE(struct stat *st)
                    118: {
                    119:     return st->st_blksize;
                    120: }
                    121: !EOF!
                    122: 
                    123: if ${CC} -c dummy.c >/dev/null 2>&1 ; then
                    124:   echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 1"
                    125: else
                    126:   echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 0"
                    127: fi
                    128: 
                    129: # Next, generate definitions for the standard types (such as mode_t)
                    130: # compatible with those in the standard C header files.
                    131: # It works by a dummy program through the C pre-processor, and then
                    132: # using sed to search for typedefs in the output.
                    133: 
                    134: cat >dummy.c <<!EOF!
                    135: #include <sys/types.h>
                    136: #include <stddef.h>
                    137: #include <stdarg.h>
                    138: #include <stdio.h>
                    139: #include <time.h>
                    140: #include <signal.h>
                    141: #ifdef size_t
                    142: typedef size_t Xsize_t;
                    143: #elif defined(__SIZE_TYPE__)
                    144: typedef __SIZE_TYPE__ Xsize_t;
                    145: #endif
                    146: #ifdef ptrdiff_t
                    147: typedef ptrdiff_t Xptrdiff_t;
                    148: #elif defined(__PTRDIFF_TYPE__)
                    149: typedef __PTRDIFF_TYPE__ Xptrdiff_t;
                    150: #endif
                    151: #ifdef wchar_t
                    152: typedef wchar_t Xwchar_t;
                    153: #elif defined(__WCHAR_TYPE__)
                    154: typedef __WCHAR_TYPE__ Xwchar_t;
                    155: #endif
                    156: #ifdef va_list
                    157: typedef va_list XXXva_list;
                    158: #endif
                    159: #ifdef BUFSIZ
                    160: int XBUFSIZ=BUFSIZ;
                    161: #endif
                    162: #ifdef FOPEN_MAX
                    163: int XFOPEN_MAX=FOPEN_MAX;
                    164: #endif
                    165: #ifdef FILENAME_MAX
                    166: int XFILENAME_MAX=FILENAME_MAX;
                    167: #endif
                    168: !EOF!
                    169: 
                    170: if ${CPP} dummy.c >TMP ; then true
                    171: else
                    172:   echo "gen-params: could not invoke ${CPP} on dummy.c" 1>&2 ; exit 1
                    173: fi
                    174: tr '   ' ' ' <TMP >dummy.out
                    175: 
                    176: 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 int32_t uint_32_t ; do
                    177:     IMPORTED=`eval 'echo $'"$TYPE"`
                    178:     if [ -n "${IMPORTED}" ] ; then
                    179:        eval "$TYPE='$IMPORTED"
                    180:     else
                    181:        # Search dummy.out for a typedef for $TYPE, and write it out
                    182:        # to TMP in #define syntax.
                    183:        rm -f TMP
                    184:        ${SED} -n -e "s|.*typedef  *\(.*\) X*$TYPE *;.*|\1|w TMP" \
                    185:          <dummy.out>/dev/null
                    186:        # Now select the first definition.
                    187:         if [ -s TMP ]; then
                    188:            # VALUE is now the typedef'd definition of $TYPE.
                    189:             eval "VALUE='`${SED} -e 's| *$||' -e '2,$d' <TMP`'"
                    190:            # Unless VALUE contains a blank, look for a typedef for it
                    191:            # in turn (this could be a loop, but that would be over-kill).
                    192:            if echo $VALUE | grep " " >/dev/null ; then true
                    193:            else
                    194:                rm -f TMP
                    195:                ${SED} -n -e "s|.*typedef[      ][      ]*\(.*[^a-zA-Z0-9_]\)${VALUE}[  ]*;.*|\1|w TMP" <dummy.out>/dev/null
                    196:                if [ -s TMP ]; then
                    197:                    eval "VALUE='`${SED} -e '2,$d' -e 's|[      ]*$||' <TMP`'"
                    198:                fi
                    199:            fi
                    200:            eval "$TYPE='$VALUE'"
                    201:        fi
                    202:     fi
                    203: done
                    204: 
                    205: cat <<!EOF!
                    206: typedef ${clock_t-int /* default */} ${macro_prefix}clock_t;
                    207: typedef ${dev_t-int /* default */} ${macro_prefix}dev_t;
                    208: typedef ${fpos_t-long /* default */} ${macro_prefix}fpos_t;
                    209: typedef ${gid_t-int /* default */} ${macro_prefix}gid_t;
                    210: typedef ${ino_t-int /* default */} ${macro_prefix}ino_t;
                    211: typedef ${mode_t-int /* default */} ${macro_prefix}mode_t;
                    212: typedef ${nlink_t-int /* default */} ${macro_prefix}nlink_t;
                    213: typedef ${off_t-long /* default */} ${macro_prefix}off_t;
                    214: typedef ${pid_t-int /* default */} ${macro_prefix}pid_t;
                    215: typedef ${ptrdiff_t-long int /* default */} ${macro_prefix}ptrdiff_t;
                    216: typedef ${sigset_t-int /* default */} ${macro_prefix}sigset_t;
                    217: typedef ${size_t-unsigned long /* default */} ${macro_prefix}size_t;
                    218: typedef ${time_t-int /* default */} ${macro_prefix}time_t;
                    219: typedef ${uid_t-int /* default */} ${macro_prefix}uid_t;
                    220: typedef ${wchar_t-int /* default */} ${macro_prefix}wchar_t;
                    221: typedef ${int32_t-int /* default */} ${macro_prefix}int32_t;
                    222: typedef ${uint32_t-unsigned int /* default */} ${macro_prefix}uint32_t;
                    223: !EOF!
                    224: 
                    225: 
                    226: # ssize_t is the signed version of size_t
                    227: if [ -n "${ssize_t}" ] ; then
                    228:     echo "typedef ${ssize_t} ${macro_prefix}ssize_t;"
                    229: elif [ -z "${size_t}" ] ; then
                    230:     echo "typedef long ${macro_prefix}ssize_t;"
                    231: else
                    232:     # Remove "unsigned" from ${size_t} to get ${ssize_t}.
                    233:     tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's|  | |g'`"
                    234:     if [ -z "$tmp" ] ; then
                    235:        tmp=int
                    236:     else
                    237:        # check $tmp doesn't conflict with <unistd.h>
                    238:        echo "#include <unistd.h>
                    239:        extern $tmp read();" >dummy.c
                    240:        ${CC} -c dummy.c >/dev/null 2>&1 || tmp=int
                    241:     fi
                    242:     echo "typedef $tmp /* default */ ${macro_prefix}ssize_t;"
                    243: fi
                    244: 
                    245: # va_list can cause problems (e.g. some systems have va_list as a struct).
                    246: # Check to see if ${va_list-char*} really is compatible with stdarg.h.
                    247: cat >dummy.C <<!EOF!
                    248: #define X_va_list ${va_list-char* /* default */}
                    249: extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
                    250: extern "C" {
                    251: #include <stdarg.h>
                    252: }
                    253: long foo(X_va_list ap) { return va_arg(ap, long); }
                    254: long bar(int i, ...)
                    255: { va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
                    256: !EOF!
                    257: if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
                    258:   # Ok: We have something that works.
                    259:   echo "typedef ${va_list-char* /* default */} ${macro_prefix}va_list;"
                    260: else
                    261:   # No, it breaks.  Indicate that <stdarg.h> must be included.
                    262:   echo "#define ${macro_prefix}NEED_STDARG_H
                    263: #define ${macro_prefix}va_list va_list"
                    264: fi
                    265: 
                    266: cat >dummy.c <<!EOF!
                    267: #include <signal.h>
                    268: extern int (*signal())();
                    269: extern int dummy (int);
                    270: main()
                    271: {
                    272:     int (*oldsig)(int) = signal (1, dummy);
                    273:     (void) signal (2, oldsig);
                    274:     return 0;
                    275: }
                    276: !EOF!
                    277: if ${CC} -c dummy.c >/dev/null 2>&1 ; then
                    278:   echo "#define ${macro_prefix}signal_return_type int"
                    279: else
                    280:   echo "#define ${macro_prefix}signal_return_type void"
                    281: fi
                    282: 
                    283: # check sprintf return type
                    284: 
                    285: cat >dummy.c <<!EOF!
                    286: #include <stdio.h>
                    287: extern int sprintf(); char buf[100];
                    288: int main() { return sprintf(buf, "%d", 34); }
                    289: !EOF!
                    290: if ${CC} -c dummy.c >/dev/null 2>&1 ; then
                    291:   echo "#define ${macro_prefix}sprintf_return_type int"
                    292: else
                    293:   echo "#define ${macro_prefix}sprintf_return_type char*"
                    294: fi
                    295: 
                    296: # Look for some standard macros
                    297: for NAME in BUFSIZ FOPEN_MAX FILENAME_MAX NULL ; do
                    298:     IMPORTED=`eval 'echo $'"$NAME"`
                    299:     if [ -n "${IMPORTED}" ] ; then
                    300:        eval "$NAME='$IMPORTED /* specified */"
                    301:     else
                    302:        rm -f TMP
                    303:        ${SED} -n -e "s|int X${NAME}=\(.*\);|\1|w TMP" <dummy.out>/dev/null
                    304:        # Now select the first definition.
                    305:        if [ -s TMP ]; then
                    306:            eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
                    307:        fi
                    308:     fi
                    309: done
                    310: 
                    311: cat <<!EOF!
                    312: #define ${macro_prefix}BUFSIZ ${BUFSIZ-1024 /* default */}
                    313: #define ${macro_prefix}FOPEN_MAX ${FOPEN_MAX-32 /* default */}
                    314: #define ${macro_prefix}FILENAME_MAX ${FILENAME_MAX-1024 /* default */}
                    315: #define ${macro_prefix}NULL ${NULL-0 /* default */}
                    316: #define ${macro_prefix}ARGS(ARGLIST) (...)
                    317: !EOF!
                    318: 
                    319: rm -f dummy.c dummy.o
                    320: 
                    321: if test -n "${HAVE_ATEXIT}" ; then
                    322:  echo "#define ${macro_prefix}HAVE_ATEXIT ${HAVE_ATEXIT}"
                    323: else
                    324:   cat >dummy.c <<!EOF!
                    325: #include <stdlib.h>
                    326: int main()
                    327: {
                    328:   atexit (0);
                    329: }
                    330: !EOF!
                    331:   if ${CC} dummy.c >/dev/null 2>&1 ; then
                    332:     echo "#define ${macro_prefix}HAVE_ATEXIT 1"
                    333:   else
                    334:     echo "#define ${macro_prefix}HAVE_ATEXIT 0"
                    335:   fi
                    336: fi
                    337: 
                    338: 
                    339: # *** Check for presence of certain include files ***
                    340: 
                    341: # check for sys/resource.h
                    342: 
                    343: if test -n "${HAVE_SYS_RESOURCE}" ; then
                    344:  echo "#define ${macro_prefix}HAVE_SYS_RESOURCE ${HAVE_SYS_RESOURCE}"
                    345: else
                    346:   cat >dummy.c <<!EOF!
                    347: #include <sys/time.h>
                    348: #include <sys/resource.h>
                    349:   int main()
                    350:   {
                    351:     struct rusage res;
                    352:     getrusage(RUSAGE_SELF, &res);
                    353:     return (int)(res.ru_utime.tv_sec + (res.ru_utime.tv_usec / 1000000.0));
                    354:   }
                    355: !EOF!
                    356:   # Note: We link because some systems have sys/resource, but not getrusage().
                    357:   if ${CC} dummy.c >/dev/null 2>&1 ; then
                    358:     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 1"
                    359:   else
                    360:     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 0"
                    361:   fi
                    362: fi
                    363: 
                    364: # check for sys/socket.h
                    365: 
                    366: if test -n "${HAVE_SYS_SOCKET}" ; then
                    367:  echo "#define ${macro_prefix}HAVE_SYS_SOCKET ${HAVE_SYS_SOCKET}"
                    368: else
                    369:   echo '#include <sys/types.h>' >dummy.c
                    370:   echo '#include <sys/socket.h>' >>dummy.c
                    371:   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
                    372:     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 1"
                    373:   else
                    374:     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 0"
                    375:   fi
                    376: fi
                    377: 
                    378: # Check for a (Posix-compatible) sys/wait.h */
                    379: 
                    380: if test -n "${HAVE_SYS_WAIT}" ; then
                    381:  echo "#define ${macro_prefix}HAVE_SYS_WAIT ${HAVE_SYS_WAIT}"
                    382: else
                    383:   cat >dummy.C <<!EOF!
                    384:   extern "C" {
                    385: #include <sys/types.h>
                    386: #include <sys/wait.h>
                    387:   }
                    388:   int f() { int i; wait(&i); return i; }
                    389: !EOF!
                    390: #define ${macro_prefix}HAVE_UNION_WAIT 1"
                    391:   if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
                    392:     echo "#define ${macro_prefix}HAVE_SYS_WAIT 1"
                    393:   else
                    394:     echo "#define ${macro_prefix}HAVE_SYS_WAIT 0"
                    395:   fi
                    396: fi
                    397: 
                    398: if test -n "${HAVE_UNISTD}" ; then
                    399:  echo "#define ${macro_prefix}HAVE_UNISTD ${HAVE_UNISTD}"
                    400: else
                    401:   echo '#include <unistd.h>' >dummy.c
                    402:   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
                    403:     echo "#define ${macro_prefix}HAVE_UNISTD 1"
                    404:   else
                    405:     echo "#define ${macro_prefix}HAVE_UNISTD 0"
                    406:   fi
                    407: fi
                    408: 
                    409: if test -n "${HAVE_DIRENT}" ; then
                    410:  echo "#define ${macro_prefix}HAVE_DIRENT ${HAVE_DIRENT}"
                    411: else
                    412:   echo '#include <sys/types.h>
                    413: #include <dirent.h>' >dummy.c
                    414:   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
                    415:     echo "#define ${macro_prefix}HAVE_DIRENT 1"
                    416:   else
                    417:     echo "#define ${macro_prefix}HAVE_DIRENT 0"
                    418:   fi
                    419: fi
                    420: 
                    421: if test -n "${HAVE_CURSES}" ; then
                    422:  echo "#define ${macro_prefix}HAVE_CURSES ${HAVE_CURSES}"
                    423: else
                    424:   echo '#include <curses.h>' >dummy.c
                    425:   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
                    426:     echo "#define ${macro_prefix}HAVE_CURSES 1"
                    427:   else
                    428:     echo "#define ${macro_prefix}HAVE_CURSES 0"
                    429:   fi
                    430: fi
                    431: 
                    432: # There is no test for this at the moment; it is just set by the
                    433: # configuration files.
                    434: if test -n "${MATH_H_INLINES}" ; then
                    435:   echo "#define ${macro_prefix}MATH_H_INLINES ${MATH_H_INLINES}"
                    436: else
                    437:   echo "#define ${macro_prefix}MATH_H_INLINES 0"
                    438: fi
                    439: 
                    440: # Uncomment the following line if you don't have working templates.
                    441: # echo "#define ${macro_prefix}NO_TEMPLATES"
                    442: 
                    443: rm -f dummy.C dummy.o dummy.c dummy.out TMP core a.out
                    444: 
                    445: echo "#endif /* !${macro_prefix}config_h */"

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.