--- stdcxx-4.2.1/etc/config/src/libc_decl.sh	2008-04-24 20:25:44.000000000 -0400
+++ stdcxx-4.2.1/etc/config/src/libc_decl.sh	2009-03-28 13:41:21.199362000 -0400
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # $Id: libc_decl.sh 648752 2008-04-16 17:01:56Z faridz $
 #
@@ -37,8 +37,44 @@
 #
 ##############################################################################
 
+export CONFIG_SHELL="/bin/bash"
+export SHELL="/bin/bash"
+export MAKESHELL="/bin/bash"
+
+if [ "x${TOPDIR}" = "x" ] ; then
+    echo "TOPDIR is not defined."
+    exit 1
+fi
+
+echo "TOPDIR set to ${TOPDIR}."
+
+if [ ! -d "${TOPDIR}/include/ansi" ] && [ ! -d "${TOPDIR}/include" ] ; then
+    echo "TOPDIR does not contain the expected header file directories."
+    exit 1
+fi
+
+export CPPFLAGS=" -I${TOPDIR}/include/ansi -I${TOPDIR}/include/tr1 -I${TOPDIR}/include ${CPPFLAGS}"
+
+if [ -f "$2" ]; then
+    echo "logfile set as argv[1] to $2."
+fi
+
+export FAILDIR="${TOPDIR}/fail"
+echo "$0: FAILDIR: $FAILDIR."
+
+rm -rf $FAILDIR
+mkdir -p $FAILDIR
+
+if [ -d $FAILDIR ] ; then
+    echo "$FAILDIR Created."
+    cd $FAILDIR
+    rm -f *.cpp *.i
+    cd -
+fi
+
 output=/dev/tty
-logfile=/dev/tty
+## logfile=/dev/tty
+logfile=$TOPDIR/libc_decl.log
 
 OSNAME=`uname -s`
 
@@ -75,10 +111,6 @@
     hdrs="$4"
 fi
 
-
-
-CPPFLAGS="`echo $CPPFLAGS | sed 's:-I *[^ ]*::g'`"
-
 if [ "$CXX" = "aCC" ] ; then
 
     cxx_major="`echo $CXX_VER | sed 's/.*\.\([0-9][0-9]*\)\..*/\1/'`"
@@ -131,6 +163,8 @@
             echo "#define _RWSTD_NO_${sym}" >> $output
             # <ciso646> is a bogus header, ignore if missing
             [ $sym != ciso646 ] && no_new_headers=1
+            failfile="`basename $tmpfile.cpp`"
+            cp -fp $tmpfile.cpp $FAILDIR/$hdr.$failfile
         fi
     fi
 
@@ -162,6 +196,10 @@
     else
         echo "no (_RWSTD_NO_${sym}_H)"
         echo "#define _RWSTD_NO_${sym}_H" >>$output
+        failfile="`basename $tmpfile.cpp`"
+        cp -fp $tmpfile.cpp $FAILDIR/$hdr.$failfile
+        failfile="`basename $tmpfile.i`"
+        cp -fp $tmpfile.i $FAILDIR/$hdr.$failfile
     fi
 
     rm -f $tmpfile.cpp $tmpfile.i
@@ -199,6 +237,11 @@
 
 cat << EOF > $tmpsrc
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
 extern "C"
 {
     typedef void (*funptr_t)();
@@ -222,17 +265,6 @@
 #    define __THROW
 #  endif   // gcc < 3 on Linux
 
-#  if    defined (__EDG__)                \
-      && !defined (__DECCXX)              \
-      && !defined (__HP_aCC)              \
-      && !defined (__INTEL_COMPILER)      \
-      && !defined (_SGI_COMPILER_VERSION)
-     // disable error #450-D: the type "long long" is nonstandard
-     // when using the vanilla EDG eccp in strict mode (i.e., w/o
-     // long long support)
-#    pragma diag_suppress 450
-#  endif   // EDG eccp on Linux
-
 #  include HDRNAME
 
 #  if !$no_namespace
@@ -314,12 +346,28 @@
         if [ "$funname" = "$f" ] ; then
             # take the address of the function
             # (the function must not be overloaded)
+            if [ "$funname" = "qsort" ] || [ "$funname" = "bsearch" ] ; then
+                take_addr=0
+            elif [ "$funname" = "abs" ] || [ "$funname" = "div" ] ; then
+                take_addr=0
+            elif [ "$funname" = "vwscanf" ] || [ "$funname" = "wcstof" ] ; then
+                take_addr=0
+            elif [ "$funname" = "wcstold" ] || [ "$funname" = "wcstoll" ] ; then
+                take_addr=0
+            elif [ "$funname" = "wcstoull" ] ; then
+                take_addr=0
+            else
             take_addr=1
+            fi
         else
             # function may be overloaded, call it instead
             take_addr=0
         fi
 
+        ####
+        take_addr=0
+        ####
+
         # starting with acosf(), look in <math.h> rather than <cmath>
         [ "$f" = acosf ] && use_libc_header=1
 
@@ -345,26 +393,31 @@
 
         sym="_RWSTD_NO_`echo $funname | $capitalize`"
 
-        echo "$CXX -c -DCHECK_DECL $CXXFLAGS $WARNFLAGS "   \
+        echo "$CXX -c -DCHECK_DECL $CPPFLAGS $CXXFLAGS $WARNFLAGS "   \
              "-DHDRNAME=\"<$hdrname>\" -DFUNNAME=$funname " \
              "-DFUN=$f -DTAKE_ADDR=$take_addr "             \
              "$tmpsrc -o $tmpobj" >>$logfile 2>&1
 
+        failfile="`basename $tmpsrc`"
+        cp -fp $tmpsrc $FAILDIR/$hdrname.$failfile
+
         # spell out all arguments just like above, being careful
         # about quoting HDRNAME
-        $CXX -c -DCHECK_DECL $CXXFLAGS $WARNFLAGS          \
+        $CXX -c -DCHECK_DECL $CPPFLAGS $CXXFLAGS $WARNFLAGS          \
                 -DHDRNAME="<$hdrname>" -DFUNNAME=$funname  \
                 -DFUN=$f -DTAKE_ADDR=$take_addr            \
              $tmpsrc -o $tmpobj >>$logfile 2>&1            \
-        && $LD $tmpobj $LDFLAGS -l$lib >>$logfile 2>&1
+        && $CXX $CPPFLAGS $CXXFLAGS $tmpobj $LDFLAGS -l$lib >>$logfile 2>&1
 
         if [ $? -eq 0 ] ; then
             echo "ok"
+            sym="`echo $sym | sed -e 's#_AA#_#g'`"
             sym="// #define $sym"
             echo $sym >>$output
         else
             # if a symbol isn't declared in the header,
             # see if it maybe exists in the library
+            sym="`echo $sym | sed -e 's#_AA#_#g'`"
             echo "no ($sym)"
             echo "#define $sym" >>$output
 
@@ -375,18 +428,22 @@
             # define cxxflags for convenience
             cxxflags="$CXXFLAGS $WARNFLAGS -DFUNNAME=$funname"
 
-            echo "$CXX -c $cxxflags $tmpsrc -o $tmpobj \
-                 && $LD $tmpobj $LDFLAGS -l$lib" >>$logfile
+            echo "$CXX -c $CPPFLAGS $cxxflags $tmpsrc -o $tmpobj \
+                 && $CXX $CPPFLAGS $CXXFLAGS $tmpobj $LDFLAGS -l$lib" >>$logfile
 
-            $CXX -c $cxxflags $tmpsrc -o $tmpobj >>$logfile 2>&1 \
-            && $LD $tmpobj $LDFLAGS -l$lib >>$logfile 2>&1
+            $CXX -c $CPPFLAGS $cxxflags $tmpsrc -o $tmpobj >>$logfile 2>&1 \
+            && $CXX $CPPFLAGS $CXXFLAGS $tmpobj $LDFLAGS -l$lib >>$logfile 2>&1
 
             if [ $? -eq 0 ] ; then
                 echo "ok"
+                sym="`echo $sym | sed -e 's#_AA#_#g'`"
                 sym="// #define $sym"
             else
+                sym="`echo $sym | sed -e 's#_AA#_#g'`"
                 echo "no ($sym)"
                 sym="#define $sym"
+                failfile="`basename $tmpsrc`"
+                cp -fp $tmpsrc $FAILDIR/fail.$sym.$failfile
             fi
             echo $sym >>$output
         fi
@@ -438,3 +495,4 @@
     echo "#endif   // _RWSTD_NO_$sym"
     echo
 done
+
