How to Install Cross-Assembler and Cross-Compiler

This document describes how GCC (GNU C Compiler) can be used to install a cross-assembler and a C cross-compiler for the Hitachi H8/300 processor.

Getting the files

GCC is distributed as two separate packages: gcc, which is the actual C compiler and binutils which contains assembler, linker and other tools for manipulating object files. The packages are distributed from the GNU projects ftp server ftp.gnu.org, but is also available from e.g. a SunSite in Ålborg:

      binutils-2.10.tar.gz
      gcc-core-2.95.2.tar.gz

Download the files using your favourite ftp client and extract the archives; you could create a subdirectory called hitachi-gcc in your home directory. To extract the files use the tar command:

      tar xfz binutils-2.10.tar.gz
      tar xfz gcc-core-2.95.2.tar.gz

This will create two subdirectories: binutils-2.10 and gcc-2.95.2, containing the source code for the programs.

Compiling binutils

With the files extracted, the next thing to do is to compile binutils. This must be done before compiling gcc, since this process depends on binutils being available for the Hitachi architecture, H8/300. Both binutils and gcc needs to be configured for the particular setup, i.e. cross-compiling to Hitachi H8/300 from e.g. a Linux system. The shell script configure, which is distributed with binutils, does exactly this:

      cd binutils-2.10
      ./configure --target=h8300-hitachi-hms --prefix=$HOME/hitachi

Since we want gcc to work as a cross-compiler, we also need the assembler and the linker to generate code for Hitachi H8/300. This is what the --target=h8300-hitachi-hms option specifies. The option --prefix=$HOME/hitachi specifies that binutils is to be installed relative to the directory $HOME/hitachi. This means that executable files are installed in $HOME/hitachi/bin, libraries in $HOME/hitachi/lib and documentation and other files in other subdirectories of $HOME/hitachi. If you want the tools installed somewhere else, say /usr/local, just specify --prefix=/usr/local.

When configure finishes checking the system setup and provided no problems were detected, binutils is now ready to be compiled. This is done using make:

      make

Compiling binutils takes about 2 minutes, depending on the speed of your machine. When the compilation is finished, binutils can be installed, which is accomplished with the make command again:

      make install

The installation process creates a number of subdirectories of $HOME/hitachi, and copies the newly built executable files, libraries, documentation and other files to these.

Compiling gcc

Having installed binutils, gcc can be compiled. As with binutils, gcc needs to be configured:

      cd gcc-2.95.2
      ./configure --target=h8300-hitachi-hms --prefix=$HOME/hitachi --with-newlib

For the same reasons as above, target and prefix is specified as shown. The option --with-newlib specifies that gcc should not expect to find a standard C library for the Hitachi H8/300 architecture.

When configure finishes, gcc can be compiled. However, during the compilation, make must be able to access the executable files from binutils, so $HOME/hitachi/bin should be added to the path. One way to do this is to invoke make as:

      env PATH=$HOME/hitachi/bin:$PATH make

The compilation of gcc takes about 8 minutes, again depending on your machine. When this is done, gcc can be installed:

      make install

As for binutils, this will install executable files and other files in subdirectories of $HOME/hitachi.

Using the compiler

A simple Makefile and link script can be obtained from "Compilation of Programs for the RCX". In the Makefile the path to the tools is specified using the variable BINDIR:

      # Makefile for H8/300 cross compilation of C and assembler programs.

      # Path to C compiler (gcc), assembler (as) and linker (ld).
      BINDIR = /users/kursus/dArk/solaris/h8300-hitachi-hms/bin/
      CC = $(BINDIR)gcc
      AS = $(BINDIR)as
      LD = $(BINDIR)ld
      
      ...

To adapt this Makefile to use the newly built tools, just change the value of BINDIR to $HOME/hitachi/h8300-hitachi-hms/bin/:

      # Makefile for H8/300 cross compilation of C and assembler programs.

      # Path to C compiler (gcc), assembler (as) and linker (ld).
      BINDIR = $HOME/hitachi/h8300-hitachi-hms/bin/
      CC = $(BINDIR)gcc
      AS = $(BINDIR)as
      LD = $(BINDIR)ld
      
      ...