OSDN Git Service

(handle_braces): Rework last change.
[pf3gnuchains/gcc-fork.git] / gcc / fixincludes
index 8a4ba5d..2df5a45 100755 (executable)
@@ -75,14 +75,11 @@ do
     for d in $dirs
     do
        echo " Searching $INPUT/$d"
-       if [ "$d" != . ]
-       then
-           d=$d/.
-       fi
 
        # Find all directories under $d, relative to $d, excluding $d itself.
-        files="$files `find $d -type d -print | \
-                      sed -e '/\/\.$/d' -e '/^\.$/d'`"
+       # (The /. is needed after $d in case $d is a symlink.)
+        files="$files `find $d/. -type d -print | \
+                      sed -e '/\/\.$/d' -e 's@/./@/@g'`"
        # Find all links to directories.
        # Using `-exec test -d' in find fails on some systems,
        # and trying to run test via sh fails on others,
@@ -90,7 +87,7 @@ do
        # First find all the links, then test each one.
        theselinks=
        $LINKS && \
-         theselinks=`find $d -type l -print`
+         theselinks=`find $d/. -type l -print | sed -e 's@/./@/@g'`
        for d1 in $theselinks --dummy--
        do
            # If the link points to a directory,
@@ -185,7 +182,7 @@ if $LINKS; then
          # root area.
          for file2 in $files; do
            case $file2 in
-             $file/./*)
+             $file/*)
                dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
                echo "Duplicating ${file}'s ${dupdir}"
                if [ -d ${dupdir} ]
@@ -264,6 +261,8 @@ while [ $# != 0 ]; do
        || echo "Can't copy $file"
        chmod +w $2/$file
        chmod a+r $2/$file
+       # The fixinc_eol stuff is to work around a bug in the sed
+       # program on HP/UX 10.20.
        # Here is how the sed commands in braces work.
        # (It doesn't work to put the comments inside the sed commands.)
                # Surround each word with spaces, to simplify matching below.
@@ -273,7 +272,9 @@ while [ $# != 0 ]; do
        sed -e '
                                   :loop
          /\\$/                 N
+         s/\\$/\\*fixinc_eol*/
          /\\$/                 b loop
+         s/\\\*fixinc_eol\*/\\/g
          s%^\([        ]*#[    ]*else\)[       ]*/[^*].*%\1%
          s%^\([        ]*#[    ]*else\)[       ]*[^/   ].*%\1%
          s%^\([        ]*#[    ]*endif\)[      ]*/[^*].*%\1%
@@ -1325,7 +1326,7 @@ if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
 fi
 
 if [ -r ${LIB}/$file ]; then
-  if grep 'class[(]' ${LIB}/$file >/dev/null; then
+  if grep '[^a-zA-Z_]class[(]' ${LIB}/$file >/dev/null; then
     echo Fixing $file
     sed -e '/class[(]/i\
 #ifndef __cplusplus
@@ -1786,7 +1787,6 @@ fi
 # rpc/types.h on OSF1/2.0 is not C++ ready, even though NO_IMPLICIT_EXTERN_C
 # is defined for the alpha.  The problem is the declaration of malloc.
 file=rpc/types.h
-ls -l $file ${LIB}/$file
 if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
   mkdir ${LIB}/rpc 2>/dev/null
   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
@@ -2082,13 +2082,17 @@ for files in curses.h; do
 
     echo Fixing $file
     sed -e '/^#[       ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/i\
-#ifndef __cplusplus'\
+#ifndef __cplusplus
+'\
        -e '/^#[        ]*define[       ][      ]*bool[         ][      ]*char[         ]*$/a\
-#endif'\
+#endif
+'\
        -e '/^typedef[  ][      ]*char[         ][      ]*bool[         ]*;/i\
-#ifndef __cplusplus'\
+#ifndef __cplusplus
+'\
        -e '/^typedef[  ][      ]*char[         ][      ]*bool[         ]*;/a\
-#endif'\
+#endif
+'\
        ${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
@@ -2153,6 +2157,33 @@ for file in stdio.h stdlib.h; do
   fi
 done
 
+# Fix __page_size* declarations in pthread.h AIX 4.1.[34].
+# The original ones fail if uninitialized externs are not common.
+# This is the default for all ANSI standard C++ compilers.
+for file in pthread.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, __page_size* declarations
+    sed -e 's/^int __page_size/extern int __page_size/' \
+      ${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
+    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
+
 # Determine if we're on Interactive Unix 2.2 or later, in which case we
 # need to fix some additional files.  This is the same test for ISC that
 # Autoconf uses.
@@ -2267,40 +2298,41 @@ struct exception;
   fi
 fi
 
-# assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
-# is defined on HP/UX.
-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
+# assert.h and sys/mman.h on HP/UX are not C++ ready, even though
+# NO_IMPLICIT_EXTERN_C is defined on HP/UX.
+for file in assert.h 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
+    chmod a+r ${LIB}/$file 2>/dev/null
+  fi
 
-if [ -r ${LIB}/$file ]; then
-  if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
-     || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
-    true
-  else
-    echo Fixing $file
-    echo '#ifdef __cplusplus
+  if [ -r ${LIB}/$file ]; then
+    if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
+       || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
+      true
+    else
+      echo Fixing $file
+      echo '#ifdef __cplusplus
 extern "C" {
 #endif' > ${LIB}/${file}.sed
-    cat ${LIB}/${file} >> ${LIB}/${file}.sed
-    echo '#ifdef __cplusplus
+      cat ${LIB}/${file} >> ${LIB}/${file}.sed
+      echo '#ifdef __cplusplus
 }
 #endif' >> ${LIB}/${file}.sed 
-    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
+      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
+    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"
+       dir=`echo $file | sed -e s'|/[^/]*$||'`
+       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
       done
     fi
   fi
-fi
+done
 
 # check for broken assert.h that needs stdio.h or stdlib.h
 file=assert.h
@@ -2316,9 +2348,7 @@ if [ -r ${LIB}/$file ]; then
       true
     else
       echo "Fixing $file (needs stdio.h)"
-      echo '#ifdef __cplusplus
-#include <stdio.h>
-#endif' >>${LIB}/$file
+      echo '#include <stdio.h>' >>${LIB}/$file
     fi
   fi
   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
@@ -2553,6 +2583,173 @@ if [ -r ${LIB}/$file ]; then
   fi
 fi
     
+# Another bad dependency in VxWorks 5.2 <time.h>.
+file=time.h
+if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
+  mkdir ${LIB}/sys 2>/dev/null
+  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 egrep VOIDFUNCPTR ${LIB}/$file >/dev/null 2>&1; then
+    if [ -r vxWorks.h ]; then
+      echo Fixing $file
+      sed -e '/VOIDFUNCPTR/i\
+#ifndef __gcc_VOIDFUNCPTR_defined\
+#ifdef __cplusplus\
+typedef void (*__gcc_VOIDFUNCPTR) (...);\
+#else\
+typedef void (*__gcc_VOIDFUNCPTR) ();\
+#endif\
+#define __gcc_VOIDFUNCPTR_defined\
+#endif
+' \
+         -e 's/VOIDFUNCPTR/__gcc_VOIDFUNCPTR/g' \
+       ${LIB}/$file > ${LIB}/${file}.sed
+      rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${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
+    
+# This file in A/UX 3.0.x/3.1.x contains an __asm directive for c89; gcc
+# doesn't understand it.
+file=sys/param.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
+  echo "Fixing __asm directive in sys/param.h"
+  sed -e 's|#ifndef NOINLINE|#if !defined(NOINLINE) \&\& !defined(__GNUC__)|' \
+    ${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
+  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
+
+# signal.h on SunOS defines signal using (), which causes trouble when
+# compiling with g++ -pedantic.
+for file in signal.h sys/signal.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 "Checking for bad C++ prototype in $file"
+    sed -e '/^void     (\*signal())();$/i\
+  #ifdef __cplusplus\
+  void (*signal(...))(...);\
+  #else
+  ' \
+       -e '/^void      (\*signal())();$/a\
+  #endif
+  ' \
+      ${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
+    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
+
+# sys/signal.h on some versions of AIX uses volatile in the typedef of
+# sig_atomic_t, which causes gcc to generate a warning about duplicate
+# volatile when a sig_atomic_t variable is declared volatile, as
+# required by ANSI C.
+file=sys/signal.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
+  echo "Checking for duplicate volatile in sys/signal.h"
+  sed -e 's/typedef volatile int sig_atomic_t/typedef int sig_atomic_t/' \
+    ${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
+  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
+
+# Some math.h files define struct exception, which conflicts with
+# the class exception defined in the C++ file std/stdexcept.h.  We
+# redefine it to __math_exception.  This is not a great fix, but I
+# haven't been able to think of anything better.
+file=math.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
+  echo Fixing $file, exception
+  sed -e '/struct exception/i\
+#ifdef __cplusplus\
+#define exception __math_exception\
+#endif'\
+      -e '/struct exception/a\
+#ifdef __cplusplus\
+#undef exception\
+#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'\
+        -e '/matherr/a\
+#ifdef __cplusplus\
+#undef exception\
+#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
+    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
 
 # This loop does not appear to do anything, because it uses file
 # rather than $file when setting target.  It also appears to be