Stand Alone Erlang

One of the better hidden things in the latest Open Source release is "SAE" (Stand Alone Erlang) - with this you can make stand-alone Erlang applications which run quickly from the unix command line prompt (see below for measurements).

With SAE you can distribute complete applications in as little as two files. One file is a half MB shared library. The other file is your application.

SAE is currently work in progress and is not supported This document describes how to put togther SAE for R7B

Download

Building SAE

1) Fetch otp_src_R7B-1.tar.gz from www.erlang.org

2) Build Erlang - I do this in a local scratch directory

   mkdir /ldisk/scratch/joe/newerl
   cd /ldisk/scratch/joe/newerl
   cp otp_src_R7B-1.tar.gz .
   gunzip otp_src_R7B-1.tar.gz  
   tar -xf otp_src_R7B-1.tar   
   cd otp_src_R7B-1  
   ./configure
   make
   %% drink a few cups of coffee chat to mates etc. - wish I had
   %% a 4GHz machine ....

3) set a path or something so we can find the right erl and erlc

   > export PATH=/ldisk/scratch/joe/newerl/otp_src_R7B-1/bin:$PATH    

4) Build sae

   > cd /ldisk/scratch/joe/newerl/otp_src_R7B-1   
   > export ERL_TOP=`pwd` 
   > cd erts
   > make sae

5) Copy the virtual machine to somewhere in your path:

   > cp /ldisk/scratch/joe/newerl/otp_src_R7B-1/bin/i686-pc-linux-gnu/beam_evm\
     ~/bin

6) Strip it

   > cd ~/bin
   > strip beam_evm
Building the compiler and linker

Fetch sae-2.0.tgz - unpack and make.

This will build ecc, esh and elink

ecc and elink

ecc foo.erl bar.erl ....
compiles foo.erl, bar.erl, ...
elink -o E -m Mod1 Mod2 Mod3 -s Mod Func
Makes an executable E from the compiled modules Mod1.beam, Mod2.beam,.... When E Arg1 Arg2 is called Mod:Fun([Arg1, ..]) will be called.

ecc and esh

ecc will compile all Erlang files except those which make use of include files from the standard libraries.

To run the Erlang shell, or to compile files with includes you will need to obtain the open source Erlang release.

Assuming that you have installed this in $WHERE as above then give the command:

This will patch the correct path into ecc and esh.

ecc is an Erlang compiler that will correctly handle include files. esh is the good old Erlang shell with all the paths set correctly.

Hint - this do head -1 (or 2) on esh, or ecc

Basic Kit

The basic Erlang kit now requires three files:

A stand-alone application requires beam_evm + the specific application code.

A precompiled version of the kit is in eLite-2.0.tgz The entire binary kit compiler, emulator and linker is 1.14Mb less than one floppy.

Performance

Here are a few figures for hello.erl (hello world)

The next test is for ecat.erl - cat in Erlang. ecat.erl compiles to a 1474 byte executable. To launch ecat and get it to copy a half megabyte file took less than 0.1 seconds - including all the time to start and stop the system.

Note the shared library is only 555136 bytes - pretty good :-)

Which is fast and small enough to be useful for shell scripts, cgi stuff etc.

Bugs

Please report bugs on http://www.bluetail.com/wiki/showPage?node=StandAloneErlang