Cross Compiling Erlang/OTP

This document describes how to cross compile Erlang/OTP. Note that the support for cross compiling Erlang/OTP should be considered as experimental. As far as we know, the R13B04 release should cross compile fine, but since we currently have a very limited set of cross compilation environments to test with we cannot be sure. The cross compile support will stay in an experimental state until we get a lot more cross compilation environments to test with.

You are encouraged to read the whole document before attempting to cross compile Erlang/OTP. Before reading this document you should read the $ERL_TOP/INSTALL.md document which describes building Erlang/OTP in general. $ERL_TOP is the top directory in the source tree.

otp_build Versus configure/make

Building Erlang/OTP can be done either by using the $ERL_TOP/otp_build script, or by invoking $ERL_TOP/configure and make directly. Building using otp_build is easier since it involves fewer steps, but the otp_build build procedure is not as flexible as the configure/make build procedure. Note that otp_build configure will produce a default configuration that differs from what configure will produce by default. For example, currently --disable-dynamic-ssl-lib is added to the configure command line arguments unless --enable-dynamic-ssl-lib has been explicitly passed. The binary releases that we deliver are built using otp_build. The defaults used by otp_build configure may change at any time without prior notice.

Cross Configuration

The $ERL_TOP/xcomp/erl-xcomp.conf.template file contains all available cross configuration variables and can be used as a template when creating a cross compilation configuration. All cross configuration variables are also listed at the end of this document. For examples of working cross configurations see the $ERL_TOP/xcomp/erl-xcomp-TileraMDE2.0-tilepro.conf file and the $ERL_TOP/xcomp/erl-xcomp-x86_64-saf-linux-gnu.conf file. If the default behavior of a variable is satisfactory, the variable does not need to be set. However, the configure script will issue a warning when a default value is used. When a variable has been set, no warning will be issued.

A cross configuration file can be passed to otp_build configure using the --xcomp-conf command line argument. Note that configure does not accept this command line argument. When using the configure script directly, pass the configuration variables as arguments to configure using a <VARIABLE>=<VALUE> syntax. Variables can also be passed as environment variables to configure. However, if you pass the configuration in the environment, make sure to unset all of these environment variables before invoking make; otherwise, the environment variables might set make variables in some applications, or parts of some applications, and you may end up with an erroneously configured build.

What can be Cross Compiled?

All Erlang/OTP applications except the wx application can be cross compiled. The build of the wx driver will currently be automatically disabled when cross compiling.

Compatibility

The build system, including cross compilation configuration variables used, may be subject to non backward compatible changes without prior notice. Current cross build system has been tested when cross compiling some Linux/GNU systems, but has only been partly tested for more esoteric platforms. The VxWorks example file is highly dependent on our environment and is here more or less only for internal use.

Patches

Please submit any patches for cross compiling in a way consistent with this system. All input is welcome as we have a very limited set of cross compiling environments to test with. If a new configuration variable is needed, add it to $ERL_TOP/xcomp/erl-xcomp.conf.template, and use it in configure.in. Other files that might need to be updated are:

Note that this might be an incomplete list of files that need to be updated.

General information on how to submit patches can be found at: http://wiki.github.com/erlang/otp/submitting-patches

Build and Install Procedure

If you are building in Git you want to read the "Building in Git" section of $ERL_TOP/INSTALL.md before proceeding.

We will first go through the configure/make build procedure which people probably are most familiar with.

Building With configure/make Directly

(1)

Change directory into the top directory of the Erlang/OTP source tree.

$ cd $ERL_TOP

In order to compile Erlang code, a small Erlang bootstrap system has to be built, or an Erlang/OTP system of the same release as the one being built has to be provided in the $PATH. The Erlang/OTP for the target system will be built using this Erlang system, together with the cross compilation tools provided.

If you want to build the documentation out of the same source tree as you are cross compiling in, you currently need a full Erlang/OTP system of the same release as the one being built for the build machine. If this is the case, build and install one for the build machine (or use one already built) and add it to the $PATH before cross building, and building the documentation. See $ERL_TOP/INSTALL.md for information on building the documentation.

If you want to build using a compatible Erlang/OTP system in the $PATH, jump to (3).

Building a Bootstrap System

(2)

$ ./configure --enable-bootstrap-only
$ make

The --enable-bootstrap-only argument to configure isn't strictly necessary, but will speed things up. It will only run configure in applications necessary for the bootstrap, and will disable a lot of things not needed by the bootstrap system. If you run configure without --enable-boostrap-only you also have to run make as make bootstrap; otherwise, the whole system will be built.

Cross Building the System

(3)

$ ./configure --host=<HOST> --build=<BUILD> [Other Config Args]
$ make

<HOST> is the host/target system that you build for. It does not have to be a full CPU-VENDOR-OS triplet, but can be. The full CPU-VENDOR-OS triplet will be created by executing $ERL_TOP/erts/autoconf/config.sub <HOST>. If config.sub fails, you need to be more specific.

<BUILD> should equal the CPU-VENDOR-OS triplet of the system that you build on. If you execute $ERL_TOP/erts/autoconf/config.guess, it will in most cases print the triplet you want to use for this.

Pass the cross compilation variables as command line arguments to configure using a <VARIABLE>=<VALUE> syntax. Note that you can not pass a configuration file using --xcomp-conf=<FILE> when you invoke configure directly. The --xcomp-conf=<FILE> argument can only be passed to otp_build configure.

make will verify that the Erlang/OTP system used when building is of the same release as the system being built, and will fail if this is not the case. It is possible, however not recommended, to force the cross compilation even though the wrong Erlang/OTP system is used. This by invoking make like this: make ERL_XCOMP_FORCE_DIFFERENT_OTP=yes. Note that this build might fail, silently produce suboptimal code, or silently produce erroneous code.

Installing

You can either install using the installation paths determined by configure (4), or install manually using (5).

Installing Using Paths Determined by configure

(4)

$ make install DESTDIR=<TEMPORARY_PREFIX>

make install will install at a location specified when doing configure. configure arguments specifying where the installation should reside are for example: --prefix, --exec-prefix, --libdir, --bindir, etc. By default it will install under /usr/local. You typically do not want to install your cross build under /usr/local on your build machine. Using DESTDIR will cause the installation paths to be prefixed by $DESTDIR. This makes it possible to install and package the installation on the build machine without having to place the installation in the same directory on the build machine as it should be executed from on the target machine.

When make install has finished, change directory into $DESTDIR, package the system, move it to the target machine, and unpack it. Note that the installation will only be working on the target machine at the location determined by configure.

Installing Manually

(5)

$ make release RELEASE_ROOT=<RELEASE_DIR>

make release will copy what you have built for the target machine to <RELEASE_DIR>. The Install script will not be run. The content of <RELEASE_DIR> is what by default ends up in /usr/local/lib/erlang.

The Install script used when installing Erlang/OTP requires common Unix tools such as sed to be present in your $PATH. If your target system does not have such tools, you need to run the Install script on your build machine before packaging Erlang/OTP. The Install script should currently be invoked as follows in the directory where it resides (the top directory):

$ ./Install [-cross] [-minimal|-sasl] <ERL_ROOT>

where:

If neither -minimal, nor -sasl is passed as argument you will be prompted.

You can now either do:

(6)

or:

(7)

Building With the otp_build Script

(8)

$ cd $ERL_TOP

(9)

$ ./otp_build configure --xcomp-conf=<FILE> [Other Config Args]

alternatively:

$ ./otp_build configure --host=<HOST> --build=<BUILD> [Other Config Args]

If you have your cross compilation configuration in a file, pass it using the --xcomp-conf=<FILE> command line argument. If not, pass --host=<HOST>, --build=<BUILD>, and the configuration variables using a <VARIABLE>=<VALUE> syntax on the command line (same as in (3)). Note that <HOST> and <BUILD> have to be passed one way or the other; either by using erl_xcomp_host=<HOST> and erl_xcomp_build=<BUILD> in the configuration file, or by using the --host=<HOST>, and --build=<BUILD> command line arguments.

otp_build configure will configure both for the boostrap system on the build machine and the cross host system.

(10)

$ ./otp_build boot -a

otp_build boot -a will first build a bootstrap system for the build machine and then do the cross build of the system.

(11)

$ ./otp_build release -a <RELEASE_DIR>

otp_build release -a will do the same as (5), and you will after this have to do a manual install either by doing (6), or (7).

Currently Used Configuration Variables

Note that you cannot define arbitrary variables in a cross compilation configuration file. Only the ones listed below will be guaranteed to be visible throughout the whole execution of all configure scripts. Other variables needs to be defined as arguments to configure or exported in the environment.

Variables for otp_build Only

Variables in this section are only used, when configuring Erlang/OTP for cross compilation using $ERL_TOP/otp_build configure.

NOTE! These variables currently have no effect if you configure using the configure script directly.

Cross Compiler and Other Tools

If the cross compilation tools are prefixed by <HOST>- you probably do not need to set these variables (where <HOST> is what has been passed as --host=<HOST> argument to configure).

All variables in this section can also be used when native compiling.

Dynamic Erlang Driver Linking

NOTE! Either set all or none of the DED_LD* variables.

Large File Support

NOTE! Either set all or none of the LFS_* variables.

Other Tools

Cross System Root Locations

Optional Feature, and Bug Tests

These tests cannot (always) be done automatically when cross compiling. You usually do not need to set these variables. Only set these if you really know what you are doing.

Note that some of these values will override results of tests performed by configure, and some will not be used until configure is sure that it cannot figure the result out.

The configure script will issue a warning when a default value is used. When a variable has been set, no warning will be issued.

Copyright and License

%CopyrightBegin%

Copyright Ericsson AB 2009-2010. All Rights Reserved.

The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/.

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.

%CopyrightEnd%