cross-compiling with PCC and musl
16 August, 2015
TL;DR: See the full script here: cross-pcc.sh. It will
create your toolchain in $HOME/cross/pcc-x86_64
and name the tools
x86_64-linux-musl-*
.
I've recently been playing around with PCC and musl, and to make the process of compiling softwares with them easier, I decided to setup a cross-compiler relying on both.
The process is (in theory) pretty simple:
- download and extract sources
- patch everything
- install linux headers
- build binutils
- build musl
- build pcc/pcc-libs
- (optionnal) add a pkg-config wrapper
1. grabbing sources
This part is pretty simple. You just need to choose which version of the software you want to use. Here is my list at the time of writing:
- pcc : 1.1.0
- binutils : 2.25
- musl : 1.1.10
- kernel : 4.1.4
You can get the sources by following these links:
ftp://pcc.ludd.ltu.sehttp://pub.z3bra.org/monochromatic/pcc-releases ftp://ftp.gnu.org/gnu http://www.musl-libc.org/releases https://www.kernel.orghttp://pub.z3bra.org/monochromatic/linux/kernel/v4.x
Once you have all your tarballs, extract them somewhere.
2. patch everything
Everything doesn't need patching, but when you're playing with musl, you'll quickly realise how heavily softwares rely on the GNU libc.
GregorR did all the dirty job here, and provide patches for use with cross-compilers to work with musl. Check what's in, and grab those you might need.
The 1.1.0 version of pcc require some patching too, in order to work flawlessly
with an alternative libc. It seems to be fixed in 1.2.0 (DEVEL version), if
you're interrested. They fix the configure
script to accept musl based
targets, and fix the default library pass of the compiler.
3,4,5,6. build everything
For this part, just check the appropriate sections in the original script. You might want to enable shared libraries, or avoid compiling everything statically, so tweak it however you want.
For PCC, the PCCINCDIR
and PCCLIBDIR
are important, as they will tell the
compiler where are the PCC libraries. The --with-incdir
and --with-libdir
parameters are used to tell the compiler where to search for default libraries,
so make sure you set them properly.
Enjoy!
You compiler should be ready to go! You can test it by running the following snippet:
$ echo 'main(){}' > dummy.c
$ PATH="$HOME/cross/pcc-x86_64/bin:$PATH"; export PATH
$ x86_64-linux-musl-pcc dummy.c
For the sake of the experience, I also built a gcc cross-compiler using the same method, and tested both compilers on the libressl code base. The packages are simply tar.bz2 archives of libressl installed on a chroot (so there are only the libressl files):
$ du -h libressl-*.pkg
8.1M libressl-gcc-2.1.6.pkg
8.9M libressl-glibc-2.1.6.pkg
4.4M libressl-pcc-2.1.6.pkg
Looks like we have a winner!