OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [toolchain_install_scripts/] [MOF_ORSOC_TCHN_v5c_or32-elf.sh] - Diff between revs 73 and 74

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 73 Rev 74
#!/bin/bash
#!/bin/bash
 
 
# Copyright (C) 2008,2009,2010 www.meansoffreedom.org, www.orsoc.se
# Copyright (C) 2008,2009,2010 www.meansoffreedom.org, www.orsoc.se
# This file is free software; you can redistribute it and/or modify it
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful, but
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
 
##Date: 11/03/2010
##Date: 11/03/2010
##Title: MOF_ORSOC_TCN_v5c_or32-elf.sh
##Title: MOF_ORSOC_TCN_v5c_or32-elf.sh
##Purpose: Complete Toolchain Builder from MOF & ORSoC.
##Purpose: Complete Toolchain Builder from MOF & ORSoC.
##initial rgd, mse
##initial rgd, mse
##updated jb
##updated jb
 
 
#Changelog
#Changelog
# 090306 - jb
# 090306 - jb
#        - added exit code checking after each make and patch
#        - added exit code checking after each make and patch
#        - changed download method to instead generate a script and run it in
#        - changed download method to instead generate a script and run it in
#          kermit (requiring single ftp logon per host)
#          kermit (requiring single ftp logon per host)
# 090309 - jb
# 090309 - jb
#        - changed download of GNU tools so they occurr from the GNU.org ftp
#        - changed download of GNU tools so they occurr from the GNU.org ftp
#          (except binutils-2.18.50, it's not there)
#          (except binutils-2.18.50, it's not there)
#        - changed download of Linux kernel so it's now from ftp.kernel.org
#        - changed download of Linux kernel so it's now from ftp.kernel.org
#        - changed patch for binutils (fixes gcc-4.3.2 compilation problem
#        - changed patch for binutils (fixes gcc-4.3.2 compilation problem
#          caused by non-string literals in printf)
#          caused by non-string literals in printf)
#        - changed or1ksim version from 0.3.0rc2 to 0.3.0
#        - changed or1ksim version from 0.3.0rc2 to 0.3.0
#        - changed Linux kernel version from 2.6.19 to 2.6.24
#        - changed Linux kernel version from 2.6.19 to 2.6.24
#        - changed Linux kernel patch version for this new kernel version
#        - changed Linux kernel patch version for this new kernel version
#          generated new patch for Linux kernel, based on one from MOF
#          generated new patch for Linux kernel, based on one from MOF
#          (www.meansoffreedom.net) which contains a more complete config file.
#          (www.meansoffreedom.net) which contains a more complete config file.
#          removing need for user input during "make oldconfig"
#          removing need for user input during "make oldconfig"
#        - changed organisation so that all the packages are not copied into
#        - changed organisation so that all the packages are not copied into
#          the build directory before they are extracted, instead it's done
#          the build directory before they are extracted, instead it's done
#          from where they are.
#          from where they are.
#        - changed gdb-6.8 patch version due to stricter gcc-4.3.2 checking
#        - changed gdb-6.8 patch version due to stricter gcc-4.3.2 checking
#          return types.
#          return types.
#        - included better or1ksim config file in Linux sources patch, now
#        - included better or1ksim config file in Linux sources patch, now
#          named "or1ksim_linux.cfg"
#          named "or1ksim_linux.cfg"
# 100309 - jb
# 100309 - jb
#        - changed back to wget for file retrieval
#        - changed back to wget for file retrieval
#        - changed introduction readme
#        - changed introduction readme
#        - changed install destination checking and setup
#        - changed install destination checking and setup
#        - added md5sum checking of any existing downloaded files, removing
#        - added md5sum checking of any existing downloaded files, removing
#          need for redownloading things every time
#          need for redownloading things every time
#        - added debug build mode - run script with -d at command line
#        - added debug build mode - run script with -d at command line
#          note: not everything in this mode has been tested, may not work
#          note: not everything in this mode has been tested, may not work
#          in certain combinations!
#          in certain combinations!
# 120309 - jb
# 120309 - jb
#        - New OS X version - busybox doesn't work (removed from script),
#        - New OS X version - busybox doesn't work (removed from script),
#          nor does ors1ksim (compiles but segfaults somewhere during test).
#          nor does ors1ksim (compiles but segfaults somewhere during test).
# 140309 - Added ability to change target name. Included some sed commands to
# 140309 - Added ability to change target name. Included some sed commands to
#          change or32-uclinux to whatever $TARGET is set to in some scripts
#          change or32-uclinux to whatever $TARGET is set to in some scripts
#          (mainly for uClibc install, the are set at configure time)
#          (mainly for uClibc install, the are set at configure time)
# 160309 - (v5a) Replaced busybox sources in download list (removed for OS X
# 160309 - (v5a) Replaced busybox sources in download list (removed for OS X
#          version and forgot to replace it when running on Linux again.)
#          version and forgot to replace it when running on Linux again.)
# 270309 - Changed the declaration of the check_exit_code function to be without
# 270309 - Changed the declaration of the check_exit_code function to be without
#          the preceeding "function" as this isn't valid in sh, and the new way
#          the preceeding "function" as this isn't valid in sh, and the new way
#          appears to be valid in bash.
#          appears to be valid in bash.
#        - Changed the link in the error output to the new OpenCores forum.
#        - Changed the link in the error output to the new OpenCores forum.
# 210409 - Changed linux kernel and uClibc patch versions to latest
# 210409 - Changed linux kernel and uClibc patch versions to latest
#        - Changed output to all be piped to appropriate files, makes things neater
#        - Changed output to all be piped to appropriate files, makes things neater
# 260409 - Added Cygwin exports section
# 260409 - Added Cygwin exports section
#        - Hopefully now runs on Cygwin with new patch for uClibc
#        - Hopefully now runs on Cygwin with new patch for uClibc
# 300409 - New Binutils patch - fixes objdump instruction decode issue
# 300409 - New Binutils patch - fixes objdump instruction decode issue
# 110509 - (v5c) Put in check for required build tools before building
# 110509 - (v5c) Put in check for required build tools before building
# 260509 - Changed gcc's package download to gcc-core as we only use the
# 260509 - Changed gcc's package download to gcc-core as we only use the
#          c-language compiler and libraries right now.
#          c-language compiler and libraries right now.
# 030609 - Fixed odd problem with uClibc build on latest Cygwin where it tried
# 030609 - Fixed odd problem with uClibc build on latest Cygwin where it tried
#          to run the INSTALL script file instead of the systems install binary
#          to run the INSTALL script file instead of the systems install binary
#          by adding a suffix to the text file.
#          by adding a suffix to the text file.
# 290609 - Changed linux patch to 2.3 - is a patch derived from revision 42 of
# 290609 - Changed linux patch to 2.3 - is a patch derived from revision 42 of
#          OpenRISC repository's kernel.
#          OpenRISC repository's kernel.
# 301109 - Changed GCC patch to one with single precision floating point as
# 301109 - Changed GCC patch to one with single precision floating point as
#          default
#          default
# 021209 - Added --disable-werror flag to gdb-6.8 configure line to fix issue
# 021209 - Added --disable-werror flag to gdb-6.8 configure line to fix issue
#          with gcc-4.4.1
#          with gcc-4.4.1
# 110310 - Moved or1ksim to its own directory in the chosen install directory
# 110310 - Moved or1ksim to its own directory in the chosen install directory
# 140310 - Fixed problem with mkdir command
# 140310 - Fixed problem with mkdir command
 
# 140310 - Fixed ncurses header checking
 
 
# TODO: OS X build things - need an "elf.h" from some Linux machine's
# TODO: OS X build things - need an "elf.h" from some Linux machine's
#       /usr/local/include dir and put in Mac's /usr/local/include dir -
#       /usr/local/include dir and put in Mac's /usr/local/include dir -
#       this solves issue with Linux compilation
#       this solves issue with Linux compilation
# TODO: OS X build things - add HOST_LOADLIBES="lintl" to make line of uClibc
# TODO: OS X build things - add HOST_LOADLIBES="lintl" to make line of uClibc
# TODO: OS X build things - must remove the -Werror line in $GDB_VER/gdb/Makefile,
# TODO: OS X build things - must remove the -Werror line in $GDB_VER/gdb/Makefile,
#       sed command:
#       sed command:
#       sed 's/WERROR\_CFLAGS\ \=\ \-Werror/WERROR\_CFLAGS\ \=/' $GDB_VER/gdb/Makefile
#       sed 's/WERROR\_CFLAGS\ \=\ \-Werror/WERROR\_CFLAGS\ \=/' $GDB_VER/gdb/Makefile
#       Can also just change the gdb-6.8/gdb/Makefile.in and remove the Werror= thing
#       Can also just change the gdb-6.8/gdb/Makefile.in and remove the Werror= thing
# TODO: OS X build things - or1ksim, in or1ksim-0.3.0/peripheral/atadevice.c, it
# TODO: OS X build things - or1ksim, in or1ksim-0.3.0/peripheral/atadevice.c, it
#       includes byteswap.h - actually it's abstract.h that defines #LE_16() bswap_16(),
#       includes byteswap.h - actually it's abstract.h that defines #LE_16() bswap_16(),
#       so in abstract.h we put in defines for bswap_16 as
#       so in abstract.h we put in defines for bswap_16 as
#       #define bswap_16(value) ((((value) & 0xff) << 8) | ((value) >> 8))
#       #define bswap_16(value) ((((value) & 0xff) << 8) | ((value) >> 8))
# TODO: OS X Build things - or1ksim strndup.c, in or1k-0.3.0/port/strndup.c strndup function,
# TODO: OS X Build things - or1ksim strndup.c, in or1k-0.3.0/port/strndup.c strndup function,
#       types not exist etc. Need to include sys/types.h and string.h to this file to fix
#       types not exist etc. Need to include sys/types.h and string.h to this file to fix
#       a few problems.
#       a few problems.
# TODO: OS X build things - or1ksim - or1ksim-0.3.0/sim-cmd.c passes one of our functions
# TODO: OS X build things - or1ksim - or1ksim-0.3.0/sim-cmd.c passes one of our functions
#       to a readline function, rl_event_hook, but this is not defined in the OS X (BSD)
#       to a readline function, rl_event_hook, but this is not defined in the OS X (BSD)
#       readline package, so the GNU readline package must be used.
#       readline package, so the GNU readline package must be used.
# TODO: OS X build things - or1ksim segfaults when run for some reason.
# TODO: OS X build things - or1ksim segfaults when run for some reason.
 
 
## A function we'll call throughout the setup process to check if the previous
## A function we'll call throughout the setup process to check if the previous
## command finished without error
## command finished without error
check_exit_code()
check_exit_code()
{
{
    if [ $? -ne 0 ]
    if [ $? -ne 0 ]
    then
    then
        echo
        echo
        echo "############################ERROR#############################"
        echo "############################ERROR#############################"
        echo
        echo
        echo "Error during toolchain installation."
        echo "Error during toolchain installation."
        echo
        echo
        echo "Please report this to the script maintainers."
        echo "Please report this to the script maintainers."
        echo
        echo
        echo "A useful report would contain information such as the tool"
        echo "A useful report would contain information such as the tool"
        echo "being built/\"make\"d when the error occurred and the relevant"
        echo "being built/\"make\"d when the error occurred and the relevant"
        echo "lines of console output or log file relating to the error. It"
        echo "lines of console output or log file relating to the error. It"
        echo "also helps to include information about your the host OS and"
        echo "also helps to include information about your the host OS and"
        echo "version of GCC."
        echo "version of GCC."
        echo "A good place to look for solutions, and report any bugs, is at"
        echo "A good place to look for solutions, and report any bugs, is at"
        echo "the OpenRISC project's bug tracker on OpenCores.org:"
        echo "the OpenRISC project's bug tracker on OpenCores.org:"
        echo
        echo
        echo "           http://opencores.org/openrisc,bugtracker"
        echo "           http://opencores.org/openrisc,bugtracker"
        echo
        echo
        exit $?
        exit $?
    fi
    fi
}
}
 
 
REQUIRED_TOOL_LIST="
REQUIRED_TOOL_LIST="
make
make
patch
patch
gcc
gcc
g++
g++
bzip2
bzip2
wget
wget
makeinfo
makeinfo
"
"
 
header_check() {
 
    # Compile a simple program, including the header we're checking for
 
    echo "#include <$1.h>" > header_check.c
 
    echo "int main () { return 0; }" >> header_check.c
 
    gcc header_check.c
 
}
 
 
check_essential_build_tools()
check_essential_build_tools()
{
{
 
 
echo "#########################Checking for required build tools######################"
    echo "#########################Checking for required build tools######################"
echo
    echo
        for TOOL in $REQUIRED_TOOL_LIST
    for TOOL in $REQUIRED_TOOL_LIST
        do
    do
            echo -n "Checking for $TOOL    "
        echo -n "Checking for $TOOL    "
            WHICHTOOL=`which $TOOL`
        WHICHTOOL=`which $TOOL`
            echo "$WHICHTOOL"
        echo "$WHICHTOOL"
            if [ -z $WHICHTOOL ]
        if [ -z $WHICHTOOL ]
            then
        then
                echo
            echo
                echo "\t$TOOL not found"
            echo "\t$TOOL not found"
                echo
            echo
                echo "Please install $TOOL and re-run this script"
            echo "Please install $TOOL and re-run this script"
                echo
            echo
                exit 2
            exit 2
            fi
        fi
        done
    done
 
 
# Now check if libncurses-dev has been installed - check for the header
 
# Get host system's GCC prefix dir (usually /usr, but just to be sure)
 
# Get the verbose output of GCC, redirect STDERR to STDOUT, pipe to grep replacing spaces with newlines
 
# grep for the prefix dir line, cut away after the equals sign and we should have the right dir
 
        echo "Checking for libncurses-dev (headers)"
        echo "Checking for libncurses-dev (headers)"
        GCC_V_LIST=`gcc -v 2>&1 | sed -e s/\ /'\\\n'/g`
    header_check "ncurses"
        HOST_GCC_PREFIX=`echo $GCC_V_LIST | grep prefix | cut -d = -f 2 | head -1`
    # Now check the return value of that function
        NCURSES_HEADER_COUNT=`find $HOST_GCC_PREFIX/include -name "ncurses.h" | grep ncurses -c`
    if [ $? -ne 0 ]; then
        if [ $NCURSES_HEADER_COUNT -eq 0 ]; then
 
            echo
            echo
            echo "\tlibncurses-dev not found"
        echo "\tlibncurses-dev not found"
            echo ; echo "Please install libncurses-dev and re-run this script"; echo
            echo ; echo "Please install libncurses-dev and re-run this script"; echo
 
        rm -f header_check.c a.out
            exit 2
            exit 2
        fi
        fi
 
    rm -f header_check.c a.out
 
 
# Todo: somehow inform the user that if we're checking for makeinfo they need to install texinfo package
# Todo: somehow inform the user that if we're checking for makeinfo they need to install texinfo package
        echo
    echo
}
}
 
 
## SCRIPT VERSION ##
## SCRIPT VERSION ##
SCRIPT_VERSION="v5c"
SCRIPT_VERSION="v5c"
 
 
## Beginning globals ##
## Beginning globals ##
 
 
## ORSoC FTP download settings ##
## ORSoC FTP download settings ##
ORSOC_FTP_HOST="195.67.9.12"
ORSOC_FTP_HOST="195.67.9.12"
ORSOC_FTP_USER="ocuser"
ORSOC_FTP_USER="ocuser"
ORSOC_FTP_PASSWD="oc"
ORSOC_FTP_PASSWD="oc"
ORSOC_FTP_DIR="toolchain"
ORSOC_FTP_DIR="toolchain"
 
 
## GNU FTP download settings ##
## GNU FTP download settings ##
GNU_FTP_HOST="ftp.gnu.org"
GNU_FTP_HOST="ftp.gnu.org"
GNU_FTP_USER="anonymous"
GNU_FTP_USER="anonymous"
#GNU_FTP_BINUTILS_DIR="gnu/binutils"
#GNU_FTP_BINUTILS_DIR="gnu/binutils"
GNU_FTP_GCC_DIR="gnu/gcc/gcc-4.2.2"
GNU_FTP_GCC_DIR="gnu/gcc/gcc-4.2.2"
GNU_FTP_GDB_DIR="gnu/gdb"
GNU_FTP_GDB_DIR="gnu/gdb"
 
 
## Linux kernel download settings ##
## Linux kernel download settings ##
KERNEL_FTP_HOST="ftp.kernel.org"
KERNEL_FTP_HOST="ftp.kernel.org"
KERNEL_FTP_USER="anonymous"
KERNEL_FTP_USER="anonymous"
KERNEL_FTP_PASSWD="anonymous"
KERNEL_FTP_PASSWD="anonymous"
KERNEL_FTP_DIR="pub/linux/kernel/v2.6"
KERNEL_FTP_DIR="pub/linux/kernel/v2.6"
 
 
## Local directory variables ##
## Local directory variables ##
START_DIR=`pwd`
START_DIR=`pwd`
DN="n"
DN="n"
DIR=`pwd`
DIR=`pwd`
 
 
## Makedir command we'll use ##
## Makedir command we'll use ##
MKDIR='mkdir -p'
MKDIR='mkdir -p'
## Versions of the toolchain components ##
## Versions of the toolchain components ##
BINUTILS_VER=binutils-2.18.50
BINUTILS_VER=binutils-2.18.50
GCC_VER_NUM=4.2.2
GCC_VER_NUM=4.2.2
GCC_VER=gcc-$GCC_VER_NUM
GCC_VER=gcc-$GCC_VER_NUM
GDB_VER=gdb-6.8
GDB_VER=gdb-6.8
UCLIB_VER=uClibc-0.9.29
UCLIB_VER=uClibc-0.9.29
LINUX_VER=linux-2.6.24
LINUX_VER=linux-2.6.24
BUSY_VER=busybox-1.7.5
BUSY_VER=busybox-1.7.5
SIM_VER=or1ksim-0.3.0
SIM_VER=or1ksim-0.3.0
 
 
## Patches ##
## Patches ##
BINUTILS_PATCH="$BINUTILS_VER.or32_fixed_patch-v2.1.bz2"
BINUTILS_PATCH="$BINUTILS_VER.or32_fixed_patch-v2.1.bz2"
GCC_PATCH=$GCC_VER-or32-fp.patch.bz2
GCC_PATCH=$GCC_VER-or32-fp.patch.bz2
LINUX_PATCH="linux_2.6.24_or32_unified_v2.3.bz2"
LINUX_PATCH="linux_2.6.24_or32_unified_v2.3.bz2"
UCLIBC_PATCH="uClibc-0.9.29-or32-patch-1.1.bz2"
UCLIBC_PATCH="uClibc-0.9.29-or32-patch-1.1.bz2"
GDB_PATCH="or32-gdb-6.8-patch-2.4.bz2"
GDB_PATCH="or32-gdb-6.8-patch-2.4.bz2"
 
 
## MD5sum file ##
## MD5sum file ##
MD5SUM_FILE=md5sums
MD5SUM_FILE=md5sums
 
 
## Configs ##
## Configs ##
#CONFIG1="rgd_uc_29dotconfig" ## Now changed to rgd_uc_29v5dotconfig as it uses paths to the 2.6.24 kernel ##
#CONFIG1="rgd_uc_29dotconfig" ## Now changed to rgd_uc_29v5dotconfig as it uses paths to the 2.6.24 kernel ##
CONFIG1="rgd_uc_29v5dotconfig"
CONFIG1="rgd_uc_29v5dotconfig"
CONFIG2="rgd_bb_1.75dotconfig"
CONFIG2="rgd_bb_1.75dotconfig"
 
 
## Ramdisk name ##
## Ramdisk name ##
RAMDISK_FILE=initrd-fb-03.ext2.last.work.1.7.5
RAMDISK_FILE=initrd-fb-03.ext2.last.work.1.7.5
LINUX_RAMDISK_FILE=arch/or32/support/initrd-fb-03.ext2 ## The location and name of the ramdisk that Linux wants when it compiles
LINUX_RAMDISK_FILE=arch/or32/support/initrd-fb-03.ext2 ## The location and name of the ramdisk that Linux wants when it compiles
 
 
## Toolchain prefix ##
## Toolchain prefix ##
TARGET=or32-elf
TARGET=or32-elf
 
 
 
 
## Tarballs ##
## Tarballs ##
ZBALL1=$BINUTILS_VER.tar.bz2
ZBALL1=$BINUTILS_VER.tar.bz2
TBALL1=$BINUTILS_VER.tar
TBALL1=$BINUTILS_VER.tar
ZBALL2=gcc-core-$GCC_VER_NUM.tar.bz2
ZBALL2=gcc-core-$GCC_VER_NUM.tar.bz2
TBALL2=$GCC_VER.tar
TBALL2=$GCC_VER.tar
ZBALL3=$UCLIB_VER.tar.bz2
ZBALL3=$UCLIB_VER.tar.bz2
TBALL3=$UCLIB_VER.tar
TBALL3=$UCLIB_VER.tar
ZBALL4=$LINUX_VER.tar.bz2
ZBALL4=$LINUX_VER.tar.bz2
TBALL4=$LINUX_VER.tar
TBALL4=$LINUX_VER.tar
ZBALL5=$BUSY_VER.tar.bz2
ZBALL5=$BUSY_VER.tar.bz2
TBALL5=$BUSY_VER.tar
TBALL5=$BUSY_VER.tar
ZBALL6=$SIM_VER.tar.bz2
ZBALL6=$SIM_VER.tar.bz2
TBALL6=$SIM_VER.tar
TBALL6=$SIM_VER.tar
ZBALL7=$RAMDISK_FILE.bz2
ZBALL7=$RAMDISK_FILE.bz2
ZBALL8=$GDB_VER.tar.bz2
ZBALL8=$GDB_VER.tar.bz2
TBALL8=$GDB_VER.tar
TBALL8=$GDB_VER.tar
 
 
ORSOC_FTP_FILE_LIST="$ZBALL1
ORSOC_FTP_FILE_LIST="$ZBALL1
        $ZBALL3
    $ZBALL3
        $ZBALL5
    $ZBALL5
        $ZBALL6
    $ZBALL6
        $ZBALL7
    $ZBALL7
        $BINUTILS_PATCH
    $BINUTILS_PATCH
        $GCC_PATCH
    $GCC_PATCH
        $LINUX_PATCH
    $LINUX_PATCH
        $UCLIBC_PATCH
    $UCLIBC_PATCH
        $GDB_PATCH
    $GDB_PATCH
        $CONFIG1
    $CONFIG1
        $CONFIG2"
    $CONFIG2"
 
 
GNU_FTP_FILE_LIST="$ZBALL2
GNU_FTP_FILE_LIST="$ZBALL2
$ZBALL8"
$ZBALL8"
 
 
KERNEL_FTP_FILE_LIST=$ZBALL4
KERNEL_FTP_FILE_LIST=$ZBALL4
 
 
 
 
 
 
## Check if we've been given the debug mode flag ##
## Check if we've been given the debug mode flag ##
## We won't clear away all the directories if run with the -d or -D options ##
## We won't clear away all the directories if run with the -d or -D options ##
DBG_BUILD=0
DBG_BUILD=0
while getopts d OPT; do
while getopts d OPT; do
    case "$OPT" in
    case "$OPT" in
        d)
        d)
        DBG_BUILD=1
            DBG_BUILD=1
        ;;
            ;;
    esac
    esac
done
done
 
 
##Welcome message
##Welcome message
echo
echo
echo "The OpenRISC toolchain install script - Provided by ORSoC & MeansOfFreedom.net"
echo "The OpenRISC toolchain install script - Provided by ORSoC & MeansOfFreedom.net"
echo "Version $SCRIPT_VERSION"
echo "Version $SCRIPT_VERSION"
echo
echo
echo "#####################################README#####################################"
echo "#####################################README#####################################"
echo
echo
echo "This script will install tools required for development on the OpenRISC platform"
echo "This script will install tools required for development on the OpenRISC platform"
echo "This version ($SCRIPT_VERSION) includes: "
echo "This version ($SCRIPT_VERSION) includes: "
echo "        $GCC_VER, $BINUTILS_VER, $UCLIB_VER"
echo "        $GCC_VER, $BINUTILS_VER, $UCLIB_VER"
echo "        $LINUX_VER, $GDB_VER, $BUSY_VER and $SIM_VER"
echo "        $LINUX_VER, $GDB_VER, $BUSY_VER and $SIM_VER"
echo
echo
echo "Please follow the prompts to select the install location."
echo "Please follow the prompts to select the install location."
echo
echo
echo "Note: Two new directories, or32-build and or32-download, will be created in the"
echo "Note: Two new directories, or32-build and or32-download, will be created in the"
echo "current directory for storing downloaded files and building the tools."
echo "current directory for storing downloaded files and building the tools."
echo "Also: This script attempts to mount a ramdisk image in a local directory to copy"
echo "Also: This script attempts to mount a ramdisk image in a local directory to copy"
echo "in the freshly built busybox. This requires root user privileges - if they are"
echo "in the freshly built busybox. This requires root user privileges - if they are"
echo "not deteceted the existing busybox binaries will remain in the ramdisk image."
echo "not deteceted the existing busybox binaries will remain in the ramdisk image."
echo
echo
echo "#####################################README#####################################"
echo "#####################################README#####################################"
echo
echo
 
 
echo "Install the toolchain under current directory?"
echo "Install the toolchain under current directory?"
echo "Current directory: [$DIR]"
echo "Current directory: [$DIR]"
echo "Tools will be installed in [$DIR/$TARGET]"
echo "Tools will be installed in [$DIR/$TARGET]"
echo [Y/n]:
echo [Y/n]:
read YN
read YN
 
 
 
 
## $YN will be zero length string if user just pressed enter ##
## $YN will be zero length string if user just pressed enter ##
if [ -z $YN ]
if [ -z $YN ]
    then
then
    VAL="y"
    VAL="y"
else
else
    VAL=$(echo $YN | tr [:upper:] [:lower:])
    VAL=$(echo $YN | tr [:upper:] [:lower:])
fi
fi
 
 
if [ $VAL = "n" ]
if [ $VAL = "n" ]
    then
then
    # Optional install path
    # Optional install path
    echo "Enter the path the toolchain will be installed in:"
    echo "Enter the path the toolchain will be installed in:"
    read DIR
    read DIR
 
 
    # Check if the path exists and ask the user to verify it
    # Check if the path exists and ask the user to verify it
    until [ $DN = "y" ]
    until [ $DN = "y" ]
      do
    do
 
 
        #Check the path exists
        #Check the path exists
        if [ -d $DIR ]
        if [ -d $DIR ]
            then
        then
            # The path entered is OK
            # The path entered is OK
            echo "Chosen directory is [$DIR]"
            echo "Chosen directory is [$DIR]"
            echo "Tools will be installed in [$DIR/$TARGET], or1ksim in [$DIR/or1ksim]"
            echo "Tools will be installed in [$DIR/$TARGET], or1ksim in [$DIR/or1ksim]"
            echo "[y/n]:"
            echo "[y/n]:"
            read DN
            read DN
 
 
            if [ -z $DN ]
            if [ -z $DN ]
                then
            then
                # Presume yes here
                # Presume yes here
                DN="y"
                DN="y"
            fi
            fi
 
 
            VAL=$(echo $DN | tr [:upper:] [:lower:])
            VAL=$(echo $DN | tr [:upper:] [:lower:])
        else
        else
            echo
            echo
            #echo "Path does not exist. Please create it and ensure user has correct permissions."
            #echo "Path does not exist. Please create it and ensure user has correct permissions."
            echo "Path does not exist. Create $DIR now?"
            echo "Path does not exist. Create $DIR now?"
            echo "[y/N]:"
            echo "[y/N]:"
            read MKPATH
            read MKPATH
            if [ -z $MKPATH ]
            if [ -z $MKPATH ]
                then
            then
                ## $MKPATH was zero, so user probably just pressed enter without entering anything, which we'll interpret as "n" ##
                ## $MKPATH was zero, so user probably just pressed enter without entering anything, which we'll interpret as "n" ##
                MKPATHYN="n"
                MKPATHYN="n"
            else
            else
                MKPATHYN=$(echo $MKPATH | tr [:upper:] [:lower:])
                MKPATHYN=$(echo $MKPATH | tr [:upper:] [:lower:])
            fi
            fi
 
 
            if [ $MKPATHYN = "y" ]
            if [ $MKPATHYN = "y" ]
                then
            then
                `mkdir -p $DIR`
                `mkdir -p $DIR`
 
 
                # Check we made it successfully
                # Check we made it successfully
                if [ $? -ne 0 ]
                if [ $? -ne 0 ]
                    then
                then
                    DN="n"
                    DN="n"
                else
                else
                    DN="x" # Set this so we do go back through and ask the user to verify
                    DN="x" # Set this so we do go back through and ask the user to verify
                fi
                fi
 
 
            else
            else
                DN="n"
                DN="n"
            fi
            fi
        fi
        fi
 
 
        if [ $DN = "n" ]
        if [ $DN = "n" ]
            then
        then
            echo "Enter the path the toolchain should be installed in:"
            echo "Enter the path the toolchain should be installed in:"
            read DIR
            read DIR
        fi
        fi
 
 
    done
    done
    cd $DIR
    cd $DIR
#    echo "loop done"
#    echo "loop done"
#    echo "Working in " `pwd`
#    echo "Working in " `pwd`
fi
fi
 
 
## Now check that the required tools to build the toolchain are installed
## Now check that the required tools to build the toolchain are installed
check_essential_build_tools
check_essential_build_tools
 
 
BUILD_TOP=$START_DIR/or32-build
BUILD_TOP=$START_DIR/or32-build
export BUILD_TOP
export BUILD_TOP
 
 
## Set donload directory to be under the current directory ##
## Set donload directory to be under the current directory ##
DOWNLOAD_DIR=$START_DIR/or32-download
DOWNLOAD_DIR=$START_DIR/or32-download
 
 
## Setup the target tool installation directory ##
## Setup the target tool installation directory ##
INSTALL_DIR=$DIR
INSTALL_DIR=$DIR
 
 
$MKDIR $INSTALL_DIR
$MKDIR $INSTALL_DIR
 
 
####################################################################################################
####################################################################################################
## Now check which sources have already been downloaded, if any ##
## Now check which sources have already been downloaded, if any ##
DO_DOWNLOADS="y" ## Default is to NOT do downloads
DO_DOWNLOADS="y" ## Default is to NOT do downloads
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should do downloads ##
    ## Ask if we should do downloads ##
    echo "Do downloads?"
    echo "Do downloads?"
    echo "[y/N]:"
    echo "[y/N]:"
    read DO_DOWNLOADS
    read DO_DOWNLOADS
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $DO_DOWNLOADS ]
    if [ -z $DO_DOWNLOADS ]
        then
    then
        DO_DOWNLOADS="n"
        DO_DOWNLOADS="n"
    else
    else
        DO_DOWNLOADS=$(echo $DO_DOWNLOADS | tr [:upper:] [:lower:])
        DO_DOWNLOADS=$(echo $DO_DOWNLOADS | tr [:upper:] [:lower:])
    fi
    fi
 
 
fi
fi
 
 
if [ $DO_DOWNLOADS = "y" ]
if [ $DO_DOWNLOADS = "y" ]
then
then
## Check if download directory exists, if not create it ##
## Check if download directory exists, if not create it ##
    if [ ! -d $DOWNLOAD_DIR ]; then
    if [ ! -d $DOWNLOAD_DIR ]; then
        $MKDIR $DOWNLOAD_DIR
        $MKDIR $DOWNLOAD_DIR
    fi
    fi
 
 
    cd $DOWNLOAD_DIR
    cd $DOWNLOAD_DIR
 
 
## We'll need the md5sum file ##
## We'll need the md5sum file ##
## This is a file stored on the ORSoC FTP server, containing checksums of all the files we need ##
## This is a file stored on the ORSoC FTP server, containing checksums of all the files we need ##
    rm -f $MD5SUM_FILE
    rm -f $MD5SUM_FILE
    wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$MD5SUM_FILE
    wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$MD5SUM_FILE
## Make sure we got that OK ##
## Make sure we got that OK ##
    check_exit_code
    check_exit_code
 
 
## We have lists of what to get from each FTP let's create a loop for each ##
## We have lists of what to get from each FTP let's create a loop for each ##
 
 
## ORSoC FTP server downloads ##
## ORSoC FTP server downloads ##
    for CURRENT_FILE in $ORSOC_FTP_FILE_LIST
    for CURRENT_FILE in $ORSOC_FTP_FILE_LIST
      do
    do
  # Check if we've already got the file
  # Check if we've already got the file
      if [ -e $CURRENT_FILE ]
        if [ -e $CURRENT_FILE ]
          then
        then
          echo "File $CURRENT_FILE exists locally."
            echo "File $CURRENT_FILE exists locally."
          echo "Verifying MD5 checksum:"
            echo "Verifying MD5 checksum:"
      ## Verify it's right by checking the MD5 checksum ##
      ## Verify it's right by checking the MD5 checksum ##
      ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
      ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
      ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
      ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
          cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
            cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
          if [ $? -ne 0 ]
            if [ $? -ne 0 ]
              then
            then
          #MD5sum of $CURRENT_FILE differs from expected value - we'll download it again
          #MD5sum of $CURRENT_FILE differs from expected value - we'll download it again
              echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
                echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
              rm -f $CURRENT_FILE
                rm -f $CURRENT_FILE
              wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$CURRENT_FILE
                wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$CURRENT_FILE
              check_exit_code
                check_exit_code
          fi
            fi
      else
        else
      # File doesn't exist locally - we'll download it
      # File doesn't exist locally - we'll download it
          echo "Downloading $CURRENT_FILE"
            echo "Downloading $CURRENT_FILE"
          wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$CURRENT_FILE
            wget ftp://$ORSOC_FTP_USER:$ORSOC_FTP_PASSWD@$ORSOC_FTP_HOST/$ORSOC_FTP_DIR/$CURRENT_FILE
          check_exit_code
            check_exit_code
      fi
        fi
      echo
        echo
    done
    done
 
 
## GNU FTP server downloads ##
## GNU FTP server downloads ##
    for CURRENT_FILE in $GNU_FTP_FILE_LIST
    for CURRENT_FILE in $GNU_FTP_FILE_LIST
      do
    do
  ## Check if we've already got the file ##
  ## Check if we've already got the file ##
      if [ -e $CURRENT_FILE ]
        if [ -e $CURRENT_FILE ]
          then
        then
          echo "File $CURRENT_FILE exists locally."
            echo "File $CURRENT_FILE exists locally."
          echo "Verifying MD5 checksum:"
            echo "Verifying MD5 checksum:"
      ## Verify it's right by checking the MD5 checksum ##
      ## Verify it's right by checking the MD5 checksum ##
      ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
      ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
      ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
      ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
          cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
            cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
          if [ $? -ne 0 ]
            if [ $? -ne 0 ]
              then
            then
          ## MD5sum of present one is incorrect - we'll download it again ##
          ## MD5sum of present one is incorrect - we'll download it again ##
              echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
                echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
              rm -f $CURRENT_FILE
                rm -f $CURRENT_FILE
          ## Depending on the file, we need a specific path ##
          ## Depending on the file, we need a specific path ##
          ## gcc's path on ftp ##
          ## gcc's path on ftp ##
              if [ $CURRENT_FILE = $ZBALL2 ]; then
                if [ $CURRENT_FILE = $ZBALL2 ]; then
                  GNU_FTP_DIR=$GNU_FTP_GCC_DIR
                    GNU_FTP_DIR=$GNU_FTP_GCC_DIR
              fi
                fi
          ## gdb's path on ftp ##
          ## gdb's path on ftp ##
              if [ $CURRENT_FILE = $ZBALL8 ]; then
                if [ $CURRENT_FILE = $ZBALL8 ]; then
                  GNU_FTP_DIR=$GNU_FTP_GDB_DIR
                    GNU_FTP_DIR=$GNU_FTP_GDB_DIR
              fi
                fi
              wget ftp://$GNU_FTP_USER:$GNU_FTP_USER@$GNU_FTP_HOST/$GNU_FTP_DIR/$CURRENT_FILE
                wget ftp://$GNU_FTP_USER:$GNU_FTP_USER@$GNU_FTP_HOST/$GNU_FTP_DIR/$CURRENT_FILE
              check_exit_code
                check_exit_code
          fi
            fi
      else
        else
      # File doesn't exist - we'll download it
      # File doesn't exist - we'll download it
          echo "Downloading $CURRENT_FILE"
            echo "Downloading $CURRENT_FILE"
      ## Depending on the file, we need a specific path ##
      ## Depending on the file, we need a specific path ##
      ## gcc's path on ftp ##
      ## gcc's path on ftp ##
          if [ $CURRENT_FILE = $ZBALL2 ]; then
            if [ $CURRENT_FILE = $ZBALL2 ]; then
              GNU_FTP_DIR=$GNU_FTP_GCC_DIR
                GNU_FTP_DIR=$GNU_FTP_GCC_DIR
          fi
            fi
      ## gdb's path on ftp ##
      ## gdb's path on ftp ##
          if [ $CURRENT_FILE = $ZBALL8 ]; then
            if [ $CURRENT_FILE = $ZBALL8 ]; then
              GNU_FTP_DIR=$GNU_FTP_GDB_DIR
                GNU_FTP_DIR=$GNU_FTP_GDB_DIR
          fi
            fi
          wget ftp://$GNU_FTP_USER:$GNU_FTP_USER@$GNU_FTP_HOST/$GNU_FTP_DIR/$CURRENT_FILE
            wget ftp://$GNU_FTP_USER:$GNU_FTP_USER@$GNU_FTP_HOST/$GNU_FTP_DIR/$CURRENT_FILE
          check_exit_code
            check_exit_code
      fi
        fi
      echo
        echo
    done
    done
 
 
## Kernel.org FTP server downloads ##
## Kernel.org FTP server downloads ##
    CURRENT_FILE=$KERNEL_FTP_FILE_LIST
    CURRENT_FILE=$KERNEL_FTP_FILE_LIST
## Usually just a single file from the kernel.org ftp site ##
## Usually just a single file from the kernel.org ftp site ##
    if [ -e $CURRENT_FILE ]
    if [ -e $CURRENT_FILE ]
    then
    then
        echo "File $CURRENT_FILE exists locally."
        echo "File $CURRENT_FILE exists locally."
        echo "Verifying MD5 checksum:"
        echo "Verifying MD5 checksum:"
    ## Verify it's right by checking the MD5 checksum ##
    ## Verify it's right by checking the MD5 checksum ##
    ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
    ## First we get the line for $CURRENT_FILE out of the $MD5SUM_FILE, then feed it to "md5sum -c"
    ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
    ## which checks it and sets the return code, $? to 0 if OK, 1 if problem ##
        cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
        cat $MD5SUM_FILE | grep $CURRENT_FILE | md5sum -c
        if [ $? -ne 0 ]
        if [ $? -ne 0 ]
            then
        then
        #MD5sum of present one is incorrect - we'll download it again
        #MD5sum of present one is incorrect - we'll download it again
            echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
            echo "MD5 checksum of $CURRENT_FILE differs from expected value. Re-downloading."
            rm -f $CURRENT_FILE
            rm -f $CURRENT_FILE
            wget ftp://$KERNEL_FTP_USER:$KERNEL_FTP_USER@$KERNEL_FTP_HOST/$KERNEL_FTP_DIR/$CURRENT_FILE
            wget ftp://$KERNEL_FTP_USER:$KERNEL_FTP_USER@$KERNEL_FTP_HOST/$KERNEL_FTP_DIR/$CURRENT_FILE
            check_exit_code
            check_exit_code
        fi
        fi
    else
    else
    ## Download it ##
    ## Download it ##
        echo "Downloading $CURRENT_FILE"
        echo "Downloading $CURRENT_FILE"
        wget ftp://$KERNEL_FTP_USER:$KERNEL_FTP_PASSWD@$KERNEL_FTP_HOST/$KERNEL_FTP_DIR/$CURRENT_FILE
        wget ftp://$KERNEL_FTP_USER:$KERNEL_FTP_PASSWD@$KERNEL_FTP_HOST/$KERNEL_FTP_DIR/$CURRENT_FILE
    check_exit_code
        check_exit_code
    fi
    fi
 
 
echo
    echo
fi # if [ $DO_DOWNLOADS = "y" ]
fi # if [ $DO_DOWNLOADS = "y" ]
 
 
####################################################################################################
####################################################################################################
 
 
## Cygwin exports ##
## Cygwin exports ##
ON_CYGWIN=`set | grep -i mach|grep -i -c cygwin`
ON_CYGWIN=`set | grep -i mach|grep -i -c cygwin`
if [ $ON_CYGWIN -ge 1 ]
if [ $ON_CYGWIN -ge 1 ]
    then
then
    echo
    echo
    echo "Cygwin host detected"
    echo "Cygwin host detected"
    echo "Platform specific exports:"
    echo "Platform specific exports:"
    echo  "export HOST_LOADLIBES=\"-lcurses -lintl\" "
    echo  "export HOST_LOADLIBES=\"-lcurses -lintl\" "
    echo
    echo
    export ON_CYGWIN=1
    export ON_CYGWIN=1
    export HOST_LOADLIBES="-lcurses -lintl"
    export HOST_LOADLIBES="-lcurses -lintl"
fi
fi
 
 
####################################################################################################
####################################################################################################
 
 
cd $START_DIR
cd $START_DIR
 
 
## if not debug building, let's remove all the old stuff ##
## if not debug building, let's remove all the old stuff ##
 
 
if [ $DBG_BUILD -eq 0 ]
if [ $DBG_BUILD -eq 0 ]
    then
then
## Always start with a clean build dir ##
## Always start with a clean build dir ##
    rm -fr $BUILD_TOP
    rm -fr $BUILD_TOP
    $MKDIR $BUILD_TOP
    $MKDIR $BUILD_TOP
    chmod 777 $BUILD_TOP
    chmod 777 $BUILD_TOP
 
 
    $MKDIR $BUILD_TOP/b-gcc
    $MKDIR $BUILD_TOP/b-gcc
    $MKDIR $BUILD_TOP/b-b
    $MKDIR $BUILD_TOP/b-b
fi
fi
 
 
## default build option is yes ##
## default build option is yes ##
BUILD_THIS="y"
BUILD_THIS="y"
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should build binutils ##
    ## Ask if we should build binutils ##
    echo "Re-build $BINUTILS_VER ?"
    echo "Re-build $BINUTILS_VER ?"
    echo "[y/N]:"
    echo "[y/N]:"
    read YN
    read YN
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $YN ]
    if [ -z $YN ]
        then
    then
        BUILD_THIS="n"
        BUILD_THIS="n"
    else
    else
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
    fi
    fi
 
 
    if [ $BUILD_THIS = "y" ]
    if [ $BUILD_THIS = "y" ]
        then
    then
        ## Delete and recreate the binutils directory ##
        ## Delete and recreate the binutils directory ##
        rm -rf $BUILD_TOP/b-b
        rm -rf $BUILD_TOP/b-b
        rm -rf $BUILD_TOP/$BINUTILS_VER
        rm -rf $BUILD_TOP/$BINUTILS_VER
        $MKDIR $BUILD_TOP/b-b
        $MKDIR $BUILD_TOP/b-b
 
 
    fi
    fi
fi
fi
 
 
##########################Building Binutils#######################
##########################Building Binutils#######################
if [ $BUILD_THIS = "y" ]
if [ $BUILD_THIS = "y" ]
    then
then
 
 
    echo "############################## Building binutils ###############################"
    echo "############################## Building binutils ###############################"
    echo
    echo
    echo "Decompressing source"
    echo "Decompressing source"
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
## Extract sources ##
## Extract sources ##
    tar xjf $DOWNLOAD_DIR/$ZBALL1
    tar xjf $DOWNLOAD_DIR/$ZBALL1
 
 
    echo
    echo
    echo "Patching binutils with $BINUTILS_PATCH"
    echo "Patching binutils with $BINUTILS_PATCH"
 
 
    cd $BINUTILS_VER
    cd $BINUTILS_VER
 
 
    bzip2 -dc $DOWNLOAD_DIR/$BINUTILS_PATCH | patch -p1 > $BINUTILS_VER-patch.log 2>&1
    bzip2 -dc $DOWNLOAD_DIR/$BINUTILS_PATCH | patch -p1 > $BINUTILS_VER-patch.log 2>&1
 
 
## Make sure that patched ok ##
## Make sure that patched ok ##
    check_exit_code
    check_exit_code
 
 
    cd ..
    cd ..
    cd $BUILD_TOP/b-b
    cd $BUILD_TOP/b-b
 
 
    echo
    echo
    echo "Configuring $BINUTILS_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-checking"
    echo "Configuring $BINUTILS_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-checking"
    echo "Logging output to $BINUTILS_VER-configure.log"
    echo "Logging output to $BINUTILS_VER-configure.log"
    $BUILD_TOP/$BINUTILS_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-checking > $BINUTILS_VER-configure.log 2>&1
    $BUILD_TOP/$BINUTILS_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-checking > $BINUTILS_VER-configure.log 2>&1
 
 
    echo
    echo
    echo "Making and installing $BINUTILS_VER"
    echo "Making and installing $BINUTILS_VER"
    echo "Logging output to $BINUTILS_VER-make.log "
    echo "Logging output to $BINUTILS_VER-make.log "
    make all install > $BINUTILS_VER-make.log 2>&1
    make all install > $BINUTILS_VER-make.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
fi
fi
#######################Finish Building Binutils#####################
#######################Finish Building Binutils#####################
 
 
## Export the path to the new or32 binaries directory, used by the rest of this script ##
## Export the path to the new or32 binaries directory, used by the rest of this script ##
echo
echo
echo "Adding $INSTALL_DIR/$TARGET/bin to the PATH variable"
echo "Adding $INSTALL_DIR/$TARGET/bin to the PATH variable"
export PATH=$INSTALL_DIR/$TARGET/bin:$PATH
export PATH=$INSTALL_DIR/$TARGET/bin:$PATH
 
 
## default build option is yes ##
## default build option is yes ##
BUILD_THIS="y"
BUILD_THIS="y"
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should do the initial builds of GCC and Linux ##
    ## Ask if we should do the initial builds of GCC and Linux ##
    echo "Re-do initial $GCC_VER and $LINUX_VER builds (note if you choose to do this then it's EXTREMELY likely that you will have to do the rest of the script, particularly the re-build of gcc that occurs later)?"
    echo "Re-do initial $GCC_VER and $LINUX_VER builds (note if you choose to do this then it's EXTREMELY likely that you will have to do the rest of the script, particularly the re-build of gcc that occurs later)?"
    echo "[y/N]:"
    echo "[y/N]:"
    read YN
    read YN
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $YN ]
    if [ -z $YN ]
        then
    then
        BUILD_THIS="n" # default is no
        BUILD_THIS="n" # default is no
    else
    else
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
    fi
    fi
 
 
    if [ $BUILD_THIS = "y" ]
    if [ $BUILD_THIS = "y" ]
        then
    then
        ## Delete and recreate the gcc directory ##
        ## Delete and recreate the gcc directory ##
        rm -rf $BUILD_TOP/b-gcc
        rm -rf $BUILD_TOP/b-gcc
        rm -rf $BUILD_TOP/$GCC_VER
        rm -rf $BUILD_TOP/$GCC_VER
        rm -rf $BUILD_TOP/$LINUX_VER
        rm -rf $BUILD_TOP/$LINUX_VER
 
 
        $MKDIR $BUILD_TOP/b-gcc
        $MKDIR $BUILD_TOP/b-gcc
 
 
        ## Undo everything done in the next part
        ## Undo everything done in the next part
        rm -rf $INSTALL_DIR/$TARGET/include
        rm -rf $INSTALL_DIR/$TARGET/include
        unlink $INSTALL_DIR/$TARGET/sys-include
        unlink $INSTALL_DIR/$TARGET/sys-include
 
 
    fi
    fi
fi
fi
 
 
##########################Building GCC and Linux############################
##########################Building GCC and Linux############################
if [ $BUILD_THIS = "y" ]
if [ $BUILD_THIS = "y" ]
    then
then
 
 
    echo
    echo
    echo "####################### Building or32 gcc and Linux ############################"
    echo "####################### Building or32 gcc and Linux ############################"
    echo
    echo
    echo "Decompressing source"
    echo "Decompressing source"
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
## Extract sources ##
## Extract sources ##
    tar xjf $DOWNLOAD_DIR/$ZBALL2 ## gcc sources ##
    tar xjf $DOWNLOAD_DIR/$ZBALL2 ## gcc sources ##
 
 
    tar xjf $DOWNLOAD_DIR/$ZBALL4 ## Linux kernel sources ##
    tar xjf $DOWNLOAD_DIR/$ZBALL4 ## Linux kernel sources ##
 
 
    echo
    echo
    echo "Patching $LINUX_VER with patch file $LINUX_PATCH"
    echo "Patching $LINUX_VER with patch file $LINUX_PATCH"
 
 
    cd $LINUX_VER
    cd $LINUX_VER
 
 
## Apply patch to linux kernel sources ##
## Apply patch to linux kernel sources ##
    bzip2 -dc $DOWNLOAD_DIR/$LINUX_PATCH | patch -p1 > $LINUX_VER-patch.log 2>&1
    bzip2 -dc $DOWNLOAD_DIR/$LINUX_PATCH | patch -p1 > $LINUX_VER-patch.log 2>&1
 
 
## Make sure that patched ok ##
## Make sure that patched ok ##
    check_exit_code
    check_exit_code
## Copy our preconfigured configuration file into place ##
## Copy our preconfigured configuration file into place ##
    cp rgd_dot_config .config
    cp rgd_dot_config .config
 
 
    echo
    echo
    echo "Making Linux oldconfig"
    echo "Making Linux oldconfig"
 
 
    make oldconfig > $LINUX_VER-make-oldconfig.log 2>&1
    make oldconfig > $LINUX_VER-make-oldconfig.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
    $MKDIR $INSTALL_DIR/$TARGET/include
    $MKDIR $INSTALL_DIR/$TARGET/include
    $MKDIR $INSTALL_DIR/$TARGET/include/asm
    $MKDIR $INSTALL_DIR/$TARGET/include/asm
    $MKDIR $INSTALL_DIR/$TARGET/include/linux
    $MKDIR $INSTALL_DIR/$TARGET/include/linux
 
 
    cp -f -dR $LINUX_VER/include/linux/* $INSTALL_DIR/$TARGET/include/linux
    cp -f -dR $LINUX_VER/include/linux/* $INSTALL_DIR/$TARGET/include/linux
    cp -f -dR $LINUX_VER/include/asm-or32/* $INSTALL_DIR/$TARGET/include/asm
    cp -f -dR $LINUX_VER/include/asm-or32/* $INSTALL_DIR/$TARGET/include/asm
 
 
    cd $INSTALL_DIR/$TARGET
    cd $INSTALL_DIR/$TARGET
    ln -s include sys-include
    ln -s include sys-include
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
    cd $GCC_VER
    cd $GCC_VER
 
 
## Patch gcc ##
## Patch gcc ##
    echo
    echo
    echo "Patching $GCC_VER with $GCC_PATCH"
    echo "Patching $GCC_VER with $GCC_PATCH"
 
 
    bzip2 -dc $DOWNLOAD_DIR/$GCC_PATCH | patch -p1 > $GCC_VER-patch.log 2>&1
    bzip2 -dc $DOWNLOAD_DIR/$GCC_PATCH | patch -p1 > $GCC_VER-patch.log 2>&1
 
 
## Make sure that patched ok ##
## Make sure that patched ok ##
    check_exit_code
    check_exit_code
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
    cd b-gcc
    cd b-gcc
 
 
    # configure GCC
    # configure GCC
    echo
    echo
    echo "Configuring $GCC_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c"
    echo "Configuring $GCC_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c"
    echo "Logging output to $GCC_VER-configure.log"
    echo "Logging output to $GCC_VER-configure.log"
    $BUILD_TOP/$GCC_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c > $GCC_VER-configure.log 2>&1
    $BUILD_TOP/$GCC_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c > $GCC_VER-configure.log 2>&1
 
 
    echo
    echo
    echo "Making and installing $GCC_VER"
    echo "Making and installing $GCC_VER"
    echo "Logging output to $GCC_VER-make.log"
    echo "Logging output to $GCC_VER-make.log"
    make all install > $GCC_VER-make.log 2>&1
    make all install > $GCC_VER-make.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
    echo
    echo
    echo "Making vmlinux image"
    echo "Making vmlinux image"
    echo "Logging output to vmlinux-make.log"
    echo "Logging output to vmlinux-make.log"
 
 
    cd $LINUX_VER
    cd $LINUX_VER
    make vmlinux ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > vmlinux-make.log 2>&1
    make vmlinux ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > vmlinux-make.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
fi
fi
##########################Finish Building GCC and Linux############################
##########################Finish Building GCC and Linux############################
 
 
 
 
## default build option is yes ##
## default build option is yes ##
BUILD_THIS="y"
BUILD_THIS="y"
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should rebuild uClibc ##
    ## Ask if we should rebuild uClibc ##
    echo "Re-build $UCLIB_VER ?"
    echo "Re-build $UCLIB_VER ?"
    echo "[y/N]:"
    echo "[y/N]:"
    read YN
    read YN
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $YN ]
    if [ -z $YN ]
        then
    then
        BUILD_THIS="n" # default is no
        BUILD_THIS="n" # default is no
    else
    else
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
    fi
    fi
 
 
    if [ $BUILD_THIS = "y" ]
    if [ $BUILD_THIS = "y" ]
        then
    then
        ## Delete the uClibc directory ##
        ## Delete the uClibc directory ##
        rm -rf $BUILD_TOP/$UCLIB_VER
        rm -rf $BUILD_TOP/$UCLIB_VER
    fi
    fi
fi
fi
 
 
##########################Building uClibc#########################
##########################Building uClibc#########################
if [ $BUILD_THIS = "y" ]
if [ $BUILD_THIS = "y" ]
    then
then
 
 
    echo
    echo
    echo "############################## Building uClibc #################################"
    echo "############################## Building uClibc #################################"
    echo
    echo
    echo "Decompressing source"
    echo "Decompressing source"
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
    tar xjf $DOWNLOAD_DIR/$ZBALL3 ## uClibc sources ##
    tar xjf $DOWNLOAD_DIR/$ZBALL3 ## uClibc sources ##
 
 
    echo
    echo
    echo "Patching $UCLIB_VER with $UCLIBC_PATCH"
    echo "Patching $UCLIB_VER with $UCLIBC_PATCH"
 
 
    cd $UCLIB_VER
    cd $UCLIB_VER
 
 
## Patch uClibc sources ##
## Patch uClibc sources ##
    bzip2 -dc $DOWNLOAD_DIR/$UCLIBC_PATCH  | patch -p1 > $UCLIB_VER-patch.log 2>&1
    bzip2 -dc $DOWNLOAD_DIR/$UCLIBC_PATCH  | patch -p1 > $UCLIB_VER-patch.log 2>&1
 
 
## Make sure that patched ok ##
## Make sure that patched ok ##
    check_exit_code
    check_exit_code
 
 
    export CC=$TARGET-gcc
    export CC=$TARGET-gcc
    export BUILD_TOP
    export BUILD_TOP
    #cp $DOWNLOAD_DIR/$CONFIG1  $BUILD_TOP/$UCLIB_VER/.config
    #cp $DOWNLOAD_DIR/$CONFIG1  $BUILD_TOP/$UCLIB_VER/.config
    #cp $DOWNLOAD_DIR/$CONFIG1  $BUILD_TOP/$UCLIB_VER/.config.old
    #cp $DOWNLOAD_DIR/$CONFIG1  $BUILD_TOP/$UCLIB_VER/.config.old
 
 
    ## $TARGET name implementation into config script ##
    ## $TARGET name implementation into config script ##
    ## First get the second part of the target name, after the "-", the "elf" in "or32-elf", for example ##
    ## First get the second part of the target name, after the "-", the "elf" in "or32-elf", for example ##
    TARGET_SECOND_PART=`echo $TARGET | cut -f 2 -d "-"`
    TARGET_SECOND_PART=`echo $TARGET | cut -f 2 -d "-"`
    ## First change any references to the uclinux target ##
    ## First change any references to the uclinux target ##
    ## And delete the line saying DEVEL_PREFIX so we can put our $INSTALL_DIR path in ##
    ## And delete the line saying DEVEL_PREFIX so we can put our $INSTALL_DIR path in ##
    sed "s/or32\-uclinux/\or32\-$TARGET_SECOND_PART/" $DOWNLOAD_DIR/$CONFIG1 | sed "/DEVEL\_PREFIX\=/d"  > $BUILD_TOP/$UCLIB_VER/.config  ## Output to the .config ##
    sed "s/or32\-uclinux/\or32\-$TARGET_SECOND_PART/" $DOWNLOAD_DIR/$CONFIG1 | sed "/DEVEL\_PREFIX\=/d"  > $BUILD_TOP/$UCLIB_VER/.config  ## Output to the .config ##
    ## Now output the new DEVEL_PATH= value ##
    ## Now output the new DEVEL_PATH= value ##
    echo "DEVEL_PREFIX=\"$INSTALL_DIR/$TARGET\"" >> $BUILD_TOP/$UCLIB_VER/.config
    echo "DEVEL_PREFIX=\"$INSTALL_DIR/$TARGET\"" >> $BUILD_TOP/$UCLIB_VER/.config
    ## copy it to .config.old ##
    ## copy it to .config.old ##
    cp $BUILD_TOP/$UCLIB_VER/.config $BUILD_TOP/$UCLIB_VER/.config.old
    cp $BUILD_TOP/$UCLIB_VER/.config $BUILD_TOP/$UCLIB_VER/.config.old
    ## Do the configuration ##
    ## Do the configuration ##
 
 
## Change the cross compiler name in the Config.or32 file
## Change the cross compiler name in the Config.or32 file
## First get the second part of the target name, after the "-" ##
## First get the second part of the target name, after the "-" ##
    TARGET_SECOND_PART=`echo $TARGET | cut -f 2 -d "-"`
    TARGET_SECOND_PART=`echo $TARGET | cut -f 2 -d "-"`
## Removes the uclinux line and changes to whatever our current target is ##
## Removes the uclinux line and changes to whatever our current target is ##
    sed "s/or32\-uclinux/\or32\-$TARGET_SECOND_PART/" $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32  > $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32.newtarget
    sed "s/or32\-uclinux/\or32\-$TARGET_SECOND_PART/" $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32  > $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32.newtarget
    mv $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32.newtarget $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32
    mv $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32.newtarget $BUILD_TOP/$UCLIB_VER/extra/Configs/Config.or32
 
 
if [ $ON_CYGWIN -ge 1 ]
    if [ $ON_CYGWIN -ge 1 ]
    then
    then
## If on Cygwin, fix strange error where 'install' command by the makefile ##
## If on Cygwin, fix strange error where 'install' command by the makefile ##
## results in it trying to execute the INSTALL text file in the root of the ##
## results in it trying to execute the INSTALL text file in the root of the ##
## package ##
## package ##
    mv INSTALL INSTALL.txt
        mv INSTALL INSTALL.txt
fi
    fi
 
 
    echo
    echo
    echo "Making uClibc oldconfig"
    echo "Making uClibc oldconfig"
 
 
    HOST_LOADLIBES="-lcurses -lintl" HOSTCC=`which gcc` make oldconfig > $UCLIB_VER-make-oldconfig.log 2>&1
    HOST_LOADLIBES="-lcurses -lintl" HOSTCC=`which gcc` make oldconfig > $UCLIB_VER-make-oldconfig.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    ln -s extra/Configs/Config.or32 Config
    ln -s extra/Configs/Config.or32 Config
 
 
    echo
    echo
    echo "Making and install $UCLIB_VER"
    echo "Making and install $UCLIB_VER"
    echo "Logging output to $UCLIB_VER-make.log"
    echo "Logging output to $UCLIB_VER-make.log"
    make all install > $UCLIB_VER-make.log 2>&1
    make all install > $UCLIB_VER-make.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    unset CC
    unset CC
fi
fi
##########################Finish Building uClibc#########################
##########################Finish Building uClibc#########################
 
 
 
 
## default build option is yes ##
## default build option is yes ##
BUILD_THIS="y"
BUILD_THIS="y"
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should rebuild gcc ##
    ## Ask if we should rebuild gcc ##
    echo "Perform $GCC_VER re-build? - YES (y) if you rebuilt GCC and Linux previously, otherwise definitely NO (n)."
    echo "Perform $GCC_VER re-build? - YES (y) if you rebuilt GCC and Linux previously, otherwise definitely NO (n)."
    echo "[y/N]:"
    echo "[y/N]:"
    read YN
    read YN
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $YN ]
    if [ -z $YN ]
        then
    then
        BUILD_THIS="n" # default is no
        BUILD_THIS="n" # default is no
    else
    else
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
    fi
    fi
 
 
    if [ $BUILD_THIS = "y" ]
    if [ $BUILD_THIS = "y" ]
        then
    then
        ## Undo some things we did before after doing this compile ##
        ## Undo some things we did before after doing this compile ##
        unlink $INSTALL_DIR/$TARGET/$TARGET/sys-include
        unlink $INSTALL_DIR/$TARGET/$TARGET/sys-include
        rm -rf $INSTALL_DIR/$TARGET/$TARGET/lib/*
        rm -rf $INSTALL_DIR/$TARGET/$TARGET/lib/*
    fi
    fi
fi
fi
 
 
 
 
##########################re-Building GCC########################
##########################re-Building GCC########################
if [ $BUILD_THIS = "y" ]
if [ $BUILD_THIS = "y" ]
    then
then
 
 
    echo
    echo
    echo "############################## Re-building or-32 gcc ###########################"
    echo "############################## Re-building or-32 gcc ###########################"
    echo
    echo
    echo "Re-building $GCC_VER"
    echo "Re-building $GCC_VER"
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
    cd b-gcc
    cd b-gcc
 
 
    echo
    echo
    echo "Re-configuring $GCC_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c"
    echo "Re-configuring $GCC_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c"
    echo "Logging output to $GCC_VER-rebuild-configure.log"
    echo "Logging output to $GCC_VER-rebuild-configure.log"
 
 
    $BUILD_TOP/$GCC_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c > $GCC_VER-rebuild-configure.log 2>&1
    $BUILD_TOP/$GCC_VER/configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --with-local-prefix=$INSTALL_DIR/$TARGET/$TARGET --with-gnu-as --with-gnu-ld --disable-libssp --enable-languages=c > $GCC_VER-rebuild-configure.log 2>&1
 
 
 
 
 
 
    echo
    echo
    echo "Re-building and re-installing $GCC_VER"
    echo "Re-building and re-installing $GCC_VER"
    echo "Logging output to $GCC_VER-rebuild-make.log"
    echo "Logging output to $GCC_VER-rebuild-make.log"
    make all install > $GCC_VER-rebuild-make.log 2>&1
    make all install > $GCC_VER-rebuild-make.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    cd $INSTALL_DIR/$TARGET/$TARGET
    cd $INSTALL_DIR/$TARGET/$TARGET
    ln -s ../include sys-include
    ln -s ../include sys-include
    cd lib
    cd lib
    cp -f -dR ../../lib/* .
    cp -f -dR ../../lib/* .
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
fi
fi
 
 
##########################finish re-Building GCC########################
##########################finish re-Building GCC########################
 
 
 
 
## default build option is yes ##
## default build option is yes ##
BUILD_THIS="y"
BUILD_THIS="y"
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should rebuild gdb ##
    ## Ask if we should rebuild gdb ##
    echo "Rebuild $GDB_VER?"
    echo "Rebuild $GDB_VER?"
    echo "[y/N]:"
    echo "[y/N]:"
    read YN
    read YN
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $YN ]
    if [ -z $YN ]
        then
    then
        BUILD_THIS="n" # default is no
        BUILD_THIS="n" # default is no
    else
    else
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
    fi
    fi
 
 
    if [ $BUILD_THIS = "y" ]
    if [ $BUILD_THIS = "y" ]
        then
    then
        ## Delete existing gdb dir ##
        ## Delete existing gdb dir ##
        rm -rf $BUILD_TOP/$GDB_VER
        rm -rf $BUILD_TOP/$GDB_VER
    fi
    fi
fi
fi
 
 
 
 
########################## GDB build ################
########################## GDB build ################
if [ $BUILD_THIS = "y" ]
if [ $BUILD_THIS = "y" ]
    then
then
 
 
    echo
    echo
    echo "############################## Building GDB ####################################"
    echo "############################## Building GDB ####################################"
    echo
    echo
    echo "Decompressing source"
    echo "Decompressing source"
 
 
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
    tar xjf $DOWNLOAD_DIR/$ZBALL8
    tar xjf $DOWNLOAD_DIR/$ZBALL8
 
 
    echo
    echo
    echo "Patching $GDB_VER with $GDB_PATCH"
    echo "Patching $GDB_VER with $GDB_PATCH"
    echo "Logging output to $GDB_VER-patch.log"
    echo "Logging output to $GDB_VER-patch.log"
    cd $GDB_VER
    cd $GDB_VER
 
 
    bzcat -dc $DOWNLOAD_DIR/$GDB_PATCH | patch -p1 > $GDB_VER-patch.log 2>&1
    bzcat -dc $DOWNLOAD_DIR/$GDB_PATCH | patch -p1 > $GDB_VER-patch.log 2>&1
 
 
## Make sure that patched ok ##
## Make sure that patched ok ##
    check_exit_code
    check_exit_code
 
 
    echo
    echo
    echo "Configuring $GDB_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-werror"
    echo "Configuring $GDB_VER: --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-werror"
    echo "Logging output to $GDB_VER-configure.log"
    echo "Logging output to $GDB_VER-configure.log"
 
 
    ./configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-werror > $GDB_VER-configure.log 2>&1
    ./configure --target=$TARGET --prefix=$INSTALL_DIR/$TARGET --disable-werror > $GDB_VER-configure.log 2>&1
 
 
    echo
    echo
    echo "Making and installing $GDB_VER"
    echo "Making and installing $GDB_VER"
    echo "Logging output to $GDB_VER-make.log"
    echo "Logging output to $GDB_VER-make.log"
    make all install > $GDB_VER-make.log 2>&1
    make all install > $GDB_VER-make.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
fi
fi
########################## finish GDB build ################
########################## finish GDB build ################
 
 
## default build option is yes ##
## default build option is yes ##
BUILD_THIS="y"
BUILD_THIS="y"
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should rebuild busybox ##
    ## Ask if we should rebuild busybox ##
    echo "Rebuild $BUSY_VER?"
    echo "Rebuild $BUSY_VER?"
    echo "[y/N]:"
    echo "[y/N]:"
    read YN
    read YN
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $YN ]
    if [ -z $YN ]
        then
    then
        BUILD_THIS="n" # default is no
        BUILD_THIS="n" # default is no
    else
    else
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
    fi
    fi
 
 
    if [ $BUILD_THIS = "y" ]
    if [ $BUILD_THIS = "y" ]
        then
    then
        ## Delete existing busybox stuff ##
        ## Delete existing busybox stuff ##
        rm -rf $BUILD_TOP/$BUSY_VER
        rm -rf $BUILD_TOP/$BUSY_VER
    fi
    fi
fi
fi
 
 
##########################Building Busybox########################
##########################Building Busybox########################
if [ $BUILD_THIS = "y" ]
if [ $BUILD_THIS = "y" ]
    then
then
 
 
    echo
    echo
    echo "############################## Building BusyBox ################################"
    echo "############################## Building BusyBox ################################"
    echo
    echo
    echo "Decompressing source"
    echo "Decompressing source"
 
 
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
    tar xjf $DOWNLOAD_DIR/$ZBALL5
    tar xjf $DOWNLOAD_DIR/$ZBALL5
 
 
 
 
    cd $BUSY_VER
    cd $BUSY_VER
    cp $DOWNLOAD_DIR/$CONFIG2  $BUILD_TOP/$BUSY_VER/.config
    cp $DOWNLOAD_DIR/$CONFIG2  $BUILD_TOP/$BUSY_VER/.config
    cp $DOWNLOAD_DIR/$CONFIG2  $BUILD_TOP/$BUSY_VER/.config.old
    cp $DOWNLOAD_DIR/$CONFIG2  $BUILD_TOP/$BUSY_VER/.config.old
 
 
    echo
    echo
    echo "Making $BUSY_VER oldconfig"
    echo "Making $BUSY_VER oldconfig"
    make oldconfig > $BUSY_VER-make-oldconfig.log 2>&1
    make oldconfig > $BUSY_VER-make-oldconfig.log 2>&1
 
 
## Make Sure that built ok ##
## Make Sure that built ok ##
    check_exit_code
    check_exit_code
 
 
## Put the Linux headers in BusyBox's include dir ##
## Put the Linux headers in BusyBox's include dir ##
 
 
    ln -s $BUILD_TOP/$LINUX_VER/include/linux $BUILD_TOP/$BUSY_VER/include/.
    ln -s $BUILD_TOP/$LINUX_VER/include/linux $BUILD_TOP/$BUSY_VER/include/.
    ln -s $BUILD_TOP/$LINUX_VER/include/asm $BUILD_TOP/$BUSY_VER/include/.
    ln -s $BUILD_TOP/$LINUX_VER/include/asm $BUILD_TOP/$BUSY_VER/include/.
 
 
    echo
    echo
    echo "Making $BUSY_VER"
    echo "Making $BUSY_VER"
    echo "Logging output to $BUSY_VER-make.log"
    echo "Logging output to $BUSY_VER-make.log"
    make ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > $BUSY_VER-make.log 2>&1
    make ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > $BUSY_VER-make.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    echo
    echo
    echo "Installing $BUSY_VER"
    echo "Installing $BUSY_VER"
    echo "Logging output to $BUSY_VER-install.log"
    echo "Logging output to $BUSY_VER-install.log"
    make install ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > $BUSY_VER-install.log 2>&1
    make install ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > $BUSY_VER-install.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
## Copy and extract the ramdisk image file
## Copy and extract the ramdisk image file
 
 
    cp $DOWNLOAD_DIR/$ZBALL7 . ## Ramdisk file ##
    cp $DOWNLOAD_DIR/$ZBALL7 . ## Ramdisk file ##
 
 
    bunzip2 $RAMDISK_FILE.bz2
    bunzip2 $RAMDISK_FILE.bz2
 
 
## We can only play with the ext2 image if we're not on Cygwin ##
## We can only play with the ext2 image if we're not on Cygwin ##
    if [ -z $ON_CYGWIN ]
    if [ -z $ON_CYGWIN ]
        then
    then
 
 
        RT=`whoami`
        RT=`whoami`
        if [ $RT = "root" ];then
        if [ $RT = "root" ];then
            $MKDIR rd_mount
            $MKDIR rd_mount
            chmod 777 rd_mount
            chmod 777 rd_mount
            mount -t ext2 -o loop $RAMDISK_FILE rd_mount
            mount -t ext2 -o loop $RAMDISK_FILE rd_mount
            cp -f -dR $BUILD_TOP/busy_out.1.7.5/* $BUILD_TOP/rd_mount
            cp -f -dR $BUILD_TOP/busy_out.1.7.5/* $BUILD_TOP/rd_mount
            umount rd_mount
            umount rd_mount
            cp -f $RAMDISK_FILE $LINUX_VER/$LINUX_RAMDISK_FILE
            cp -f $RAMDISK_FILE $LINUX_VER/$LINUX_RAMDISK_FILE
        else
        else
            echo
            echo
            echo "User is not root. Unable to mount Linux ramdisk."
            echo "User is not root. Unable to mount Linux ramdisk."
            echo "Note that this program built BusyBox but did not"
            echo "Note that this program built BusyBox but did not"
            echo "install it on the ramdisk. Defaults are used."
            echo "install it on the ramdisk. Defaults are used."
            cp -f $RAMDISK_FILE $LINUX_VER/$LINUX_RAMDISK_FILE
            cp -f $RAMDISK_FILE $LINUX_VER/$LINUX_RAMDISK_FILE
        fi
        fi
 
 
    fi ## if [ -z $ON_CYGWIN ]
    fi ## if [ -z $ON_CYGWIN ]
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
fi
fi
 
 
########################## Finish BusyBox build ################
########################## Finish BusyBox build ################
 
 
## default build option is yes ##
## default build option is yes ##
BUILD_THIS="y"
BUILD_THIS="y"
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should rebuild linux again##
    ## Ask if we should rebuild linux again##
    echo "Rebuild the $LINUX_VER rebuild (only ever yes (y) if performed previous linux rebuild)?"
    echo "Rebuild the $LINUX_VER rebuild (only ever yes (y) if performed previous linux rebuild)?"
    echo "[y/N]:"
    echo "[y/N]:"
    read YN
    read YN
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $YN ]
    if [ -z $YN ]
        then
    then
        BUILD_THIS="n" # default is no
        BUILD_THIS="n" # default is no
    else
    else
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
    fi
    fi
 
 
fi
fi
 
 
#echo "Start Building Linux kernel?"
#echo "Start Building Linux kernel?"
#read Q
#read Q
##########################Final Linux kernel build################
##########################Final Linux kernel build################
if [ $BUILD_THIS = "y" ]
if [ $BUILD_THIS = "y" ]
    then
then
 
 
    echo
    echo
    echo "########################### Linux image generation #############################"
    echo "########################### Linux image generation #############################"
    cd $BUILD_TOP
    cd $BUILD_TOP
    cd $LINUX_VER
    cd $LINUX_VER
 
 
    echo
    echo
    echo "Making vmlinux"
    echo "Making vmlinux"
    echo "Logging output to vmlinux-remake.log"
    echo "Logging output to vmlinux-remake.log"
    make vmlinux ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > vmlinux-remake.log 2>&1
    make vmlinux ARCH=or32 CROSS_COMPILE=$INSTALL_DIR/$TARGET/bin/$TARGET- > vmlinux-remake.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
fi
fi
##########################Finished Final Linux kernel build################
##########################Finished Final Linux kernel build################
 
 
BUILD_THIS="y"
BUILD_THIS="y"
 
 
if [ $DBG_BUILD -eq 1 ]
if [ $DBG_BUILD -eq 1 ]
    then
then
    ## Ask if we should rebuild or1ksim##
    ## Ask if we should rebuild or1ksim##
    echo "Rebuild $SIM_VER ?"
    echo "Rebuild $SIM_VER ?"
    echo "[y/N]:"
    echo "[y/N]:"
    read YN
    read YN
    ## $YN will be zero length string if user just pressed enter ##
    ## $YN will be zero length string if user just pressed enter ##
    if [ -z $YN ]
    if [ -z $YN ]
        then
    then
        BUILD_THIS="n" # default is no
        BUILD_THIS="n" # default is no
    else
    else
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
        BUILD_THIS=$(echo $YN | tr [:upper:] [:lower:])
    fi
    fi
 
 
    if [ $BUILD_THIS = "y" ]
    if [ $BUILD_THIS = "y" ]
        then
    then
        ## Clean previous or1ksim directories ##
        ## Clean previous or1ksim directories ##
        rm -rf $BUILD_TOP/$SIM_VER
        rm -rf $BUILD_TOP/$SIM_VER
    fi
    fi
fi
fi
 
 
 
 
##########################Simulator build#########################
##########################Simulator build#########################
if [ $BUILD_THIS = "y" ]
if [ $BUILD_THIS = "y" ]
    then
then
 
 
    echo
    echo
    echo "############################## Building or1ksim ################################"
    echo "############################## Building or1ksim ################################"
    echo
    echo
    echo "Decompressing source"
    echo "Decompressing source"
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
 
 
    tar xjf $DOWNLOAD_DIR/$ZBALL6
    tar xjf $DOWNLOAD_DIR/$ZBALL6
 
 
    cd $SIM_VER
    cd $SIM_VER
 
 
    echo
    echo
    echo "Configuring $SIM_VER: --target=$TARGET --prefix=$INSTALL_DIR/$SIM_VER"
    echo "Configuring $SIM_VER: --target=$TARGET --prefix=$INSTALL_DIR/$SIM_VER"
 
 
    ./configure --target=$TARGET --prefix=$INSTALL_DIR/$SIM_VER > $SIM_VER-configure.log 2>&1
    ./configure --target=$TARGET --prefix=$INSTALL_DIR/$SIM_VER > $SIM_VER-configure.log 2>&1
 
 
    echo
    echo
    echo "Making and installing $SIM_VER"
    echo "Making and installing $SIM_VER"
    echo "Logging output to $SIM_VER-make.log"
    echo "Logging output to $SIM_VER-make.log"
    make all install > $SIM_VER-make.log 2>&1
    make all install > $SIM_VER-make.log 2>&1
 
 
## Make sure that built ok ##
## Make sure that built ok ##
    check_exit_code
    check_exit_code
 
 
## Setup symbolic link from or1ksim-x.y.z to simply or1ksim
## Setup symbolic link from or1ksim-x.y.z to simply or1ksim
 
 
    echo "Symbolically linking $INSTALL_DIR/$SIM_VER to $INSTALL_DIR/or1ksim"
    echo "Symbolically linking $INSTALL_DIR/$SIM_VER to $INSTALL_DIR/or1ksim"
    if [ -e $INSTALL_DIR/or1ksim ]; then
    if [ -e $INSTALL_DIR/or1ksim ]; then
        echo "Symlink $INSTALL_DIR/or1ksim already exists. Updating to this version"
        echo "Symlink $INSTALL_DIR/or1ksim already exists. Updating to this version"
        unlink $INSTALL_DIR/or1ksim;
        unlink $INSTALL_DIR/or1ksim;
        check_exit_code
        check_exit_code
    fi
    fi
    echo "ln -s $INSTALL_DIR/$SIM_VER $INSTALL_DIR/or1ksim"
    echo "ln -s $INSTALL_DIR/$SIM_VER $INSTALL_DIR/or1ksim"
    ln -s $INSTALL_DIR/$SIM_VER $INSTALL_DIR/or1ksim
    ln -s $INSTALL_DIR/$SIM_VER $INSTALL_DIR/or1ksim
 
 
    cd $BUILD_TOP
    cd $BUILD_TOP
fi
fi
##########################Finish Simulator build#########################
##########################Finish Simulator build#########################
 
 
 
 
##########################Code Test###############################
##########################Code Test###############################
cd $BUILD_TOP
cd $BUILD_TOP
echo "Launch the simulator with the newly compiled Linux image and BusyBox apps?"
echo "Launch the simulator with the newly compiled Linux image and BusyBox apps?"
echo "[y/N]:"
echo "[y/N]:"
read SI
read SI
 
 
if [ -z $SI ]
if [ -z $SI ]
    then
then
    SVAL="n" ## Default is no ##
    SVAL="n" ## Default is no ##
else
else
    SVAL=$(echo $SI | tr [:upper:] [:lower:])
    SVAL=$(echo $SI | tr [:upper:] [:lower:])
fi
fi
 
 
if [ $SVAL = "y" ];then
if [ $SVAL = "y" ];then
 
 
    ## Check for X's xterm, if we find it, and a valid $DISPLAY variable, we'll open the simulator with an xterm tty ##
    ## Check for X's xterm, if we find it, and a valid $DISPLAY variable, we'll open the simulator with an xterm tty ##
    which xterm
    which xterm
 
 
 
 
    if [ $? -eq 0 ]
    if [ $? -eq 0 ]
        then
    then
        # Xterm exists, check if the $DISPLAY variable is set
        # Xterm exists, check if the $DISPLAY variable is set
        # Get the display variable
        # Get the display variable
        DISPLAY=`printenv DISPLAY`
        DISPLAY=`printenv DISPLAY`
        echo "DISPLAY variable is set to $DISPLAY"
        echo "DISPLAY variable is set to $DISPLAY"
        if [ -n $DISPLAY ]
        if [ -n $DISPLAY ]
            then
        then
            ## It appears display is set, let's set the or1ksim_linux.cfg file to use an xterm instead of telnet ##
            ## It appears display is set, let's set the or1ksim_linux.cfg file to use an xterm instead of telnet ##
            cd $LINUX_VER
            cd $LINUX_VER
            ## Rename the original script, adding .orig to the end ##
            ## Rename the original script, adding .orig to the end ##
            mv or1ksim_linux.cfg or1ksim_linux.cfg.orig
            mv or1ksim_linux.cfg or1ksim_linux.cfg.orig
            ## Now use sed to comment the line specifiying a telnet tty and uncomment the xterm line, restoring the original script ##
            ## Now use sed to comment the line specifiying a telnet tty and uncomment the xterm line, restoring the original script ##
            sed 's/channel\ \=\ \"tcp\:10084\"/\/\*\ channel\ \=\ \"tcp\:10084\"\ \*\//' or1ksim_linux.cfg.orig | sed 's/\/\*\ channel\ \=\ \"xterm\:\"\ \*\//\ channel\ \=\ \"xterm\:\"\ /' > or1ksim_linux.cfg
            sed 's/channel\ \=\ \"tcp\:10084\"/\/\*\ channel\ \=\ \"tcp\:10084\"\ \*\//' or1ksim_linux.cfg.orig | sed 's/\/\*\ channel\ \=\ \"xterm\:\"\ \*\//\ channel\ \=\ \"xterm\:\"\ /' > or1ksim_linux.cfg
            echo "########################## or1ksim ###############################"
            echo "########################## or1ksim ###############################"
            echo
            echo
            echo "or1ksim will open an xterm for console output as Linux is booting."
            echo "or1ksim will open an xterm for console output as Linux is booting."
            echo
            echo
            echo "########################## or1ksim ###############################"
            echo "########################## or1ksim ###############################"
            cd $BUILD_TOP
            cd $BUILD_TOP
        fi
        fi
 
 
    else
    else
        echo "########################## or1ksim ###############################"
        echo "########################## or1ksim ###############################"
        echo
        echo
        echo "     To connect to the simulator run: telnet 127.0.0.1 10084"
        echo "     To connect to the simulator run: telnet 127.0.0.1 10084"
        echo
        echo
        echo "########################## or1ksim ###############################"
        echo "########################## or1ksim ###############################"
 
 
    fi
    fi
 
 
 
 
    cd $BUILD_TOP/$LINUX_VER
    cd $BUILD_TOP/$LINUX_VER
    $INSTALL_DIR/or1ksim/bin/$TARGET-sim -f or1ksim_linux.cfg vmlinux
    $INSTALL_DIR/or1ksim/bin/$TARGET-sim -f or1ksim_linux.cfg vmlinux
 
 
else
else
    ## User didn't run the sim, but tell them how to anyway ##
    ## User didn't run the sim, but tell them how to anyway ##
    echo "The compiled linux image is found in $BUILD_TOP/$LINUX_VER/vmlinux"
    echo "The compiled linux image is found in $BUILD_TOP/$LINUX_VER/vmlinux"
    echo "To run it in the simulator, cd to $BUILD_TOP/$LINUX_VER"
    echo "To run it in the simulator, cd to $BUILD_TOP/$LINUX_VER"
    echo "and run:"
    echo "and run:"
    echo "$TARGET-sim -f or1ksim_linux.cfg vmlinux"
    echo "$TARGET-sim -f or1ksim_linux.cfg vmlinux"
    echo
    echo
 
 
fi
fi
 
 
echo
echo
echo "OpenRISC toolchain and architectural simulator build is complete!"
echo "OpenRISC toolchain and architectural simulator build is complete!"
echo
echo
echo "Your tools are installed in: $INSTALL_DIR/$TARGET"
echo "Your tools are installed in: $INSTALL_DIR/$TARGET"
echo "or1ksim has been installed in: $INSTALL_DIR/$SIM_VER"
echo "or1ksim has been installed in: $INSTALL_DIR/$SIM_VER"
echo
echo
echo "Please add the paths:"
echo "Please add the paths:"
echo "\t$INSTALL_DIR/$TARGET/bin"
echo "\t$INSTALL_DIR/$TARGET/bin"
echo "\t$INSTALL_DIR/or1ksim/bin"
echo "\t$INSTALL_DIR/or1ksim/bin"
echo "to your PATH variable, for example, in most systems add the line"
echo "to your PATH variable, for example, in most systems add the line"
echo "below to your ~/.bashrc file:"
echo "below to your ~/.bashrc file:"
echo
echo
echo "\texport PATH=\$PATH:$INSTALL_DIR/$TARGET/bin:$INSTALL_DIR/or1ksim/bin"
echo "\texport PATH=\$PATH:$INSTALL_DIR/$TARGET/bin:$INSTALL_DIR/or1ksim/bin"
echo
echo
echo "For further support please visit the OpenRISC forum at OpenCores"
echo "For further support please visit the OpenRISC forum at OpenCores"
echo "http://opencores.org/forum,OpenRISC"
echo "http://opencores.org/forum,OpenRISC"
echo
echo
exit 0
exit 0
 
 
##########################End Script##############################
##########################End Script##############################
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.