view · edit · print · history

The idea here is to speed up compile times by using a cross-compiler while using the native build scripts. This will only work if the version of the native and cross compilers are the same.

This document assumes you are using a debian based host; but this technique should be usable with other distros.

1/ make and test the cross compile host by following these instructions (or use the precompiled debian packages): http://www.nslu2-linux.org/wiki/DebianSlug/CrossCompiling

2/ install/configure distcc

 apt-get install distcc
 vi /etc/default/distcc

That should pretty much do it for the Cross Host.

On the armeb host:

1/ install the important build tools:

 apt-get install build-essential

2/ install/configure distcc

 apt-get install distcc
 vi /etc/default/distcc

3/ divert gcc to distcc: tweak distcc_hosts, compile the file and install the binary into /usr/local/bin/gcc.

  * simple distcc wrapper by Lennert Buytenhek
  * Released into the public domain.
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>

 static char *distcc = "/usr/bin/distcc";
 static char *build_host_gcc = "/usr/bin/armeb-linux-gcc";
 static char *distcc_hosts = "DISTCC_HOSTS=";

 static int count(char **array)
         int i;

         for (i = 0; array[i] != NULL; i++)

         return i;

 int main(int argc, char *argv[], char *envp[])
         char **new_argv;
         char **new_envp;
         int envc;

         envc = count(envp);

         new_argv = malloc((argc + 2) * sizeof(char *));
         new_envp = malloc((envc + 2) * sizeof(char *));
         if (new_argv != NULL && new_envp != NULL) {
                 int i;

                 new_argv[0] = distcc;
                 memcpy(new_argv + 1, argv, argc * sizeof(char *));
                 new_argv[1] = build_host_gcc;
                 new_argv[argc + 1] = NULL;

                 memcpy(new_envp, envp, envc * sizeof(char *));
                 for (i=0;i<envc;i++) {
                         if (!strncmp(new_envp[i], "DISTCC_HOSTS=", 13)) {
                                 new_envp[i] = distcc_hosts;
                 new_envp[envc] = NULL;
                 if (i == envc) {
                         new_envp[envc] = distcc_hosts;
                         new_envp[envc + 1] = NULL;

                 execve(distcc, new_argv, new_envp);

         perror("exec failed");

         return 1;

3b/ Repeat, changing gcc to g++ to support c++ dist/cross too.

4/ support other common compiler names:

 cd /usr/local/bin
 ln -s gcc cc
 ln -s gcc armeb-linux-gcc

 ln -s g++ c++
 ln -s g++ armeb-linux-g++

Test it!

 mkdir /home/build
 apt-get source hello
 cd hello-*

watch it go much faster than on the slug!

note: I carefully diffed only 2 packages; but for those two packages, the binaries generated were identical.

view · edit · print · history · Last edited by dyoung.
Based on work by buytenh and dyoung.
Originally by dyoung.
Page last modified on October 06, 2005, at 08:35 PM