|
|
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
|
|
|
|
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
|
|
Fetch sae-2.0.tgz - unpack and make.
This will build ecc, esh and elink
|
|
|
|
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:
ecc -install $WHERE/otp_src_R6B-0/
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
|
|
The basic Erlang kit now requires three files:
| File | Description | # Bytes |
| beam_evm | Erlang virtual machine | 551316 |
| ecc | Erlang compiler | 836632 |
| elink | Erlang linker | 20251 |
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.
|
|
Here are a few figures for hello.erl (hello world)
> time ecc hello.erl
"hello.erl" {ok,hello}
0.57user 0.04system 0:00.61elapsed 99%CPU
>time elink time elink -o hello -m hello -s hello main
0.01user 0.03system 0:00.03elapsed 102%CPU
> time hello a b c
{hello,start,args,'=',["beam_evm","a","b","c"]}
{xy,false,false}
"Hello World"
0.00user 0.02system 0:00.01elapsed 111%CPU
> ls -l hello
-rwxr-xr-x 1 joe staff 879 Dec 6 13:18 hello*
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 :-)
>ecc ecat.erl
"ecat.erl" {ok,ecat}
> ./elink -o ecat -m ecat erlang erl_open_port -s ecat main
> time ./ecat <beam_evm >aa
0.03user 0.05system 0:00.08elapsed 96%CPU
> ls -l ecat.beam beam_evm
-rwxr-xr-x 1 joe staff 551316 Dec 6 15:15 beam_evm*
-rw-r--r-- 1 joe staff 1474 Dec 6 15:21 ecat.beam
Which is fast and small enough to be useful for shell scripts, cgi stuff etc.
|
|
Please report bugs on http://www.bluetail.com/wiki/showPage?node=StandAloneErlang