|
| 1 | +# Cross Compiling Concord |
| 2 | + |
| 3 | +Unlike most Autoconf-based projects, Concord uses normal Makefiles. As such, |
| 4 | +cross-compilation can be rather daunting at first. Fortunately, once you |
| 5 | +understand it, you won't have any trouble (unless your compiler malfunctions |
| 6 | +or is misconfigured). |
| 7 | + |
| 8 | +## Step 1: getting a cross compiler |
| 9 | +Debian-based Linux distros have cross compilers available in their package |
| 10 | +repositories. For example, to get an ARM cross compiler suitable for building |
| 11 | +for an old 32-bit Raspberry Pi, run `apt-get install gcc-arm-linux-gnueabihf`. |
| 12 | +Search the Debian package repositories for "gcc" to see other cross compilers |
| 13 | +available. |
| 14 | + |
| 15 | +If you aren't on Debian, you can use cross-compilers from [here](https://mirrors.edge.kernel.org/pub/tools/crosstool/), although, do note that these compilers |
| 16 | +might take a fair bit of work to get working perfectly. If you do use one of |
| 17 | +these, ensure that `$PATH` gets updated to include the compiler's bin directory, |
| 18 | +or you won't be able to invoke the compiler. |
| 19 | + |
| 20 | +## Step 2: cross-compiling Concord |
| 21 | +For this example, we will assume that your host system is a standard x86_64 |
| 22 | +PC, and uses the target triplet `x86_64-pc-linux-gnu`. We will be |
| 23 | +cross-compiling to a 64-bit Raspberry Pi 4, with the target triplet |
| 24 | +`aarch64-linux-gnu`. Now, when GCC cross-compilers are made, all of the built |
| 25 | +executables for the compiler are prefixed with the target tripet. This means |
| 26 | +that our actual C compiler command is `aarch64-linux-gnu-gcc`. This will be |
| 27 | +our `CC` value. |
| 28 | + |
| 29 | +The gencodecs system that Concord uses requires that the system C compiler is |
| 30 | +available. This means we have to set `HOSTCC` when we compile. Since our |
| 31 | +target triplet is `x86_64-pc-linux-gnu`, this means that our host C compiler |
| 32 | +is named `x86_64-pc-linux-gnu-gcc`. However, since this is the primary C |
| 33 | +compiler on the system, we can just use `gcc` for `CC`. |
| 34 | + |
| 35 | +Finally, we will install Concord to the Raspberry Pi by directly accessing its |
| 36 | +root filesystem via NFS. The Pi's Linux image has been mounted read-write into |
| 37 | +`/mnt`. Since we want Concord to go into `/usr/local`, our target `PREFIX` |
| 38 | +path for `make install` is `/mnt/usr/local`. |
| 39 | + |
| 40 | +Okay, we can now run the commands to actually compile. |
| 41 | + |
| 42 | +```console |
| 43 | +cd gencodecs |
| 44 | +make HOSTCC=gcc CC=aarch64-linux-gnu-gcc |
| 45 | +cd .. |
| 46 | +make CC=aarch64-linux-gnu-gcc |
| 47 | +make install PREFIX=/mnt/usr/local |
| 48 | +``` |
| 49 | + |
| 50 | +Easy as that! Granted, you can perform a compilation with fewer typed commands |
| 51 | +if you `export` those three variables beforehand, but, this guide was written |
| 52 | +with maximum learning in mind (and demonstrating why gencodecs needs the |
| 53 | +split compilation procedure). |
| 54 | + |
| 55 | + |
0 commit comments