monochromatic

monochromatic blog: http://blog.z3bra.org
git clone git://z3bra.org/monochromatic
Log | Files | Refs

cross-compiling-with-pcc-and-musl.txt (3451B)


      1 # [cross-compiling with PCC and musl](#)
      2 ## — 16 August, 2015
      3 
      4 **TL;DR**: See the full script here: [cross-pcc.sh](http://pub.z3bra.org/monochromatic/misc/cross-pcc.sh). It will
      5 create your toolchain in `$HOME/cross/pcc-x86_64` and name the tools
      6 `x86_64-linux-musl-*`.
      7 
      8 I've recently been playing around with [PCC](http://pcc.ludd.ltu.se/) and
      9 [musl](http://www.musl-libc.org/), and to make the process of compiling
     10 softwares with them easier, I decided to setup a cross-compiler relying on both.
     11 
     12 The process is (in theory) pretty simple:
     13 
     14 0. download and extract sources
     15 1. patch everything
     16 2. install linux headers
     17 3. build binutils
     18 4. build musl
     19 5. build pcc/pcc-libs
     20 6. (optionnal) add a pkg-config wrapper
     21 
     22 ### 1. grabbing sources
     23 
     24 This part is pretty simple. You just need to choose which version of the
     25 software you want to use. Here is my list at the time of writing:
     26 
     27 + pcc : 1.1.0
     28 + binutils : 2.25
     29 + musl : 1.1.10
     30 + kernel : 4.1.4
     31 
     32 You can get the sources by following these links:
     33 
     34 ftp://pcc.ludd.ltu.sehttp://pub.z3bra.org/monochromatic/pcc-releases
     35 ftp://ftp.gnu.org/gnu
     36 http://www.musl-libc.org/releases
     37 https://www.kernel.orghttp://pub.z3bra.org/monochromatic/linux/kernel/v4.x
     38 
     39 Once you have all your tarballs, extract them somewhere.
     40 
     41 ### 2. patch everything
     42 
     43 Everything doesn't need patching, but when you're playing with musl, you'll
     44 quickly realise how heavily softwares rely on the GNU libc.
     45 
     46 GregorR did all the dirty job here, and provide
     47 [patches](https://github.com/GregorR/musl-cross/tree/master/patches) for use
     48 with cross-compilers to work with musl. Check what's in, and grab those you
     49 might need.
     50 
     51 The 1.1.0 version of pcc require some patching too, in order to work flawlessly
     52 with an alternative libc. It *seems* to be fixed in 1.2.0 (DEVEL version), if
     53 you're interrested. They fix the `configure` script to accept musl based
     54 targets, and fix the default library pass of the compiler.
     55 
     56 + [pcc-1.1.0-musl.diff](http://pub.z3bra.org/monochromatic/misc/pcc-1.1.0-musl.diff)
     57 + [pcc-libs-1.1.0-musl.diff](http://pub.z3bra.org/monochromatic/misc/pcc-libs-1.1.0-musl.diff)
     58 + [pcc-1.1.0-deflibdirs.diff](http://pub.z3bra.org/monochromatic/misc/pcc-1.1.0-deflibdirs.diff)
     59 
     60 ### 3,4,5,6. build everything
     61 
     62 For this part, just check the appropriate sections in the original script. You
     63 might want to enable shared libraries, or avoid compiling everything statically,
     64 so tweak it however you want.
     65 
     66 For PCC, the `PCCINCDIR` and `PCCLIBDIR` are important, as they will tell the
     67 compiler where are the PCC libraries. The `--with-incdir` and `--with-libdir`
     68 parameters are used to tell the compiler where to search for default libraries,
     69 so make sure you set them properly.
     70 
     71 ### Enjoy!
     72 
     73 You compiler should be ready to go! You can test it by running the following
     74 snippet:
     75 
     76         $ echo 'main(){}' > dummy.c
     77         $ PATH="$HOME/cross/pcc-x86_64/bin:$PATH"; export PATH
     78         $ x86_64-linux-musl-pcc dummy.c
     79 
     80 For the sake of the experience, I also built a gcc cross-compiler using the same
     81 method, and tested both compilers on the [libressl](http://www.libressl.org)
     82 code base. The packages are simply tar.bz2 archives of libressl installed on a
     83 chroot (so there are only the libressl files):
     84 
     85         $ du -h libressl-*.pkg
     86         8.1M    libressl-gcc-2.1.6.pkg
     87         8.9M    libressl-glibc-2.1.6.pkg
     88         4.4M    libressl-pcc-2.1.6.pkg
     89 
     90 Looks like we have a winner!
     91 
     92 <!-- vim: set ft=markdown ts=4 et tw=80: -->