antime
Extra Hard Mid Boss
If you can't or don't want to use a prebuilt toolchain there is the option to build one yourself. Since the Saturn is a "bare-metal" environment this is a much simpler process than what is described in most tutorials, and there is no need for any extra tools. The instructions here work on Linux and OS X. They should work on Cygwin as well, but I haven't tried it myself. Getting the build working under MinGW probably requires some extra work, but on Windows you're probably better off using the GNUSH kit anyway.
To build the toolchain you obviously need the developer tools for your OS. On OS X this means installing Xcode, and on Linux you need at least GCC, GNU make and the autotools (autoconf/automake). The binutils and GCC documentation lists the requirements in more detail.
Before you start building, there are two things you must decide: the toolchain object format and install location. The object formats available are COFF and ELF. COFF is an older, partly proprietary standard that is being deprecated in favour of the more open, capable ELF format. Sega's binary libraries are in COFF format, so if you intend to use them you may want to configure your toolchain for COFF, but otherwise ELF is recommended. Note that this choice affects the object format your toolchain produces - it can still understand both formats and you can convert object files using the objcopy tool.
If you picked COFF, your TARGET will be sh-coff and if you picked ELF it is sh-elf. (The canonical name or "configuration triplet" is sh-unknown-coff or sh-unknown-elf, but typing the full name gets annoying very quickly and the shorter form works just as well.)
The install location can be basically anywhere on your system. If you pick a system folder (eg. /usr/local) you will need to run the installation steps with root privileges, but you can just as well install the toolchain in your own home directory. The only thing you must do is to add INSTALLDIR/bin to your path. The installed tools will find their other bits automatically. Note that INSTALLDIR should not contain any spaces.
The first thing to build are the binutils, so download the newest version of the sources to a new folder somewhere on your harddrive. The path to this folder should not contain any spaces either, and will be referred to as the "build root folder". Open a terminal, go to the build root folder and extract the binutils source archive. Then create a new folder in the build root folder called "build-binutils" and change to the build-binutils folder:
All the toolchain components use a system where the build is done outside the source folder. This has the advantage that if something goes wrong you can start over just by deleting your build-folder and creating a new one. Next configure the build environment:
The "2>&1 | tee configure-log" at the end means that all output is captured to a file called "configure-log" which can be useful if you run into problems. There are a number of other configure-time tweaks which are documented either in the manuals or the source code, but it's best to leave them alone unless you're absolutely certain what they do. One useful option is "--disable-nls" which means all the messages printed by the tools will be in English rather than translated to whatever language your operating system is set to use. This is good because you don't have to worry about poor translations and other people will understand the error messages as well. It doesn't affect the produced code in any way. Once the configuration is finished, you can compile and install the binutils:
To verify that the build completed succesfully, run "sh-(elf/coff)-as --version" and the assembler should print out its version string. If you get an error that the command can't be found, verify that you've added INSTALLDIR/bin to your path directive.
To build the C compiler you need the C library, but to build the C library you need a C compiler. To solve this chicken-and-egg problem you will first build a bootstrap compiler that can be used to build the C library. First download the GCC sources to the build root folder (you only need the gcc-core and gcc-g++ packages), then change to the build root folder, unarchive the GCC sources and create a folder called "bootstrap-gcc":
Next configure, compile and install the bootstrap compiler:
Now you're ready to build the C library. Download the newlib sources to the build root folder, unarchive them and create a "build-newlib" folder:
Configuring and building newlib is pretty straightforward:
As the final step we build the full C and C++ compilers. Go to the build root folder, create a "build-gcc" folder, configure and build. The options that are disabled either aren't supported on SuperH or require special operating system or library support. Note that the "--disable-nls" option works with GCC as well.
That's it! The same instructions can be used to build a 68000 toolchain, just set the target to m68k-elf or m68k-coff. After you're done, you can freely delete the source and build folders, and when new versions of the tools are released you can install them on top of the older versions.
To build the toolchain you obviously need the developer tools for your OS. On OS X this means installing Xcode, and on Linux you need at least GCC, GNU make and the autotools (autoconf/automake). The binutils and GCC documentation lists the requirements in more detail.
Before you start building, there are two things you must decide: the toolchain object format and install location. The object formats available are COFF and ELF. COFF is an older, partly proprietary standard that is being deprecated in favour of the more open, capable ELF format. Sega's binary libraries are in COFF format, so if you intend to use them you may want to configure your toolchain for COFF, but otherwise ELF is recommended. Note that this choice affects the object format your toolchain produces - it can still understand both formats and you can convert object files using the objcopy tool.
If you picked COFF, your TARGET will be sh-coff and if you picked ELF it is sh-elf. (The canonical name or "configuration triplet" is sh-unknown-coff or sh-unknown-elf, but typing the full name gets annoying very quickly and the shorter form works just as well.)
The install location can be basically anywhere on your system. If you pick a system folder (eg. /usr/local) you will need to run the installation steps with root privileges, but you can just as well install the toolchain in your own home directory. The only thing you must do is to add INSTALLDIR/bin to your path. The installed tools will find their other bits automatically. Note that INSTALLDIR should not contain any spaces.
The first thing to build are the binutils, so download the newest version of the sources to a new folder somewhere on your harddrive. The path to this folder should not contain any spaces either, and will be referred to as the "build root folder". Open a terminal, go to the build root folder and extract the binutils source archive. Then create a new folder in the build root folder called "build-binutils" and change to the build-binutils folder:
Code:
cd [i]build root folder[/i]
tar jxf binutils-x.yy.tar.bz2
mkdir build-binutils
cd build-binutils
All the toolchain components use a system where the build is done outside the source folder. This has the advantage that if something goes wrong you can start over just by deleting your build-folder and creating a new one. Next configure the build environment:
Code:
../binutils-x.yy/configure --prefix=[i]INSTALLDIR[/i] --target=[i]TARGET[/i] 2>&1 | tee configure-log
The "2>&1 | tee configure-log" at the end means that all output is captured to a file called "configure-log" which can be useful if you run into problems. There are a number of other configure-time tweaks which are documented either in the manuals or the source code, but it's best to leave them alone unless you're absolutely certain what they do. One useful option is "--disable-nls" which means all the messages printed by the tools will be in English rather than translated to whatever language your operating system is set to use. This is good because you don't have to worry about poor translations and other people will understand the error messages as well. It doesn't affect the produced code in any way. Once the configuration is finished, you can compile and install the binutils:
Code:
make all 2>&1 | tee make-all-log
make install 2>&1 | tee make-install-log
To verify that the build completed succesfully, run "sh-(elf/coff)-as --version" and the assembler should print out its version string. If you get an error that the command can't be found, verify that you've added INSTALLDIR/bin to your path directive.
To build the C compiler you need the C library, but to build the C library you need a C compiler. To solve this chicken-and-egg problem you will first build a bootstrap compiler that can be used to build the C library. First download the GCC sources to the build root folder (you only need the gcc-core and gcc-g++ packages), then change to the build root folder, unarchive the GCC sources and create a folder called "bootstrap-gcc":
Code:
cd [i]build root folder[/i]
tar jxf gcc-core-x.y.tar.bz2
tar jxf gcc-g++-x.y.tar.bz2
mkdir bootstrap-gcc
cd bootstrap-gcc
Next configure, compile and install the bootstrap compiler:
Code:
../gcc-x.y/configure --prefix=[i]INSTALLDIR[/i] --target=[i]TARGET[/i] --without-headers --with-newlib --disable-shared --disable-threads 2>&1 | tee configure-log
make all-gcc 2>&1 | tee make-all-gcc-log
make install-gcc 2>&1 | tee make-install-gcc-log
Now you're ready to build the C library. Download the newlib sources to the build root folder, unarchive them and create a "build-newlib" folder:
Code:
cd [i]build root folder[/i]
tar zxf newlib-x.yy.tar.gz
mkdir build-newlib
cd build-newlib
Configuring and building newlib is pretty straightforward:
Code:
../newlib-x.yy/configure --prefix=[i]INSTALLDIR[/i] --target=[i]TARGET[/i] 2>&1 | tee configure-log
make all 2>&1 | tee make-all-log
make install 2>&1 | tee make-install-log
As the final step we build the full C and C++ compilers. Go to the build root folder, create a "build-gcc" folder, configure and build. The options that are disabled either aren't supported on SuperH or require special operating system or library support. Note that the "--disable-nls" option works with GCC as well.
Code:
cd [i]build root folder[/i]
mkdir build-gcc
cd build-gcc
../gcc-x.y/configure --prefix=[i]INSTALLDIR[/i] --target=[i]TARGET[/i] --enable-languages="c,c++" --disable-shared --disable-threads --disable-multilib --disable-mudflap --with-newlib 2>&1 | tee configure-log
make all 2>&1 | tee make-all-log
make install 2>&1 | tee make-install-log
That's it! The same instructions can be used to build a 68000 toolchain, just set the target to m68k-elf or m68k-coff. After you're done, you can freely delete the source and build folders, and when new versions of the tools are released you can install them on top of the older versions.