26

What tool do you use to build an Erlang program: Emake, makiefile or another?

Jonas
  • 121,568
  • 97
  • 310
  • 388
Kirill Trofimov
  • 1,218
  • 1
  • 14
  • 26

7 Answers7

24

Since these answers, a new standard has emerged in the Erlang community:

Rebar https://github.com/basho/rebar/

bjnortier
  • 2,008
  • 18
  • 18
  • 4
    It is not a standard indeed, but a contribution. Erlang's make is a standard because it is included with the distribution. – tuscland Apr 14 '14 at 08:56
15

We use a similar Emakefile as well.

{"src/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.

I use the erlang make functionality to run tests after succesful compilation.

Makefile extract:

all: compile

compile:
        erlc -o ebin +debug_info erl_make.erl       
        erl -pa ./ebin -eval "erl_make:make(development)" -s init stop -noshell

erl_make.erl

-module(erl_make).

-export([make/1]).

make(Mode) ->
    case make:all([{d, Mode}]) of
        error ->
            error;
        _ ->
            test_suite:test()
    end.
scatterbrain
  • 354
  • 2
  • 7
7

I use a Rakefile calling an Emakefile. Rakefile for flexibility and Emakefile for speed !

This build system is quite powerful, see erl_rake on GitHub

Generates .app files, builds releases automatically, runs EUnit test. And given it's build around a Rakefile, I've added easily pushing release to AWS and run my tests with etap instead.

I customized an old version on for my github projects.

Eric
  • 2,706
  • 18
  • 18
  • 1
    Thanks Thom. Although this comment is outdated. Like everyone else, I now use rebar – Eric Jan 18 '13 at 14:44
6

Here is the Makefile and Emakefile I usually use with make (origin unknown).

Makefile:

ERL=erl
APPFILE=myApp.app

all: ebin/$(APPFILE)
    $(ERL) -make 

ebin/$(APPFILE): src/$(APPFILE)
    cp $< $@ 

Emakefile:

{"src/*", [debug_info, {outdir, "ebin"}, {i, "include"}]}.
Zed
  • 57,028
  • 9
  • 76
  • 100
4

I propose my own tool :) Eake ... is very similar to rake from Ruby environment:

http://github.com/andrzejsliwa/eake

or

http://andrzejsliwa.com/2009/05/28/eake-narzedzie-budowania-dla-erlanga-bazujace-na-rake/

Here is example eakefile

-module(eakefile).
-compile([export_all]).
-import(eake, [task/3, namespace/3, run_target/2, run/1]).

execute() -> [

  namespace(db, "test", [
    task(migrate, "That is migration", fun(Params) ->
      io:format("in migration params: ~w", [Params]),
      run_target('db:rollback', [])
    end),

    task(rollback, "That is rollback", fun(_) ->
      io:format("in rollback"),
      run("ls")
    end)
  ])
].

and this is example using:

$ eake db:migrate
$ eake db:migrate db:rollback
$ eake db:migrate=[1,atom]
$ eake db:migrate=name
Andrzej Śliwa
  • 1,684
  • 2
  • 14
  • 17
2

Use Sinan for building and Faxien for installing! Check out erlware.org. They are way better than a make file and provide ease of distribution. They are both in heavy active development and will be featured in: http://www.manning.com/logan/

1

You can check my Makefiles, i took them from mochiweb or something like that. Sorry but code have some project-specified parts

http://github.com/JLarky/eadc-hub/blob/master/Makefile

MARKDOWN_SOURCES=$(wildcard doc/*.md)
MARKDOWN_TARGETS=$(patsubst doc/%.md,doc/html/%.html,$(MARKDOWN_SOURCES))

all: eadc boot deps

eadc: ebin
cd src && $(MAKE)

deps:
(cd deps/somedeps;$(MAKE);)

docs: erlang-docs # html-docs

erlang-docs: doc/edoc
(cd src;$(MAKE) docs)

html-docs: doc/html $(MARKDOWN_TARGETS)

doc/edoc:
mkdir -p doc/edoc

doc/html:
mkdir -p doc/html

doc/html/%.html: doc/%.md
(title=`grep '^# ' $ $@ ;\
python doc/buildtoc.py  $$t ;\
markdown $$t >> $@ ;\
rm $$t ;\
cat doc/footer.html >> $@)

ebin:
mkdir -p ebin

clean: clean-docs
(cd src;$(MAKE) clean)
(cd deps/*/; $(MAKE) clean)
$(RM) -r priv
$(RM) ebin/*.boot ebin/*.script ebin/*crash.dump ebin/*~ src/*~ priv/*~ *~ \#*\#

clean-docs: clean-html
$(rm) -rf doc/edoc

clean-html:
rm -rf doc/html

boot: ebin/eadc.boot

ebin/eadc.boot: ebin/eadc.rel ebin/eadc.app
erl -pa ebin -noshel -run eadc_utils make_script -run erlang halt

cleandb:
$(RM) -r ebin/Mnesia*

http://github.com/JLarky/eadc-hub/blob/master/support/include.mk

## -*- makefile -*- ## Erlang

ERL := erl
ERLC := $(ERL)c

INCLUDE_DIRS := ../include $(wildcard ../deps/*/include)
EBIN_DIRS := $(wildcard ../deps/*/ebin)
ERLC_FLAGS := -W $(INCLUDE_DIRS:../%=-I ../%) $(EBIN_DIRS:%=-pa %)

ifndef no_debug_info
  ERLC_FLAGS += +debug_info
endif

ifdef debug
  ERLC_FLAGS += -Ddebug
endif

EBIN_DIR := ../ebin
DOC_DIR := ../doc/edoc
EMULATOR := beam

ERL_SOURCES := $(wildcard *.erl)
ERL_HEADERS := $(wildcard *.hrl) $(wildcard ../include/*.hrl)
ERL_OBJECTS := $(ERL_SOURCES:%.erl=$(EBIN_DIR)/%.$(EMULATOR))
ERL_DOCUMENTS := $(ERL_SOURCES:%.erl=$(DOC_DIR)/%.html)
ERL_OBJECTS_LOCAL := $(ERL_SOURCES:%.erl=./%.$(EMULATOR))
APP_FILES := $(wildcard *.app)
REL_FILES := $(wildcard *.rel)
EBIN_FILES_NO_DOCS = $(ERL_OBJECTS) $(APP_FILES:%.app=../ebin/%.app) $(REL_FILES:%.rel=../ebin/%.rel)
EBIN_FILES = $(ERL_DOCUMENTS) $(EBIN_FILES_NO_DOCS)

MODULES = $(ERL_SOURCES:%.erl=%)

../ebin/%.app: %.app
cp $

http://github.com/JLarky/eadc-hub/blob/master/src/Makefile

include ../support/include.mk

all: $(EBIN_FILES_NO_DOCS)

docs: $(ERL_DOCUMENTS)
 *emphasized text*
debug:
$(MAKE) DEBUG=-DDEBUG

clean:
rm -rf $(EBIN_FILES) $(PLUGINS_OBJECTS)
expelledboy
  • 2,033
  • 18
  • 18
JLarky
  • 9,833
  • 5
  • 36
  • 37