diff options
Diffstat (limited to 'contrib/gcc/fixincludes')
-rwxr-xr-x | contrib/gcc/fixincludes | 155 |
1 files changed, 117 insertions, 38 deletions
diff --git a/contrib/gcc/fixincludes b/contrib/gcc/fixincludes index 09e10bb..e5cc1c3 100755 --- a/contrib/gcc/fixincludes +++ b/contrib/gcc/fixincludes @@ -7,53 +7,68 @@ # Directory containing the original header files. # (This was named INCLUDES, but that conflicts with a name in Makefile.in.) -INPUT=${2-${INPUT-/usr/include}} +if [ "x$1" = "x" ] +then echo fixincludes: no output directory specified +exit 1 +fi + +LIB=${1} +shift -# Directory in which to store the results. -LIB=${1?"fixincludes: output directory not specified"} +# Make sure it exists. +if [ ! -d $LIB ]; then + mkdir $LIB || { + echo fixincludes: output dir '`'$LIB"' cannot be created" + exit 1 + } +else + ( \cd $LIB && touch DONE && rm DONE ) || { + echo fixincludes: output dir '`'$LIB"' is an invalid directory" + exit 1 + } +fi # 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 + target_canonical="`sed -n -e 's,^target[ ]*=[ ]*\(.*\)$,\1,p' < Makefile`" +fi + +# If not from the Makefile, then try config.guess +# +if test -z "${target_canonical}" ; then + if test -x ./config.guess ; then + target_canonical="`config.guess`" ; fi + test -z "${target_canonical}" && target_canonical=unknown fi +export target_canonical +# # # # # # # # # # # # # # # # # # # # # +# # Define PWDCMD as a command to use to get the working dir # in the form that we want. PWDCMD=pwd -case "`pwd`" in + +case "`$PWDCMD`" in //*) - # On an Apollo, discard everything before `/usr'. - PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'" - ;; + # On an Apollo, discard everything before `/usr'. + PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'" + ;; esac # Original directory. ORIGDIR=`${PWDCMD}` -# Make sure it exists. -if [ ! -d $LIB ]; then - mkdir $LIB || exit 1 -fi - # Make LIB absolute only if needed to avoid problems with the amd. case $LIB in /*) - ;; + ;; *) - cd $LIB; LIB=`${PWDCMD}` - ;; + cd $LIB; LIB=`${PWDCMD}` + ;; esac -# Fail if no arg to specify a directory for the output. -if [ x$1 = x ] -then echo fixincludes: no output directory specified -exit 1 -fi - -echo Building fixed headers in ${LIB} +echo Fixing headers into ${LIB} for ${target_canonical} target # Determine whether this system has symbolic links. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then @@ -66,8 +81,30 @@ else LINKS=false fi +# # # # # # # # # # # # # # # # # # # # # +# +# Search each input directory for broken header files. +# This loop ends near the end of the file. +# +if test $# -eq 0 +then + INPUTLIST="/usr/include" +else + INPUTLIST="$@" +fi + +for INPUT in ${INPUTLIST} ; do + +cd ${ORIGDIR} + +cd ${INPUT} || continue +INPUT=`${PWDCMD}` + +# +# # # # # # # # # # # # # # # # # # # # # +# echo Finding directories and links to directories -cd ${INPUT} + # Find all directories and all symlinks that point to directories. # Put the list in $files. # Each time we find a symlink, add it to newdirs @@ -301,6 +338,7 @@ while [ $# != 0 ]; do /#[ ]*define[ ]*[ ]CTRL/ s/'\''\([cgx]\)'\''/\1/g /#[ ]*define[ ]*[ ]_CTRL/ s/'\''\([cgx]\)'\''/\1/g /#[ ]*define.BSD43_CTRL/ s/'\''\([cgx]\)'\''/\1/g + /#[ ]*define[ ]*[ ][_]*ISCTRL/ s/'\''\([cgx]\)'\''/\1/g /#[ ]*[el]*if/{ s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g @@ -964,6 +1002,7 @@ if [ -r ${LIB}/$file ]; then -e 's/char[ ]*\*[ ]*calloc/void \* calloc/g' \ -e 's/char[ ]*\*[ ]*malloc/void \* malloc/g' \ -e 's/char[ ]*\*[ ]*realloc/void \* realloc/g' \ + -e 's/char[ ]*\*[ ]*bsearch/void \* bsearch/g' \ -e 's/int[ ][ ]*exit/void exit/g' \ -e "/$size_t_pattern/"'i\ #ifndef _GCC_SIZE_T\ @@ -1657,6 +1696,34 @@ if [ -r ${LIB}/$file ]; then fi fi +# sys/utsname.h on Ultrix V4.[35] puts the declaration of uname before the +# definition of struct utsname, so the prototype (added by fixproto) causes +# havoc. +file=sys/utsname.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 +fi + +if [ -r ${LIB}/$file ] \ + && grep 'ULTRIX' ${LIB}/$file >/dev/null; then + echo Fixing $file, uname declaration + sed -e '/^[ ]*extern[ ]*int[ ]*uname();$/i\ +struct utsname; +'\ + ${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 + # sys/wait.h on AIX 3.2.5 puts the declaration of wait3 before the definition # of struct rusage, so the prototype (added by fixproto) causes havoc. file=sys/wait.h @@ -2186,16 +2253,16 @@ if [ -r ${LIB}/$file ]; then fi # For C++, avoid any typedef or macro definition of bool, and use the -# built in type instead. -for files in curses.h; do - if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then - if [ ! -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 - - echo Fixing $file +# built in type instead. HP/UX 10.20, at least, also has it +# in curses_colr/curses.h. +for file in curses.h curses_colr/curses.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 ] && egrep bool ${LIB}/$file >/dev/null 2>&1; then + echo Fixing $file, typedef or macro for bool is invalid in C++ sed -e '/^#[ ]*define[ ][ ]*bool[ ][ ]*char[ ]*$/i\ #ifndef __cplusplus '\ @@ -3177,10 +3244,22 @@ find . -name DONE -exec rm -f '{}' ';' echo 'Removing unneeded directories:' cd $LIB -files=`find . -type d -print | sort -r` +files=`find . -type d \! -name '.' -print | sort -r` for file in $files; do rmdir $LIB/$file > /dev/null 2>&1 done +# # # # # # # # # # # # # # # # # # # # # +# +# End of for INPUT directories +# +done +# +# # # # # # # # # # # # # # # # # # # # # + +cd $ORIGDIR +rm -f include/assert.h +cp ${srcdir}/assert.h include/assert.h || exit 1 +chmod a+r include/assert.h exit 0 |