I found the instructions at Ngine and Hitmen to be an excellent start. But as I progressed I found that these just weren't enough help to be completely useful because I needed C++ as well as C.
At work, I did start using CygWin (later installed Linux at work) and although it is very good (for what it is), the best platform to use for development is Linux. I say this, because the tools you will be using were developed on Linux and were meant for a Unix(ish) environment. So, the instructions here will be aimed at Linux users.
First, get the following software:
Alternately, you can get GCC from GNU and Newlib from RedHat.
I got these patches originally from MRBrown, but they didn't apply cleanly; so I applied them by hand and created some newer patches for the above packages. I have compiled the libdream 320x240 demo using these patches and they seem to work, so here they are:
Specify the environment variables:
BASH$ target=sh-elf; prefix=/usr/local; i=$prefix/bin
Compile binutils for SH4:
First, you want to make a directory to put all of your source code into. It's probably better to log in as root and do in /usr/src. We'll call our directory xgcc.
Make your /usr/src/xgcc directory and cd into it. Then type the following commands:
BASH$ tar -xzvpf binutils-2.11.tar.gz
BASH$ mkdir build-binutils-sh4
BASH$ cd build-binutils-sh4
BASH$ ../binutils-2.11/configure --target=$target --prefix=$prefix
BASH$ make all install
At this point you will want to export the path to your new tools: export PATH=/usr/src/xgcc/bin, this will stop the gcc build failing halfway through.
Compile GCC for SH4:
BASH$ tar -xzvpf gcc-core-3.0.tar.gz
BASH$ tar -xzvpf gcc-g++-3.0.tar.gz
BASH$ mkdir build-gcc-sh4
BASH$ cd build-gcc-sh4
BASH$ ../gcc-3.0/configure --target=$target --prefix=$prefix --without-headers --with-newlib --enable-languages=c
BASH$ make all-gcc
BASH$ make install-gcc
Compile Newlib for SH4:
BASH$ tar -xzvpf newlib-1.9.0.tar.gz
BASH$ mkdir build-newlib-sh4
BASH$ cd build-newlib-sh4
BASH$ ../newlib-1.9.0/configure --target=$target --prefix=$prefix
BASH$ make all install CC_FOR_TARGET=$i/${target}-gcc AS_FOR_TARGET=$i/${target}-as LD_FOR_TARGET=$i/${target}-ld AR_FOR_TARGET=$i/${target}-ar RANLIB_FOR_TARGET=$i/${target}-ranlib
At this point you will want to export the path to your new tools: export PATH=/usr/src/xgcc/bin, this will stop the gcc build failing halfway through.
Compile GCC for SH4:
BASH$ cd build-gcc-sh4
BASH$ make clean
BASH$ ../gcc-3.0/configure --target=$target --prefix=$prefix --without-headers --with-newlib --enable-languages=c,c++
BASH$ make all install
I have a simple script to handle this compile, you can get that here.
That's almost it! You still need a couple more files to be ready to compile:
Now, you need to assemble the startup file and install it in the correct place:
BASH$ sh-elf-as -little crt0.clean.s -o /usr/local/xgcc/sh-elf/lib/ml/m4-single-only/crt0.o
That's it! You should now have a complete (C/C++) installation of the cross tools for SH4 in /usr/local!