Edit2016-03-20 Fuck Microchip


  1. Attempt to build XC compiler from source.
  2. Realize that Microchip deliberately excluded some files required for the build.
  3. Try to find these files somewhere on the forum. Realize that this is still not enough because it is crystal clear that the whole thing is uncompilable.
  4. Edit the SHA sum in cc1, cc1plus and lto1 binaries so that it accepts any xclm binary.
  5. Never use Microchip products again.

There's no point to try this, but still…

These instructions are mostly based on this page: http://www.jubatian.com/articles/turning-on-optimizations-in-microchips-xc32/

First you have to download the source of the compiler. Go to http://www.microchip.com/mplab/compilers, click on “Downloads Archive”, scroll down and find “Source Archives”. There you can choose which version to download. At the time of writing the latest link is for xc32-v1.40.

# ⚠ change these variables according to your setup.
installpath="$HOME/microshit" # this is where the compiler will be installed
pic32mxpath='/opt/microchip/xc32/v1.40/pic32mx/' # assuming that you already have installed xc32 from microchip
mkdir -- "$installpath"

export CPPFLAGS="-I$installpath/usr/include"
export LDFLAGS="-L$installpath/usr/lib"
# gmp
mkdir -p gmp_build && cd gmp_build
../gmp/configure "--prefix=$installpath/usr" --disable-shared --enable-static --enable-cxx
make install
cd ..
# ppl
mkdir -p ppl_build && cd ppl_build
../ppl/configure "--prefix=$installpath/usr" --disable-shared --enable-static
make install
cd ..

Unfortunately I get this error during make:

../../ppl/src/Generator_System.defs.hh:253:7: error: ‘ptrdiff_t’ was not declared in this scope

It seems like it does not compile under newer gcc versions.

This leads me to this page: https://gcc.gnu.org/gcc-4.6/porting_to.html
It says that you should #include <cstddef>. You have to do that with these files:

Just add #include <cstddef> and save. Now run *make* again.

Now you'll probably see this error:

../../ppl/src/Interval.defs.hh:451:77: error: ‘f_info’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
     Result rl = Boundary_NS::assign(UPPER, upper(), info(), UPPER, x, f_info(x, open));

It looks like it can be solved by using -fpermissive flag.

Try rerunning make like this:

make CXXFLAGS='-g -O2 -frounding-math -W -Wall -fpermissive'

This should probably work.

# cloog
mkdir -p cloog_build && cd cloog_build
../cloog/configure "--prefix=$installpath/usr" --disable-shared --enable-static "--with-ppl=$installpath/usr"
make install
cd ..
# libelf
mkdir -p libelf_build && cd libelf_build
../libelf/configure "--prefix=$installpath/usr" --disable-shared
make install
cd ..
# zlib
cd zlib
./configure "--prefix=$installpath/usr"
make install
cd ..
# binutils
mkdir -p binutils_build && cd binutils_build
../binutils/configure "--prefix=$installpath/usr" --disable-shared --enable-static --target=pic32mx --with-dwarf2
make install
cd ..

You will get this error:

../../binutils/bfd/cpu-pic32.c:32:55: fatal error: ../../c30_resource/src/xc32/resource_info.h: No such file or directory

OK this is a real issue. It seems like they forgot to include the file. See this link: http://www.microchip.com/forums/m897811.aspx

# Microchip libraries
cp -a -- "$pic32mxpath" "$installpath/usr/pic32mx"
# gcc
mkdir -p gcc_build && cd gcc_build
../gcc/configure "--prefix=$installpath/usr" --disable-shared --enable-static --target=pic32mx --enable-languages=c,c++,lto --disable-objc-gc --enable-lto --with-host-libstdcxx=-lstdc++ --enable-multilib --with-dwarf2 --disable-sjlj-exceptions "--with-sysroot=$installpath/usr/pic32mx"
make install

Uhh… What?

After all these efforts you end up with a half-broken build.

Just edit the SHA sum in cc1, cc1plus and lto1 binaries and you're done. No need to compile anything.

There is a chance that the build process will become easier once Microchip updates their compiler to the latest GCC version. Latest XC compiler version is 1.40 (2015-06-17), which is pretty old. The reason for such delay is probably that they are unable to compile the thing with the newer GCC versions. Ha-ha. Good luck, Microchip.

Spam protection!

Please write "I promise not to take things too close to my heart":