OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [scan-types.sh] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
#! /bin/sh
#! /bin/sh
# Deduce values of standard ANSI and POSIX types (e.g. size_t, pid_t).
# Deduce values of standard ANSI and POSIX types (e.g. size_t, pid_t).
# Emits macros definitions for these, and some other types.
# Emits macros definitions for these, and some other types.
# Intended to be used to massage the sys-protos.h file.
# Intended to be used to massage the sys-protos.h file.
# Expects one arg, which is the GCC source directory.
# Expects one arg, which is the GCC source directory.
 
 
CC=${CC-"./xgcc -B$1/"}
CC=${CC-"./xgcc -B$1/"}
CPP=${CPP-`echo ${CC} -E -I"$1/"`}
CPP=${CPP-`echo ${CC} -E -I"$1/"`}
SED=sed
SED=sed
 
 
# Generate definitions for the standard types (such as mode_t)
# Generate definitions for the standard types (such as mode_t)
# compatible with those in the standard C header files.
# compatible with those in the standard C header files.
# It works by a dummy program through the C pre-processor, and then
# It works by a dummy program through the C pre-processor, and then
# using sed to search for typedefs in the output.
# using sed to search for typedefs in the output.
 
 
cat >st-dummy.c <<!EOF!
cat >st-dummy.c <<!EOF!
#include <sys/types.h>
#include <sys/types.h>
#include <stddef.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <time.h>
#include <time.h>
#include <signal.h>
#include <signal.h>
#ifdef size_t
#ifdef size_t
typedef size_t Xsize_t;
typedef size_t Xsize_t;
#elif defined(__SIZE_TYPE__)
#elif defined(__SIZE_TYPE__)
typedef __SIZE_TYPE__ Xsize_t;
typedef __SIZE_TYPE__ Xsize_t;
#endif
#endif
#ifdef va_list
#ifdef va_list
typedef va_list XXXva_list;
typedef va_list XXXva_list;
#endif
#endif
!EOF!
!EOF!
 
 
if ${CPP} st-dummy.c >TMP ; then true
if ${CPP} st-dummy.c >TMP ; then true
else
else
  echo "scan-types: could not invoke ${CPP} on st-dummy.c" 1>&2 ; exit 1
  echo "scan-types: could not invoke ${CPP} on st-dummy.c" 1>&2 ; exit 1
fi
fi
tr '    ' ' ' <TMP >st-dummy.out
tr '    ' ' ' <TMP >st-dummy.out
 
 
for TYPE in dev_t clock_t fpos_t gid_t ino_t mode_t nlink_t off_t pid_t size_t ssize_t time_t uid_t va_list int32_t uint_32_t ; do
for TYPE in dev_t clock_t fpos_t gid_t ino_t mode_t nlink_t off_t pid_t size_t ssize_t time_t uid_t va_list int32_t uint_32_t ; do
    IMPORTED=`eval 'echo $'"$TYPE"`
    IMPORTED=`eval 'echo $'"$TYPE"`
    if [ -n "${IMPORTED}" ] ; then
    if [ -n "${IMPORTED}" ] ; then
        eval "$TYPE='$IMPORTED"
        eval "$TYPE='$IMPORTED"
    else
    else
        # Search st-dummy.out for a typedef for $TYPE, and write it out
        # Search st-dummy.out for a typedef for $TYPE, and write it out
        # to TMP in #define syntax.
        # to TMP in #define syntax.
        rm -f TMP
        rm -f TMP
        ${SED} -n -e "s|.*typedef  *\(.*\) X*$TYPE *;.*|\1|w TMP" <st-dummy.out>/dev/null
        ${SED} -n -e "s|.*typedef  *\(.*\) X*$TYPE *;.*|\1|w TMP" <st-dummy.out>/dev/null
        # Now select the first definition.
        # Now select the first definition.
        if [ -s TMP ]; then
        if [ -s TMP ]; then
            # VALUE is now the typedef'd definition of $TYPE.
            # VALUE is now the typedef'd definition of $TYPE.
            eval "VALUE='`${SED} -e 's| *$||' -e '2,$d' <TMP`'"
            eval "VALUE='`${SED} -e 's| *$||' -e '2,$d' <TMP`'"
            # Unless VALUE contains a blank, look for a typedef for it
            # Unless VALUE contains a blank, look for a typedef for it
            # in turn (this could be a loop, but that would be over-kill).
            # in turn (this could be a loop, but that would be over-kill).
            # Ensure $VALUE is double quoted to protect cases where it
            # Ensure $VALUE is double quoted to protect cases where it
            # contains an asterisk and would cause filename expansion.
            # contains an asterisk and would cause filename expansion.
            # E.g. when va_list is "char *".
            # E.g. when va_list is "char *".
            if echo "$VALUE" | grep " " >/dev/null ; then true
            if echo "$VALUE" | grep " " >/dev/null ; then true
            else
            else
                rm -f TMP
                rm -f TMP
                ${SED} -n -e "s|.*typedef[      ][      ]*\(.*[^a-zA-Z0-9_]\)${VALUE}[  ]*;.*|\1|w TMP" <st-dummy.out>/dev/null
                ${SED} -n -e "s|.*typedef[      ][      ]*\(.*[^a-zA-Z0-9_]\)${VALUE}[  ]*;.*|\1|w TMP" <st-dummy.out>/dev/null
                if [ -s TMP ]; then
                if [ -s TMP ]; then
                    eval "VALUE='`${SED} -e '2,$d' -e 's|[      ]*$||' <TMP`'"
                    eval "VALUE='`${SED} -e '2,$d' -e 's|[      ]*$||' <TMP`'"
                fi
                fi
            fi
            fi
            eval "$TYPE='$VALUE'"
            eval "$TYPE='$VALUE'"
        fi
        fi
    fi
    fi
done
done
 
 
cat <<!EOF!
cat <<!EOF!
#define ${macro_prefix}clock_t ${clock_t-int /* default */}
#define ${macro_prefix}clock_t ${clock_t-int /* default */}
#define ${macro_prefix}dev_t ${dev_t-int /* default */}
#define ${macro_prefix}dev_t ${dev_t-int /* default */}
#define ${macro_prefix}fpos_t ${fpos_t-long /* default */}
#define ${macro_prefix}fpos_t ${fpos_t-long /* default */}
#define ${macro_prefix}gid_t ${gid_t-int /* default */}
#define ${macro_prefix}gid_t ${gid_t-int /* default */}
#define ${macro_prefix}ino_t ${ino_t-int /* default */}
#define ${macro_prefix}ino_t ${ino_t-int /* default */}
#define ${macro_prefix}mode_t ${mode_t-int /* default */}
#define ${macro_prefix}mode_t ${mode_t-int /* default */}
#define ${macro_prefix}nlink_t ${nlink_t-int /* default */}
#define ${macro_prefix}nlink_t ${nlink_t-int /* default */}
#define ${macro_prefix}off_t ${off_t-long /* default */}
#define ${macro_prefix}off_t ${off_t-long /* default */}
#define ${macro_prefix}pid_t ${pid_t-int /* default */}
#define ${macro_prefix}pid_t ${pid_t-int /* default */}
#define ${macro_prefix}ptrdiff_t __PTRDIFF_TYPE__
#define ${macro_prefix}ptrdiff_t __PTRDIFF_TYPE__
#define ${macro_prefix}size_t __SIZE_TYPE__
#define ${macro_prefix}size_t __SIZE_TYPE__
#define ${macro_prefix}time_t ${time_t-int /* default */}
#define ${macro_prefix}time_t ${time_t-int /* default */}
#define ${macro_prefix}uid_t ${uid_t-int /* default */}
#define ${macro_prefix}uid_t ${uid_t-int /* default */}
#define ${macro_prefix}wchar_t __WCHAR_TYPE__
#define ${macro_prefix}wchar_t __WCHAR_TYPE__
#define ${macro_prefix}int32_t ${int32_t-int /* default */}
#define ${macro_prefix}int32_t ${int32_t-int /* default */}
#define ${macro_prefix}uint32_t ${uint32_t-unsigned int /* default */}
#define ${macro_prefix}uint32_t ${uint32_t-unsigned int /* default */}
!EOF!
!EOF!
 
 
# (wait_arg_t*) should be (int*), according to Posix, but
# (wait_arg_t*) should be (int*), according to Posix, but
# BSD traditionally used (union wait*).  Use (void*) to allow either usage.
# BSD traditionally used (union wait*).  Use (void*) to allow either usage.
echo "#define ${macro_prefix}wait_arg_t void"
echo "#define ${macro_prefix}wait_arg_t void"
 
 
# ssize_t is the signed version of size_t
# ssize_t is the signed version of size_t
if [ -n "${ssize_t}" ] ; then
if [ -n "${ssize_t}" ] ; then
    echo "#define ${macro_prefix}ssize_t ${ssize_t}"
    echo "#define ${macro_prefix}ssize_t ${ssize_t}"
elif [ -z "${size_t}" ] ; then
elif [ -z "${size_t}" ] ; then
    echo "#define ${macro_prefix}ssize_t long"
    echo "#define ${macro_prefix}ssize_t long"
else
else
    # Remove "unsigned" from ${size_t} to get ${ssize_t}.
    # Remove "unsigned" from ${size_t} to get ${ssize_t}.
    tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's|  | |g'`"
    tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's|  | |g'`"
    if [ -z "$tmp" ] ; then
    if [ -z "$tmp" ] ; then
        tmp=int
        tmp=int
    else
    else
        # check $tmp doesn't conflict with <unistd.h>
        # check $tmp doesn't conflict with <unistd.h>
        echo "#include <unistd.h>
        echo "#include <unistd.h>
        extern $tmp read();" >st-dummy.c
        extern $tmp read();" >st-dummy.c
        ${CC} -c st-dummy.c >/dev/null 2>&1 || tmp=int
        ${CC} -c st-dummy.c >/dev/null 2>&1 || tmp=int
    fi
    fi
    echo "#define ${macro_prefix}ssize_t $tmp /* default */"
    echo "#define ${macro_prefix}ssize_t $tmp /* default */"
fi
fi
 
 
# va_list can cause problems (e.g. some systems have va_list as a struct).
# va_list can cause problems (e.g. some systems have va_list as a struct).
# Check to see if ${va_list-char*} really is compatible with stdarg.h.
# Check to see if ${va_list-char*} really is compatible with stdarg.h.
cat >st-dummy.c <<!EOF!
cat >st-dummy.c <<!EOF!
#define X_va_list ${va_list-char* /* default */}
#define X_va_list ${va_list-char* /* default */}
extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
#include <stdarg.h>
#include <stdarg.h>
long foo(X_va_list ap) { return va_arg(ap, long); }
long foo(X_va_list ap) { return va_arg(ap, long); }
long bar(int i, ...)
long bar(int i, ...)
{ va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
{ va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
!EOF!
!EOF!
if ${CC} -c st-dummy.c >/dev/null 2>&1 ; then
if ${CC} -c st-dummy.c >/dev/null 2>&1 ; then
  # Ok: We have something that works.
  # Ok: We have something that works.
  echo "#define ${macro_prefix}va_list ${va_list-char* /* default */}"
  echo "#define ${macro_prefix}va_list ${va_list-char* /* default */}"
else
else
  # No, it breaks.  Indicate that <stdarg.h> must be included.
  # No, it breaks.  Indicate that <stdarg.h> must be included.
  echo "#define ${macro_prefix}NEED_STDARG_H
  echo "#define ${macro_prefix}NEED_STDARG_H
#define ${macro_prefix}va_list va_list"
#define ${macro_prefix}va_list va_list"
fi
fi
 
 
# stuff needed for curses.h
# stuff needed for curses.h
 
 
# This isn't correct for SVR4 (for example).  However, we only
# This isn't correct for SVR4 (for example).  However, we only
# use this when adding a missing prototype, so it shouldn't matter.
# use this when adding a missing prototype, so it shouldn't matter.
echo "#define chtype int"
echo "#define chtype int"
# sys-protos.h uses non-standard names (due to the CHTYPE argument problem).
# sys-protos.h uses non-standard names (due to the CHTYPE argument problem).
echo "#define box32 box"
echo "#define box32 box"
echo "#define initscr32 initscr"
echo "#define initscr32 initscr"
echo "#define w32addch waddch"
echo "#define w32addch waddch"
echo "#define w32insch winsch"
echo "#define w32insch winsch"
 
 
rm -f st-dummy.c st-dummy.o TMP st-dummy.out
rm -f st-dummy.c st-dummy.o TMP st-dummy.out
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.