# port-xgcc.sh -- script to build the xgcc-mpc8xx-v1 cross-compiler binaries for
# the Motorola MPC8xx processors
# Copyright (C) 2002 CONNOTECH Experts-conseils inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA  02111-1307  USA
#
# This work was created by CONNOTECH Experts-conseils inc.,
# Montreal, Quebec, Canada.
# web site: http://www.connotech.com/
# e-mail: info@connotech.com

export TARGT_DIR_NAME=xgcc-mpc8xx-v1
export BUILD_DIR_NAME=groupe_4th
export TARGET=powerpc-eabi
export PREFIX=/usr/${TARGT_DIR_NAME}

export PATH=${PREFIX}/bin:$PATH

mkdir ${PREFIX}
mkdir ${BUILD_DIR_NAME}
cd ${BUILD_DIR_NAME}

echo "================== x-compiler build script =================="  2>&1 | tee ../${TARGT_DIR_NAME}.log

# First, we make the binutils tools

echo "================== x-compiler build step-1.1.0 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
../binutils-2.13/configure --host=i386-pc-linux --target=${TARGET} --prefix=${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.1.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make all 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.1.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make install 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.1.3 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
rm config.cache 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

# We now have a GNU cross-assember that takes PowerPC assembler source code and
# a linker that produces ELF format, the foremost file format for PowerPC
# embedded software image. These tools should be all right, but we will re-build
# them again later.

echo "================== x-compiler build step-1.1.8.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ../${BUILD_DIR_NAME} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.1.8.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

# Then, we make the gcc tools with a special configure option
# "--without-headers" which means the run-time library headers are absent

echo "================== x-compiler build step-1.2.0 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
../gcc-3.2.1/configure --host=i386-pc-linux --target=${TARGET} --prefix=${PREFIX} --without-headers --with-newlib --enable-cxx-flags='-fno-exceptions' 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.2.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make all-gcc 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.2.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make install-gcc 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.2.3 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
rm config.cache 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

echo "================== x-compiler build step-1.2.8.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ../${BUILD_DIR_NAME} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.2.8.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

# Now, we are ready to compile the run-time library with the cross-compiler

echo "================== x-compiler build step-1.3.0 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
../newlib-1.10.0/configure --host=i386-pc-linux --target=${TARGET} --prefix=${PREFIX} --enable-cxx-flags='-fno-exceptions' 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.3.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make all 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.3.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make install 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.3.3 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
rm config.cache 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

echo "================== x-compiler build step-1.3.8.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ../${BUILD_DIR_NAME} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-1.3.8.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

# Now, we erase the target directory

echo "================== x-compiler build step-2.1.0 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
chmod -R ugo+w ${PREFIX}/*
rm -r ${PREFIX}/share/locale/*
rmdir ${PREFIX}/share/locale
rmdir ${PREFIX}/share
rm -r ${PREFIX}/powerpc-eabi/sys-include/*
rmdir ${PREFIX}/powerpc-eabi/sys-include
rm -r ${PREFIX}/powerpc-eabi/lib/*
rmdir ${PREFIX}/powerpc-eabi/lib
rm -r ${PREFIX}/powerpc-eabi/include/*
rmdir ${PREFIX}/powerpc-eabi/include
rm -r ${PREFIX}/powerpc-eabi/bin/*
rmdir ${PREFIX}/powerpc-eabi/bin
rmdir ${PREFIX}/powerpc-eabi
rm -r ${PREFIX}/man/*
rmdir ${PREFIX}/man
rm -r ${PREFIX}/lib/*
rmdir ${PREFIX}/lib
rm -r ${PREFIX}/info/*
rmdir ${PREFIX}/info
rm -r ${PREFIX}/include/*
rmdir ${PREFIX}/include
rm -r ${PREFIX}/bin/*
rmdir ${PREFIX}/bin

echo "================== x-compiler build step-2.1.8.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ../${BUILD_DIR_NAME} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-2.1.8.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

# We immediately re-install the run-time library

echo "================== x-compiler build step-2.2.0 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make install 2>&1 | tee -a ../${TARGT_DIR_NAME}

# We got rid of the gcc tools qualified with the "--without-headers" option,
# but we kept a version of the run-time library with header files configured
# properly

echo "================== x-compiler build step-2.2.8.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ../${BUILD_DIR_NAME} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-2.2.8.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

# Now we erase the build directory, and start over again

echo "================== x-compiler build step-2.3.0 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
chmod -R ugo+w *
rm -r Makefile
rm -r bfd/*
rmdir bfd
rm -r binutils/*
rmdir binutils
rm -r etc/*
rmdir etc
rm -r fastjar/*
rmdir fastjar
rm -r gas/*
rmdir gas
rm -r gcc/*
rmdir gcc
rm -r i386-pc-linux/*
rmdir i386-pc-linux
rm -r intl/*
rmdir intl
rm -r ld/*
rmdir ld
rm -r libiberty/*
rmdir libiberty
rm -r opcodes/*
rmdir opcodes
rm -r powerpc-eabi/*
rmdir powerpc-eabi
rm -r texinfo/*
rmdir texinfo
rm -r zlib/*
rmdir zlib
rm config.status
rm config.temp

echo "================== x-compiler build step-2.3.8.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ../${BUILD_DIR_NAME} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-2.3.8.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

# First, we make the binutils tools

echo "================== x-compiler build step-3.1.0 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
../binutils-2.13/configure --host=i386-pc-linux --target=${TARGET} --prefix=${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-3.1.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make all 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-3.1.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make install 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-3.1.3 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
rm config.cache 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

echo "================== x-compiler build step-3.1.8.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ../${BUILD_DIR_NAME} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-3.1.8.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

# Finally, we make the gcc tools, this time without the special configure option

echo "================== x-compiler build step-3.2.0 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
../gcc-3.2.1/configure --host=i386-pc-linux --target=${TARGET} --prefix=${PREFIX} --with-newlib --enable-cxx-flags='-fno-exceptions' 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-3.2.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make all-gcc 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-3.2.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
make install-gcc 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-3.2.3 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
rm config.cache 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

echo "================== x-compiler build step-3.2.8.1 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ../${BUILD_DIR_NAME} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log
echo "================== x-compiler build step-3.2.8.2 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log
tree ${PREFIX} 2>&1 | tee -a ../${TARGT_DIR_NAME}.log

echo "================== x-compiler build step-9.9.9 =================="  2>&1 | tee -a ../${TARGT_DIR_NAME}.log

