erlang cross compilation
Sat Jul 2 19:30:34 CEST 2005
I'd like to share what I did to cross compile erlang for NSLU2
The compilation build host machine:
$ uname -a
Linux hostname 2.6.10-co-0.6.2 #5 Sat Feb 5 10:19:16 IST 2005 i686 GNU/Linux
The target machine:
$ uname -a
Linux slug 2.4.22-xfs #1 Sun Jun 12 21:17:17 PDT 2005 armv5b unknown unknown
The general steps should work for other cross compilation settings as well,
it has been used to package R10B-5 and R10B-6. The Makefile and patches are
The steps are fully automated in the Makefile, basically
1. Make sure there's an erlang version on the build host with matching
version. To be absolutely sure and minimize build dependencies, a host
version is built first in erlang-host/ subdirectory.
2. Patch erts/emulator/Makefile.in to use host gcc for the mkliteral tool.
See sources/erlang/erts-emulator-Makefile.in.patch for detail.
3. Configure. It's always a good idea to run configure natively so we have a
reference. The goal is for the cross configure to generate the exact same
erts/$arch/config.h as a native configure does.
Lots of the configuration settings can be overriden using ac_cv_ environment
variables. Examples here are
In some other cases you have to patch erts/configure.in and run "autoconf
configure.in > configure" in erts/, see
sources/erlang/erts-configure.in.patch for example.
4. Build the target erlang, this can take a little while (much better than
the 10+ hours native build anyway). Start the build by
PATH="fullpath_of_erlang-host/bin:$PATH" make -C erlang noboot
5. Building SAE will involve some more patches. The basic idea is to build
host version of SAE first, then use the host version of ecc and elink to
build the native SAE, see erts-boot-src-Makefile.patch.
6. Packaging. The only tricky part is start_sasl.boot. This can be
accomplished by patching erts/etc/unix/Install.src to use the erlang-host/
executables. For NSLU2, we also need to use /opt as prefix for everything.
Some simple tests I did:
# ipkg install erlang
Erlang (BEAM) emulator version 5.4.6 [source]
Eshell V5.4.6 (abort with ^G)
User switch command
$ cat fib2
J = list_to_integer(X),
N = fib(J),
io:format("fib ~w = ~w~n",[J, N]).
fib(0) -> 0;
fib(1) -> 1;
fib(N-1) + fib(N-2).
$ ./fib2 20
fib 20 = 6765
Thanks Matthias Lang for the wonderful web page about his previous erlang
cross compilation experience
More information about the erlang-questions