fix()
{
    if [ ! -f ${RELEASE_ROOT}/${EXECDIR}/${TARGET}/install-tools/fixincludes ]
    then
        echo "Fixincludes not run for this cross-target."
        return
    fi

    if [ "$FIXINCDIR" = "" ]; then
        cat << EOF
***	There was no directory specified for fixincludes although
***	fixincludes is necessary.  If you already have fixed files
***	for ${TARGET} installed, this is OK.  If not, rerun $0 as
***	    $0 --installdir=<IDIR> --fixincludesdir=<FDIR> fix
***     where <IDIR> is your install directory and <FDIR> is the
***     location of the include files for ${TARGET}.
EOF
        return
    fi

    if [ "${INSTALLHOST}" != "${HOST}" -a "${NOWARN}" != "1" ] ; then
	cat << EOF
***	This machine appears to be for \"${INSTALLHOST}\", while the
***	software on this tape is meant for \"${HOST}\"  
***
***	You may still run \"$0 --extract ...\" on this machine and then
***	run the other steps on the machine on which you wish to install.
***	You will need to do these steps separately.
***	For more information, please refer to
***     ${ANOTHER_TAPE} in ${NOTES}.
EOF
    else
        fixincludes
    fi
}


fixincludes()
{
    LOGFILE=${LOGDIR}/fixincludes.log

    echo Running fixincludes for ${TARGET}.
    echo Verbose output will be stored in ${LOGFILE}.
    echo This will take some time.

    # this used to be exported -- does it still need to be? 
    LIB=${RELEASE_ROOT}/${EXECDIR}/lib/gcc-lib/${TARGET}/${GCCvn}/include 

    CPP="${RELEASE_ROOT}/${EXECDIR}/bin/gcc -E"
    export CPP		# needed by fixincludes and fixproto
    GCC_EXEC_PREFIX=${RELEASE_ROOT}/${EXECDIR}/lib/gcc-lib/
    export GCC_EXEC_PREFIX

    if [ -f ${RELEASE_ROOT}/${EXECDIR}/${TARGET}/install-tools/fix-header ]
    then
        FIX_HEADER=${RELEASE_ROOT}/${EXECDIR}/${TARGET}/install-tools/fix-header
        export FIX_HEADER   # fixproto needs this
    fi

    if [ -f ${RELEASE_ROOT}/${EXECDIR}/${TARGET}/install-tools/fixproto-defines ]
    then
        FIXPROTO_DEFINES="`${RELEASE_ROOT}/${EXECDIR}/${TARGET}/install-tools/fixproto-defines`"
        export FIXPROTO_DEFINES   # fixproto needs this
    fi

    if mkdir ${LIB}/../tmpdir && cp ${LIB}/*.h ${LIB}/../tmpdir ; then
	true
    else
	cat << EOF
*** Unable to create temporary directory ${LIB}/../tmpdir
***     Please ensure that write permissions for
***     ${LIB} are allowed.
***     Or call ${HOTLINE} for more information.
EOF
        exit 1
    fi

    # See below.  We remove limits.h to see if fixincludes
    # fixed /usr/include/limits.h.
    rm -f ${LIB}/limits.h

    ${RELEASE_ROOT}/${EXECDIR}/${TARGET}/install-tools/fixincludes ${LIB} ${FIXINCDIR} ${RELEASE_ROOT}/src/gcc > ${LOGFILE} 2>&1
    if [ $? -ne 0 ]; then
	cat << EOF
*** There seems to have been a problem with fixincludes.
***	The verbose output from the fixincludes script has been logged in
***     ${LOGFILE}.
***     I do not know how to continue until this problem has been
***     corrected.  If you do not know how to fix it either, please
***     call ${HOTLINE}.
EOF
	mv ${LIB}/../tmpdir/* ${LIB} && rmdir ${LIB}/../tmpdir
	exit 1
    fi  # 
    echo '   ' system header files now ANSI compatible 

    ${RELEASE_ROOT}/${EXECDIR}/${TARGET}/install-tools/fixproto ${LIB} ${LIB} ${FIXINCDIR} >> ${LOGFILE} 2>&1
    if [ $? -ne 0 ]; then
	cat << EOF
*** There seems to have been a problem with fixproto.
***     The verbose output from the fixproto script has been logged in
***     ${LOGFILE}.
***     I do not know how to continue until this problem has been
***     corrected.  If you do not know how to fix it either, please
***     call ${HOTLINE}.
EOF
	mv ${LIB}/../tmpdir/* ${LIB} && rmdir ${LIB}/../tmpdir
	exit 1
    fi	
    echo '   ' ansi/posix prototypes added to include files

    # See the GCC Makefile, target stmp-fixinc, for the details on
    # limits.h handling.  If fixincludes fixed /usr/include/limits.h,
    # it gets installed as ${LIB}/syslimits.h.
    if [ -f ${LIB}/limits.h ]; then
      rm -f ${LIB}/limits.h.sys
      mv ${LIB}/limits.h ${LIB}/limits.h.sys
    fi

    mv ${LIB}/../tmpdir/* ${LIB} && rmdir ${LIB}/../tmpdir 

    if [ -f ${LIB}/limits.h.sys ]; then
      rm -f ${LIB}/syslimits.h
      mv ${LIB}/limits.h.sys ${LIB}/syslimits.h
    fi

    echo Fixed include files installed!
}
