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