OSDN Git Service

* lex.c (lang_init_options): New function.
[pf3gnuchains/gcc-fork.git] / gcc / fixincludes
index af03dfb..b795a94 100755 (executable)
@@ -12,6 +12,14 @@ INPUT=${2-${INPUT-/usr/include}}
 # Directory in which to store the results.
 LIB=${1?"fixincludes: output directory not specified"}
 
+# Define what target system we're fixing.
+if test -r ./Makefile; then
+       target_canonical="`sed -n -e 's,^target[        ]*=[    ]*\(.*\)$,\1,p' < Makefile`"
+       test -z "${target_canonical}" && target_canonical=unknown
+else
+       target_canonical=unknown
+fi
+
 # Define PWDCMD as a command to use to get the working dir
 # in the form that we want.
 PWDCMD=pwd
@@ -244,9 +252,10 @@ while [ $# != 0 ]; do
 # But the argument to egrep must be kept small, or many versions of egrep
 # won't be able to handle it.
 #
-# We use the pattern [!-.0-~] instead of [^/   ] to match a noncomment
+# We use the pattern [!-.0-z{|}~] instead of [^/       ] to match a noncomment
 # following #else or #endif because some buggy egreps think [^/] matches
 # newline, and they thus think `#else ' matches `#e[ndiflse]*[         ]+[^/   ]'.
+# [!-.0-~] does not work properly on AIX 4.1.
 #
 # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
 # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
@@ -255,7 +264,7 @@ while [ $# != 0 ]; do
 # identifiers below start with `d' or `l'.  It also greatly improves
 # performance, since many files contain lines of the form `#if ... defined ...'
 # or `#if lint'.
-    if egrep '//|[     _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-zA-Z][a-zA-Z0-9]' $file >/dev/null; then
+    if egrep '//|[     _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-z\{\|\}\~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-zA-Z][a-zA-Z0-9]' $file >/dev/null; then
       if [ -r $file ]; then
        cp $file $2/$file >/dev/null 2>&1       \
        || echo "Can't copy $file"
@@ -281,6 +290,7 @@ while [ $# != 0 ]; do
          s%^\([        ]*#[    ]*endif\)[      ]*\*[^/].*%\1%
          s%^\([        ]*#[    ]*endif\)[      ]*[^/*  ].*%\1%
          /\/\/[^*]/                    s|//\(.*\)$|/*\1*/|
+         /^[   ]*\/\/[         ]*/s///
          /[    ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[  ]*(\)\(.\),/\1'\''\2'\'',/
          /[    ]BSD43__IO[A-Z]*[       ]*(/    s/(\(.\),/('\''\1'\'',/
          /#[   ]*define[       ]*[     ]_IO/                   s/'\''\([cgxtf]\)'\''/\1/g
@@ -358,6 +368,13 @@ for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
   if [ -r ${LIB}/$file ]; then
     echo Fixing size_t, ptrdiff_t and wchar_t in $file
     sed \
+      -e '/^[  ]*\*[   ]*typedef unsigned int size_t;/N'       \
+      -e 's/^\([       ]*\*[   ]*typedef unsigned int size_t;\n[       ]*\*\/\)/\1\
+#ifndef __SIZE_TYPE__\
+#define __SIZE_TYPE__ long unsigned int\
+#endif\
+typedef __SIZE_TYPE__ size_t;\
+/'     \
       -e '/typedef[    ][      ]*[a-z_][       a-z_]*[         ]size_t/i\
 #ifndef __SIZE_TYPE__\
 #define __SIZE_TYPE__ long unsigned int\
@@ -394,6 +411,37 @@ for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
   fi
 done
 
+# Fix #defines under Alpha OSF/1:
+# The following files contain '#pragma extern_prefix "_FOO"' followed by
+# a '#define something(x,y,z) _FOOsomething(x,y,z)'.  The intent of these
+# statements is to reduce namespace pollution.  While these macros work
+# properly in most cases, they don't allow you to take a pointer to the
+# "something" being modified.  To get around this limitation, change these
+# statements to be of the form '#define something _FOOsomething'.
+for file in libgen.h dirent.h ftw.h grp.h ndbm.h pthread.h pwd.h signal.h standards.h stdlib.h string.h stropts.h time.h unistd.h
+do
+  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
+    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
+    chmod +w ${LIB}/$file 2>/dev/null
+    chmod a+r ${LIB}/$file 2>/dev/null
+  fi
+
+  if [ -r ${LIB}/$file ]; then
+    echo Fixing $file extern_prefix
+    sed -e 's/^[       ]*#[    ]*define[       ]*\([^(]*\)\(([^)]*)\)[         ]*\(_.\)\1\2[   ]*$/#define \1 \3\1/' ${LIB}/$file > ${LIB}/${file}.sed
+    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
+    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
+      rm ${LIB}/$file
+    else
+      # Find any include directives that use "file".
+      for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
+       dir=`echo $file | sed -e s'|/[^/]*$||'`
+       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
+      done
+    fi
+  fi
+done
 # Fix one other error in this file: a mismatched quote not inside a C comment.
 file=sundev/vuid_event.h
 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
@@ -907,17 +955,21 @@ fi
 
 if [ -r ${LIB}/$file ]; then
   echo Fixing $file
+  if grep _GCC_SIZE_T ${LIB}/$file >/dev/null
+  then size_t_pattern='<<< do not double-wrap the size_t typedef >>>'
+  else size_t_pattern='typedef[        a-zA-Z_]*[      ]size_t[        ]*;'
+  fi
   sed -e 's/int        abort/void      abort/g' \
   -e 's/int    free/void       free/g' \
   -e 's/char[  ]*\*[   ]*calloc/void \*        calloc/g' \
   -e 's/char[  ]*\*[   ]*malloc/void \*        malloc/g' \
   -e 's/char[  ]*\*[   ]*realloc/void \*       realloc/g' \
   -e 's/int[   ][      ]*exit/void     exit/g' \
-  -e '/typedef[        a-zA-Z_]*[      ]size_t[        ]*;/i\
+  -e "/$size_t_pattern/"'i\
 #ifndef _GCC_SIZE_T\
 #define _GCC_SIZE_T
 ' \
-  -e '/typedef[        a-zA-Z_]*[      ]size_t[        ]*;/a\
+  -e "/$size_t_pattern/"'a\
 #endif
 ' \
       ${LIB}/$file > ${LIB}/${file}.sed
@@ -1114,7 +1166,7 @@ if [ -r ${LIB}/$file ]; then
   fi
 fi
 
-# And also with the HP-UX 10 sys/pci.h file
+# And also with the HP-UX 10 and HP-UX 11 sys/pci.h file
 file=sys/pci.h
 if [ -r ${LIB}/$file ]; then
   if egrep 'System Private Structures' ${LIB}/$file > /dev/null; then
@@ -1126,6 +1178,48 @@ if [ -r ${LIB}/$file ]; then
   fi
 fi
 
+# And also with a few more HP-UX 11 headers which are only broken
+# after they are "fixed".
+file=sys/ki_iface.h
+if [ -r ${LIB}/$file ]; then
+  if egrep 'These definitions are for HP Internal developers' ${LIB}/$file > /dev/null; then
+    echo Fixing $file, overeager sed script
+    rm ${LIB}/$file
+  fi
+fi
+
+file=sys/ki.h
+if [ -r ${LIB}/$file ]; then
+  if egrep '11.00 HP-UX LP64' ${LIB}/$file > /dev/null; then
+    echo Fixing $file, overeager sed script
+    rm ${LIB}/$file
+  fi
+fi
+
+file=sys/ki_calls.h
+if [ -r ${LIB}/$file ]; then
+  if egrep 'KI_MAX_PROCS is an arbitrary number' ${LIB}/$file > /dev/null; then
+    echo Fixing $file, overeager sed script
+    rm ${LIB}/$file
+  fi
+fi
+
+file=sys/ki_defs.h
+if [ -r ${LIB}/$file ] ; then
+  if egrep 'Kernel Instrumentation Definitions' ${LIB}/$file > /dev/null; then
+    echo Fixing $file, overeager sed script
+    rm ${LIB}/$file
+  fi
+fi
+
+file=sys/time.h
+if [ -r ${LIB}/$file ] ; then
+  if egrep 'For CASPEC, look in' ${LIB}/$file > /dev/null; then
+    echo Fixing $file, overeager sed script
+    rm ${LIB}/$file
+  fi
+fi
+
 # Some IRIX header files contains the string "//"
 for file in elf_abi.h elf.h; do
   if [ -r ${LIB}/$file ]; then
@@ -1841,6 +1935,7 @@ fi
 # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
 # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
 # are there, and we do not add them ourselves.
+# Also fix a nested comment problem in sys/limits.h on Motorola sysV68 R3V7.1
 for file in limits.h sys/limits.h; do
   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
     mkdir ${LIB}/sys 2>/dev/null
@@ -1890,6 +1985,7 @@ for file in limits.h sys/limits.h; do
          -e '/[        ]DBL_DIG[       ]/a\
 #endif
 '\
+         -e '/^\(\/\*#define   HUGE_VAL        3\.[0-9e+]* *\)\/\*/s//\1/'\
        ${LIB}/$file > ${LIB}/${file}.sed
       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
     fi
@@ -1983,6 +2079,7 @@ fi
 # Correct the return type for strlen in string.h on Lynx.
 # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
 # Add missing const for strdup on OSF/1 V3.0.
+# On sysV88 layout is slightly different.
 file=string.h
 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
@@ -2001,6 +2098,8 @@ if [ -r ${LIB}/$file ]; then
       -e 's/^\(        strncmp()\),\n\(        strlen(),\)$/\1;\
 extern unsigned int\
 \2/'\
+      -e '/^extern int$/N'\
+      -e 's/^extern int\(\n    strlen(),\)/extern size_t\1/' \
     ${LIB}/$file > ${LIB}/${file}.sed
   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
@@ -2148,6 +2247,31 @@ if [ -r ${LIB}/$file ]; then
   fi
 fi
 
+# Fix nested comments in Motorola's <limits.h> and <sys/limits.h>
+for file in limits.h sys/limits.h; do
+  if [ $target_canonical = m88k-motorola-sysv3 -o \
+       $target_canonical = m68k-motorola-sysv ]; then
+
+    if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
+      cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
+      chmod +w ${LIB}/$file 2>/dev/null
+      chmod a+r ${LIB}/$file 2>/dev/null
+    fi
+
+    if [ -r ${LIB}/$file ]; then
+      echo "Fixing nested comments in Motorola's $file"
+      sed \
+        -e 's@^\(#undef[       ][      ]*PIPE_BUF[     ]*/\* max # bytes atomic in write to a\)$@\1 */@' \
+        -e 's@\(/\*#define     HUGE_VAL        3.40282346638528860e+38 \)\(/\*error value returned by Math lib\*/\)$@\1*/ \2@' \
+         < ${LIB}/$file > ${LIB}/${file}.sed
+      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
+      if cmp $file ${LIB}/$file >/dev/null 2>&1; then
+        rm -f ${LIB}/$file
+      fi
+    fi
+  fi
+done
+
 # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
 for file in stdio.h stdlib.h; do
   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
@@ -2286,6 +2410,45 @@ do
   fi
 done
 
+# libm.a on m88k-motorola-sysv3 contains a stupid optimization for function
+# hypot(), which returns the second argument without even looking at its value
+# if the other is 0.0
+# Another drawback is that fix-header doesn't fix fabs' prototype, and I have
+#  no idea why.
+file=math.h
+if [ $target_canonical = m88k-motorola-sysv3 ]; then
+  if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
+    cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
+    chmod +w ${LIB}/$file 2>/dev/null
+    chmod a+r ${LIB}/$file 2>/dev/null
+  fi
+
+  if [ -r ${LIB}/$file ]; then
+    echo Fixing $file, fabs/hypot definition
+    sed \
+      -e 's/extern double floor(), ceil(), fmod(), fabs();/extern double floor(), ceil(), fmod(), fabs _PARAMS((double));/' \
+      -e '/^extern double hypot();$/a\
+\/* Workaround a stupid Motorola optimization if one\
+   of x or y is 0.0 and the other is negative!  *\/\
+#ifdef __STDC__\
+static __inline__ double fake_hypot (double x, double y)\
+#else\
+static __inline__ double fake_hypot (x, y)\
+       double x, y;\
+#endif\
+{\
+       return fabs (hypot (x, y));\
+}\
+#define hypot  fake_hypot
+' \
+      ${LIB}/$file > ${LIB}/${file}.sed
+    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
+    if cmp $file ${LIB}/$file >/dev/null 2>&1; then
+      rm -f ${LIB}/$file
+    fi
+  fi
+fi
+
 # math.h on SunOS 4 puts the declaration of matherr before the definition
 # of struct exception, so the prototype (added by fixproto) causes havoc.
 file=math.h
@@ -2314,9 +2477,9 @@ struct exception;
   fi
 fi
 
-# assert.h and sys/mman.h on HP/UX are not C++ ready, even though
+# sys/mman.h on HP/UX is not C++ ready, even though
 # NO_IMPLICIT_EXTERN_C is defined on HP/UX.
-for file in assert.h sys/mman.h; do
+for file in sys/mman.h; do
   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
     chmod +w ${LIB}/$file 2>/dev/null
@@ -2350,45 +2513,6 @@ extern "C" {
   fi
 done
 
-# check for broken assert.h that needs stdio.h or stdlib.h
-file=assert.h
-if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
-  cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
-  chmod +w ${LIB}/$file 2>/dev/null
-  chmod a+r ${LIB}/$file 2>/dev/null
-fi
-
-if [ -r ${LIB}/$file ]; then
-  if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
-    if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
-      true
-    else
-      echo "Fixing $file (needs stdio.h)"
-      echo '#include <stdio.h>' >>${LIB}/$file
-    fi
-  fi
-  if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
-     grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
-    if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
-      true
-    else
-      echo "Fixing $file (needs stdlib.h)"
-      echo '#ifdef __cplusplus
-#include <stdlib.h>
-#endif' >>${LIB}/$file
-    fi
-  fi
-  if cmp $file ${LIB}/$file >/dev/null 2>&1; then
-    rm -f ${LIB}/$file
-  else
-    # Find any include directives that use "file".
-    for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
-      dir=`echo $file | sed -e s'|/[^/]*$||'`
-      required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
-    done
-  fi
-fi
-
 # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
 file=unistd.h
 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
@@ -2765,21 +2889,25 @@ if [ -r ${LIB}/$file ]; then
   sed -e '/struct exception/i\
 #ifdef __cplusplus\
 #define exception __math_exception\
-#endif'\
+#endif
+'\
       -e '/struct exception/a\
 #ifdef __cplusplus\
 #undef exception\
-#endif' ${LIB}/$file > ${LIB}/${file}.sed
+#endif
+' ${LIB}/$file > ${LIB}/${file}.sed
   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
   if egrep 'matherr()' ${LIB}/$file >/dev/null 2>&1; then
     sed -e '/matherr/i\
 #ifdef __cplusplus\
 #define exception __math_exception\
-#endif'\
+#endif
+'\
         -e '/matherr/a\
 #ifdef __cplusplus\
 #undef exception\
-#endif' ${LIB}/$file > ${LIB}/${file}.sed
+#endif
+' ${LIB}/$file > ${LIB}/${file}.sed
     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
   fi
   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
@@ -2824,7 +2952,7 @@ if [ -r ${LIB}/$file ]; then
 fi
 
 # sys/lc_core.h on some versions of OSF1/4.x pollutes the namespace by
-# defining regex.h related types.  This causes libg++ build and usage failures.
+# defining regex.h types.  This causes C++ library build and usage failures.
 # Fixing this correctly requires checking and modifying 3 files.
 for file in reg_types.h regex.h sys/lc_core.h; do
   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
@@ -2916,10 +3044,10 @@ else
 fi
 if [ \! -z "$file_to_fix" ]; then
   echo Checking $file_to_fix
-  sed -e '/[  ]MAXINT[        ]/i\
+  sed -e '/^#[         ]*define[       ]*MAXINT[       ]/i\
 #ifndef MAXINT
 '\
-      -e '/[  ]MAXINT[        ]/a\
+      -e '/^#[         ]*define[       ]*MAXINT[       ]/a\
 #endif
 ' $file_to_fix > /tmp/$base
   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \