Building and Installing a Cortex-M Compiler on Mac, Windows or Linux

GCC is a open source C compiler which can be downloaded, compiled, and installed on Mac OS X. It is the compiler of choice for Stratify OS, and an excellent general purpose ARM Cortex-M3 compiler.

Before buidling GCC, you need to install the prerequisites.

Before building GCC, several pre-requisites must be built. The GMP, PPL, MPFR, and MPC libraries may be installed from source. The latest versions can be downloaded from:

Once you download the source, enter the following commands in the Terminal. Replace the version values with the version you download.

Specify the target directory for the compiler:

Now specify the program to download the sources (or use a browser).

Now that all prerequisites are installed, binutils, gcc, and newlib can be compiled and installed using the following commands.

You need to replace the contents of gcc/config/arm/t-arm-elf with the following snippet. This will build libgcc and newlib for the cortex-m0, cortex-m0+, cortex-m3, and cortex-m4f. Keep in mind code compiled for a smaller chip can execute directly on a larger chip. That is, v7e ISA can execute v7, and v7 can execute v6.

The binutils source needs to be built first. Again in the same directory where the binutils source was extracted, type (or copy and paste) the following commands in the terminal:

After binutils is built, GCC is next:

Now, we need to build newlib. In order to get newlib to build the floating point libraries correctly, we pass the -D__IEEE_LITTLE_ENDIAN -D__IEEE_BYTES_LITTLE_ENDIAN definitions. The BUFSIZ definition specifies what size buffer to use with printf() and file I/O. Smaller values mean slower performance using less RAM. To build newlib, type (or copy and paste) the following in a terminal window:

Finally, we need to finish building GCC.

That’s it. If all went well, a dedicated ARM Cortex M compiler is now installed in $TOOLSPATH folder. To uninstall the compiler tools, delete the $TOOLSPATH folder.