Common Makefile rules for building and testing Erlang applications.
Also features support for dependencies and a package index.
erlang.mk requires GNU Make and expects to be ran in a standard
unix environment with Erlang installed and in the
wget for downloading the package index file
pkg:// scheme is used.
Add the file
erlang.mk to your project, then use the following base
PROJECT = my_project include erlang.mk
Erlang projects often depend on other projects to run. Adding dependencies
to the Makefile is easy. You need to create the variable
the names of all the dependencies, along with one
per dependency giving the git repository and commit to retrieve.
These variables should be defined before the include line.
DEPS = cowboy bullet dep_cowboy = https://github.com/extend/cowboy.git 0.8.4 dep_bullet = https://github.com/extend/bullet.git 0.4.1
They will always be compiled using the command
make. If the dependency
does not feature a Makefile, then erlang.mk will be used for building.
You can also specify test-only dependencies. These dependencies will only
be downloaded when running
make tests. The format is the same as above,
except the variable
TEST_DEPS holds the list of test-only dependencies.
TEST_DEPS = ct_helper dep_ct_helper = https://github.com/extend/ct_helper.git master
Please note that the test dependencies will only be compiled once when they are fetched, unlike the normal dependencies.
A very basic package index is included with erlang.mk. You can list
all known packages with the
make pkg-list command. You can search
a package with the
make pkg-search q=STRING command, replacing
STRING with what you want to search. Use quotes around the string
In addition, it is possible to specify dependencies in a simplified manner if they exist in the package index. The above example could instead read as:
DEPS = cowboy bullet dep_cowboy = pkg://cowboy 0.8.4 dep_bullet = pkg://bullet 0.4.1
erlang.mk will look inside the index for the proper URL and use it for fetching the dependency.
All packages featured in the index are compatible with erlang.mk with no extra work required.
relx.config file is present, erlang.mk will download
automatically and build the release into the
_rel folder. This
is the default command when the file exists.
No special configuration is required for this to work.
The following files will be automatically compiled:
||OTP application resource file|
||Erlang source files|
||Core Erlang source files|
||Leex source files|
||Yecc source files|
||ErlyDTL template files|
.app.src file and at least one
.erl file are required.
The following targets are defined:
||Compile the application and all dependencies|
||Clean the application and all dependencies|
||Compile the application|
||Clean the application|
||Compile the dependencies|
||Clean the dependencies|
||Generate the Edoc documentation|
||Clean the Edoc documentation|
||Run the common_test suite
||Run all the common_test suites|
||Generate the PLT needed by Dialyzer|
||Run Dialyzer on the application|
||List packages in the index|
||Search for packages in the index|
||Build a release|
||Delete the previously built release|
Cleaning means removing all generated and temporary files.
Dependencies are fetched as soon as a command involving them is invoked. This means that most of the targets will trigger a dependency fetch. It is only done once per dependency.
You can run an individual test suite by using the special
targets. For example if you have a common_test suite named
and you want to run only this suite and not the others, you can
make test_spdy command.
The default target when calling
all when no
rel when it does exist.
You can combine targets to perform many operations. For example, the
make clean app will have the effect of recompiling
the application fully, without touching the dependencies.
A common workflow when editing a file would be to run
to see if it compiles (or less often
make clean app if you want to
recompile everything), followed by
make dialyze to see if there are
any type errors and then
make tests to run the test suites. The
result of the test runs can be browsed from the
The following variables can be overriden:
V defines the verbosity of the commands. You can set it
to an empty value to make commands verbose.
ERLC_OPTS allows you to change the
options. You should always compile with at least the
COMPILE_FIRST is a list of modules (not filenames) that should be
compiled before all others.
DEPS_DIR is the path to the directory where the dependencies are
downloaded to. It defaults to
deps. It will be propagated into
all the subsequent make calls, allowing all dependencies to use
the same folder as expected.
EDOC_OPTS allows you to specify
options to pass to
edoc when building the documentation. Notice: not all options are
documented in one place; follow the links to get to the options for
the various operations of the documentation generation.
CT_SUITES is the list of common_test suites to run when you use
make tests command. If your suite module is named
then you only need to put
ponies in the list.
CT_OPTS allows you to specify extra common_test options.
PLT_APPS is the list of applications to include when building the
.plt file for Dialyzer. You do not need to put
stdlib in there because they will always be included. The applications
the project depends on will also be included.
DIALYZER_OPTS allows you to change the
PKG_FILE allows you to change the location of the package index file
on your system.
PKG_FILE_URL allows you to change the URL from which the package index
file is fetched.
RELX_CONFIG is the location of the
relx.config file, if any.
RELX is the location of the
relx executable for building releases.
RELX_URL is the location where
relx can be downloaded if it is
not found locally.
RELX_OPTS is for setting relx in-line options, if any.
If you need more functionality out of your Makefile, you can add extra targets after the include line.
Defining a target before the include line will override the default
- Official IRC Channel: #ninenines on irc.freenode.net
- Mailing Lists