summaryrefslogtreecommitdiffstats
path: root/docs/en/erlang.mk/1/guide/app/index.html
blob: 51c80b321c673309fbe9c2c2f18a49e03cbd589f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">

    <title>Nine Nines: Building</title>

    <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
    <link href="/css/99s.css?r=5" rel="stylesheet">

    <link rel="shortcut icon" href="/img/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
    <link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">

    
</head>


<body class="">
  <header id="page-head">
    <div id="topbar" class="container">
        <div class="row">
          <div class="span2">
            <h1 id="logo"><a href="/" title="99s">99s</a></h1>
          </div>
          <div class="span10">
            
            <div id="side-header">
              <nav>
                <ul>
                  <li><a title="Hear my thoughts" href="/articles">Articles</a></li>
  				  <li><a title="Watch my talks" href="/talks">Talks</a></li>
  				  <li class="active"><a title="Read the docs" href="/docs">Documentation</a></li>
  				  <li><a title="Request my services" href="/services">Consulting & Training</a></li>
                </ul>
              </nav> 
              <ul id="social">
                <li>
                  <a href="https://github.com/ninenines" title="Check my Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
                </li>
                    <li>
						<a title="Contact me" href="mailto:[email protected]"><img src="/img/ico_mail.png" data-hover="/img/ico_mail_alt.png"></a>
					</li>
              </ul>
            </div>
          </div>
        </div>
    </div>


</header>

<div id="contents" class="two_col">
<div class="container">
<div class="row">
<div id="docs" class="span9 maincol">

<h1 class="lined-header"><span>Building</span></h1>

<p>Erlang.mk can do a lot of things, but it is, first and foremost, a build tool. In this chapter we will cover the basics of building a project with Erlang.mk.</p>
<p>For most of this chapter, we will assume that you are using a project <a href="../getting_started">generated by Erlang.mk</a>.</p>
<h2 id="_how_to_build">How to build</h2>
<p>To build a project, all you have to do is type <code>make</code>:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make</tt></pre>
</div></div>
<p>It will work regardless of your project: OTP applications, library applications, NIFs, port drivers or even releases. Erlang.mk also automatically downloads and compiles the dependencies for your project.</p>
<p>All this is possible thanks to a combination of configuration and conventions. Most of the conventions come from Erlang/OTP itself so any seasoned Erlang developers should feel right at home.</p>
<p>Erlang.mk supports multi-threaded building. Parallel execution is supported for all targets. To execute Erlang.mk in parallel the <code>-j</code> option must be used:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make -j<font color="#993399">8</font></tt></pre>
</div></div>
<p>The <code>MAKEFLAGS</code> variable can be used to enable parallel building permanently on your system. It can be set in your <code>.zshrc</code>, <code>.bashrc</code> or equivalent file.</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">MAKEFLAGS</font><font color="#990000">=</font><font color="#FF0000">"-j8"</font></tt></pre>
</div></div>
<h2 id="_what_to_build">What to build</h2>
<p>Erlang.mk gives you control over three steps of the build process, allowing you to do a partial build if needed.</p>
<p>A build has three phases: first any dependency is fetched and built, then the project itself is built and finally a release may be generated when applicable. A release is only generated for projects specifically configured to do so.</p>
<p>Erlang.mk handles those three phases automatically when you type <code>make</code>. But sometimes you just want to repeat one or two of them.</p>
<p>The commands detailed in this section are most useful after you have a successful build as they allow you to quickly redo a step instead of going through everything. This is especially useful for large projects or projects that end up generating releases.</p>
<h4 id="_application">Application</h4>
<p>You can build your application and dependencies without generating a release by running the following command:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make app</tt></pre>
</div></div>
<p>To build your application without touching dependencies at all, you can use the <code>SKIP_DEPS</code> variable:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make app <font color="#009900">SKIP_DEPS</font><font color="#990000">=</font><font color="#993399">1</font></tt></pre>
</div></div>
<p>This command is very useful if you have a lot of dependencies and develop on a machine with slow file access, like the Raspberry Pi and many other embedded devices.</p>
<p>Note that this command may fail if a required dependency is missing.</p>
<h4 id="_dependencies">Dependencies</h4>
<p>You can build all dependencies, and nothing else, by running the following command:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make deps</tt></pre>
</div></div>
<p>This will fetch and compile all dependencies and their dependencies, recursively.</p>
<p><a href="../deps">Packages and dependencies</a> are covered in the next chapter.</p>
<h4 id="_release">Release</h4>
<p>It is not possible to build the release without at least building the application itself, unless of course if there&apos;s no application to begin with.</p>
<p>To generate the release, <code>make</code> will generally suffice with a normal Erlang.mk. A separate target is however available, and will take care of building the release, after building the application and all dependencies:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make rel</tt></pre>
</div></div>
<p>Consult the <a href="../relx">Releases</a> chapter for more information about what releases are and how they are generated.</p>
<h2 id="_application_resource_file">Application resource file</h2>
<p>When building your application, Erlang.mk will generate the <a href="http://www.erlang.org/doc/man/app.html">application resource file</a>. This file is mandatory for all Erlang applications and is found in <em>ebin/$(PROJECT).app</em>.</p>
<p><code>PROJECT</code> is a variable defined in your Makefile and taken from the name of the directory when Erlang.mk bootstraps your project.</p>
<p>Erlang.mk can build the <em>ebin/$(PROJECT).app</em> in two different ways: from the configuration found in the Makefile, or from the <em>src/$(PROJECT).app.src</em> file.</p>
<h4 id="_application_configuration">Application configuration</h4>
<p>Erlang.mk automatically fills the <code>PROJECT</code> variable when bootstrapping a new project, but everything else is up to you. None of the values are required to build your project, although it is recommended to fill everything relevant to your situation.</p>
<dl><dt><code>PROJECT</code></dt>
<dd><p>The name of the OTP application or library.</p>
</dd>
<dt><code>PROJECT_DESCRIPTION</code></dt>
<dd><p>Short description of the project.</p>
</dd>
<dt><code>PROJECT_VERSION</code></dt>
<dd><p>Current version of the project.</p>
</dd>
<dt><code>PROJECT_MOD</code></dt>
<dd><p>The application callback module.</p>
</dd>
<dt><code>PROJECT_REGISTERED</code></dt>
<dd><p>List of the names of all registered processes.</p>
</dd>
<dt><code>PROJECT_ENV</code></dt>
<dd><p>Configuration parameters used by the application.</p>
</dd>
<dt><code>PROJECT_APP_EXTRA_KEYS</code></dt>
<dd><p>Other keys you want to add to the application <code>.app</code> file. The variable content is written as-is to the <code>.app</code> file, so be sure to format valid Erlang terms. For example: <code>PROJECT_APP_EXTRA_KEYS = {maxT, 10000}, {start_phases, [...]}</code>.</p>
</dd>
<dt><code>LOCAL_DEPS</code></dt>
<dd><p>List of Erlang/OTP applications this project depends on, excluding <code>erts</code>, <code>kernel</code> and <code>stdlib</code>, or list of dependencies local to this repository (in <code>APPS_DIR</code>).</p>
</dd>
<dt><code>DEPS</code></dt>
<dd><p>List of applications this project depends on that need to be fetched by Erlang.mk.</p>
</dd>
</dl>
<p>There&apos;s no need for quotes or anything. The relevant part of the Cowboy Makefile follows, if you need an example:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">PROJECT =</font> cowboy
<font color="#009900">PROJECT_DESCRIPTION =</font> Small<font color="#990000">,</font> fast<font color="#990000">,</font> modular HTTP server<font color="#990000">.</font>
<font color="#009900">PROJECT_VERSION =</font> 2.0.0-pre.2
<font color="#009900">PROJECT_REGISTERED =</font> cowboy_clock

<font color="#009900">LOCAL_DEPS =</font> crypto
<font color="#009900">DEPS =</font> cowlib ranch</tt></pre>
</div></div>
<p>Any space before and after the value is dropped.</p>
<p><a href="../deps">Dependencies</a> are covered in details in the next chapter.</p>
<h4 id="_application_environment">Application environment</h4>
<p>The <code>PROJECT_ENV</code> variable is used to set the application environment:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>define PROJECT_ENV
<font color="#990000">[</font>
  {chips<font color="#990000">,</font> <font color="#990000">[</font>currysauce<font color="#990000">,</font>{mushypeas<font color="#990000">,</font><b><font color="#0000FF">false</font></b>}<font color="#990000">]</font>}<font color="#990000">,</font>
  {pizza<font color="#990000">,</font> <font color="#990000">[</font>{size<font color="#990000">,</font>large}<font color="#990000">,</font>{toppings<font color="#990000">,[</font>anchovies<font color="#990000">]</font>}<font color="#990000">]</font>}
<font color="#990000">]</font>
endef</tt></pre>
</div></div>
<p>If you have a large set of environment variables, you may find it easier to use a separate file. Do this by including the following in your Makefile:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">PROJECT_ENV_FILE =</font> src/env.src
<font color="#009900">PROJECT_ENV =</font> <font color="#009900">$(</font>subst <font color="#990000">\</font>n<font color="#990000">,</font><font color="#009900">$(newline)</font><font color="#990000">,</font><font color="#009900">$(</font>shell cat <font color="#009900">$(PROJECT_ENV_FILE)</font> <font color="#990000">|</font> sed -e <font color="#FF0000">'s/$$/</font><font color="#CC33CC">\\</font><font color="#FF0000">n/;'</font><font color="#990000">))</font>
ebin<font color="#990000">/</font><font color="#009900">$(PROJECT)</font>.app<font color="#990000">::</font> <font color="#009900">$(PROJECT_ENV_FILE)</font></tt></pre>
</div></div>
<p>The file has the same contents as the <code>PROJECT_ENV</code> variable:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>[
  {<font color="#FF6600">chips</font>, [<font color="#FF6600">currysauce</font>,{<font color="#FF6600">mushypeas</font>,<font color="#000080">false</font>}]},
  {<font color="#FF6600">pizza</font>, [{<b><font color="#000080">size</font></b>,<font color="#FF6600">large</font>},{<font color="#FF6600">toppings</font>,[<font color="#FF6600">anchovies</font>]}]}
]</tt></pre>
</div></div>
<h4 id="_legacy_method">Legacy method</h4>
<p>The <em>src/$(PROJECT).app.src</em> file is a legacy method of building Erlang applications. It was introduced by the original <code>rebar</code> build tool, of which Erlang.mk owes a great deal as it is its main inspiration.</p>
<p>The <em>.app.src</em> file serves as a template to generate the <em>.app</em> file. Erlang.mk will take it, fill in the <code>modules</code> value dynamically, and save the result in <em>ebin/$(PROJECT).app</em>.</p>
<p>When using this method, Erlang.mk cannot fill the <code>applications</code> key from dependencies automatically, which means you need to add them to Erlang.mk and to the <em>.app.src</em> at the same time, duplicating the work.</p>
<p>If you really can&apos;t live without the legacy method, for one reason or another, worry not; Erlang.mk will support it. And if you need to create a new project that uses this method, you just have to say so when bootstrapping:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make -f erlang<font color="#990000">.</font>mk bootstrap-lib <font color="#009900">LEGACY</font><font color="#990000">=</font><font color="#993399">1</font></tt></pre>
</div></div>
<h2 id="_automatic_application_resource_file_values">Automatic application resource file values</h2>
<p>When building the application resource file, Erlang.mk may automatically add an <code>id</code> key with information about the Git commit (if using Git), or an empty string otherwise. It will only do this under specific conditions:</p>
<ul><li>The application was built as a dependency of another, or
</li>
<li>The legacy method was used, and the <em>.app.src</em> file contained <code>{id, &quot;git&quot;}</code>
</li>
</ul>
<p>This value is most useful when you need to help your users, as it allows you to know which version they run exactly by asking them to look in the file, or by running a simple command on their production server:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#993399">1</font><font color="#990000">&gt;</font> <b><font color="#000000">application:get_all_key</font></b>(<font color="#FF6600">cowboy</font>)<font color="#990000">.</font>
{<font color="#FF6600">ok</font>,[{<font color="#FF6600">description</font>,<font color="#FF0000">"Small, fast, modular HTTP server."</font>},
     {<font color="#FF6600">id</font>,<font color="#FF0000">"2.0.0-pre.2-25-g0ffde50-dirty"</font>},</tt></pre>
</div></div>
<h2 id="_file_formats">File formats</h2>
<p>Erlang.mk supports a variety of different source file formats. The following formats are supported natively:</p>
<table rules="all" width="100%" frame="border"
			cellspacing="0" cellpadding="4">
<thead><tr><th>Extension</th>
<th>Location</th>
<th>Description</th>
<th>Output</th>
</tr></thead><tbody><tr><td>.erl</td>
<td>src/</td>
<td>Erlang source</td>
<td>ebin/*.beam</td>
</tr>
<tr><td>.core</td>
<td>src/</td>
<td>Core Erlang source</td>
<td>ebin/*.beam</td>
</tr>
<tr><td>.xrl</td>
<td>src/</td>
<td>Leex source</td>
<td>src/*.erl</td>
</tr>
<tr><td>.yrl</td>
<td>src/</td>
<td>Yecc source</td>
<td>src/*.erl</td>
</tr>
<tr><td>.asn1</td>
<td>asn1/</td>
<td>ASN.1 files</td>
<td>include/*.hrl include/*.asn1db src/*.erl</td>
</tr>
<tr><td>.mib</td>
<td>mibs/</td>
<td>SNMP MIB files</td>
<td>include/*.hrl priv/mibs/*.bin</td>
</tr>
</tbody></table>
<p>Files are always searched recursively.</p>
<p>The build is ordered, so that files that generate Erlang source files are run before, and the resulting Erlang source files are then built normally.</p>
<p>In addition, Erlang.mk keeps track of header files (<code>.hrl</code>) as described at the end of this chapter. It can also compile C code, as described in the <a href="../ports">NIFs and port drivers</a> chapter.</p>
<p>Erlang.mk also comes with plugins for the following formats:</p>
<table rules="all" width="100%" frame="border"
			cellspacing="0" cellpadding="4">
<thead><tr><th>Extension</th>
<th>Location</th>
<th>Description</th>
<th>Output</th>
</tr></thead><tbody><tr><td>.dtl</td>
<td>templates/</td>
<td>Django templates</td>
<td>ebin/*.beam</td>
</tr>
<tr><td>.proto</td>
<td>src/</td>
<td>Protocol buffers</td>
<td>ebin/*.beam</td>
</tr>
</tbody></table>
<h2 id="_compilation_options">Compilation options</h2>
<p>Erlang.mk provides a few variables that you can use to customize the build process and the resulting files.</p>
<h4 id="_erlc_opts">ERLC_OPTS</h4>
<p><code>ERLC_OPTS</code> can be used to pass some options to <code>erlc</code>, the Erlang compiler. Erlang.mk does not restrict any option. Please refer to the <a href="http://www.erlang.org/doc/man/erlc.html">erlc Manual</a> for the full list.</p>
<p>By default, Erlang.mk will set the following options:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">ERLC_OPTS =</font> -Werror <font color="#990000">+</font>debug_info <font color="#990000">+</font>warn_export_vars <font color="#990000">+</font>warn_shadow_vars <font color="#990000">+</font>warn_obsolete_guard</tt></pre>
</div></div>
<p>In other words: warnings as errors, debug info (recommended) and enable warnings for exported variables, shadow variables and obsolete guard functions.</p>
<p>You can redefine this variable in your Makefile to change it completely, either before or after including Erlang.mk:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">ERLC_OPTS =</font> <font color="#990000">+</font>debug_info</tt></pre>
</div></div>
<p>You can also filter out some options from the defaults Erlang.mk sets, by defining ERLC_OPTS after including Erlang.mk using the <code>:=</code> operator.</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>include erlang.mk

<font color="#990000">ERLC_OPTS :=</font> <font color="#009900">$(</font>filter-out -Werror<font color="#990000">,</font><font color="#009900">$(ERLC_OPTS))</font></tt></pre>
</div></div>
<h4 id="_erlc_asn1_opts">ERLC_ASN1_OPTS</h4>
<p><code>ERLC_ASN1_OPTS</code> can be used to pass compiler options when compiling ASN.1 files.  Please refer to the <a href="http://erlang.org/doc/man/asn1ct.html">asn1ct manual</a> for the full list.</p>
<p>By default, Erlang.mk will leave this empty.</p>
<p>You can redefine this variable in your Makefile. Please see the <code>ERLC_OPTS</code> section for instructions.</p>
<h4 id="_erlc_exclude">ERLC_EXCLUDE</h4>
<p><code>ERLC_EXCLUDE</code> can be used to exclude some modules from the compilation. It&apos;s there for handling special cases, you should not normally need it.</p>
<p>To exclude a module, simply list it in the variable, either before or after including Erlang.mk:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">ERLC_EXCLUDE =</font> cowboy_http2</tt></pre>
</div></div>
<h2 id="_cold_and_hot_builds">Cold and hot builds</h2>
<p>The first time you run <code>make</code>, Erlang.mk will build everything.</p>
<p>The second time you run <code>make</code>, and all subsequent times, Erlang.mk will only rebuild what changed. Erlang.mk has been optimized for this use case, as it is the most common during development.</p>
<p>Erlang.mk figures out what changed by using the dependency tracking feature of Make. Make automatically rebuilds a target if one of its dependency has changed (for example if a header file has changed, all the source files that include it will be rebuilt), and Erlang.mk leverages this feature to cut down on rebuild times.</p>
<p>Note that this applies only to building; some other features of Erlang.mk will run every time they are called regardless of files changed.</p>
<h2 id="_dependency_tracking">Dependency tracking</h2>
<p>NOTE: This section is about the dependency tracking between files inside your project, not application dependencies.</p>
<p>Erlang.mk keeps track of the dependencies between the different files in your project. This information is kept in the <em>$(PROJECT).d</em> file in your directory. It is generated if missing, and will be generated again after every file change, by default.</p>
<p>Dependency tracking is what allows Erlang.mk to know when to rebuild Erlang files when header files, behaviors or parse transforms have changed. Erlang.mk also automatically keeps track of which files should be compiled first, for example when you have behaviors used by other modules in your project.</p>
<p>If your project is stable, you may want to disable generating the dependency tracking file every time you compile. You can do this by adding the following line to your <em>Makefile</em>:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>NO_MAKEDEP <font color="#990000">?=</font> <font color="#993399">1</font></tt></pre>
</div></div>
<p>As you can see, the snippet above uses <code>?=</code> instead of a simple equal sign. This is to allow you to temporarily override this value when you do make substantial changes to your project (including a new header file, new module with dependencies, etc.) and want to rebuild the dependency tracking file. You&apos;ll be able to use the following command:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ <font color="#009900">NO_MAKEDEP</font><font color="#990000">=</font> make</tt></pre>
</div></div>
<p>Otherwise, <code>make clean app</code> will of course force the recompilation of your project.</p>
<p>Erlang.mk can also keep track of the source files generated by other means, for example if you generate code from a data file in your repository.</p>
<h2 id="_generating_erlang_source">Generating Erlang source</h2>
<p>Erlang.mk provides hooks at different stages of the build process. When your goal is to generate Erlang source files, you can add your own rules before or after the dependency tracking file is generated. To do this, you would add your hook before or after including the <em>erlang.mk</em> file.</p>
<p>The easiest way is after:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">PROJECT =</font> example

include erlang.mk

<font color="#009900">$(PROJECT)</font>.d<font color="#990000">::</font> src/generated_mod.erl

src/generated_mod.erl<font color="#990000">::</font> gen-mod.sh
	<font color="#009900">$(gen_verbose)</font> <font color="#990000">.</font>/gen-mod.sh <font color="#009900">$@</font></tt></pre>
</div></div>
<p>In this case we use <code>$(gen_verbose)</code> to hide the details of the build by default. Erlang.mk will simply say what file is it currently generating.</p>
<p>When using an external script to generate the Erlang source file, it is recommended to depend on that script, so that the source file gets generated again when the script gets modified.</p>
<p>If for whatever reason you prefer to hook before including Erlang.mk, don&apos;t forget to set the <code>.DEFAULT_GOAL</code> variable, otherwise nothing will get built:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><font color="#009900">PROJECT =</font> example

.DEFAULT_GOAL <font color="#990000">=</font> all

<font color="#009900">$(PROJECT)</font>.d<font color="#990000">::</font> src/generated_mod.erl

include erlang.mk

src/generated_mod.erl<font color="#990000">::</font> gen-mod.sh
	<font color="#009900">$(gen_verbose)</font> <font color="#990000">.</font>/gen-mod.sh <font color="#009900">$@</font></tt></pre>
</div></div>
<h2 id="_cleaning">Cleaning</h2>
<p>Building typically involves creating a lot of new files. Some are reused in rebuilds, some are simply replaced. All can be removed safely.</p>
<p>Erlang.mk provides two commands to remove them: <code>clean</code> and <code>distclean</code>. <code>clean</code> removes all the intermediate files that were created as a result of building, including the BEAM files, the dependency tracking file and the generated documentation. <code>distclean</code> removes these and more, including the downloaded dependencies, Dialyzer&apos;s PLT file and the generated release, putting your directory back to the state it was before you started working on it.</p>
<p>To clean:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make clean</tt></pre>
</div></div>
<p>Or distclean:</p>
<div class="listingblock"><div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ make distclean</tt></pre>
</div></div>
<p>That is the question.</p>
<p>Note that Erlang.mk will automatically clean some files as part of other targets, but it will never run <code>distclean</code> if you don&apos;t explicitly use it.</p>




	
		
		
		
		
		

		<nav style="margin:1em 0">
			
				<a style="float:left" href="https://ninenines.eu/docs/en/erlang.mk/1/guide/limitations/">
					Limitations
				</a>
			

			
				<a style="float:right" href="https://ninenines.eu/docs/en/erlang.mk/1/guide/deps/">
					Packages and dependencies
				</a>
			
		</nav>
	



</div>

<div class="span3 sidecol">


<h3>
	Erlang.mk
	1
	
	User Guide
</h3>

<ul>
	
	
	
</ul>

<h4 id="docs-nav">Navigation</h4>

<h4>Version select</h4>
<ul>
	
	
	
		<li><a href="/docs/en/erlang.mk/1/guide">1</a></li>
	
</ul>

<h3 id="_like_my_work__donate">Like my work? Donate!</h3>
<p>Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display:inline">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="lc" value="FR">
<input type="hidden" name="item_name" value="Loic Hoguin">
<input type="hidden" name="item_number" value="99s">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
</form><p>Recurring payment options are also available via <a href="https://salt.bountysource.com/teams/ninenines">BountySource</a>. These funds are used to cover the recurring expenses like dedicated servers or domain names.</p>



</div>
</div>
</div>
</div>

      <footer>
        <div class="container">
          <div class="row">
            <div class="span6">
              <p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
              <nav>
                <ul>
                  <li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
                </ul>
              </nav>
            </div>
            <div class="span6 credits">
               <p><img src="/img/footer_logo.png"></p>
               <p>Copyright &copy; Loïc Hoguin 2012-2018</p>
            </div>
          </div>
        </div>
      </footer>

    
    <script src="/js/custom.js"></script>
  </body>
</html>