Microchip MPLAB C30 compiling on a MAC OS X

This page tries to explain how to compile the Microchip MPLAB C30 cross-compiling tool chain for pic24 & dsPIC on a Mac OS X 10.5(Leopard) and 10.6(Snow Leopard) based system.

This procedure is an adaptation of the  Linux procedure dedicated to Mac OS X. It's mainly inspired from  VanLinkenberg Software tutorial.

Prerequisites

By default, Leopard doesn't contain development tool like GCC compiler. You must install the package development tool, which is install with XCode. XCode is available on the Install DVD of Leopard.

During this tutorial, we need to convert DOS caracters to Unix one. For that we'll use an program called DOS2Unix. This program is available for Mac OS X through a solution like  Fink or  MacPorts. In this example, we use  Macports. Install Macports then open a terminal and execute :

sudo port install dos2unix

To retrieve source code, we can also install wget, with MacPorts? too.

sudo port install wget

PIC30 Binutils

Download and extract our patches available [here]. These patches has been adapted from the  John Steele Scott's ones. Those patches contain information about resources location. Although it's not the best way to get a proper installation, path are herd-coded so if you want to changed it, please edit patches in your way:

tar -xvvf pic30-patches-3.10.tar.gz 

Get the binutils 3.10 source package from the  MPLAB IDE archives download page and extract it.

mkdir c30binutils
cd c30binutils
wget http://ww1.microchip.com/downloads/en/DeviceDoc/mplabalc30v3_10.tar.gz
tar -xvvf mplabalc30v3_10.tar.gz

Convert the Windows end-of-lines into POSIX ones for the acme folder sources

cd acme
find . -type f -exec dos2unix '{}' ';'

Let's apply patches to the sources

cd ..
patch -p0 < ../patches/binutils-libiberty-testsuite.diff
patch -p0 < ../patches/binutils-hardcode-device-info-path.diff
patch -p0 < ../patches/binutils-allow-empty-device-info-file.diff

We touch the files from the acme directory, so the yacc and flex files will effectively be parsed during the build.

find acme -name \*.y -o -name \*.l -exec touch '{}' ';'

The next command fixes configure scripts for leopard

find . -name configure -exec /usr/bin/sed -e "s/rm -f conftest\*/rm -rf conftest\*/g" -i '' '{}' ';'

Now we are ready for compiling C30binutils

mkdir objs
cd objs
CFLAGS="-O2 -DMCHP_VERSION=v3.10" ../acme/configure -v --prefix=/usr/local/pic --target=pic30-coff --disable-nls
make
sudo make install

PIC30 GCC

Get the Mplab GCC 3.10 source package from the  MPLAB IDE archives download page and extract it.

mkdir c30gcc
cd c30gcc
wget http://ww1.microchip.com/downloads/en/DeviceDoc/mplabc30v3_10.tar.gz
tar -zxvf mplabc30v3_10.tar.gz

Convert the Windows end-of-lines into POSIX ones for the acme folder sources

find . -type f -exec dos2unix '{}' ';'

Let's apply patches to the sources

patch -p1 < ../patches/gcc-default-include-path.diff
patch -p1 < ../patches/gcc-pic30-standard-prefix.diff
patch -p1 < ../patches/gcc-resource-path.diff
patch -p1 < ../patches/gcc-libiberty-testsuite.diff
patch -p1 < ../patches/gcc-t-pic30.diff
patch -p1 < ../patches/gcc-library-path-crash.diff

Touch the source file

find . -name *.y -type f -exec touch '{}' ';'
find . -name *.l -type f -exec touch '{}' ';'

The next command fixes configure scripts for leopard

find . -name configure -exec /usr/bin/sed -e "s/rm -f conftest\*/rm -rf conftest\*/g" -i '' '{}' ';'

Now we are ready for compiling C30GCC

mkdir objs && cd objs
echo version_string = \"3.10\" > version-trigger
CC="gcc -g -DMCHP_VERSION=v3.10" ../gcc-4.0.2/gcc-4.0.2/configure -v --prefix=/usr/local/pic --target=pic30-coff --enable-languages=c --disable-nls --with-gcc-version-trigger=$PWD/version-trigger
make
sudo make install

Some GCC binaries are called $TARGET-$TARGET-something, so we fix that with the next command

for i in /usr/local/pic/bin/pic30-coff-pic30-coff-*; do
    mv $i `echo $i | /usr/bin/sed -e "s/pic30-coff-pic30-coff/pic30-coff/"`
done

Import the non-free Microchip resources

To complete the toolchain installation, we need to retrieve dsPIC & PIC24 headers, libraries and link scripts from Microchip C30 v3.10 release.

First we will have to copy the following folders into the /usr/local/pic/pic30-nonfree directory from the C30 installation:

  • include
  • lib
  • support

Then copy the info/c30_device.info file from the C30 installation into the /usr/local/pic/info folder

The last step is to move the libraries use by pic30-coff-ld.

mv /usr/local/pic/pic30-nonfree/lib/*.a /usr/local/pic/pic30-coff/lib/