Odd Red Dog

Cross compiling Erlang for the BeagleBone Black on FreeBSD

02 February 2014

This is something I had done in the past on Linux (with the stock BeagleBone Black distro). I've been obsessed lately about running FreeBSD on the BBB and I wanted to see if the same cross compiling instructions would apply when compiling Erlang.

Well, the answer is yes, pretty much. There are a few differences that are mostly related to FreeBSD's environment (shell, ...) being different than Linux.

So, after having fetched and extracted Erlang/OTP's source code... here we go.

Note: among other things, you will need the various gmake, autoconf, automake packages installed. You will also, obviously, need the arm cross compiler toolkit. Mine was installed already because I had built my own BBB FreeBSD image using this great tool: crochet-freebsd.

Bootstrapping Erlang

This compiles an Erlang bootstrap natively on the build host, which is a 64-bit FreeBSD 10 virtual machine. This minimal Erlang installation will then be used when compiling the rest of the system.

$ # Extract the Erlang source code and cd under its path
$ setenv ERL_TOP `pwd`
$ autoreconf -ifv
$ ./configure --enable-bootstrap-only
$ gmake

Completing the cross compilation

To make it obvious that the environment is different, I ran the following in a different shell:

$ setenv erl_xcomp_sysroot "/usr/armv6-freebsd/"
$ setenv PATH "/usr/armv6-freebsd/usr/bin/:$PATH"
$ ./configure --host arm-bbb-freebsd --build x86_64-freebsd-freebsd10
$ gmake

Note the line that prepends the arm toolkit's path in front of the system path. This ensures that the cross compiler is used and not the native compiler.

Once this is done, you can stage the installation into a given folder then transfer the content of that folder onto the target BeagleBone to use it.

$ mkdir /tmp/bb_erlang
$ make install DESTDIR=/tmp/bb_erlang
$ cd /tmp/bb_erlang
$ tar zcvf bb_erlang.tar.gz usr/
$ # transfer the file to the target and enjoy