#! /bin/sh
#
# Compiler tool-chain installer for the CRIS architecture.
# Copyright (C) 1998, 1999, 2000, 2001, 2002 Axis Communications.
#
# Will install a source distribution of all tools and libraries needed
# for compilation in a simplified directory layout, based on helpful
# interaction.
#
# Stuff is stolen from the Axis "axinstall" printserver installation script
# and GNU configure, the latter found in the source of the programs to install.
# This isn't as portable as GNU configure or autoconf generated stuff though.
#
#  arg1=target-lib-dir arg2=target-bin-dir arg3=man-dir arg4=info_dir
#  arg5=temp-dir arg6=install-prefix
#
ICT_VERSION=1.24

file_archname=cris
archname=CRIS
contact=compiler-contact@axis.com

program0=install-$file_archname-tools
program="$program0 v$ICT_VERSION"
default_lib=/usr/local/$file_archname/lib/gcc-lib/$file_archname
default_bin=/usr/local/$file_archname
default_tmp=./tmpdir
default_installprefix=
dist_os_file=dist-os
default_lib_file=dist-libdir
dist_gccver_file=dist-gccver
dist_utils_file=dist-utils
default_mandir=/usr/local/man/man1
default_infodir=/usr/local/info
compiler_binaries="gcc ar as objdump objcopy readelf addr2line ranlib"
compiler_binaries="$compiler_binaries nm size strip strings ld collect2"
compiler_binaries="$compiler_binaries g++ c++ c++filt cpp"
# Make sure these match those of the installation stage (with directories).
infodir_file=dist-infodir
startdate=`date`

##### DEBUG STUFF HERE

# For debugging, set this to something other than "$$".
pid=$$

# Skip some parts.  This is *only* for debugging purposes; might cause
# unexpected inconsistencies.
skip_binutils_configure=no
skip_binutils_make=no
skip_binutils_install=no
skip_romtools=no
skip_gcc_configure=no
skip_gcc_make=no
skip_glibc_configure=no
skip_glibc_build=no
skip_lib_make=no
skip_gcc_install=no
skip_glibc_install=no
skip_relibs=no
skip_man=no
skip_info=no

# More generic ones, to be used when we skip *some* parts of the gcc installation.
skip_gcc=no
test $skip_gcc_configure$skip_gcc_make$skip_gcc_install != nonono \
 && skip_gcc=yes

skip_binutils=no
test $skip_binutils_configure$skip_binutils_make$skip_binutils_install != nonono \
 && skip_binutils=yes

#####

#
# Maybe choose another shell for some reason.
#

# --- if we do have a /bin/sh5 then use that instead

test "X$1" != "Xuse_sh5" && test "X$1" != "Xuse_ksh" && test -f /bin/sh5 && exec /bin/sh5 $0 use_sh5 $*

# --- if we're running HP-UX, use ksh instead

OSNAME=
test -f /usr/bin/uname && OSNAME=`/usr/bin/uname -sr`
test -f /bin/uname && OSNAME=`/bin/uname -sr`

OSVERSION=
test -f /usr/bin/uname && OSVERSION=`/usr/bin/uname -v`

echo $OSNAME | grep "HP-UX" >/dev/null
test $? = 0 && test "X$1" != "Xuse_sh5" && test "X$1" != "Xuse_ksh" && test -f /bin/ksh && exec /bin/ksh $0 use_ksh $*

if test "X$1" = "Xuse_sh5" || test "X$1" = "Xuse_ksh"
then shift
fi

#
# We may now, after removing "other shell" arguments, extract the "normal"
# arguments.
#
lib_arg=$1
bin_arg=$2
man_arg=$3
info_arg=$4
tmp_arg=$5
installprefix_arg=$6

# -----------------------------------------------------------------------------

test -f /usr/bsd/clear  && clear=/usr/bsd/clear
test -f /usr/ucb/clear  && clear=/usr/ucb/clear
test -f /bin/clear      && clear=/bin/clear
test -f /usr/bin/clear  && clear=/usr/bin/clear

test -f /usr/etc/mknod  && mknod=/usr/etc/mknod
test -f /etc/mknod      && mknod=/etc/mknod
test -f /etc/sbin/mknod && mknod=/etc/sbin/mknod

test -f /usr/bin/cut    && cut=/usr/bin/cut
test -f /bin/cut        && cut=/bin/cut

test -f /usr/bin/tee    && tee=/usr/bin/tee
test -f /bin/tee        && tee=/bin/tee

# --- echo come in many colours. ----------------------------------------------

madepaths=

echo_n=NO
test X`echo -n` = X && echo_n=YES

cleanup()
{
#
# Remove all made directories unless it is one on the paths to $*
#
  for removedir in $madepaths
  do
    keep=no
    for keepdir in $*
    do
      case $keepdir in
	$removedir/*)
	  keep=yes
	  break
	  ;;
	*) ;;
      esac
    done
    if test $keep = no
    then
      #echo '***' Removing $removedir and below.
      rm -rf $removedir 2>/dev/null
    # else echo Keeping $removedir
    fi
  done
}

myecho()
{
  if test X"$1" = "X-n"
  then
    shift
    test $echo_n = YES && echo -n "$*"
    test $echo_n = NO  && echo "$*" '\c'
  else echo $*
  fi
}

echodo()
{
 # Eval used to make an argument "more than one" expand into multiple
 # arguments for visibility, while retaining the one-ness for command
 # execution.

 eval echo $*
 eval "$*"
}

abort_install()
{
  touch $errfile || echo "*** Could not mark error by creating $errfile"

  echo "*** The installation is aborted, the time is:" `date`
  echo
  cleanup $instalog $errfile
}

bug_report()
{
cat <<EOF

Please email a bug report to $contact
The bug report should have a subject containing the text $program0-bug
and the location of the file $instalog
(or the file itself, if you can not put it at a convenient place)
in the message.  Thank you for your patience.

EOF
  abort_install
}

installprog ()
   # $1 is src
   # $2 is dest
{
  installprog_prog=$1
  test -f $1 || installprog_prog=$1.exe

  if test -d $2
  then
    base=`basename $installprog_prog`
    cp -p $installprog_prog $2 && $strip $2/$base
  else cp -p $installprog_prog $2 && $strip $2
  fi
}

installdata ()
   # $1 is src
   # $2 is dest
{
  cp -p $1 $2
}

# --- Prompt with default for a yes or no answer. -----------------------------
# --- Leave answer in yes_or_no.

yes_or_no=
yes_or_noP()
   # $1 is prompt string.
   # $2 is default answer (yes/no).
{
  yes_or_no=
  while true
  do
    myecho -n "$1 [yn] ? (default $2): "
    read yes_or_no

    test "X$yes_or_no" = "X" && yes_or_no=$2

    case $yes_or_no in
      y | Y | yes | Yes | YES)
	yes_or_no=YES
	break # out of the while loop
	;;
      n | N | no | No | NO)
	yes_or_no=NO
	break # out of the while loop
	;;
      *)
	yes_or_no=
	;;
      esac
  done
}

# --- Simple prompt with default for a text string answer.
# --- Leave answer in variable answer.

answer=
answerP()
   # $1 is prompt string.
   # $2 is default answer.
{
  answer=
  if test "X$2" !=  "X"
  then
    myecho -n "$1 (default $2): "
    read answer
  else
    myecho -n "$1":
    read answer
  fi
  test "X$answer" = "X" && answer=$2
}

# --- Change relative paths to absolute paths
# --- Leave answer in variable abs_path
abs_path=
pwdify()
   # $1 is a path, perhaps "./"-prefixed or "."
{
 abs_path=$1
 case $1 in
   /*) ;;
   .)   abs_path=`pwd`;;
   ./*) abs_path=`pwd`/`echo $1 | $cut -c3-`;;
   *)   abs_path=`pwd`/$1;;
 esac
 # Strip a trailing "/".  It works long enough that arising
 # problems seem non-obvious.
 abs_path=`echo $abs_path | sed -e 's,/$,,'`
}

# --- Simple prompt with default for a file path and name.
# --- The path MUST begin with a / or "./" or will be assumed
#     to start with "."
# --- Leave answer in variable path_answer.

path_answer=
path_answerP()
   # $1 is prompt string.
   # $2 is default answer.
{
  path_answer=
  while true
  do
    if test "X$2" !=  "X"
    then
      myecho -n "$1 (default $2): "
      read path_answer
    else
      myecho -n "$1":
      read path_answer
    fi
    test "X$path_answer" = "X" && path_answer=$2
    pwdify $path_answer
    path_answer=$abs_path
    if test "X$path_answer" = "X/dev/null"
    then break
    elif test X$ipp != X
    then break
    elif has_permission $path_answer
    then break
    else
      echo "Wrong answer: \"$path_answer\" is not as a directory writable by you."
    fi
  done
}

# --- Prompt for one character of a given character class.
# --- Leave answer in variable range_answer

range_answer=
range_answerP()
   # $1 is prompt string.
   # $2 is allowed answer characters class, in range [1-X], X>9.
   # $3 is default answer (must belong to class in $2).
{
  range_answer=
  while true
  do
    if test "X$3" != "X"
    then
      myecho -n "$1" "$2" "(default $3): "
      read range_answer
    else
      myecho -n "$1 $2: "
      read range_answer
    fi

    test "X$range_answer" = "X" && range_answer=$3

    low=`echo $2 | $cut -c2`
    hi=`echo $2 | $cut -c4,5`

    if test $low -le $range_answer -a $range_answer -le $hi
    then break # out of the while loop.
    else range_answer=
    fi
  done
}


# --- Prompt for one character of a given character class.
# --- Leave answer in variable class_answer

class_answer=
class_answerP()
   # $1 is prompt string.
   # $2 is allowed answer characters class, e.g. [0-9] for one of the digits.
   # $3 is default answer (must belong to class in $2).
{
  class_answer=
  while true
  do
    if test "X$3" != "X"
    then
      myecho -n "$1" "$2" "(default $3): "
      read class_answer
    else
      myecho -n "$1 $2: "
      read class_answer
    fi

    test "X$class_answer" = "X" && class_answer=$3

    case $class_answer in
      $2)
	 break # out of the while loop.
	 ;;
      *)
	 class_answer=
	 ;;
    esac
  done
}

# --- Say not if the parameter = NO

say_not()
{
  test "X$1" = "XNO" && echo " NOT"
}

# --- Say y or n when $1 is YES or NO.

say_y_or_n()
{
  test "X$1" = "XYES" && echo y
  test "X$1" = "XNO"  && echo n
}

# --- Say i or o when $1 is if or of.

say_io()
{
  test "X$1" = "Xif" && echo i
  test "X$1" = "Xof" && echo o
}

# --- Say in or out when $1 is if or of.

say_in_or_out()
{
  test "X$1" = "Xif" && echo input
  test "X$1" = "Xof" && echo output
}

# --- Test if we hawe write permission for this file.

has_permission()
   # $1 is path to test
{
  # If this is not a directory but is a file, then check write
  # permissions for the directory and the file.
  if test ! -d $1 && test -f $1
  then has_permission `dirname $1` && test -w $1

  # If not a directory and not a symlink, then we deduce that it does not
  # exist, and we go check parent dir.
  # (It seems -h is the most portable way to test for symlink-ness.  It is
  #  not confirmed to work for all systems, but does so for bash in linux
  #  and some sh on solaris/sunos.)
  elif test ! -d $1 && test ! -h $1
  then has_permission `dirname $1`
  elif test -w $1
  then true
  else false
  fi
}

# --- Create the directory and its path if it does not exist.

mkdir_path()
   # $1 is path to test
{
  if test ! -d $1
  then mkdir_path `dirname $1` && mkdir $1 && madepaths="$madepaths $1"
  else test -w $1
  fi
}

# --- not <command> do boolean negation on return value of <command>.

not()
{
  if $*
  then false
  else true
  fi
}

# --- Welcome.  The main program starts here. ------------------------------------

# FIXME: Trap?  What do we want to do then?  I guess we just don't
# want to touch anything, so no traps.

# Remove write permissions for g o
umask 022

#
# Try to find things
#
srcpath=`echo $0 | sed 's|//|/|' | sed 's|/[^/]*$||'`
test "x$srcpath" = "x$0" && srcpath=.

case $srcpath in
 /*) srcpath=$srcpath;;
 *) srcpath=`pwd`/$srcpath;;
esac

#
# Check for standard OS:es we have tested.
#
osfound=NO
# Temporarily(?) remove hpux; the system compiler cannot compile g++-cross.
#altlist="SunOS4-sparczSolaris2-sparczAIXzHP-UXzFreeBSD-intelzLinux-intel"
#greplist='SunOS 4[^ ]* sun4zSunOS 5[^ ]* sun4zAIXzHP-UXzFreeBSD [^ ]* i[3-9]86zLinux 2[^ ]* i[3-9]86'
altlist="SunOS4-sparczSolaris2-sparczAIXzFreeBSD-intelzLinux-intel"
greplist='SunOS 4[^ ]* sun4zSunOS 5[^ ]* sun4zAIXzFreeBSD [^ ]* i[3-9]86zLinux 2[^ ]* i[3-9]86'
num_alts=6
oscnt=1
OSNAME=

test -f /usr/bin/uname && OSNAME=`/usr/bin/uname -srm` && OSTOT=`/usr/bin/uname -a`
test -f /bin/uname && OSNAME=`/bin/uname -srm` && OSTOT=`/bin/uname -a`

while test $osfound != YES -a $oscnt -le $num_alts
do
  sys_type=`echo $altlist | $cut -f$oscnt -dz`
  sys_grep=`echo $greplist | $cut -f$oscnt -dz`

  echo $OSNAME | grep "`echo $sys_grep`" >/dev/null
  if test $? = 0
  then
    osfound=YES
    ostype=$sys_type
  else oscnt=`expr $oscnt + 1`
  fi
done

#foo=`echo "'"$greplist"'"`
#echo $foo
#echo $srcpath $bindist "'"$OSTOT"'" "'"$OSNAME"'" $osfound "'"$ostype"'"
#exit 0

cat << WELCOME_END

================================================================

 This is the installation script for $file_archname-tools.  It will
 lead you through the procedure to install the cross-compilation
 tools for the $archname architecture on your system.  You can stop
 this installation with the interrupt key sequence (normally <ctrl-C>)
 at any time.

 After the following questions about file locations are answered, an
 installation log will be saved to a file, logging all events in the
 installation process.  Should the installation fail, that log is
 useful to people at Axis and will help speed up the process of
 finding a correction.

 As the tools are distributed in source form they will be compiled,
 which may take a long time.  Therefore, now is a good time to exit,
 or make this script run "nice".

 The renice command might be "renice 10 $pid", depending on the
 type of this system.

WELCOME_END

#
# If the system is not "supported" then let the user stop here.
#
if test $osfound = NO
then cat <<EOF
Your system has not been tested for installation of this distribution.
Proceed at own risk.
EOF
  yes_or_noP "Do you want to quit now" y
  if test "X$yes_or_no" = "XYES"
  then
    echo "*** Installation aborted."
    exit 0
  fi
fi
#
# Find out the version of the compiler
#
if test -f $srcpath/gnu-toplev/gcc/version.c
then
  gccver=`sed -n -e 's/^[^"]*version_string[^"]*"\([^" ]*\).*/\1/p;' \
   < $srcpath/gnu-toplev/gcc/version.c`
else
cat <<EOF
Installation problem: there should be a directory in the distribution
by the name "$srcpath/gnu-toplev/gcc" with a file "version.c",
but it seems to be absent.  Has anybody tampered with the distribution?
Sorry, I cannot continue.
EOF
  exit 1
fi

default_lib=$default_lib/$gccver

#
# Make sure the user is on the right track in the first place.
#
yes_or_noP "Do you want to continue" y
test $yes_or_no = NO && exit 0

echo
echo

#
# Make the user confirm the arguments or default-values.
# Check the permissions.
#

# First check the installprefix argument (if any) for correctness, so
# we can (if needed) it when checking the other options.  We don't get
# interactive over this one.

if test "X$installprefix_arg" != "X"
then
  pwdify $installprefix_arg
  specify="You have specified that"
  installprefixpath=$abs_path
else
  specify="The default value"
  installprefixpath=$default_installprefix
fi

if test "X$installprefixpath" != "X" && not has_permission $installprefixpath
then
  echo "***  $specify $installprefixpath"
  echo " will be prepended to installation paths during the installation"
  echo " but you don't have permissions to create or write"
  echo " in $installprefixpath."
  echo "Sorry, I cannot continue."
  exit 1
fi

# Save some typing and reading.
ipp=$installprefixpath

# Loop until user ^C:s out or accepts.
while true
do

# Compiler libraries.

  if test "X$lib_arg" != "X"
  then
    pwdify $lib_arg
    specify="You have specified that"
    libpath=$abs_path
  else
    specify="The default value"
    libpath=$default_lib
  fi

  cat <<EOF
  $specify "$libpath"
 is the directory where compiler-libraries will be installed.
 It has to end in "gcc-lib/$file_archname/$gccver" just as
 "$default_lib" does.
 That suffix will be added, if it is missing.  The directory
 must be empty, so remove any previous installation now.
 If you plan to move these files in the future, please consider
 a re-installation instead; some file-paths are hard-coded into
 the compiler binaries.

EOF

  while true
  do
    clear_lib=no
    path_answerP "Choose directory" $libpath

    case $path_answer in
      */gcc-lib/$file_archname/$gccver) ;;
      *)  path_answer=$path_answer/gcc-lib/$file_archname/$gccver
	  echo
	  echo "(I added gcc-lib/$file_archname/$gccver to make that $path_answer)";;
    esac

    if test $skip_binutils$skip_romtools$skip_gcc$ipp = nonono
    then
      if test -f $path_answer/cpp || test -d $path_answer/include
      then
	echo "*** The directory $path_answer is not empty."
	echo "    You may want to save it now."
	yes_or_noP "*** Do you want me to delete all files in
     $path_answer as a destructive update" y

	if test $yes_or_no = YES
	then
	  clear_lib=yes
	  break
	else
	  echo "*** Please remove those files yourself (always backup),"
	  echo "    or choose another directory."
	fi
      else break
      fi
    else break
    fi
  done

  libpath=$path_answer
  lib_arg=$libpath


# Compiler-tool binaries

  echo
  echo

  if test "X$bin_arg" != "X"
  then
    specify="You have specified that"
    pwdify $bin_arg
    binpath=$abs_path
  else
    specify="The default value"
    binpath=$default_bin
  fi

  cat <<EOF
  $specify $binpath
 is the directory where the compiler tools, for example
  $compiler_binaries
 will be installed, with these names, both suffixed with "-$file_archname",
 and prefixed with "$file_archname-".  That is, gcc-$file_archname and $file_archname-gcc
 will both be available.

EOF

  while true
  do
    clear_bin=no
    path_answerP "Choose directory" $binpath

    if test $skip_binutils$skip_romtools$skip_gcc$ipp = nonono
    then
      # Test with both -r (there is a file) and -h (there is a symlink).
      # Note that test -h works with both Solaris /bin/sh and bash,
      # hence a more portable test than "-L", which is not a builtin
      # test in e.g. Solaris 2.8/SunOS 5.8.
      if test -r $path_answer/gcc-$file_archname \
	|| test -h $path_answer/objdump-$file_archname \
	|| test -r $path_answer/gcc-$file_archname \
	|| test -h $path_answer/objdump-$file_archname
      then
	echo "*** The directory $path_answer is not empty."
	echo "    You may want to save it now."
	yes_or_noP "*** Do you want me to delete all files in
     $path_answer as a destructive update" y

	if test $yes_or_no = YES
	then
	  clear_bin=yes
	  break
	else
	  echo "*** Please remove those files yourself (always backup),"
	  echo "    or choose another directory."
	fi
      else break
      fi
    else break
    fi
  done

  binpath=$path_answer
  bin_arg=$binpath

# Manpath

  echo
  echo

  if test "X$man_arg" != "X"
  then
    pwdify $man_arg
    specify="You have specified that"
    manpath=$abs_path
  else
    specify="The default value"
    manpath=$default_mandir
  fi

  new_man=NO
  cat <<EOF
  $specify $manpath
 is the directory for installation of Unix-type man-page manuals.
 If you do not want to install the manuals, specify /dev/null.
 The specified path must end in "/man1", which will be added, if
 it is missing.  Note that man-pages may be out of date.  Please
 consider using the info-pages (next question) instead.

EOF

  while true
  do
    clear_man=no
    path_answerP "Choose directory" $manpath
    if test "X$path_answer" = "X/dev/null"
    then break
    else
      case $path_answer in
	*/man1) ;;
	*) path_answer=$path_answer/man1
	   echo
	   echo "(I added /man1 to make that $path_answer)";;
      esac
    fi

    if test X$ipp = X && test -f $path_answer/gcc-$file_archname.1
    then
      echo "*** There is a previous installation of gcc-$file_archname & Co. manuals there:"
      ls -l $path_answer/*-$file_archname.1
      echo "*** The directory $path_answer is not empty.  You may want to save it now."
      yes_or_noP "*** Do you want me to delete these *-$file_archname.1 files
    as a destructive update" y
      if test $yes_or_no = YES
      then
	clear_man=yes
	break
      else
	echo "*** Please remove those files yourself (always backup),"
	echo "    or choose another directory."
      fi

      # Note that the "test -f" above thankfully already covered the
      # previous-installation case.
    elif test X$ipp != X || test -d $path_answer
    then break
    else
      echo "*** There was no directory called $path_answer."
      echo "    You'll also need to modify your \$MANPATH."
      yes_or_noP "Is it ok to create $path_answer anyway" y
      if test $yes_or_no = YES
      then
	new_man=YES
	break
      fi
    fi
  done

  manpath=$path_answer
  man_arg=$manpath

# Info files

  echo
  echo

  if test "X$info_arg" != "X"
  then
    pwdify $info_arg
    specify="You have specified that"
    infopath=$abs_path
  else
    specify="The default value"
    infopath=$default_infodir
  fi

  ro_infodir=NO

  cat <<EOF
  $specify $infopath
 is the directory where the GNU info-files (more up-to-date than
 the man-pages) will be installed.  If you do not want to install
 the info-files, specify "/dev/null".

EOF

  while true
  do
    clear_info=no
    path_answerP "Choose directory" $infopath
    if test "X$path_answer" = "X/dev/null"
    then break
    fi

    if test $skip_binutils$skip_romtools$skip_gcc$ipp = nonono
    then
      # FIXME: Add more library-info files to the test.
      if test -f $path_answer/gcc-$file_archname.info \
	|| test -f $path_answer/binutils-$file_archname.info \
	|| test -f $path_answer/bfd-$file_archname.info
      then
	echo "*** There is a previous overlapping installation"
	echo "    of $info_files files in $path_answer:"
	ls -l $path_answer/*-$file_archname.info*
	yes_or_noP "*** Do you want me to delete these *-$file_archname.info*
    files as a destructive update" y

	if test $yes_or_no = YES
	then
	  clear_info=yes

	  # Duplicated from below.  Keep in sync.  Sorry.
	  if not has_permission $path_answer/dir
	  then
	    echo "*** I do not have permissions to modify the index-file $path_answer/dir"
	    if not has_permission $path_answer/dir2
	    then
	      echo "*** I need at least to modify \"$path_answer/dir2\", but I can not."
	      echo "    Give me another info-path"
	    else
	      echo "*** I will remind you to remedy this at the end of the installation."
	      ro_infodir=YES
	      break
	    fi
	  else break
	  fi
	  # End of duplicate from below.
	else
	  echo "*** Please remove those files yourself (always backup),"
	  echo "    or choose another directory."
	fi
      else
	if not has_permission $path_answer/dir
	then
	  echo "*** I do not have permissions to modify the index-file $path_answer/dir"
	  if not has_permission $path_answer/dir2
	  then
	    echo "*** I need at least to modify dir2.  Give me another info-path"
	  else
	    echo "*** I will remind you to remedy this at the end of the installation"
	    ro_infodir=YES
	    break
	  fi
	else break
	fi
      fi
    else break
    fi
  done

  infopath=$path_answer
  info_arg=$infopath

# Tempdir

  echo
  echo

  if test "X$tmp_arg" != "X"
  then
    pwdify $tmp_arg
    specify="You have specified that"
    tmppath=$abs_path
  else
    specify="The default value"
    tmppath=$default_tmp
  fi

  echo "  $specify $tmppath"
  echo " is the directory for temporary files during the installation"
  echo

  while true
  do
    path_answerP "Choose directory" $tmppath
    if not has_permission $path_answer
    then
      echo "*** You do not have permissions to create or write in $path_answer."
    else break
    fi
  done

  tmppath=$path_answer
  tmp_arg=$tmppath

  cat <<EOF



 Please confirm
 Compiler tools libraries:        $libpath
EOF
  test "X$clear_lib" = "Xyes" \
    && echo " (all current files there will be deleted)" \
    && echo
  echo " Compiler tools binaries:         $binpath"
  test "X$clear_bin" = "Xyes" \
    && echo " (all current files there will be deleted)" \
    && echo
  echo " Manuals:                         $manpath"
  test "X$clear_man" = "Xyes" \
    && echo " (all *-$file_archname.1 files there will be deleted)" \
    && echo
  echo " Info-files:                      $infopath"
  test "X$clear_info" = "Xyes" \
    && echo " (all related *-$file_archname.info* files there will be overwritten)" \
    && echo

  echo " Temporaries during installation: $tmppath"

  if test X$ipp != X
  then
    echo " ( Installation path prefix:      $ipp )"
  else
    echo " ( Installation path prefix:      (none) )"
  fi

  yes_or_noP "Use these directories" y

  if test $yes_or_no = YES
  then break # Out of the big honking  while-loop around user input.
  else
    echo
    echo "Here we go again."
    echo
  fi
done # Big honking while-loop around user input.

cat << WELCOME_2_END
================================================================

WELCOME_2_END

# Go down one level, create a session-specific temporary directory.
mytmpdir=$tmppath/$program0.$pid

# Make a logfile as promised.
if not mkdir_path $mytmpdir
then
  echo "Could not create temporary directory $mytmpdir, despite checking,"
  echo "in preparation for making a log-file; no log-file created yet."
  echo "Sorry."
  exit 1
fi

instalog=$mytmpdir/$program0"_log"
errfile=$mytmpdir/$program0"_log.err"

rm -f $errfile 2>/dev/null

cat << START_MSG_END

----------------------------------------------------------------

			   $program

       An installation log will be saved in the file
       $instalog

----------------------------------------------------------------
START_MSG_END

supported=`say_not $osfound`
cat > $instalog << INSTALOG_HEAD_END
================= $program installation log ====================

The program run is:     $0
The log file is:        $instalog
Sources were in:        $srcpath
Compiler libraries in:  $libpath
Compiler binaries in:   $binpath
Installation temps:     $tmppath
Installation prefix:    $ipp
Manual files:           $manpath
New mandir:             $new_man
Info files:             $infopath
Non-writable dir:       $ro_infodir
The system is a:        $OSNAME
The total system id is: $OSTOT
It is$supported officially supported.
The installation date:  $startdate
INSTALOG_HEAD_END

if test "X$clear_lib" = "Xyes"
then
  if rm -rf $libpath/* 2>&1 | tee -a $instalog
  then true
  else
    bug_report
    exit 1
  fi
fi

echo

if test "X$clear_bin" = "Xyes"
then
  if rm -rf $binpath/* 2>&1 | tee -a $instalog
  then true
  else
    bug_report
    exit 1
  fi
fi

if mkdir_path $ipp$binpath
then echo "Binaries $ipp$binpath ok" >>$instalog
else
  echo "*** Binaries path $ipp$binpath could not be created: $?" \
    | $tee -a $instalog
  bug_report
  exit 1
fi

if mkdir_path $ipp$libpath/elinux \
   && mkdir_path $ipp$libpath/linux \
   && mkdir_path $ipp$libpath/elinux/include
then echo "Libraries $ipp$libpath ok" >>$instalog
else
  echo "*** Libraries path $ipp$libpath(/elinux, /linux) could not be created: $?" \
   | $tee -a $instalog
  bug_report
  exit 1
fi

if test "X$clear_man" = "Xyes"
then
  if rm -rf $manpath/*-$file_archname.1 2>&1 | tee -a $instalog
  then true
  else
    bug_report
    exit 1
  fi
fi

if test $manpath != /dev/null
then
  if mkdir_path $ipp$manpath
  then echo "Manuals $ipp$manpath ok" >>$instalog
  else
    echo "*** Manpath $ipp$manpath could not be created: $?" | $tee -a $instalog
    bug_report
    exit 1
 fi
fi

if test "X$clear_info" = "Xyes"
then
  # It might be that we will be asked to delete a non-existing
  # info-bunch, so check that the main file is there.
  if rm -rf $infopath/*-$file_archname.1 2>&1 | tee -a $instalog
  then true
  else
    bug_report
    exit 1
  fi
fi

if test $infopath != /dev/null
then
  if mkdir_path $ipp$infopath
  then echo "Info-files $infopath ok" >> $instalog
  else
    echo "*** Info path $infopath could not be created: $?" \
      | $tee -a $instalog
    bug_report
    exit 1
  fi
fi

# Prepare for compiling the four parts: utilities, binutils, compiler, libraries.

#
# Set up environment variables; some are shortnames for long paths.
#

# These are for modules to store into, so we can just forget it if we
# will not install man or info pages.
# do something.
mantmp=$mytmpdir/mantmp
infotmp=$mytmpdir/infotmp

# Path for modules to put unused things in.
dummydir=$mytmpdir/dummydir

topobj=$mytmpdir/top
topgcc=$topobj/gcc
binuobj=$mytmpdir/binutils
romobj=$mytmpdir/rom
glibcobj=$mytmpdir/glibc
libsubdir=$libpath
bob=$binuobj/binutils
libtmp=$mytmpdir/mergelibs

if test X$ipp != X
then
  ippmakeopts="RANLIB_FOR_TARGET=$ipp$libsubdir/ranlib AR_FOR_TARGET=$ipp$libsubdir/ar NM_FOR_TARGET=$ipp$libsubdir/nm"
  ngcc="$ipp$binpath/gcc-$file_archname -B$ipp$libsubdir/"
  ngxx="$ipp$binpath/g++-$file_archname -B$ipp$libsubdir/ -isystem $ipp$libsubdir/g++-include"

  # The order of -B switches will change, so make it symmetric, with
  # the least wanted in the center.
  egbflags="-B$ipp$libsubdir/elinux/ -B$ipp$libsubdir/ -B$ipp$libsubdir/elinux/"
  lgbflags="-B$ipp$libsubdir/linux/ -B$ipp$libsubdir/ -B$ipp$libsubdir/linux/"
  negcc="$ipp$binpath/gcc-$file_archname $egbflags"
  negxx="$ipp$binpath/g++-$file_archname $egbflags -isystem $ipp$libsubdir/g++-include"
  nlgcc="$ipp$binpath/gcc-$file_archname $lgbflags"
  nlgxx="$ipp$binpath/g++-$file_archname $lgbflags -isystem $ipp$libsubdir/g++-include"
  # We can't use GCC_EXEC_PREFIX, because that interferes with the
  # host compiler.  Try this trick to pass flags to the target compilations.
  ipbgcc="libsubdir=$ipp$libsubdir $ippmakeopts 'GCC_FOR_TARGET=$topgcc/xgcc -B$topgcc/ -B$ipp$libsubdir/ -isystem $ipp$libsubdir/include -isystem $ipp$libsubdir/g++-include'"
  ipb="LIBGCC1_TEST=Makefile $ippmakeopts 'CFLAGS_FOR_TARGET=-B$ipp$libsubdir/ -O2 -g' 'CXXFLAGS_FOR_TARGET=-B$ipp$libsubdir/ -g -O2'"
  noipbflags="LIBGCC1_TEST=Makefile $ippmakeopts CFLAGS_FOR_TARGET=-g CXXFLAGS_FOR_TARGET=-g"
  # libc.so is a script which contains absolute paths, so avoid it
  # when we have an installroot.
  linux_test_compile_flags=-static
else
  ippmakeopts=
  egbflags=
  lgbflags=
  ngcc=$binpath/gcc-$file_archname
  ngxx=$binpath/g++-$file_archname
  negcc=$binpath/gcc-$file_archname
  negxx=$binpath/g++-$file_archname
  nlgcc=$binpath/gcc-$file_archname
  nlgxx=$binpath/g++-$file_archname
  ipb=
  ipbgcc=
  noipbflags=
  linux_test_compile_flags=
fi

#
# Make sure that libgccdir (${libdir} in makefiles and configure) has
# gcc-lib/$file_archname/$gccver removed if specified.
# Anyway, libsubdir should be exactly as specified (it normally has
# gcc-lib/$file_archname/$gccver) as the final components.
#
case $libpath in
 */gcc-lib/$file_archname/$gccver)
    libgccdir=`dirname $libpath | xargs dirname | xargs dirname`;;
 *) echo "*** $program: Internal inconsistency:
    $libpath does not end in gcc-lib/$file_archname/$gccver" \
    | $tee -a $instalog
    exit 1;;
esac

#
# Make directories from some of those variables
#
if { mkdir_path $topobj \
     && mkdir_path $binuobj \
     && mkdir_path $glibcobj \
     && mkdir_path $romobj \
     && mkdir_path $libtmp \
     && mkdir_path $dummydir
   } >>$instalog 2>&1
then true
else
  echo "*** Could not create temporary files in $mytmpdir" | $tee -a $instalog
  bug_report
  exit 1
fi

echo "*** Created temp directories $topobj $binuobj $glibcobj $romobj $libtmp $dummydir" \
  >> $instalog

# Check for GNU make.  Ask user if MAKE not set, and if gnumake or
# gmake or make is not GNU make.
if test "X$MAKE" = "X"
then
   if (xargs </dev/null make --version -f /dev/null nothing 2>/dev/null | grep GNU >/dev/null)
   then
     MAKE=make
   elif (xargs </dev/null gnumake --version -f /dev/null nothing 2>/dev/null | grep GNU >/dev/null)
   then
     MAKE=gnumake
   elif (xargs </dev/null gmake --version -f /dev/null nothing 2>/dev/null | grep GNU >/dev/null)
   then
     MAKE=gmake
   else
     echo "*** I cannot find the GNU make program."
     echo "    as neither \"make\" nor \"gnumake\" nor \"gmake\"."
     answerP "Please tell how to call GNU make on this system" make
     MAKE=$answer
   fi
fi

(echo
 echo "*** Using \"$MAKE\" as a GNU make compatible program."
 echo
 echo "  Invoke an equivalent session as:"
 echo "  env \"MAKE=$MAKE\" $0 $libpath $binpath $manpath $infopath $tmppath $ipp"
 echo "  Add \"</dev/null\" to it make non-interactive."
 echo) | tee -a $instalog

# We assume that we found GNU make above.  For glibc, we also need it
# to be >= 3.79, so test that and abort installation if we find
# an unusable version, rather than failing later when configuring glibc.
ict_make_prog_version=`$MAKE --version 2>&1 | sed -n 's/^.*GNU Make[^0-9]*\([0-9][0-9.]*\).*$/\1/p'`
case $ict_make_prog_version in
  '') ict_make_prog_version="unknown, unusable for glibc"; ict_make_verc_fail=yes;;
  3.79* | 3.[89]*)
     ict_make_prog_version="GNU make $ict_make_prog_version, ok for glibc"; ict_make_verc_fail=no;;
  *) ict_make_prog_version="GNU make $ict_make_prog_version, unusable for glibc"; ict_make_verc_fail=yes;;
esac
echo "*** Make program is $ict_make_prog_version" >> $instalog
echo >> $instalog

# Unfortunately the glibc makefile contains too many dependencies of
# tools being GNUish, so it cannot be built on e.g. SUN systems.  Stop it
# from failing, only allowing when uname -s says Linux (or perhaps GNU
# or Hurd?).
#
# We use the somewhat CRIS-linux-specific "doconf" script, so check that it is
# there (someone too-smart might have added a standard tarball which would
# lose).

have_glibc=no
glibcsrcpath=$mytmpdir/glibcsrc

# If there's *any* indication of a wish to build and install glibc by
# any of the sources present, try it and fail visibly if we can't.
if test -f $srcpath/glibc/doconf \
   || test -f $srcpath/glibc/COPYING.LIB \
   || test -f $srcpath/linux-headers/asm/types.h
then
  fail=;
  if test -f $srcpath/glibc/COPYING.LIB
  then
    test -f $srcpath/glibc/doconf \
     || fail="$fail@glibc sources are not from an Axis distribution"
  else   
    fail="$fail@Axis glibc sources are not present"
  fi
  test -f $srcpath/linux-headers/asm/types.h \
    || fail="$fail@linux headers are not present"
  test "`echo $OSNAME | sed -e 's/.*Linux.*/GNUish/g;' \
    | sed -e 's/.*GNU.*/GNUish/g;'`" = "GNUish" \
    || fail="$fail@the host OS environment is not GNU/Linux-like enough"
  test $ict_make_verc_fail = no \
    || fail="$fail@the make program is $ict_make_prog_version"
  if test "X$fail" != "X"
  then
    echo "*** Installation problem.  Some glibc or kernel header sources are present, but"
    IFS="${IFS=		}"; save_ifs="$IFS"; IFS="@"
    set $fail; shift;
    for msg; do
      echo "    - $msg"
    done
    IFS="$save_IFS"
    abort_install
  fi | tee -a $instalog
  have_glibc=yes
fi

test -f $errfile && exit 1

if test $have_glibc = yes
then
  echo
  echo "*** The glibc libraries and header files will be installed"
  echo "    in  $ipp$libsubdir/linux."
else
  echo
  echo "*** No glibc and no system headers: proceeding with partial installation."
  echo "    The glibc libraries and header files would have been installed"
  echo "    in $ipp$libsubdir/linux."
fi | tee -a $instalog

(echo
 echo "*** Starting the main compilation and installation stage."
 echo "    The time is:" `date`
 echo "    Now preparing to configure the source code.") | tee -a $instalog

if test $skip_binutils$skip_romtools$skip_gcc = nonono
then
  # If people checked this out via CVS, we need to touch *some* of the generated
  # (the ones that are not trivially regenerated) so they are not attempted to
  # be re-generated.
  (cd $srcpath/gnu-toplev \
   && $srcpath/gnu-toplev/contrib/gcc_update --touch 2>&1) >> $instalog

  # Partly stolen from egcs/contribute/egcs_update.
  # Never mind if we can't touch them; if the files are read-only then they
  # hopefully have OK dates.  Else there will be big kaboom later.
  find $srcpath/binutils/. -name configure -exec touch {} \;
  for f in \
   binutils/binutils/arparse.c \
   binutils/binutils/arparse.h \
   binutils/binutils/arlex.c \
   binutils/ld/ldlex.c \
   binutils/ld/ldgram.c \
   binutils/ld/ldgram.h \
   gnu-toplev/newlib/libc/machine/cris/aclocal.m4 \
   gnu-toplev/newlib/libc/machine/cris/Makefile.in \
   gnu-toplev/newlib/libc/machine/cris/configure \

  do
    if test -f $srcpath/$f
    then touch $srcpath/$f 2>/dev/null
      sleep 1 # FIXME: Can we have a shorter discernible portable delay?
#    else
#      echo $srcpath/$f is gone
    fi
  done
fi

if test $skip_binutils_configure = no
then
  # Then configure the binary tools.
  (echo
   echo "*** Starting configuration of binutils (please be patient):"
   echo) | $tee -a $instalog

  # Glibc of some versions collide with the NLS gettext functions, so
  # we disable that.
  if (echodo cd $binuobj
      echodo $srcpath/binutils/configure --target=$file_archname --disable-nls) 2>&1
  then true
  else
    echo
    echo "*** $program: Could not configure binutils for $archname: configure failed"
    bug_report
  fi | $tee -a $instalog

  test -f $errfile && exit 1

  (echo
   echo "*** $program: Configuration of binutils succeeded.") | $tee -a $instalog
fi # skip_binutils_configure = no

# We grep the compiler from the binutils Makefile.  This is brittle
# since we don't get linker flags, for example; and the existence and
# meaning of a "CC = " line is not cast in stone.
if test "X$CC" != "X"
then
  myCC=$CC
else
  myCC=`sed -n -e 's/^CC[ 	]*=[ 	]*//p' \
          -e 's/^CFLAGS[ 	]*=[ 	]*//p' \
        < $binuobj/Makefile | xargs echo`
fi

if test "X$myCC" = "X"
then
  echo "*** Failed to read compiler flags from the binutils Makefile"
  bug_report
else
  if (cd $dummydir; $myCC -v 2>&1) | grep gcc >/dev/null 2>&1
  then
    echo "*** Compiler is \"$myCC\" which seems to be gcc:"
    echo
    echo $myCC -v -c -xc /dev/null
    (cd $dummydir; $myCC 2>&1 -v -c -xc /dev/null)
  else
    echo "*** Unknown compiler \"$myCC\""
  fi
  echo
fi | $tee -a $instalog

test -f $errfile && exit 1

# We'll need basic test files from now on.
ctestf=$mytmpdir/test.c
cat >$ctestf <<EOF
#include <stdio.h>
int main() { printf("%cHello, world%c",10,10); exit (0);}
EOF

cxxtestf=$mytmpdir/hello.cc
cat >$cxxtestf <<EOF
#include <iostream>
int main () { cout << "%cHello, world%c" << endl; }
EOF

# Check for a strip utility, but accept its absence if we don't find it right away.

tstexe=$mytmpdir/mytst.stripit
if $myCC -o $tstexe $ctestf 2>/dev/null \
   && strip $tstexe 2>/dev/null \
   && $tstexe > $mytmpdir/testout \
   && grep '^Hello, world$' $mytmpdir/testout >/dev/null
then
  strip=strip
  msg="Host strip program working, will strip binaries at installation."
else
  strip=:
  msg="Host strip program not working, so binaries will not be stripped at installation."
fi

echo "*** $msg" | $tee -a $instalog
rm -f $tstexe 2>/dev/null

if test $skip_binutils_make = no
then
   # Then make the binutils
   (echo "*** Now making binutils (please be patient):"
    echo) | $tee -a $instalog

  if (echodo cd $binuobj
      echodo $MAKE all)  2>&1
  then true
  else
    echo
    echo "*** $program: Make all failed for binutils."
    bug_report
  fi | $tee -a $instalog

  test -f $errfile && exit 1
fi # skip_binutils_make = no

if test $skip_binutils_install = no
then
  (echo
   echo "*** $program: Made binutils."
   echo "*** Now moving the binutils binaries.") | $tee -a $instalog

  if { mkdir_path $ipp$libsubdir/include/machine \
       && mkdir_path $ipp$libsubdir/include/sys \
       && mkdir_path $ipp$libsubdir/g++-include \
       && installprog $bob/ar $ipp$libsubdir \
       && installprog $binuobj/gas/as?new $ipp$libsubdir/as \
       && installprog $binuobj/ld/ld?new $ipp$libsubdir/ld \
       && installprog $bob/nm?new $ipp$libsubdir/nm \
       && installprog $bob/ranlib $ipp$libsubdir \
       && installprog $bob/readelf $ipp$libsubdir \
       && installprog $bob/addr2line $ipp$libsubdir \
       && installprog $bob/objcopy $ipp$libsubdir \
       && installprog $bob/objdump $ipp$libsubdir \
       && installprog $bob/strings $ipp$libsubdir \
       && installprog $bob/size $ipp$libsubdir \
       && installprog $bob/strip?new $ipp$libsubdir/strip
     } 2>&1
  then
    rm -f $ipp$binpath/dis$file_archname 2>/dev/null
    ln -s $libsubdir/objdump $ipp$binpath/dis$file_archname

    for tool in $compiler_binaries
    do
      case $tool in
        c++)
	   # Seldom used alias: foo-c++ and c++-foo.  Let's do it anyway
	   # and link it to g++.
	   rm -f $ipp$binpath/$tool-$file_archname \
		 $ipp$binpath/$file_archname-$tool $ipp$libsubdir/$tool 2>/dev/null
	   if ln -s $binpath/g++-$file_archname $ipp$binpath/$file_archname-$tool \
              && ln -s $binpath/g++-$file_archname $ipp$binpath/$tool-$file_archname \
              && ln -s $binpath/g++-$file_archname $ipp$libsubdir/$tool
	   then true
	   else
	     echo
	     echo "*** $program: Could not link compiler $tool into $ipp$binpath"
	     echo "An 'ls' of $ipp$binpath:" && ls -l $ipp$binpath
	     bug_report
	     exit 1
	   fi;;
	gcc | g++)
	   rm -f $ipp$libsubdir/$tool $ipp$binpath/$file_archname-$tool 2>/dev/null
	   if ln -s $binpath/$tool-$file_archname $ipp$libsubdir/$tool \
	      && ln -s $binpath/$tool-$file_archname $ipp$binpath/$file_archname-$tool
	   then true
	   else
	     echo
	     echo "*** $program: Could not link compiler $tool into $ipp$binpath"
	     echo "An 'ls' of $ipp$binpath:" && ls -l $ipp$binpath
	     bug_report
	     exit 1
	   fi;;
	*)
	   rm -f $ipp$binpath/$tool-$file_archname $ipp$binpath/$file_archname-$tool 2>/dev/null
	   if ln -s $libsubdir/$tool $ipp$binpath/$tool-$file_archname \
	      && ln -s $libsubdir/$tool $ipp$binpath/$file_archname-$tool
	   then true
	   else
	     echo
	     echo "*** $program: Could not link binutils tool $tool into $ipp$binpath"
	     echo "An 'ls' of $ipp$binpath:" && ls -l $ipp$binpath
	     bug_report
	     exit 1
	   fi;;
      esac
    done
  else
    echo
    echo "*** $program: Could not move the binutils binaries into $ipp$libsubdir"
    echo "An 'ls' of $ipp$libsubdir:" && ls -l $ipp$libsubdir
    bug_report
  fi | $tee -a $instalog

  test -f $errfile && exit 1

  echo "*** Moved the binutils binaries." | $tee -a $instalog
fi # skip_binutils_install = no

if test $skip_romtools = no
then
  # Install our own little tools and wrappers.
  (echo "*** Now installing simple tools from" $srcpath/$file_archname-romtools
   echo) | $tee -a $instalog

  # Note that binpath is not stored anywhere or used to create
  # symbolic links in "$file_archname-romtools", or else we will have to
  # add a final_binpath there too.
  if (cd $romobj
      $MAKE -f $srcpath/$file_archname-romtools/Makefile \
	   strip=$strip clean install "CC=$myCC" \
	   libsubdir=$ipp$libsubdir final_libsubdir=$libsubdir binpath=$ipp$binpath \
	   srcdir=`echo $srcpath/$file_archname-romtools*`) 2>&1
  then true
  else
    echo
    echo "*** $program: Could not install $archname romtools"
    bug_report
  fi | $tee -a $instalog

  test -f $errfile && exit 1
fi # skip_romtools = no

(echo
 echo "*** $program: Installation of simple tools succeeded."
 echo "*** Now configuring compiler and libraries."
 echo) | $tee -a $instalog

if test $skip_gcc_configure = no
then
  # Then configure GCC and others from toplev and down.
  # Specify everything the user specified.
  # We can not win currently by specifying libsubdir only; it has to end in
  # gcc-lib/$arch$ver.
  # Glibc of some versions collide with the NLS gettext functions, so
  # we disable that.
  if (echodo cd $topobj
      echodo $srcpath/gnu-toplev/configure --mandir=$mantmp --infodir=$infotmp \
       --enable-version-specific-runtime-libs --disable-nls \
       --program-suffix=-$file_archname --target=$file_archname \
       --enable-languages=c,c++ --with-gxx-include-dir=$libsubdir/g++-include \
       --exec-prefix=$binpath --prefix=$binpath --bindir=$binpath \
       --libdir=$libgccdir --enable-threads=posix --enable-shared) 2>&1
  then true
  else
    echo
    echo "*** $program: Could not configure; $srcpath/gnu-toplev/configure failed."
    bug_report
  fi | $tee -a $instalog

  test -f $errfile && exit 1
fi # skip_gcc_configure = no

if test $skip_gcc_make = no
then
  (echo
   echo "*** $program: Configuration of compiler succeeded."
   echo "*** Now making the compiler (please be patient):"
   echo) | $tee -a $instalog

  # Then make the compiler and its core support libraries.
  # We sanitize some variables by setting them here; the unsubdir thing
  # makes me dizzy, and it pokes dirs in unexpected places.
  # We have to make gcc separately, or its gcc_tooldir will mess up.
  if (echodo cd $topobj \
      && echodo env PATH=$ipp$binpath:$PATH $MAKE $ipb all-libiberty all-texinfo tooldir=$libsubdir \
      && echodo cd gcc \
      && echodo env PATH=$ipp$binpath:$PATH $MAKE all \
          $ipbgcc gcc_tooldir=$libsubdir tooldir=$libsubdir SYSTEM_HEADER_DIR=$mytmpdir/nonexist) 2>&1
  then
    echo
    echo "*** $program: Built the gcc compiler for $archname."
  else
    echo
    echo "*** $program: Could not make gcc for $archname."
    bug_report
  fi | $tee -a $instalog

  test -f $errfile && exit 1
fi # skip_gcc_make = no

# We will now configure glibc and install its headers, so libstdc++ will
# get the correct header files for compiling.
if test $have_glibc = yes
then
  if test $skip_glibc_configure = no
  then
    # Since glibc does not like when objdir (tmpdir) is on another fs
    # than srcdir, we copy srcdir to a sibling directory (better than
    # insist the user to specify a tmpdir on the same fs as srcpath).
    # We used to do this only when different fs (based on a test if a
    # hardlink between a file in glibc and tmpdir was successful),
    # but since glibc pokes a lot of dependency files into its srcdir
    # (perhaps when dates are out of sync due to CVS), we now do it
    # always, so we don't have to track dependencies if the src fs is
    # read-only.
    if mkdir_path $glibcsrcpath/glibc \
      && (cd $srcpath/glibc && tar fc - .) \
    	  | (cd $glibcsrcpath/glibc && tar fx -) 2>&1
    then true
    else
      bug_report
      exit 1
    fi

    echo "*** Installing kernel header files in"
    echo "        $ipp$libsubdir/linux/include"
    echo
    if mkdir_path $ipp$libsubdir/linux/include \
       && (cd $srcpath/linux-headers
	   tar fc - .) \
	  | (cd $ipp$libsubdir/linux/include
	     tar fx -) 2>&1
    then true
    else
      echo
      echo "*** Installation of kernel headers failed."
      bug_report
      exit 1
    fi

    echo "*** Now configuring glibc for linux."
    echo

    # There's a bug (or undocumented omission) in the glibc configure
    # machinery: --libdir= is accepted by configure, but has no effect
    # on what happens at "make" (does not go into the Makefile or
    # config.make).  We specify it here anyway.
    if (echodo cd $glibcobj \
	&& echo env "TARGET_CC=$topgcc/xgcc -mlinux -B$topgcc/ $lgbflags" \
	       CC_opts= $ippmakeopts \
               PATH=$ipp$binpath:$PATH "BUILD_CC=$myCC" $glibcsrcpath/glibc/doconf --host=cris-axis-linux-gnu \
	     --prefix= --enable-add-ons --disable-profile --enable-kernel=2.4.3 \
	     --with-headers=$ipp$libsubdir/linux/include \
	&& env "TARGET_CC=$topgcc/xgcc -mlinux -B$topgcc/ $lgbflags" \
	       CC_opts= $ippmakeopts \
               PATH=$ipp$binpath:$PATH "BUILD_CC=$myCC" $glibcsrcpath/glibc/doconf --host=cris-axis-linux-gnu \
	     --prefix= --enable-add-ons --disable-profile --enable-kernel=2.4.3 \
	     --with-headers=$ipp$libsubdir/linux/include) 2>&1
    then
      echo
      echo "*** $program: glibc configured."
    else
      echo
      echo "*** $program: glibc configure failed."
      bug_report
      exit 1
    fi
  fi # skip_glibc_configure = no

  echo "*** Compiling glibc (please be patient):"
  echo

  if test $skip_glibc_build = yes
  then true
  else
    if (echodo cd $glibcobj \
	&& echo env PATH=$ipp$binpath:$PATH $MAKE \
             user-defined-trusted-dirs=/usr/lib \
             install_root=$dummydir/linux inst_libdir=$ipp$libsubdir/linux \
             inst_slibdir=$ipp$libsubdir/linux inst_infodir=$infotmp \
             inst_includedir=$ipp$libsubdir/linux/include all \
	&& env PATH=$ipp$binpath:$PATH $MAKE \
             user-defined-trusted-dirs=/usr/lib \
             install_root=$dummydir/linux inst_libdir=$ipp$libsubdir/linux \
             inst_slibdir=$ipp$libsubdir/linux inst_infodir=$infotmp \
             inst_includedir=$ipp$libsubdir/linux/include all) 2>&1
    then
      echo
      echo "*** $program: glibc built"
    else
      echo
      echo "*** $program: glibc build failed"
      bug_report
      exit 1
    fi

  fi # skip_glibc_build
fi | $tee -a $instalog # have_glibc = yes

test -f $errfile && exit 1

if test $skip_lib_make = no
then
  # First saying we made glibc, then saying we make libraries looks
  # weird.  Make it look a bit saner.
  other_lib=
  test $have_glibc = yes && other_lib=" other"

  (echo "*** Now making$other_lib libraries (please be patient):"
   echo) | $tee -a $instalog

  # Then make the other libraries (mostly cause of libstdc++).
  if (echodo cd $topobj \
      && echodo env PATH=$ipp$binpath:$PATH $MAKE $ipb all tooldir=$libsubdir) 2>&1
  then true
  else
    echo
    echo "*** $program: Could not make libraries for $archname"
    bug_report
  fi | $tee -a $instalog

  test -f $errfile && exit 1
fi # skip_lib_make = no

if test $skip_gcc_install = no
then
  echo
  echo "*** $program: Made the compiler and libraries."
  echo "    Now installing the compiler and libraries."
  echo

  # Fingers crossed; we actually let some Makefiles do parts of this,
  # but we have to hold a strong hand over it, lest it go astray and
  # install "$file_archname-foo" everywhere, and $(tooldir)/bin/bar and
  # $(tooldir)/lib/libfoo.a.
  # Maybe the PATH setting isn't necessary, but sometimes some parts
  # are re-made (because of a .PHONY target), like libgcc1-test.
  # We let gcc install its info and manpages, provided it does not
  # munge the names.
  if (cd $topobj \
      && env PATH=$ipp$binpath:$PATH $MAKE $ippmakeopts install-target-libio install-target-libstdc++ \
               exec_prefix=$ipp$binpath prefix=$ipp$binpath bindir=$ipp$binpath \
               gxx_include_dir=$ipp$libsubdir/g++-include libdir=$ipp$libgccdir \
      && (cd gcc \
	  && PATH=$ipp$binpath:$PATH $MAKE $ippmakeopts install-info install-man \
	      program_transform_cross_name=s,x,x, \
	      exec_prefix=$ipp$binpath prefix=$ipp$binpath bindir=$ipp$binpath \
              gcc_tooldir=$ipp$libsubdir tooldir=$ipp$libsubdir \
	      libdir=$ipp$libgccdir libsubdir=$ipp$libsubdir \
	      includedir=$mytmpdir/dummydir) \
      && (cd $file_archname/newlib \
	  && env PATH=$ipp$binpath:$PATH $MAKE $ippmakeopts install-data-am \
	      exec_prefix=$ipp$binpath prefix=$ipp$binpath bindir=$ipp$binpath \
	      libdir=$ipp$libsubdir tooldir=$ipp$libsubdir \
	      toollibdir=$ipp$libsubdir MULTIDO=: ) ) 2>&1
  then true
  else
    echo
    echo "*** $program: Could not install gcc and libraries for $archname"
    bug_report
    exit 1
  fi

  # Copy multilibbed variants.  Note that some libraries in some multilib
  # variants are non-functional.  If you change anything, make sure the dummy
  # crt0.o installed by newlib gets overridden by the one from libgloss.
  for ml in `$topgcc/xgcc -B$topgcc/ -print-multi-lib 2>/dev/null`
  do
    dir=`echo $ml | sed -e 's/;.*$//'`
    test -d $ipp$libsubdir/$dir || mkdir $ipp$libsubdir/$dir
    if installdata $topgcc/$dir/libgcc.a $ipp$libsubdir/$dir \
       && installdata $topgcc/$dir/crtbegin.o $ipp$libsubdir/$dir \
       && installdata $topgcc/$dir/crtbegin2.o $ipp$libsubdir/$dir \
       && installdata $topgcc/$dir/crtend.o $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/libgloss/libnosys/libnosys.a $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/libgloss/$file_archname/libbsp.a $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/libgloss/$file_archname/libsyssim.a $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/libgloss/$file_archname/crt0.o $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/libgloss/$file_archname/scrt0.o $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/libgloss/$file_archname/s2crt0.o $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/newlib/libc/machine/$file_archname/libic.a $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/newlib/libc.a $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/newlib/libg.a $ipp$libsubdir/$dir \
       && installdata $topobj/$file_archname/$dir/newlib/libm.a $ipp$libsubdir/$dir \
       && true
    then true
    else
      echo
      echo "*** $program: Could not copy libraries into $ipp$libsubdir/$dir"
      echo "An 'ls' of $ipp$libsubdir/$dir:" && ls -l $ipp$libsubdir/$dir
      bug_report
      exit 1
    fi
  done

  # Merge libsyslinux.a with libc.a for libgloss+newlib for linux.
  # In the generic loop above, we installed the newlib part only; we need to overwrite it here.
  if { (cd $libtmp \
        && $bob/ar x $topobj/$file_archname/linux/libgloss/$file_archname/libsyslinux.a \
        && (for f in *.o; do mv $f lg_$f || exit 1; done) \
        && $bob/ar x $topobj/$file_archname/linux/newlib/libc.a \
	&& rm $ipp$libsubdir/linux/libc.a \
	&& $bob/ar rc $ipp$libsubdir/linux/libc.a *.o \
	&& $bob/ranlib $ipp$libsubdir/linux/libc.a \
	&& rm *.o)
     } 2>&1
  then true
  else
    echo
    echo "*** $program: Could not copy linux libraries into $ipp$libsubdir/linux"
    echo "An 'ls' of $ipp$libsubdir/linux:" && ls -l $ipp$libsubdir/linux
    bug_report
    exit 1
  fi

  # Install some stuff manually.
  # We install manually the programs from gcc, since the gcc install
  # process does not strip programs.
  # We also do some overrides of some multilibbed installs.
  # Note that elinux/crt0.o from lcrt0.c is already in place.
  # The pthread.h installed in the main include directory is bogus; it
  # was only used to make libgcc.a support threads.  No pthreads
  # implementation is included except for linux.
  if { installprog $topgcc/xgcc $ipp$binpath/gcc-$file_archname \
	&& installprog $topgcc/c++filt $ipp$libsubdir \
	&& installprog $topgcc/g++ $ipp$binpath/g++-$file_archname \
	&& installprog $topgcc/cc1 $ipp$libsubdir \
	&& installprog $topgcc/cc1plus $ipp$libsubdir \
	&& installprog $topgcc/cpp $ipp$libsubdir \
	&& installprog $topgcc/collect2 $ipp$libsubdir \
	&& installdata $topgcc/specs $ipp$libsubdir \
	&& installdata $topgcc/linux/crtbeginS.o $ipp$libsubdir/linux \
	&& installdata $topgcc/linux/crtendS.o $ipp$libsubdir/linux \
	&& rm $ipp$libsubdir/include/pthread.h \
	&& installdata $topobj/$file_archname/elinux/libgloss/$file_archname/libsyslinux.a $ipp$libsubdir/elinux \
	&& (test $have_glibc = yes \
	    || (installdata $topobj/$file_archname/linux/libgloss/$file_archname/lcrt0.o $ipp$libsubdir/linux/crt1.o \
         	&& installdata $topobj/$file_archname/linux/libgloss/$file_archname/crti.o $ipp$libsubdir/linux \
		&& installdata $topobj/$file_archname/linux/libgloss/$file_archname/crtn.o $ipp$libsubdir/linux ) ) \
        && true
     } 2>&1
  then true
  else
    echo
    echo "*** $program: Could not move gcc binaries into $ipp$libsubdir"
    echo "An 'ls' of $ipp$libsubdir:" && ls -l $ipp$libsubdir
    bug_report
    exit 1
  fi

  # Install some header files from gcc, but not as gcc does, all in
  # $ipp$libsubdir/include; some are C++ and belong in
  # $ipp$libsubdir/g++-include.
  for f in $topgcc/include/*
  do
    case $f in
     */cxxabi.h | */README) ;; # Unusable, unused.
     */new.h) installdata $f $ipp$libsubdir/g++-include 2>&1 || bug_report;;
     *.h) installdata $f $ipp$libsubdir/include 2>&1 || bug_report;;
     *)  installdata $f $ipp$libsubdir/g++-include 2>&1 || bug_report;;
    esac
    test -f $errfile && exit 1
  done
fi | tee -a $instalog # skip_gcc_install = no

test -f $errfile && exit 1 \
 || (echo; echo "*** Compiler binaries and libraries moved."; echo) \
| $tee -a $instalog

if test $have_glibc = yes && test $skip_glibc_install = no
then
  echo
  echo "*** Installing glibc in $ipp$libsubdir/linux"
  echo "    (Automatically picked up with \"gcc-$file_archname -mlinux\")."
  echo

  # The library path replacement in libc.so must point at the
  # prefixed installation directory until libstdc++ is recompiled.
  if (echodo cd $glibcobj \
	&& echo env PATH=$ipp$binpath:$PATH $MAKE \
           install_root=$dummydir/linux inst_libdir=$ipp$libsubdir/linux \
           inst_slibdir=$ipp$libsubdir/linux inst_infodir=$infotmp \
           inst_includedir=$ipp$libsubdir/linux/include install \
	&& env PATH=$ipp$binpath:$PATH $MAKE \
           install_root=$dummydir/linux inst_libdir=$ipp$libsubdir/linux \
           inst_slibdir=$ipp$libsubdir/linux inst_infodir=$infotmp \
           inst_includedir=$ipp$libsubdir/linux/include install \
	&& echo "(Replacing /lib/ path with $ipp$libsubdir/linux/ in libc.so)" \
	&& perl -p -i -e "s,/lib/,$ipp$libsubdir/linux/,g" $ipp$libsubdir/linux/libc.so) 2>&1
  then
    echo
    echo "*** $program: glibc installed"
    echo "    in $ipp$libsubdir/linux"
  else
    echo
    echo "*** $program: glibc install failed"
    bug_report
    exit 1
  fi
fi | tee -a $instalog # skip_glibc_install = no

test -f $errfile && exit 1

if test $have_glibc = yes && test $skip_relibs = no
then
  echo "*** Now preparing to configure libstdc++ for glibc"
  echo

  # Unfortunately, the libio objects in libstdc++ are not usable
  # for elinux/glibc; for example the FILE structure is different from
  # newlib (perhaps that's "all"?  At least that's the point where I
  # had to give up on having a unified libstdc++ library).
  # So, we recompile libio and libstdc++ to fit.
  # FIXME: This does not necessarily mean that C++ (and its
  # streams) work on Linux; its just a necessary infrastructure, a
  # step bringing us closer there.  It needs to be tested, at least
  # with the libio/libstdc++ testsuite.
  # FIXME: Instead make sure the right header files are included when
  # libstdc++ is built the first time.
  # We can use the generated Makefile if make sure nothing gets
  # rebuilt that shouldn't.  But first cleanup after the newlib
  # build.
  # Note that we do not install headers from there.
  if (cd $topobj \
	&& (cd $file_archname/linux/libio && $MAKE clean) \
	&& (cd $file_archname/linux/libstdc++ && $MAKE clean) \
	&& (cd $file_archname/libio \
	  && (echo; echo "*** $program: Compiling libio for linux"; echo) \
	    && env PATH=$ipp$binpath:$PATH $MAKE $ippmakeopts all \
		CC="$nlgcc -O2 -mlinux" \
		CXX="$nlgxx -O2 -mlinux" \
		CFLAGS="-O2 -g" CXXFLAGS="-g -O2" \
		CXXINCLUDES="-I- -I$ipp$libsubdir/linux/include -I$ipp$libsubdir/include -I$srcpath/gnu-toplev/libio -nostdinc++" \
		CINCLUDES="-I- -I$ipp$libsubdir/linux/include -I$ipp$libsubdir/include -I$srcpath/gnu-toplev/libio" \
	      exec_prefix=$ipp$binpath prefix=$ipp$binpath bindir=$ipp$binpath \
	      gxx_include_dir=$ipp$libsubdir/g++-include libdir=$ipp$libgccdir \
		NOSTDINC= $noipbflags ) \
	&& (cd $file_archname/libstdc++ \
	  && (echo; echo "*** $program: Compiling libstdc++ for linux"; echo) \
	    && env PATH=$ipp$binpath:$PATH $MAKE $ippmakeopts all install-libs \
		CC="$nlgcc -O2 -mlinux -isystem $ipp$libsubdir/linux/include" \
		CXX="$nlgxx -O2 -mlinux -isystem $ipp$libsubdir/linux/include -isystem $ipp$libsubdir/g++-include" \
		CFLAGS="-O2 -g" CXXFLAGS="-g -O2" CXXINCLUDES="-I- -nostdinc++" CINCLUDES=-I- \
	      exec_prefix=$ipp$binpath prefix=$ipp$binpath bindir=$ipp$binpath \
	      gxx_include_dir=$ipp$libsubdir/g++-include libdir=$ipp$libgccdir \
		NOSTDINC= ARLINK=no ARLIB=libstdc++.a LIBS=libstdc++.a $noipbflags ) \
      && (test "$ipp" = "" \
	  || (echo "(Replacing $ipp$libsubdir/linux/ path with $libsubdir/linux/ in libc.so)" \
		&& perl -p -i -e "s,$ipp$libsubdir/linux/,$libsubdir/linux/,g" \
			 $ipp$libsubdir/linux/libc.so ) ) ) 2>&1
  then
    echo
    echo "*** $program: glibc libstdc++ files built and installed"
    echo "    in  $ipp$libsubdir/linux"
  else
    echo "*** $program: glibc libstdc++ build and install failed"
    bug_report
  fi
fi | $tee -a $instalog # have_glibc = yes && skip_relibs = no

test -f $errfile && exit 1

# Do a simple sanity check; compile hello, world (C and C++) and check it by grepping for
# that string in the final binary.

(echo
 echo "*** Now checking the installation:") | $tee -a $instalog

rm -f $mytmpdir/mytst* 2> /dev/null

# Let's test glibc-related options separately.
if test $have_glibc = yes
then
  echo "*** Testing $negcc -melinux and"
  echo "    $negxx -melinux  and"
  echo "    $nlgcc -mlinux  and"
  echo "    $nlgxx -mlinux..."
  echo

  if (echodo cd $mytmpdir \
      && echodo $negcc -melinux $ctestf -o mytst \
      && echodo $negxx -melinux $cxxtestf -o mytst2 \
      && echodo $nlgcc -mlinux $linux_test_compile_flags $ctestf -o mytst3 \
      && echodo $nlgxx -mlinux $linux_test_compile_flags $cxxtestf -o mytst4) 2>&1
  then
    echo
    echo "*** ... all seem to work."
    echo
  else
    echo
    echo "*** do NOT work!"
    bug_report
  fi | $tee -a $instalog

  test -f $errfile && exit 1
fi

rm -f $mytmpdir/mytst* 2> /dev/null
(echo "*** Testing $ngcc and"
 echo "    $ngxx (both linking system calls using simulator library) ..."
 echo) | $tee -a $instalog

if (echodo cd $mytmpdir \
    && echodo $ngcc -sim $mytmpdir/test.c -o mytst \
    && echodo $ngxx -sim $cxxtestf -o mytst2) 2>&1
then
  echo
  echo "*** ... both seem to work."
  echo
else
  echo
  echo "*** do NOT work!"
  bug_report
fi | $tee -a $instalog

test -f $errfile && exit 1

# Note that we do not test $file_archname-burn anymore, since it's just a
# courtesy-copy of bin-$file_archname, and everybody should really be using
# objcopy instead.
rm -f $mytmpdir/mytst*.bin 2> /dev/null

# Don't test if we have an installation prefix; bin-$file_archname
# will not find objcopy, and tweaking the situation is likely to be
# misleading.
if test X$ipp = X
then
  if (echodo cd $mytmpdir \
      && echodo $ipp$binpath/bin-$file_archname -w1 -b0 -o mytst.bin mytst \
      && echodo $ipp$binpath/bin-$file_archname -w1 -b0 -o mytst2.bin mytst2  \
      && tr '\000-\037\200-\377' '\n' < mytst.bin \
	  | fgrep '%cHello, world%c' >/dev/null \
      && tr '\000-\037\200-\377' '\n' < mytst2.bin \
	  | fgrep '%cHello, world%c' >/dev/null) 2>&1
  then
    echo
    echo "*** ... bin-$file_archname works"
  else
    rm -f $ipp$binpath/bin-$file_archname 2>/dev/null
  fi
else
  echo  "*** (having installation prefix, not testing bin-$file_archname)"
fi | $tee -a $instalog

if not test -x $ipp$binpath/bin-$file_archname
then
  echo
  echo "*** The bin-$file_archname tool does not work."
  echo "    If you're in a hurry, tweak this script and use"
  echo "    \"objcopy-$file_archname -O binary\" instead."
  echo "    (There's probably a problem with objcopy-$file_archname, as"
  echo "    bin-$archname is a simple shell-script that uses it internally.)"
  bug_report
fi | $tee -a $instalog

test -f $errfile && exit 1

if test $skip_man = no && test "X$manpath" != "X/dev/null"
then
  echo
  echo "*** $program: Now installing manual pages"
  bsm=$srcpath/binutils
  gcm=$mantmp/man1
  for f in $bsm/binutils/doc/ar $bsm/binutils/doc/nm $bsm/binutils/doc/objcopy \
	  $bsm/binutils/doc/objdump $bsm/binutils/doc/ranlib $bsm/binutils/doc/size \
	  $bsm/binutils/doc/strings $bsm/binutils/doc/strip $bsm/gas/doc/as \
	  $bsm/ld/ld $bsm/gprof/gprof $gcm/cpp $gcm/gcc $gcm/g++
  do
    if cp -p $f.1 $ipp$manpath/`basename $f`-$file_archname.1 2>&1
    then true
    else
      echo "*** Could not install manual pages: failed on $f.1"
      bug_report
      exit 1
    fi
  done
  echo "*** Manual pages installed"
fi | $tee -a $instalog

test -f $errfile && exit 1

infodir=$mytmpdir/info-dir
rm -f $infodir 2>/dev/null
# Make sure it exists when we later cat from it, since it will not be
# created unless changes are needed.  It is better to see an updated
# date on "dir" than to avoid changing it.
touch $infodir
if test $skip_info = no && test "X$infopath" != "X/dev/null"
then
  echo
  echo "*** Now installing info pages"
  bsi=$srcpath/binutils
  gci=$infotmp
  if not test -s $ipp$infopath/dir
  then
    if cat >>$infodir <<EOF
-*- Text -*-
This is the file .../info/dir, which contains the topmost node of the
Info hierarchy.  The first time you invoke Info you start off
looking at that node, which is (dir)Top.

File: dir	Node: Top	This is the top of the INFO tree
  This (the Directory node) gives a menu of major topics.
  Typing "d" returns here, "q" exits, "?" lists all INFO commands, "h"
  gives a primer for first-timers, "mTexinfo<Return>" visits Texinfo topic,
  etc.
  Or click mouse button 2 on a menu item or cross reference to select it.
  --- PLEASE ADD DOCUMENTATION TO THIS TREE. (See INFO topic first.) ---

* Menu: The list of major topics begins on the next line.


EOF
    then true
    else
      echo "*** $program: Could not install info pages, failed on \"dir\": $?"
      bug_report
      exit 1
    fi
  fi

  # We could jump through hoops to find makeinfo or abort on missing
  # makeinfo much earlier.  But it just doesn't seem worth it.
  glibcinfo=
  if test $have_glibc = yes
  then
    glibcinfo=$gci/libc.info
    if test -f $glibcinfo
    then true
    else
      echo
      echo "*** $program: Warning: Glibc info files not created."
      echo "    Supposedly you don't have makeinfo 4.0 or later installed,"
      echo "    so glibc did not create them.  This isn't fatal, you will"
      echo "    just not have glibc documentation installed."
      echo
      glibcinfo=
    fi
  fi

  # Change name to contain suffix "-$file_archname" right before ".info".
  # Add dir entries unless we find one that should be suitable (in which case it is not updated).
  # FIXME: Some binutils *.info are new or moved.
  for f in $gci/cpp.info $gci/gcc.info $bsi/binutils/doc/binutils.info \
       $bsi/gas/doc/as.info $bsi/ld/ld.info $glibcinfo
  do
    basenam=`basename $f .info`
    for g in $f*
    do
      newname=`basename $g | sed -e "s/\\.info/-$file_archname.info/g;"`
      if sed -e "s/$basenam\\.info/$basenam-$file_archname.info/g;" \
	     -e '/^START-INFO-DIR-ENTRY$/,/^END-INFO-DIR-ENTRY$/ s/'"($basenam)/($basenam-$file_archname)/g" \
	 < $g > $ipp$infopath/$newname
      then true
      else
	echo "*** $program: Could not install info pages, failed on $g: $?"
	bug_report
	exit 1
      fi
    done

    if (test -s $ipp$infopath/dir \
	&& fgrep " ($basenam-$file_archname). " $ipp$infopath/dir >/dev/null) \
       || awk < $ipp$infopath/$newname '/END-INFO-DIR-ENTRY/ {prt= 0;} {if (prt) {print;}} /START-INFO-DIR-ENTRY/ {prt=1;}' >>$infodir
    then true
    else
      echo "*** $program: Could not install info pages, failed on $f: $?"
      bug_report
      exit 1
    fi
  done
  if test ro_infodir = YES
  then
    if mv $infodir $ipp$infopath/dir2
    then true
    else
      echo "*** $program: Could not install info 'dir2'-file"
      bug_report
      exit 1
    fi
  else
    if cat $infodir >>$ipp$infopath/dir
    then true
    else
      echo "*** $program: Could not add to info 'dir'-file"
      bug_report
      exit 1
    fi
  fi
  echo "*** $program: Info pages installed"
  echo
fi | $tee -a $instalog

test -f $errfile && exit 1

# All must be ok since we got here.

(echo
 echo "*** $program: The installation of tools for $archname went well. ***") \
 | $tee -a $instalog

(echo
 echo "    Programs were installed in:    $binpath"
 echo "    Libraries/subprograms in:      $libpath"
 test "X$manpath" != "X/dev/null" && \
 echo "    Manual pages in:               $manpath"
 test "X$infopath" != "X/dev/null" && \
 echo "    Info pages in:                 $infopath"
 test X$ipp != X && \
 echo "    ** Paths above prepended with: $ipp **"
 echo)  | $tee -a $instalog

if test $manpath != /dev/null && test $new_man = YES
then
  echo "*** Now do not forget to update your \$MANPATH environment variable with:"
  echo "    "`dirname $manpath`
  echo "    A suitable line to add in your .profile or shell resource file"
  echo "    (.bashrc .cshrc .zshrc .tcshrc etc) after other settings, may be:"
  echo "    MANPATH="`dirname $manpath`":\$MANPATH"
  echo
fi | $tee -a $instalog

if test $infopath != /dev/null && test $ro_infodir = YES
then
  echo "*** Do not forget to merge $infopath/dir2 with $infopath/dir"
  echo
fi | $tee -a $instalog

(echo "*** Do not forget to update your \$PATH environment variable with:"
 echo "    $binpath"
 echo "    A suitable line to add in your .profile or shell resource file"
 echo "    (.bashrc .cshrc .zshrc .tcshrc etc) after other settings, may be:"
 echo "    PATH=$binpath:\$PATH"
 echo
 echo "*** The installation finished successfully, the time is:" `date` ) \
 | $tee -a $instalog

echo
yes_or_noP "Do you want to remove the log and the temporary files" y
echo
test "X$yes_or_no" = "XNO" && exit 0

# Remove any directory and such that was created but *NOT* on the path to the
# files that were installed.
cleanup $ipp$binpath/gcc-$file_archname $ipp$libpath/include/stdio.h \
 $ipp$libpath/elinux/include/. $ipp$libpath/elinux/crt0.o \
 $ipp$manpath/gcc-$file_archname.1 $ipp$infopath/dir \
 $ipp$libpath/linux/crt1.o $ipp$libpath/g++-include/iostream
exit 0
