From d2a3f2cedd7c00d0933222aed9c06b3149aa4db4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?=
To build a project, all you have to do is type make
:
You can build your application and dependencies without generating a release by running the following command:
To build your application without touching dependencies
at all, you can use the SKIP_DEPS
variable:
You can build all dependencies, and nothing else, by running the following command:
There’s no need for quotes or anything. The relevant part of the Cowboy Makefile follows, if you need an example:
By default, Erlang.mk will set the following options:
You can redefine this variable in your Makefile to change it completely, either before or after including Erlang.mk:
:=
operator.To exclude a module, simply list it in the variable, either before or after including Erlang.mk:
The easiest way is after:
.DEFAULT_GOAL
variable,
otherwise nothing will get built:To clean:
$ make clean
Or distclean:
To build all documentation:
$ make docs
To build only the AsciiDoc documentation:
$ make asciidoc
To build only the user guide:
$ make asciidoc-guide
To build only the manual:
$ make asciidoc-manual
To install man pages on Unix:
3 7
.To install man pages to a custom location:
At the time of writing, this is how you would test against all the most recent patch releases of Erlang/OTP 19 and above:
If you want to test against HiPE and ErLLVM but only with the latest version of Erlang/OTP, the following could work:
-k
. It will ensure that tests are run for all configured
Erlang/OTP versions, even if there are errors:The ci
target can be extended. For example to run Dialyzer
at the end of CI:
For example, to ensure dependencies are re-fetched/built before testing individual Erlang/OTP releases:
http
:The CT_LOGS_DIR
variable can be used to set where HTML
log files are to be written. This defaults to logs/.
To run all tests (including Common Test):
$ make tests
To run all tests and static checks (including Common Test):
$ make check
You can also run Common Test separately:
ct-http
will run that specific test suite:ct-http
example above.To run all tests from the http_compress
group in the
http_SUITE
test suite, write:
$ make ct-http t=http_compress
Similarly, to run a specific test case in that group:
To do the same against a multi-application repository,
you can use the -C
option:
Note that this also applies to dependencies. When using Cowboy as a dependency, you can run the following directly:
Erlang.mk comes with a target that generates a rebar.config file when invoked:
app
target:Packages can be added to the index using the pkg_add.sh
script.
To find a package, search for it:
You can also list everything and use regular command line tools to find what you need, for example:
Once you find the package you need, adding it as a dependency to your project is a one-liner:
For example, you could add a parse transform project like this to make it available only at build time:
Or you could depend on a C project directly, if you are building a NIF:
You could depend on the Crypto application, for example:
Erlang.mk comes with additional types of dependencies.
It has TEST_DEPS
for dependencies used only for testing:
DOC_DEPS
for dependencies used only when building documentation:
REL_DEPS
for dependencies required to build the release,
or to include extra applications in the release:
And SHELL_DEPS
for dependencies to make available when running
the make shell
command:
dep_$(DEP_NAME)_commit
variable. In the case of Cowboy, this would look like this:dep_$(DEP_NAME)
variable with everything:For example, to fetch Cowboy with tag 2.0.0-pre.2 from Git:
dep_cowboy = git https://github.com/ninenines/cowboy 2.0.0-pre.2
Or to fetch Ehsa tag 4.0.3 from Mercurial:
git submodule add
:This would fetch an example project from the trunk:
And this would fetch a separate example project from a specific commit:
You can copy a directory from your machine using the cp
method.
It only takes the path to copy from:
Finally, you can use a package from the Hex repository:
To give an example, this is what the Git method does:
To ignore a dependency, simply add it to the IGNORE_DEPS
variable:
This will only ignore dependencies that are needed for building. It is therefore safe to write:
=
will work. But to avoid it biting you later on, do this:For example, to create a full fledged OTP application as a local dependency:
$ make new-app in=webchat
Or, the same as an OTP library:
You can disable the replacing of the erlang.mk file by
defining the NO_AUTOPATCH_ERLANG_MK
variable:
You can also disable autopatch entirely for a few select
projects using the NO_AUTOPATCH
variable:
A typical usage would be:
To perform an analysis, run the following command:
The analysis will also be performed when you run the following command, alongside tests:
A common use for this variable is to enable Markdown in doc
comments, using the edown
application:
To build all documentation, you would typically use:
You can generate EDoc documentation directly:
You can enable automatic generation on make docs
by adding
the following to your Makefile:
p7zip
; on Ubuntu you need p7zip-full
.
If p7zip
is unavailable, zip
may be used by setting
the ESCRIPT_ZIP
variable. For example:
Run the following command to generate an escript:
relx
then the escript will be in ./relx
.You can run the escript as you would any executable:
TEST
macro. It is only defined
when running tests:TEST
macro. Make sure to only include
it inside an ifdef
block, otherwise tests will always be
compiled.verbose
:erl
when running EUnit tests. For example,
you can load the vm.args and sys.config files:To run all tests (including EUnit):
$ make tests
To run all tests and static checks (including EUnit):
$ make check
You can also run EUnit separately:
EUnit will be quiet by default, only outputting errors. You can easily make it verbose for a single invocation:
t
.$ make eunit t=cow_http_hd
Similarly, to run a specific test case:
To do the same against a multi-application repository,
you can use the -C
option:
Note that this also applies to dependencies. From Cowboy, you can run the following directly:
For example, if you have cowboy
in DEPS
, add cowboy
in
DEP_PLUGINS
also:
DEP_PLUGINS = cowboy/plugins.mk
.For example, the following Makefile loads a plugin in the mk subdirectory:
DEP_PLUGINS = $(PROJECT)/mk/dist.mk
This also works with early-stage plugins:
The first step is always to create a new folder that will contain your project.
The next step is therefore to download it:
$ wget https://erlang.mk/erlang.mk
Or:
This kind of project can be automatically generated by Erlang.mk.
All you need to do is use the bootstrap
target:
Something similar to the following snippet will then appear on your screen:
Of course, the generated project can now be compiled:
This kind of project can also be generated by Erlang.mk, using
the bootstrap-lib
target:
Erlang.mk will once again bootstrap itself and generate all the files for your project. You can now compile it:
Erlang.mk can of course bootstrap your project to generate releases.
You can use the bootstrap-rel
target for this purpose:
This target can be combined with bootstrap
or bootstrap-lib
to
create a project that will build a release:
When you run make
from now on, Erlang.mk will compile your
project and build the release:
make run
. The latter will also compile
your project and build the release if it wasn’t already:include erlang.mk
For a step by step:
For example, if you prefer two spaces per indentation level:
You can list all available templates with the list-templates
target:
To generate a module, let’s say a gen_server
, all you need to
do is to call make new
with the appropriate arguments:
gen_server
template.This module is automatically compiled the next time you run
make
:
During development, if you don’t remember the name of a target,
you can always run make help
:
The commands to install packages vary between distributions:
$ pacman -S erlang git make
Alpine Linux and other distributions based on BusyBox come
+with an incompatible awk
program. Installing the GNU Awk
+(gawk
on Alpine) solves this issue.
FreeBSD comes with binary and source packages:
pacman
directly:You can use pacman -Ss
to search packages. For example,
to find all packages related to GCC:
ERLANG_OTP
variable in your Makefile before including
Erlang.mk. For example, to use OTP-20.0.4
:You can get a list of all packages known to Erlang.mk by using
the search
target:
You can also use this target to search across all packages, for example to find all packages related to Cowboy:
You can include the env.mk file to benefit from the Erlang environment detection:
By adding this to your Makefile all five variables will be made available to sub-Makefiles when building C code:
You can specify additional Relx options using the RELX_OPTS
variable. For example, to enable dev_mode
:
RELX_OUTPUT_DIR
. It defaults to the _rel
directory. You can also override it:If you need to generate the release, and only the release,
the rel
target can be used:
$(RELX_OUTPUT_DIR)/<name>/<name>-<vsn>.tar.gz
Erlang.mk provides a convenience function for running the
release with one simple command:
-
@@ -174,7 +174,7 @@ release will be example
.
Once all this is done, you can build the tarball for the
release upgrade:
-
@@ -184,7 +184,7 @@ release, $RELX_OUTPUT_DIR/example/example-2.tar.gz
.
Move the archive to the correct location on the running
node. From the release’s root directory:
-
@@ -192,14 +192,14 @@ http://www.gnu.org/software/src-highlite -->
$ mv path/to/example-2.tar.gz releases/2/
Finally, upgrade the release:
-
$ bin/example_release upgrade "2/example_release"
Or on Windows:
-
@@ -214,14 +214,14 @@ http://www.gnu.org/software/src-highlite -->
generated by Relx based on VCS history.
Create a file rel/version with only one line inside:
-
{{ release_version }}
Add/Update the overlay
section of your relx.config
:
-
@@ -231,7 +231,7 @@ http://www.gnu.org/software/src-highlite -->
When you run make rel
it creates the file $(RELX_OUTPUT_DIR)/example/version
which contains the version value generated by Relx.
-
@@ -240,14 +240,14 @@ http://www.gnu.org/software/src-highlite -->
In your Makefile
you can use this simple snippet to get the version,
but please keep in mind that this should depend on the rel
target:
-
$(shell cat $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/version)
For example:
-
@@ -258,7 +258,7 @@ http://www.gnu.org/software/src-highlite -->
echo APP_VERSION = $(APP_VERSION)
Would output:
-
diff --git a/docs/en/erlang.mk/1/guide/sfx/index.html b/docs/en/erlang.mk/1/guide/sfx/index.html
index 5ef06d47..2877244e 100644
--- a/docs/en/erlang.mk/1/guide/sfx/index.html
+++ b/docs/en/erlang.mk/1/guide/sfx/index.html
@@ -7,7 +7,7 @@
-
+
Nine Nines: Self-extracting releases
@@ -82,7 +82,7 @@ appreciated.
is pass the SFX=1
variable to Make when you build the
release:
-
@@ -98,7 +98,7 @@ the file will be located at _rel/hello_world.run
.
Simply execute the script to get started:
-
diff --git a/docs/en/erlang.mk/1/guide/shell/index.html b/docs/en/erlang.mk/1/guide/shell/index.html
index 95cc3da1..1d87f835 100644
--- a/docs/en/erlang.mk/1/guide/shell/index.html
+++ b/docs/en/erlang.mk/1/guide/shell/index.html
@@ -7,7 +7,7 @@
-
+
Nine Nines: Erlang shell
@@ -76,7 +76,7 @@ with all the paths set properly to experiment with your code.
that are only to be used when the make shell
command is called.
For example, if you want to use kjell as your shell:
-
@@ -88,7 +88,7 @@ To continue with our example, if you want to use kjell as your
shell, you also need to change SHELL_ERL
and point it to the
kjell
executable:
-
@@ -96,14 +96,14 @@ http://www.gnu.org/software/src-highlite -->
You can specify additional options to be used when starting the
shell using the SHELL_OPTS
variable:
-
SHELL_OPTS = -setcookie chocolate
Any of the usual erl
options can be used, including -eval
:
-
@@ -115,7 +115,7 @@ http://www.gnu.org/software/src-highlite -->
To start the shell, all you need is the following command:
-
@@ -136,8 +136,8 @@ command q().
.
That’s why updating Erlang.mk is so simple. All you need
to do is to call make erlang-mk
:
-
@@ -124,7 +124,7 @@ and in what order.
the build. For example, to exclude the package index and the EDoc
plugin when bootstrapping your application:
-
@@ -133,7 +133,7 @@ http://www.gnu.org/software/src-highlite -->
you update it, until you change your mind and use the WITHOUT
variable again when you upgrade:
-
diff --git a/docs/en/erlang.mk/1/guide/why/index.html b/docs/en/erlang.mk/1/guide/why/index.html
index 7aed235e..c7e18c6d 100644
--- a/docs/en/erlang.mk/1/guide/why/index.html
+++ b/docs/en/erlang.mk/1/guide/why/index.html
@@ -7,7 +7,7 @@
-
+
Nine Nines: Why Erlang.mk
diff --git a/docs/en/erlang.mk/1/guide/xref/index.html b/docs/en/erlang.mk/1/guide/xref/index.html
index 2dc4951c..4f0a27c6 100644
--- a/docs/en/erlang.mk/1/guide/xref/index.html
+++ b/docs/en/erlang.mk/1/guide/xref/index.html
@@ -7,7 +7,7 @@
-
+
Nine Nines: Xref
--
cgit v1.2.3