Introduction
How to use the Makefile
Targets
You can build individual modules with target names composed of the module name and a .beam extension. Applications targets are the application name with a .app extension. Release targets are the release name with a .rel extension suffix. The default target will build everything.
Project structure
The Makefile expects to find a lib and releases directory next to it, in a similar shape to an OTP source tree. The lib must contain application directories, each with src and priv directories. Similarly, releases must contain release directories, each with src and priv directories too. Both releases and applications must have a vsn.mk file in src, containing a line saying
VSN = X.Y.Z
so that the version suffixes can be added to the results directories, and inserted into the .app.src files and .rel.src files. Header files with nested includes are not catered for: do not use nested -include_lib across applications.
For example:
$> tree -d
.
|-- lib
| `-- application_name
| |-- include
| | `-- header_file.hrl
| |-- priv
| `-- src
| |-- application_name.app.src
| |-- module_file.erl
| |-- snmp_file.mib
| `-- vsn.mk
`-- releases
`-- release_name
|-- priv
`-- src
|-- release_name.rel.src
|-- start.src
|-- sys.config.src
`-- vsn.mk
$>cat lib/application_name/src/vsn.mk
VSN = 1.0
$>cat releases/release_name/src/release_name.rel.src
{release,
{"release description","release_name-%VSN%"},
{erts, "%erts%"},
[{kernel, "%kernel%"},
{stdlib, "%stdlib%"},
{sasl, "%sasl%"},
{runtime_tools, "%runtime_tools%"},
{os_mon, "%os_mon%"},
{snmp, "%snmp%"},
{mnesia, "%mnesia%"},
{application_name, "%application_name%"}
]}.The %VSN% token is replaced with the release version, obtained from releases/release_name/src/vsn.mk. All the %erts%, %kernel% etc. tokens are replaced with the version for that application. For the OTP applications, this is deduced from the Erlang installation in the $PATH. For the application_name, this is obtained from the corresponding vsn.mk file.
The possible targets are, for example:
- make will make all the release tarballs
- make release_name.rel will make one of the release tarballs
- make application_name.app will make one of the applications
- make module_file.beam will compile one of the Erlang source files
The result of building will be:
$> tree -d
.
|-- lib
| |-- application_name
| | |-- include
| | | `-- header_file.hrl
| | |-- priv
| | `-- src
| | |-- application_name.app.src
| | |-- module_file.erl
| | |-- snmp_file.mib
| | `-- vsn.mk
| `-- application_name-1.0
| |-- priv
| | `-- mibs
| | `-- snmp_file.bin
| `-- ebin
| |-- application_name.app
| `-- module_file.beam
`-- releases
|-- release_name
| |-- priv
| `-- src
| |-- release_name.rel.src
| |-- start.src
| |-- sys.config.src
| `-- vsn.mk
`-- release_name-1.0
|-- release_name-1.0.boot
|-- release_name-1.0.rel
|-- release_name-1.0.script
|-- release_name-1.0.tar.gz
|-- start
`-- sys.configIndividual files are valid targets too:
make lib/application_name-1.0/priv/mibs/snmp_file.bin
Note on included files
The Makefile requires that the usage of -include and -include_lib is consistent and disciplined.
- Use -include for header files used only within the application, and not shared between applications. The file is specified with only the file name, no path. These header files are located in the src directory of the application. E.g:
-include("header_file.hrl").Use -include_lib for header files shared between applications. Ensure that the file is specified with a path. These are located in the include directory of the application. E.g: -include_lib("application_name/include/header_file.hrl").