This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: help for MIPS cross compiler


I recently struggled mightily with getting a mips cross-compile
working.  While it was on Solaris instead of Cygwin, the script I came
up with is still probably of use to you...

My setup:

I extracted each of gcc, binutils, and newlib to the /usr/src
directory, from where I run the script.  Note that I use zsh for the
script which you probably don't have installed, so I changed the
script to bash.  This will break the logging, so you might want to
remove the use of log files (delete appropriate lines from the
script).

Invocation:

I generally use the folloing invocation:

./build.sh -G 2.95.3 -N 1.9.0 -B 2.10.1 -t target -p /usr/gnu/target -a#

Where you replace 'target' in the -t and -p options with the target
for your build, and replace "#" for a build number as defined in the
script (at the very bottom).

Generally, there are 12 steps to the full build:

Configure, Make, Install Binutils
Configure, Make, Install Core GCC (C only)
Configure, Make, Install Newlib (make fully functional C Compiler)
Configure, Make, Install Full GCC (I use only C & C++)

I have labeled these steps as a1 through a12 for purposes of the build
script, while the parameter "-a0" will run all 12 steps.

This script works for all mips-* targets I have tried, and should work
for all most other targets as well.

Remember, this script is primitive, and was not written with public
use in mind...merely to make my own life easier.  However, it does
list all the steps I needed to build a working compiler, and provide
a script to easily automate the task.

Note that to get the final step to build (C/C++ compiler "make all"
step), I had to play arround with a bit with file locations in the
gcc-2.95.3/gcc/cp directory, and gcc-2.95.3/libstdc++/stl directory.
If anyone is interested, I can post details on what went wrong and on
what I needed to do to fix it all...

Hope this helps...

--David

#!/bin/bash
#
# (bash shell used, but log-files improperly saved...use zsh for
# proper logging).
#
#!/bin/zsh
#set -x
#
# File:     build.sh
# Purpose:  Build Specified GNU Utilities
################################################################################
# Global Settings
#
# This section lists settings for what type of compiler to build, and where
# it should be installed.
#
##
# The target we are cross-compiling for:
target=mips-idt-ecoff

##
# The directory where we will be installing tools
prefix=/usr/gnu/$target

##
# Native Compiler Location
#CC=/usr/gnu/gcc-sparc-sun-solaris2.8/bin/gcc
CC=/usr/gnu/sparc-sun-solaris2.8/bin/gcc

##
# Native Assembler
AS=/usr/gnu/sparc-sun-solaris2.8/bin/as

##
# Use sudo to install (set to empty string to not use sudo)
#
# XXX Change this so that we detect install mode and change XXX
# XXX script so as to work in a more automated (type and    XXX
# XXX forget) fasion.                                       XXX
SUDO=""

################################################################################
# buildUtil
# 
##
# User Settings
function buildUtil()
{
    progName=
    version=
    configure=
    build=
    install=
    configArgs=
    target=
    deleteOldConfig=

    # Parse inputs
    optstr="C:cdimMp:t:v:"

#echo $*
#echo $#

    OPTIND=1
    getopts $optstr opt
    OPTIND=1

#    while [[ $OPTIND < $# || $OPTIND = $# ]]; do
    while [[ $? == 0 ]]; do
#echo "NumArgs = $#"
#echo "OPTIND =  $OPTIND"
#echo $opt $OPTARG $OPTIND
        case $opt in 
            "C")
                configArgs=$OPTARG
                ;;
            "c")
                configure=1
                ;;
            "d")
                deleteOldConfig=1
                ;;
            "i")
                install=1
                ;;
            "m")
                build=1
                ;;
            "M")
                buildArgs=$OPTARG
                ;;
            "p")
                progName=$OPTARG
                ;;
            "t")
                target=$OPTARG
                ;;
            "v")
                version=$OPTARG
                ;;
            "--")
                configArgs=$OPTARG
                ;;
            *)
                echo "Invalid Argument to $0: $opt"
                exit -2
                ;;
        esac
        getopts $optstr opt
    done

#echo $configArgs

    ##
    # Set the path for binutils if not building binutils
    if [[ $progName != 'binutils' ]]; then
        export PATH=$PATH':'$prefix'/bin'
    fi


    echo "Building $progName version $version for $target"
#echo "configure = $configure"
#echo "build = $build"
#echo "install = $install"

    ##
    # Configureation
    if [[ $configure == 1 ]]; then
        if [[ $deleteOldConfig == 1 ]]; then
            rm -rf build-$progName-$version-$target
            mkdir build-$progName-$version-$target
        fi
        cd build-$progName-$version-$target

# target=           Target system to build for
# prefix=           Install location

        ../$progName-$version/configure \
            --target=$target \
            --prefix=$prefix \
            -v \
            $configArgs

        cd ..
    fi

    ##
    # Build Section
    if [[ $build == 1 ]]; then
        cd build-$progName-$version-$target
        make $buildArgs all
        cd ..
    fi

    ##
    # Installation
    if [[ $install == 1 ]]; then
        cd build-$progName-$version-$target
        if [[ $? == 0 ]]; then
            $SUDO make install
        else
            cd ..
            echo "Build of $progName-$version failed!"
            exit -1
        fi
        cd ..
    fi

    exit 0
}

################################################################################
# Main Script

actionargs=
del=
optstr="a:B:bcdD:G:gmN:p:t:"
binutilsver=2.9.1
gccver=2.95.3
newlibver=1.9.0
action=
dateStr=`date +%Y%m%d-%H%M%S`

getopts $optstr opt
OPTIND=1

while [[ $? == 0 ]]; do

    case $opt in
        "a")
            action="all"
            action=$action$OPTARG
            ;;
        "b")
            action="binutils"
            ;;
        "d")
            del="-d"
            ;;
        "D")
            dateStr=$OPTARG
            ;;
        "g")
            action="gcc"
            ;;
        "m")
            actionargs=$actionargs' -m'
            ;;
        "c")
            actionargs=$actionargs' -c'
            ;;
        "t")
            target=$OPTARG
            ;;
        "G")
            gccver=$OPTARG
            ;;
        "B")
            binutilsver=$OPTARG
            ;;
        "N")
            newlibver=$OPTARG
            ;;
        "p")
            prefix=$OPTARG
            ;;
        *)
            echo "Invalid Argument to $0: $opt"
            exit -2
            ;;
    esac
    getopts $optstr opt
done

case $action in
    "gcc")
        buildUtil -p gcc -v $gccver -t $target $actionargs
        ;;
    "binutils")
        buildUtil -p binutils -v $binutilsver -t $target $actionargs
        ;;
    "all0")
        test -d $prefix
        if [[ $? == 0 ]]; then
            echo "Error:  Directory $prefix already exists!"
            echo "Error:  Bailing out so we don't overwrite existing tools!"
            exit -1
        fi

        $0 -a1  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a2  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a3  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a4  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a5  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a6  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a7  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a8  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a9  -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a10 -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a11 -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        excd=$?
        if [[ $excd != 0 ]]; then
            exit $excd
        fi
        $0 -a12 -t $target -p $prefix -G $gccver -B $binutilsver -N $newlibver $del -D $dateStr
        ;;
    "all1")
# Format for Creating Files...
# ./tst > out.log 1>&2 2>&1 2> out.err
        echo "Configuring binutils"
        buildUtil -c $del -p binutils -v $binutilsver -t $target \
            2>> ./logs/binutils-$target-$dateStr.err 2>&1 1>> ./logs/binutils-$target-$dateStr.log 2>&1
        ;;
    "all2")
        echo "Building binutils"
        buildUtil -m -p binutils -v $binutilsver -t $target \
            2>> ./logs/binutils-$target-$dateStr.err 2>&1 1>> ./logs/binutils-$target-$dateStr.log 2>&1
        ;;
    "all3")
        echo "Installing binutils"
        buildUtil -i -p binutils -v $binutilsver -t $target \
            2>> ./logs/binutils-$target-$dateStr.err 2>&1 1>> ./logs/binutils-$target-$dateStr.log 2>&1
        ;;
    "all4")
        echo "Configuring gcc for core build"
        buildUtil -c $del -p gcc -v $gccver -t $target \
            -C "--with-gnu-ar \
                --with-gnu-as \
                --with-gnu-ld \
                --with-newlib \
                --enable-languages=c" \
            2>> ./logs/gcc-$target-$dateStr.err 2>&1 1>> ./logs/gcc-$target-$dateStr.log 2>&1
        ;;
    "all5")
        echo "Building GCC Core Build"
        buildUtil -m -p gcc -v $gccver -t $target \
            2>> ./logs/gcc-$target-$dateStr.err 2>&1 1>> ./logs/gcc-$target-$dateStr.log 2>&1
            #-M "LANGUAGES=c" \
        ;;
    "all6")
        echo "Installing GCC Core Build"
        buildUtil -i -p gcc -v $gccver -t $target \
            2>> ./logs/gcc-$target-$dateStr.err 2>&1 1>> ./logs/gcc-$target-$dateStr.log 2>&1
        ;;
    "all7")
        echo "Configuring newlib"
        buildUtil -c $del -p newlib -v $newlibver -t $target \
            -C "--with-gnu-ar \
                --with-gnu-as \
                --with-gnu-ld" \
            2>> ./logs/newlib-$target-$dateStr.err 2>&1 1>> ./logs/newlib-$target-$dateStr.log 2>&1
        ;;
    "all8")
        echo "Building newlib"
        buildUtil -m -p newlib -v $newlibver -t $target \
            2>> ./logs/newlib-$target-$dateStr.err 2>&1 1>> ./logs/newlib-$target-$dateStr.log 2>&1
        ;;
    "all9")
        echo "Installing newlib"
        buildUtil -i -p newlib -v $newlibver -t $target \
            2>> ./logs/newlib-$target-$dateStr.err 2>&1 1>> ./logs/newlib-$target-$dateStr.log 2>&1
        ;;
    "all10")
        echo "Configuring gcc for full build"
        buildUtil -c -p gcc -v $gccver -t $target \
            -C "--with-gnu-ar \
                --with-gnu-as \
                --with-gnu-ld \
                --with-newlib \
                --enable-languages=c,c++" \
            2>> ./logs/gcc-full-$target-$dateStr.err 2>&1 1>> ./logs/gcc-full-$target-$dateStr.log 2>&1
        ;;
    "all11")
        echo "Building gcc Full Build"
        buildUtil -m -p gcc -v $gccver -t $target \
            2>> ./logs/gcc-full-$target-$dateStr.err 2>&1 1>> ./logs/gcc-full-$target-$dateStr.log 2>&1
        ;;
    "all12")
        echo "Installing GCC Full Build"
        buildUtil -i -p gcc -v $gccver -t $target \
            2>> ./logs/gcc-full-$target-$dateStr.err 2>&1 1>> ./logs/gcc-full-$target-$dateStr.log 2>&1
        ;;
    *)
        echo "Nothing to do!"
        exit 0
        ;;
esac

if [[ $? == 0 ]]; then
    exit 0
else
    exit -1
fi

exit -2

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]