--- /tmp/crosstool-0.28-rc37.orig/all.sh	2004-09-29 00:37:46.000000000 -0500
+++ crosstool-0.28-rc37/all.sh	2005-01-20 09:22:47.000000000 -0600
@@ -45,12 +45,6 @@
 fi
 
 # Sanity checks
-case x$PREFIX in
-x/) abort "Don't set PREFIX to /, as \$PREFIX gets deleted!" ;;
-x/usr) abort "Don't set PREFIX to /usr, as \$PREFIX gets deleted!" ;;
-*) ;;
-esac
-
 case x$USER in
 xroot) abort "Don't run all.sh or crosstool.sh as root, it's dangerous" ;;
 *) ;;
@@ -80,6 +74,9 @@
 	--nobuild|-nobuild) 
 	   opt_no_build=1
 	   ;;
+	--nopurge|-nopurge) 
+	   opt_no_purge=1
+	   ;;
 	--builduserland|-builduserland) 
 	   opt_builduserland=1
 	   ;;
@@ -93,11 +90,19 @@
 	   opt_buildrpm=1
 	   ;;
 	*)
-	    abort "Usage: all.sh [--nounpack|--nobuild|--testlinux|--builduserland|--notest|--buildrpm]"
+	    abort "Usage: all.sh [--nounpack|--nobuild|--nopurge|--testlinux|--builduserland|--notest|--buildrpm]"
     esac
     shift
 done
 
+if test "$opt_no_purge" = ""; then
+    case x$PREFIX in
+    x/) abort "Don't set PREFIX to /, as \$PREFIX gets deleted!" ;;
+    x/usr) abort "Don't set PREFIX to /usr, as \$PREFIX gets deleted!" ;;
+    *) ;;
+    esac
+fi
+
 if test "$opt_no_unpack" = ""; then
    if test "$opt_builduserland" = "1"; then
       # Ah, nobody would want to change this :-)
@@ -111,7 +116,11 @@
 
 if test "$opt_no_build" = ""; then
     # Build
-    rm  -rf  $PREFIX
+    if test "$opt_no_purge" = ""; then
+        # Wipe out everything in/below $PREFIX without wiping out $PREFIX itself -
+        # in case we don't have write permission in $PREFIX/..
+        [ -d $PREFIX ] && find $PREFIX -type d -depth -mindepth 1 -exec rm -rf {} \;
+    fi
     mkdir -p $PREFIX
     mkdir -p $BUILD_DIR
     cd $BUILD_DIR
--- /tmp/crosstool-0.28-rc37.orig/crosstool.sh	2004-09-30 05:44:05.000000000 -0500
+++ crosstool-0.28-rc37/crosstool.sh	2005-02-02 09:59:52.000000000 -0600
@@ -70,10 +70,21 @@
 test -z "${CFLAGS}"    || abort "Don't set CFLAGS, it screws up the build"
 test -z "${CXXFLAGS}"  || abort "Don't set CXXFLAGS, it screws up the build"
 
+NATIVE_CROSS=""
+DESTDIR_ARG=""
 if test "$GCC_HOST" != ""; then
 	# Modify $BUILD so gcc never, ever thinks $build = $host
 	UNIQUE_BUILD=`echo $BUILD | sed s/-/-build_/`
 	CANADIAN_BUILD="--build=$UNIQUE_BUILD"
+	if test "$GCC_HOST" = "$TARGET"; then
+        echo "cross-building native toolchain for $TARGET"
+        export CC=${CC-$GCC_HOST-gcc}
+        export AR=${AR-$GCC_HOST-ar}
+        NATIVE_CROSS=yes
+        test -z "${TARGET_ROOT}"    && abort "Please set TARGET_ROOT to the root directory of the target"
+        DESTDIR_ARG="DESTDIR=$TARGET_ROOT"
+        TARGET_ROOT=$TARGET_ROOT/
+    fi
 	echo "canadian cross, configuring gcc & binutils with $CANADIAN_BUILD"
 	# make sure we have a host compiler (since $GCC_HOST-gcc won't work)
 	"$CC" --version || abort "Must set CC to a compiler targeting $GCC_HOST.  PATH is $PATH"
@@ -85,12 +96,14 @@
 	CANADIAN_BUILD=""
 fi
 
-# Modify GCC_HOST to never be equal to $BUILD or $TARGET
-# This strange operation causes gcc to always generate a cross-compiler
-# even if the build machine is the same kind as the host.
-# This is why CC has to be set when doing a canadian cross;
-# you can't find a host compiler by appending -gcc to our whacky $GCC_HOST
-GCC_HOST=`echo $GCC_HOST | sed s/-/-host_/`
+if test "$NATIVE_CROSS" = ""; then
+    # Modify GCC_HOST to never be equal to $BUILD or $TARGET
+    # This strange operation causes gcc to always generate a cross-compiler
+    # even if the build machine is the same kind as the host.
+    # This is why CC has to be set when doing a canadian cross;
+    # you can't find a host compiler by appending -gcc to our whacky $GCC_HOST
+    GCC_HOST=`echo $GCC_HOST | sed s/-/-host_/`
+fi
 
 set -ex
 
@@ -134,43 +147,57 @@
 	export PATH
 fi
 
-# test that we have write permissions to the install dir
-mkdir -p ${PREFIX}/${TARGET}
-touch ${PREFIX}/${TARGET}/test-if-write
-test -w ${PREFIX}/${TARGET}/test-if-write || abort "You don't appear to have write permissions to ${PREFIX}/${TARGET}."
-rm -f ${PREFIX}/${TARGET}/test-if-write
-
-if test -z "$USE_SYSROOT"; then
-    # plain old way.  all libraries in prefix/target/lib
-    SYSROOT=${PREFIX}/${TARGET}
-    HEADERDIR=$SYSROOT/include
-    # hack!  Always use --with-sysroot for binutils.
-    # binutils 2.14 and later obey it, older binutils ignore it.
-    # Lets you build a working 32->64 bit cross gcc
-    BINUTILS_SYSROOT_ARG="--with-sysroot=${SYSROOT}"
-    # Use --with-headers, else final gcc will define disable_glibc while building libgcc, and you'll have no profiling
-    GCC_SYSROOT_ARG_CORE="--without-headers"
-    GCC_SYSROOT_ARG="--with-headers=${HEADERDIR}"
-    GLIBC_SYSROOT_ARG=prefix=
+if test -z "$NATIVE_CROSS"; then
+    # Building a cross-compiler
+    if test -z "$USE_SYSROOT"; then
+        # plain old way.  all libraries in prefix/target/lib
+        SYSROOT=${PREFIX}/${TARGET}
+        HEADERDIR=$SYSROOT/include
+        # hack!  Always use --with-sysroot for binutils.
+        # binutils 2.14 and later obey it, older binutils ignore it.
+        # Lets you build a working 32->64 bit cross gcc
+        BINUTILS_SYSROOT_ARG="--with-sysroot=${SYSROOT}"
+        # Use --with-headers, else final gcc will define disable_glibc while building libgcc, and you'll have no profiling
+        GCC_SYSROOT_ARG_CORE="--without-headers"
+        GCC_SYSROOT_ARG="--with-headers=${HEADERDIR}"
+        GCC_LOCAL_PREFIX_ARG="--with-local-prefix=${TARGET_ROOT}${SYSROOT}"
+        GLIBC_SYSROOT_ARG=prefix=
+    else
+        # spiffy new sysroot way.  libraries split between
+        # prefix/lib and prefix/usr/lib
+        SYSROOT=${PREFIX}
+        HEADERDIR=$SYSROOT/usr/include
+        BINUTILS_SYSROOT_ARG="--with-sysroot=${SYSROOT}"
+        GCC_SYSROOT_ARG="--with-sysroot=${SYSROOT}"
+        GCC_SYSROOT_ARG_CORE=$GCC_SYSROOT_ARG
+        GCC_LOCAL_PREFIX_ARG="--with-local-prefix=${TARGET_ROOT}${SYSROOT}"
+        GLIBC_SYSROOT_ARG=""
+        # glibc's prefix must be exactly /usr, else --with-sysroot'd
+        # gcc will get confused when $sysroot/usr/include is not present
+        # Note: --prefix=/usr is magic!  See http://www.gnu.org/software/libc/FAQ.html#s-2.2
+    fi
 else
-    # spiffy new sysroot way.  libraries split between
-    # prefix/target/sys-root/lib and prefix/target/sys-root/usr/lib
-    SYSROOT=${PREFIX}/${TARGET}/sys-root
-    HEADERDIR=$SYSROOT/usr/include
-    BINUTILS_SYSROOT_ARG="--with-sysroot=${SYSROOT}"
-    GCC_SYSROOT_ARG="--with-sysroot=${SYSROOT}"
+    # Building a native compiler
+    SYSROOT=""
+    HEADERDIR=${TARGET_ROOT}usr/include
+    BINUTILS_SYSROOT_ARG=""
+    GCC_SYSROOT_ARG=""
     GCC_SYSROOT_ARG_CORE=$GCC_SYSROOT_ARG
+    GCC_LOCAL_PREFIX_ARG=""
     GLIBC_SYSROOT_ARG=""
-    # glibc's prefix must be exactly /usr, else --with-sysroot'd
-    # gcc will get confused when $sysroot/usr/include is not present
-    # Note: --prefix=/usr is magic!  See http://www.gnu.org/software/libc/FAQ.html#s-2.2
 fi
 
+# test that we have write permissions to the install dir
+mkdir -p ${TARGET_ROOT}${SYSROOT}
+touch ${TARGET_ROOT}${SYSROOT}/test-if-write
+test -w ${TARGET_ROOT}${SYSROOT}/test-if-write || abort "You don't appear to have write permissions to ${TARGET_ROOT}${SYSROOT}."
+rm -f ${TARGET_ROOT}${SYSROOT}/test-if-write
+
 # Make lib directory in sysroot, else the ../lib64 hack used by 32 -> 64 bit
 # crosscompilers won't work, and build of final gcc will fail with 
 #  "ld: cannot open crti.o: No such file or directory"
-mkdir -p $SYSROOT/lib
-mkdir -p $SYSROOT/usr/lib
+mkdir -p ${TARGET_ROOT}$SYSROOT/lib
+mkdir -p ${TARGET_ROOT}$SYSROOT/usr/lib
 
 echo
 echo "Building for --target=$TARGET, --prefix=$PREFIX"
@@ -232,12 +259,12 @@
 fi
 
 make $PARALLELMFLAGS all 
-make install 
+make install $DESTDIR_ARG
 
 cd ..
 
 # test to see if this step passed
-test -x ${PREFIX}/bin/${TARGET}-ld || abort Build failed during binutils 
+test -x ${TARGET_ROOT}${PREFIX}/${TARGET}/bin/ld || abort Build failed during binutils 
 
 #---------------------------------------------------------
 echo "Install glibc headers needed to build bootstrap compiler -- but only if gcc-3.x"
@@ -288,7 +315,7 @@
         touch stdio-common/errlist-compat.c
     fi
     libc_cv_ppc_machine=yes \
-    make cross-compiling=yes install_root=${SYSROOT} $GLIBC_SYSROOT_ARG install-headers
+    make cross-compiling=yes install_root=${TARGET_ROOT}${SYSROOT} $GLIBC_SYSROOT_ARG install-headers
 
     # Two headers -- stubs.h and features.h -- aren't installed by install-headers,
     # so do them by hand.  We can tolerate an empty stubs.h for the moment.
@@ -305,35 +332,37 @@
     cd ..
 fi
 
-#---------------------------------------------------------
-echo "Build gcc-core (just enough to build glibc)"
+if test -z "$NATIVE_CROSS"; then
+    #---------------------------------------------------------
+    echo "Build gcc-core (just enough to build glibc)"
 
-mkdir -p build-gcc-core; cd build-gcc-core
+    mkdir -p build-gcc-core; cd build-gcc-core
 
-# Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
+    # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
 
-if test '!' -f Makefile; then
-    ${GCC_DIR}/configure $CANADIAN_BUILD --target=$TARGET --host=$GCC_HOST --prefix=$PREFIX \
-	--with-local-prefix=${SYSROOT} \
-	--disable-multilib \
-	--with-newlib \
-        ${GCC_EXTRA_CONFIG} \
-	${GCC_SYSROOT_ARG_CORE} \
-	--disable-nls \
-	--enable-threads=no \
-	--enable-symvers=gnu \
-	--enable-__cxa_atexit \
+    if test '!' -f Makefile; then
+        ${GCC_DIR}/configure $CANADIAN_BUILD --target=$TARGET --host=$GCC_HOST --prefix=$PREFIX \
+    	${GCC_LOCAL_PREFIX_ARG} \
+    	--disable-multilib \
+    	--with-newlib \
+            ${GCC_EXTRA_CONFIG} \
+    	${GCC_SYSROOT_ARG_CORE} \
+    	--disable-nls \
+    	--enable-threads=no \
+    	--enable-symvers=gnu \
+    	--enable-__cxa_atexit \
         --enable-languages=c \
-	--disable-shared
-fi
+    	--disable-shared
+    fi
 
-test "$CANADIAN_BUILD" = "" || make $PARALLELMFLAGS all-build-libiberty || true
-make $PARALLELMFLAGS all-gcc 
-make install-gcc
+    test "$CANADIAN_BUILD" = "" || make $PARALLELMFLAGS all-build-libiberty || true
+    make $PARALLELMFLAGS all-gcc 
+    make install-gcc
 
-cd ..
+    cd ..
 
-test -x ${PREFIX}/bin/${TARGET}-gcc || abort Build failed during gcc-core 
+    test -x ${PREFIX}/bin/${TARGET}-gcc || abort Build failed during gcc-core 
+fi
 
 #---------------------------------------------------------
 echo Build glibc and linuxthreads
@@ -376,11 +405,11 @@
 # Note: LD and RANLIB needed by glibc-2.1.3's c_stub directory, at least on macosx
 # No need for PARALLELMFLAGS here, Makefile already reads this environment variable
 make LD=${TARGET}-ld RANLIB=${TARGET}-ranlib
-make install install_root=${SYSROOT} $GLIBC_SYSROOT_ARG
+make install install_root=${TARGET_ROOT}${SYSROOT} $GLIBC_SYSROOT_ARG
 
 # This doesn't seem to work when building a crosscompiler,
 # as it tries to execute localedef using the just-build ld.so!?
-#make localedata/install-locales install_root=${SYSROOT}
+#make localedata/install-locales install_root=${TARGET_ROOT}${SYSROOT}
 
 # Fix problems in linker scripts.
 # 
@@ -397,19 +426,19 @@
 # To make "strip *.so.*" not fail (ptxdist does this), rename to .so_orig rather than .so.orig
 for file in libc.so libpthread.so libgcc_s.so; do
   for lib in lib lib64 usr/lib usr/lib64; do
-	if test -f ${SYSROOT}/$lib/$file && test ! -h ${SYSROOT}/$lib/$file; then
-		mv ${SYSROOT}/$lib/$file ${SYSROOT}/$lib/${file}_orig
+	if test -f ${TARGET_ROOT}${SYSROOT}/$lib/$file && test ! -h ${TARGET_ROOT}${SYSROOT}/$lib/$file; then
+		mv ${TARGET_ROOT}${SYSROOT}/$lib/$file ${TARGET_ROOT}${SYSROOT}/$lib/${file}_orig
 		if test -z "$USE_SYSROOT"; then
-		  sed 's,/usr/lib/,,g;s,/usr/lib64/,,g;s,/lib/,,g;s,/lib64/,,g;/BUG in libc.scripts.output-format.sed/d' < ${SYSROOT}/$lib/${file}_orig > ${SYSROOT}/$lib/$file
+		  sed 's,/usr/lib/,,g;s,/usr/lib64/,,g;s,/lib/,,g;s,/lib64/,,g;/BUG in libc.scripts.output-format.sed/d' < ${TARGET_ROOT}${SYSROOT}/$lib/${file}_orig > ${TARGET_ROOT}${SYSROOT}/$lib/$file
 	        else
-		  sed '/BUG in libc.scripts.output-format.sed/d' < ${SYSROOT}/$lib/${file}_orig > ${SYSROOT}/$lib/$file
+		  sed '/BUG in libc.scripts.output-format.sed/d' < ${TARGET_ROOT}${SYSROOT}/$lib/${file}_orig > ${TARGET_ROOT}${SYSROOT}/$lib/$file
 		fi
 	fi
     done
 done
 cd ..
 
-test -f ${SYSROOT}/lib/libc.a || test -f ${SYSROOT}/lib64/libc.a || test -f ${SYSROOT}/usr/lib/libc.a || test -f ${SYSROOT}/usr/lib64/libc.a || abort Building libc failed
+test -f ${TARGET_ROOT}${SYSROOT}/lib/libc.a || test -f ${TARGET_ROOT}${SYSROOT}/lib64/libc.a || test -f ${TARGET_ROOT}${SYSROOT}/usr/lib/libc.a || test -f ${TARGET_ROOT}${SYSROOT}/usr/lib64/libc.a || abort Building libc failed
 
 #---------------------------------------------------------
 echo Build final gcc
@@ -424,7 +453,7 @@
     ${GCC_DIR}/configure $CANADIAN_BUILD --target=$TARGET --host=$GCC_HOST --prefix=$PREFIX \
         ${GCC_EXTRA_CONFIG} \
         $GCC_SYSROOT_ARG \
-	--with-local-prefix=${SYSROOT} \
+    	${GCC_LOCAL_PREFIX_ARG} \
 	--disable-nls \
 	--enable-threads=posix \
 	--enable-symvers=gnu \
@@ -437,7 +466,7 @@
 
 test "$CANADIAN_BUILD" = "" || make $PARALLELMFLAGS all-build-libiberty || true
 make $PARALLELMFLAGS all 
-make install 
+make install $DESTDIR_ARG
 
 # FIXME: shouldn't people who want this just --disable-multilib in final gcc and be done with it?
 echo "kludge: If the chip does not have a floating point unit "
@@ -448,21 +477,23 @@
 echo "in $GCC_DIR/gcc/config/$TARGET/* to see what your arch calls it."
 case "$GLIBC_EXTRA_CONFIG" in
    *--without-fp*)
-      if test -d ${SYSROOT}/lib/nof; then
-          cp -af ${SYSROOT}/lib/nof/*.so* ${SYSROOT}/lib || echo "Warning: lib/nof not found.  Ignoring."
+      if test -d ${TARGET_ROOT}${SYSROOT}/lib/nof; then
+          cp -af ${TARGET_ROOT}${SYSROOT}/lib/nof/*.so* ${TARGET_ROOT}${SYSROOT}/lib || echo "Warning: lib/nof not found.  Ignoring."
       fi
       ;;
 esac
 
 cd ..
 
-test -x ${PREFIX}/bin/${TARGET}-gcc || Build failed during final gcc 
+test -x ${TARGET_ROOT}${PREFIX}/bin/${TARGET}-gcc || Build failed during final gcc 
 
 # Set up to let user install individual shared libraries in /etc/ld.so.conf easily
-cd $TOP_DIR
-sh mkoverride.sh
+# Disabled for now - need to reconcile with changes for cross-building of native
+# compilers
+#cd $TOP_DIR
+#sh mkoverride.sh
 
 #---------------------------------------------------------
-echo Cross-toolchain build complete.  Result in ${PREFIX}.
+echo Cross-toolchain build complete.  Result in ${TARGET_ROOT}${SYSROOT}.
 exit 0
 
