Erlang Central

Erlmerge - The install tool

From ErlangCentral Wiki






Erlmerge is a tool for installing and maintaining Erlang applications. The basic idea - which is blatantly stolen from the Gentoo emerge command - is to make it possible to retrieve, compile and install Erlang code using one simple command: erlmerge.

When installing Erlmerge, an packet database will be created in the Erlang installation directory. Assuming Erlang is installed under /usr/local/lib/erlang, we will create a new directory: /usr/local/lib/erlang/erlmerge_DB when Erlmerge is installed. This directory will hold the packet database, the current list of known packets, the downloaded packet tar-balls and a Makefile include file.

Code listing 1.1: Content of the erlmerge_DB directory.

	  # ls -l /usr/local/lib/erlang/erlmerge_DB/ 
	  total 72
	  drwxr-xr-x  2 root root  4096 Jul 16 23:45 distfiles
	  -rw-r--r--  1 root root 54313 Jul 17 00:08 erlmerge.dets
	  -rw-r--r--  1 root root  1574 Jun 14 08:51
	  -rw-r--r--  1 root root  2481 Jul 16 23:35 sync.erlmerge


A packet is simply an Erlang application, and the packet list contains the .app file contents of all the available packets. The .app file content has been extended a little bit to handle location information and dependencies to other applications. For example, the information for the esmb application looks as shown below.

Code listing 1.2: The esmb .app file content.

             [{description,"Erlang SMB Library"},


To make an application Erlmerge capable it is important that its directory structure follows the way OTP applications are laid-out. Lots of code exists in the jungerl repository where it is hard to know what status the code is in. To make an easy transition, we have prepared jungerl to make it really easy to create new releases that are erlmerge capable. Look at the Makefiles of the esmb and fd_server for example of how to setup your Erlang (and C) application. Basically, what you need to do is to add a two new targets to your Makefile.

Code listing 1.3: Example, new Makefile targets

	  release: clean appfile
	          sh ../../support/

                  (cd src;$(MAKE) ../ebin/

Don't forget to set a CVS tag on your application when producing a release. Hopefully, this would enhance the usefulness of jungerl even more.

Note: The use of Erlmerge could make it possible to start doing Erlang

releases in a completely new way. For example, the OTP team could release just a minimal Erlang system, where most (all?) of the applications could be installed aftewards, on demand. Bug fixes could be released per application, etc.

Installing Erlmerge

To install erlmerge the first time, download the latest erlmerge-X.Y_src.tar.gz tar-ball from erlmerge github. Unpack it, compile and install it as shown below:

  • tar xvzf erlmerge-0.1_src.tar.gz
  • cd erlmerge-0.1
  • make
  • make install (as root if Erlang is installed as root)

This will install a shell script named erlmerge in parallel with your erl script.

Using Erlmerge

When you have installed the erlmerge command you can search among the applications currently available as in the example below:

Code listing 1.4: Searching for any Mnesia related application(s).

	  # erlmerge search mnesia
	  Name: mnesia_session
	  Version: 1.1.5
	  Description: MNESIA_SESSION  CXC 138 12
	  Installed: true
	  Name: mnesia
	  Version: 4.2.2
	  Description: MNESIA  CXC 138 12
	  Installed: true

We can now update the Erlmerge database with other applications that are available for download. This is done with the sync operation:

Important: If you have installed Erlang as root, you will need to run

the sync operation as root as well.

Code listing 1.5: Searching for the esmb application.

	  # erlmerge sync
	  # erlmerge search esmb
	  Name: esmb
	  Version: 1.0
	  Description: Erlang SMB Library
	  Installed: false

In the example above, after the sync operation, we search for the esmb application which is available but not installed. To install this application we use the install operation. The -p (pretend) switch will perform a dry run without actually installing anything. It will however show us any possible dependencies which also will be installed.

Important: If you have installed Erlang as root, you will need to run

the install operation as root as well.

Code listing 1.6: Installing the esmb application.

	  # erlmerge -p install esmb

	  These are the packages that I would merge, in order:

	  [N  ] fd_server-2.3.0
	  [N  ] esmb-1.0
	  # erlmerge install esmb

	  unpacking: fd_server-2.3.0.tar.gz.....
	  compiling: fd_server-2.3.0.....
	  (cd config;make)
	  make[1]: Entering directory `/usr/local/lib/erlang/lib/fd_server-2.3.0/config'
	  autoheader-2.59: WARNING: Using auxiliary files such as `acconfig.h', `'
	  autoheader-2.59: WARNING: and `', to define templates for `'
	  ....we skip some printouts here.....
	  make[1]: Leaving directory `/usr/local/lib/erlang/lib/fd_server-2.3.0/c_src'
	  unpacking: esmb-1.0.tar.gz.....
	  compiling: esmb-1.0.....
	  (cd src;make)
	  make[1]: Entering directory `/usr/local/lib/erlang/lib/esmb-1.0/src'
	  erlc -b beam -W  -o ../ebin esmb.erl
	  ./esmb.erl:316: Warning: variable 'Reason' is unused
	  ....we skip some printouts here.....
	  make[1]: Leaving directory `/usr/local/lib/erlang/lib/esmb-1.0/c_src'

The output from the -p switch produces a compact "array" of information. It tells you if the application is new, if it will be upgraded to a newer version or if it will be rebuilt due to changed dependencies.

Code listing 1.7: Syntax of the 'pretend' output.

	  [N  ] <App>-<NewVsn>             % A new application
	  [ U ] <App>-<Newvsn> [<OldVsn>]  % Update to newer version
	  [  R] <App>-<NewVsn>             % Rebuild due to updated deps	  


Now we should be able to start using the esmb application:

Code listing 1.8: Check that the esmb application is installed

	  # erl
	  Erlang (BEAM) emulator version 5.4.6 [source] [hipe]
	  Eshell V5.4.6  (abort with ^G)
	  1> m(esmb).
	  Module esmb compiled: Date: July 16 2005, Time: 21.45
	  Compiler options:  [{cwd,"/usr/local/lib/erlang/lib/esmb-1.0/src"},
	  Object file: /usr/local/lib/erlang/lib/esmb-1.0/ebin/esmb.beam


To delete the esmb application we use the delete operation. In the example below, we also verify that it has been removed.

Important: If you have installed Erlang as root, you will need to run

the delete operation as root as well.

Code listing 1.9: Delete the esmb application and verify it's gone.

	  # erlmerge delete esmb
	  Deleted application: esmb
	  [tobbe@orre]~ > erl                         
	  Erlang (BEAM) emulator version 5.4.6 [source] [hipe]
	  Eshell V5.4.6  (abort with ^G)
	  1> m(esmb).
	  ** exited: {undef,[{esmb,module_info,[]},


If you want to remove the whole Erlmerge system, including all installed applications, you can use the suicide operation. This will cause the erlmerge_DB directory to be removed along with all applications installed by erlmerge. Finally, it will also remove the erlmerge script itself, restoring your Erlang installation to its original state.

Code listing 1.10: The erlmerge suicide command.

	  # erlmerge suicide
	  Removed: /usr/local/lib/erlang/lib/esmb-1.0
	  Removed: /usr/local/lib/erlang/lib/fd_server-2.3.0
	  Removed: /usr/local/lib/erlang/lib/../erlmerge_DB

Here follows all the possible arguments to the erlmerge command at the moment:

Code listing 1.11: The erlmerge command syntax.

# erlmerge

erlmerge <options> <applications>

 where  <options>:

    -u             : Update application(s) to latest version
    -p             : Dry run only (pretend)
    -i,install     : Install the following application(s)
    -d,delete      : Delete the following application(s)
    -s,search      : Search for application(s)
    suicide        : Remove erlmerge and all non-original apps
    -y,sync        : Update the application database (syncronize)
    -x,dump <app>  : Dump info about application (debug)
    -w <Url>       : Url pointing to an erlmerge sync-file