This section explains how you can compile the GNU Binutils, the GNU Compiler Collection, the GNU Debugger and the C library for 68HC11 & 68HC12. You should follow the steps indicated here in the same order.

The GNU development chain can work with 68HC11 and 68HC12 micro-controllers as target. You can select the target cpu with some option that you pass to GCC. A default target cpu exist and corresponds to the target you have specified during the configuration of the different packages.

The choice you make on the target cpu for the configuration has an importance only for the selection of the default target cpu. All packages must be configured with the same target cpu.

Three automatic builds can be used:

  • You can get the build environment provided by GNU Development Chain for 68HC11/68HC12 Savannah Project. This provides RPM templates, scripts and makefile to build the tool chain and create RPM binaries as well as Windows binaries (using a GNU/Linux cross compiler for Windows). Since it is based on Red Hat rpm tool, it only works on GNU/Linux.

  • The following script, provided by Mike, can be used to compile all the tools: build.script.2.1.1 (4 Kb)

  • The following perl script, provided by Rob, can be used to download, compile all the tools on a MacOS X: (10 Kb)

Using Mike and Rob's scripts is probably easier than the build environment as they don't create RPM binary packages and do not generate the Windows binaries. These script being portable they can be used on any Unix platform. Mike has tested its script on a FreeBSD and Rob has tested its on a MacOS X.

This description focuses on building the complete tool chain by hand. Before you start, you will need:

  • The GNU make utility (3.79 for example)
  • A host C compiler (gcc 3.2/3.3)
  • A host assembler, linker and utilities (binutils 2.14/2.15)
  • The patch program (version 2.5 at least)
  • The Texinfo documentation suite (to produce the documentation)
  • Several Unix utilities (sh, cmp, cp, test, ...)

1. Compiling GNU Binutils

The 68HC1x port is available for GNU Binutils 2.15. It is integrated in the FSF sources but a patch is still recommended (Why patching?). You need to get the following files:

1.1 Installation of the Sources

Once you have the file listed in previous section, type the following command:

   gzip -d binutils-2.15-m68hc1x-20040801.diffs.gz
   tar xvzf binutils-2.15.tar.gz
   mv binutils-2.15 binutils-2.15-m68hc1x
   cd binutils-2.15-m68hc1x
   patch -p1 < ../binutils-2.15-m68hc1x-20040801.diffs

1.2 Configuration and Build

When you build the GNU Binutils, you will get the support for 68HC11 and 68HC12 at the same time. The assembler and linker have a default cpu target based on the option you used during configuration. Depending on what is your preferred target, choose one of the following commands to configure the GNU Binutils:

  • For 68HC11:
      cd binutils-2.15-m68hc1x
      sh ./configure --target=m6811-elf \
  • For 68HC12:
      cd binutils-2.15-m68hc1x
      sh ./configure --target=m6812-elf \
Then, build everything:
This will create: ld, as, ar, ranlib and many other tools.

Typing make install will install the binutils files:

  make install
You must install the binutils before building GCC.

2. Compiling GCC

The 68HC1x port is integrated in GCC 3.x already. A patch is however necessary to fix some problems (Why patching?).

Check out the following:

GCC comes with a C, C++, Objective C, Fortran, Java and Ada compiler. You'll get the cross compiler for all these languages. However, only the C compiler was really ported at this time. The C++ compiler is known to work a little. Other compilers are not checked at all.

Before compiling GCC, you need to compile and install the GNU Binutils for the Motorola 68HC11 or 68HC12. Refer to Compiling GNU Binutils. The target assembler for the port is gas.

There is no requirement concerning the host.

2.1 Installation of the Patch

Once you have the files listed in previous section, type the following commands:

   gzip -d gcc-3.3.5-m68hc1x-20050515.diffs.gz
   tar xvzf gcc-3.3.5.tar.gz
   mv gcc-3.3.5 gcc-3.3.5-m68hc1x
   cd gcc-3.3.5-m68hc1x
   patch -p1 < ../gcc-3.3.5-m68hc1x-20050515.diffs

2.2 Configuration and Build

To configure GCC, you must use the same option you have used during configuration of the GNU Binutils. You can configure for a 68HC11 or for a 68HC12 target but you will always get the support for both micro-controllers at the same time.

  • For a 68HC11:
       sh ./configure --target=m6811-elf \
    	--program-prefix=m6811-elf- \
  • For a 68HC12:
       sh ./configure --target=m6812-elf \
    	--program-prefix=m6812-elf- \
Then, build everything with:
This will create: xgcc, cpp, cc1 and libgcc.a (as well as many other stuff). It is probably important to specify the same program-prefix that you specified for the GNU binutils configuration. Otherwise, the generation of the libgcc.a library will probably fail.

Note: You must have built and installed the GNU binutils for 68HC11 or 68HC12. Otherwise, the generation of the libgcc.a support library will fail.

Move to the gcc subdirectory and type make install to install the compiler files. They are normally installed under /usr/local/bin, and /usr/local/lib/gcc-lib/m6811-elf or /usr/local/lib/gcc-lib/m6812-elf. The GNU binutils are assumed to be installed in /usr/local/m6811-elf or /usr/local/m6812-elf. Note that, these installation directories depend on the options you have specified to configure.

  cd gcc
  make install

3. Compiling GDB

The 68HC11/68HC12 port is integrated in GDB 6.x but a patch is necessary (Why patching?). You need to get the following files:

GDB sources: gdb-6.2.tar.gz on

M68HC1x fixes and improvements (20040829): gdb-6.2-m68hc1x-20040829.diffs.gz (136 Kb)

3.1 Installation of the Patch

Once you have the files listed in previous section, type the following commands:

   gzip -d gdb-6.2-m68hc1x-20040829.diffs.gz
   tar xvzf gdb-6.2.tar.gz
   mv gdb-6.2 gdb-6.2-m68hc1x
   cd gdb-6.2-m68hc1x
   patch -p1 < ../gdb-6.2-m68hc1x-20040829.diffs

3.2 Configuration and Build

To configure and build GDB for 68HC11/68HC12, you can do:

   sh ./configure --target=m6811-elf \
Typing make install will install everything. It's not necessary to install to check or use GDB.
  make install
This will install m6811-elf-gdb and m6811-elf-run in the /usr/local/bin directory (by default).

Note: Gdb recognizes automatically when the program is for a 68HC11 or for a 68HC12. The simulator is also configured automatically according to the program file (ELF file).

4. Compiling NewLib

The 68HC1x port is available for NEWLIB 1.12.0. You need to get the following files:

Newlib sources: newlib-1.12.0.tar.gz

M68HC1x port (20040801): newlib-1.12.0-m68hc1x-20040801.diffs.gz (4 Kb)

Before compiling NEWLIB, you need to get and install:

4.1 Installation of the Patch

Once you have the files listed in previous section, type the following commands:

   gzip -d newlib-1.12.0-m68hc1x-20040801.diffs.gz
   tar xvzf newlib-1.12.0.tar.gz
   mv newlib-1.12.0 newlib-1.12.0-m68hc1x
   cd newlib-1.12.0-m68hc1x
   patch -p1 < ../newlib-1.12.0-m68hc1x-20040801.diffs

4.2 Configuration and Build

The NEWLIB 1.12.0 must be built in a separate directory from the sources. Create such directory before configuring and building NEWLIB. For example, you can type the following commands:

   cd ..
   mkdir build-newlib
   cd build-newlib
   sh ../newlib-1.12.0-m68hc1x/configure \
	--disable-newlib-io-float --disable-newlib-multithread \
	--target=m6811-elf --program-prefix=m6811-elf-
   make CFLAGS="-g -Os -Wall"

Note:When you configure Newlib, be sure to use the same GNU configure options as the options for configuring GNU Binutils and GNU CC.

This will create a sub-directory m6811-elf that will contain the libc, libm and libbcc libraries. These libraries are compiled several times so that you will get 2 sets of 4 versions of them. One set for 68HC11 and one set for 68HC12, each set being composed of libraries compiled for:

  • 32-bit integers, 64-bit double
  • 32-bit integers, 32-bit double (-fshort-double)
  • 16-bit integers, 64-bit double (-mshort)
  • 16-bit integers, 32-bit double (-mshort -fshort-double)

Note: If you don't specify the CFLAGS options at make time, the default makefile will use -g -O2 -W -Wall. You can also avoid the support for source level debugging by using: CFLAGS="-Os -Wall".

Do not pass any -mshort -m68hc11 -m68hc12 -mlong-calls or -fshort-double option because this will break the multi-lib support.

Typing make install will install the libraries and the includes in /usr/local/m6811-elf/lib and in /usr/local/m6811-elf/include