These instructions are mostly obsolete

Brian Zhou posted an improved method for cross-compiling for linux targets. Brian uses that method for an ARM-based embedded system. I have successfully done the same thing for a MIPS-based system.

Cross Compiling Erlang for the PPC860

This is just a quick note about what I did to cross compile Erlang to get it to run on a PowerPC 860 CPU. It might be useful to anyone else trying to do the same, or anyone trying to cross-compile Erlang.

Basic Idea

The platform with the compiler is an x86 PC running GNU/Linux. My target is a board with a PPC860 CPU on it. The board also runs linux with glibc. So running configure on the x86 would get me a configuration "somewhat close" to what I need.

There are other approaches, for instance there are a bunch of SED scripts included in the distribution which mangle Makefiles to make them suitable for for cross compiling to various VxWorks-based systems, including erts/autoconf/vxworks/sed.vxworks_ppc860. I chose not to use these as a starting point because they contained a lot of VxWorks-specific options.

Prerequisites

You need

Running configure

First thing to do is to untar the source. I used R7B with otp_src_R7B-0to1.patch. Then I ran configure
export ac_cv_c_bigendian=yes
./configure --prefix=/export/root/gth/opt/erlang --without-ssl
    
If you use 'csh' you probably want to write something like "setenv ac_cv_c_bigendian yes". Without this endianness fix, you get interesting problems with several things, including the binary syntax:
(mml@antilipe)3> <<19.0:32/float>>.        (antilipe is an x86 box)
<<65,152,0,0>>
...
(gth@gth)11> <<19.0:32/float>>.            (gth is a PPC860)
<<0,0,152,65>>
    

Fixing Makefiles

'Configure' assumed the compiler was called 'gcc'. But the cross compiler is probably called something like 'ppc_8xx-gcc'. So, we need a script which fixes all the makefiles. Here's the script:
#!/bin/sh
mv $1 $1.orig_mml
sed -e 's/^CC[ \t]*=.*$/CC = ppc_8xx-gcc/' $1.orig_mml | \
  sed -e 's/^SHLIB_LD[ \t]*=.*$/SHLIB_LD = ppc_8xx-gcc/' | \
  sed -e 's/^CXX[ \t]*=.*$/CXX = ppc_8xx-g++/' | \
  sed -e 's/^LD[ \t]*=.*$/LD = ppc_8xx-gcc/' | \
  sed -e 's/^LDFLAGS[ \t]*=[ \t]*$/LDFLAGS = -L\/export\/root\/gth\/lib /' \
> $1
    
You'll need to edit the compiler name and library location of your compiler and the location of your libraries. I saved it as 'mung' and ran it:
find . -name Makefile -exec ../mung \{\} \;
../mung make/i686-pc-linux-gnu/otp.mk
    

Compiling

Not too tricky:
make noboot
    
We use 'noboot' because we don't want the system to use the erlang it just built to then create the boot files. From there, all you need to do is 'make install' and then possibly fix a few symlinks and edit the 'erl' shell script to have the right root directory.

Slimming the system

If you're building for an embedded system, you probably want to save disk space so you can use cheaper flash. My installation, which includes SASL, stdlib and inets, takes just 2.7 Mb. It's no doubt possible to throw out more...

By default, the Erlang library .beam files contain debugging information. On an embedded system space might be critical. One way to get rid of the debugging code is to edit the Makefiles at the top of each directory in lib to include the +no_debug_info switch. This cuts the size of the libraries by about 40%.

You can also throw out a whole bunch of libraries which aren't very useful on an embedded system, e.g. gs, the debugger and perhaps everything to do with CORBA and COM.

If you strip the emulator, you save another few megabytes.

Finally, you can go around and delete man pages, notes.html, header files, the emacs mode, etc. etc.

Untested

Some things which may cause problems which I haven't tested are

Problems

Feel free to send me some mail (matthias@corelatus.com) and I'll try to help. If you've got suggestions how to do the above better (e.g. you've hacked the configure scripts to be able to cross compile out of the box), I'd love to hear from you.