summaryrefslogtreecommitdiffstats
path: root/docs/en/erlang.mk/1/guide/deps/index.html
blob: c4457f1d23a4ed70ffb98e534c1dc2419d412c59 (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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<!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: Packages and dependencies</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=4" 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>Packages and dependencies</span></h1>

<p>Erlang.mk can fetch and compile the dependencies that your project requires. Erlang.mk improves upon the concepts introduced by Rebar, so they should be familiar to many seasoned Erlang developers.</p>
<p>Erlang.mk is not a package manager, nor is it trying to be, but it does include an index of Erlang packages to make discovering useful projects easier.</p>
<p>This chapter will explain how to use packages, add dependencies to your project or bundle them directly in a single repository.</p>
<h2 id="_searching_packages">Searching packages</h2>
<p>Erlang.mk gives you access to nearly 500 packages, with more being added regularly.</p>
<p>To find a package, search for it:</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 search <font color="#009900">q</font><font color="#990000">=</font>pool</tt></pre>
</div></div>
<p>This will return all packages matching this word, like worker pool and acceptor pool projects.</p>
<p>You can also list everything and use regular command line tools to find what you need, for 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>$ make search <font color="#990000">|</font> less</tt></pre>
</div></div>
<!-- @todo Simplify adding packages, add a new chapter explaining-->
<!-- everything, then link to this new chapter from here.-->
<h2 id="_adding_dependencies_to_your_project">Adding dependencies to your project</h2>
<p>Once you find the package you need, adding it as a dependency to your project is a one-liner:</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">DEPS =</font> cowboy</tt></pre>
</div></div>
<p>And that&apos;s it! The next time you run <code>make</code>, Erlang.mk will fetch and compile Cowboy. Erlang.mk will also ensure Cowboy is available whenever you use the shell, run tests and any other operations.</p>
<p>Erlang.mk will fill in the application resource file with all applications found in <code>DEPS</code>. But not all dependencies are Erlang applications, and not all dependencies need to be a runtime dependency. That&apos;s where the <code>BUILD_DEPS</code> variable comes in: it works just like <code>DEPS</code>, except the dependencies listed there will not be added as runtime dependencies.</p>
<p>For example, you could add a parse transform project like this to make it available only at build time:</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">BUILD_DEPS =</font> erlando</tt></pre>
</div></div>
<p>Or you could depend on a C project directly, if you are building a NIF:</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">BUILD_DEPS =</font> leveldb
<font color="#009900">dep_leveldb =</font> git https<font color="#990000">:</font>//github.com/basho/leveldb 2.1.3</tt></pre>
</div></div>
<p>This dependency will be built before your application, so you could easily copy the resulting shared file into your <em>priv/</em> directory as part of the build process. More information about that in the <a href="../ports">NIFs and port drivers</a> chapter.</p>
<p>Another variable, <code>LOCAL_DEPS</code>, allows specifying runtime dependencies which are part of Erlang/OTP itself, but also dependencies that are included in the repository. Since they are already on your system, there is no need to fetch them. Do note that there is no way to choose the version, the application used will be the one already on your system.</p>
<p>You could depend on the Crypto application, for 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">LOCAL_DEPS =</font> crypto</tt></pre>
</div></div>
<p>Erlang.mk comes with additional types of dependencies. It has <code>TEST_DEPS</code> for dependencies used only for testing:</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">TEST_DEPS =</font> ct_helper
<font color="#009900">dep_ct_helper =</font> git https<font color="#990000">:</font>//github.com/ninenines/ct_helper master</tt></pre>
</div></div>
<p><code>DOC_DEPS</code> for dependencies used only when building documentation:</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">DOC_DEPS =</font> edown</tt></pre>
</div></div>
<p><code>REL_DEPS</code> for dependencies required to build the release, or to include extra applications in the release:</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">REL_DEPS =</font> recon</tt></pre>
</div></div>
<p>And <code>SHELL_DEPS</code> for dependencies to make available when running the <code>make shell</code> 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">SHELL_DEPS =</font> tddreloader</tt></pre>
</div></div>
<p>All these will be documented in more details in their respective chapters.</p>
<p>Note that these additional types of dependencies will only be fetched after normal dependencies by default. You can force a dependency to be downloaded first by extending the target <code>deps::</code> before including <em>erlang.mk</em>, for example:</p>
<dl><dt>deps</dt>
<dd><p>$(CURDIR)/deps/triq</p>
</dd>
</dl>
<h4 id="_modifying_the_dependency_source_or_version">Modifying the dependency source or version</h4>
<p>By default, Erlang.mk will look into its package index to find the project you are looking for, if you only provide its name. This is this case:</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">DEPS =</font> cowboy</tt></pre>
</div></div>
<p>If you need a different version, you need to define another variable. There are two ways to do this, each being useful for different reasons.</p>
<p>If you simply want to change the commit number, all you need to do is to define the <code>dep_$(DEP_NAME)_commit</code> variable. In the case of Cowboy, this would look like this:</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">DEPS =</font> cowboy
<font color="#009900">dep_cowboy_commit =</font> 2.0.0-pre.2</tt></pre>
</div></div>
<p>Erlang.mk will use the package index to get all information about Cowboy, except the commit number which will be overriden.</p>
<p>If you need to set the fetch method or repository information too, for example because you want to use your own fork, or simply because the project is missing from the index, you can define the <code>dep_$(DEP_NAME)</code> variable with everything:</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">DEPS =</font> cowboy
<font color="#009900">dep_cowboy =</font> git https<font color="#990000">:</font>//github.com/essen/cowboy 2.0.0-pre.2</tt></pre>
</div></div>
<p>This will fetch Cowboy from your fork at the given commit.</p>
<h4 id="_fetch_methods">Fetch methods</h4>
<p>Erlang.mk comes with a number of different fetch methods. You can fetch from Git, Mercurial, SVN, to name a few. There are fetch methods that will work everywhere, and fetch methods that will only work in a given environment.</p>
<p>The following table lists all existing methods:</p>
<table rules="all" width="100%" frame="border"
			cellspacing="0" cellpadding="4">
<thead><tr><th>Name</th>
<th>Format</th>
<th>Description</th>
</tr></thead><tbody><tr><td>git</td>
<td>git repo commit</td>
<td>Clone the Git repository and checkout the given version</td>
</tr>
<tr><td>git-subfolder</td>
<td>git repo commit subfolder</td>
<td>Clone the Git repository, checkout the given version and use one of its subfolders as a dependency</td>
</tr>
<tr><td>git-submodule</td>
<td>git-submodule</td>
<td>Initialize and update the Git submodule</td>
</tr>
<tr><td>hg</td>
<td>hg repo commit</td>
<td>Clone the Mercurial repository and update to the given version</td>
</tr>
<tr><td>svn</td>
<td>svn repo</td>
<td>Checkout the given SVN repository</td>
</tr>
<tr><td>cp</td>
<td>cp path/to/repo</td>
<td>Recursively copy a local directory</td>
</tr>
<tr><td>ln</td>
<td>ln path/to/repo</td>
<td>Symbolically link a local directory</td>
</tr>
<tr><td>hex</td>
<td>hex version</td>
<td>Download the given project version from hex.pm</td>
</tr>
<tr><td>fail</td>
<td>N/A</td>
<td>Always fail, reserved for internal use</td>
</tr>
<tr><td>legacy</td>
<td>N/A</td>
<td>Legacy Erlang.mk fetcher, reserved for internal use</td>
</tr>
</tbody></table>
<p>The <code>git</code> and <code>hg</code> methods both have a repository and commit. You can use any valid commit, tag or branch in that repository for the commit value.</p>
<p>For example, to fetch Cowboy with tag 2.0.0-pre.2 from Git:</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">dep_cowboy =</font> git https<font color="#990000">:</font>//github.com/ninenines/cowboy 2.0.0-pre.2</tt></pre>
</div></div>
<p>Or to fetch Ehsa tag 4.0.3 from Mercurial:</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">dep_ehsa =</font> hg https<font color="#990000">:</font>//bitbucket.org/a12n/ehsa 4.0.3</tt></pre>
</div></div>
<p>Git also comes with a concept of submodules. Erlang.mk can automatically initializes and updates submodules for dependencies, as long as they were added beforehand using <code>git submodule add</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><font color="#009900">dep_cowboy =</font> git-submodule</tt></pre>
</div></div>
<p>The <code>svn</code> method only has a repository value, but that&apos;s simply because the SVN repository URL can also contain the path and commit.</p>
<p>This would fetch an example project from the trunk:</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">dep_ex1 =</font> svn https<font color="#990000">:</font>//example.com/svn/trunk/project/ex<font color="#993399">1</font></tt></pre>
</div></div>
<p>And this would fetch a separate example project from a specific commit:</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">dep_ex2 =</font> svn svn<font color="#990000">:</font>//example.com/svn/branches/erlang-proj/ex<font color="#993399">2</font>@<font color="#993399">264</font></tt></pre>
</div></div>
<p>You can copy a directory from your machine using the <code>cp</code> method. It only takes the path to copy from:</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">dep_cowboy =</font> cp <font color="#009900">$(HOME)</font>/ninenines/cowboy</tt></pre>
</div></div>
<p>Finally, you can use a package from the <a href="https://hex.pm/">Hex repository</a>:</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">dep_cowboy =</font> hex 1.0.3</tt></pre>
</div></div>
<h4 id="_custom_fetch_methods">Custom fetch methods</h4>
<p>If none of the existing methods fit your use, you can simply define your own. Erlang.mk will consider all variables that are named as <code>dep_fetch_$(METHOD)</code> to be available fetch methods. You can do anything inside this variable, as long as you create a folder named <em>$(DEPS_DIR)/$(call dep_name,$1)</em>. Or in layman terms, if your dependency is Cowboy, this would become <em>deps/cowboy</em>.</p>
<p>To give an example, this is what the Git method does:</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 dep_fetch_git
	git clone -q -n -- <font color="#009900">$(</font>call dep_repo<font color="#990000">,</font><font color="#009900">$1</font><font color="#990000">)</font> <font color="#009900">$(DEPS_DIR)</font><font color="#990000">/</font><font color="#009900">$(</font>call dep_name<font color="#990000">,</font><font color="#009900">$1</font><font color="#990000">);</font> <font color="#990000">\</font>
	cd <font color="#009900">$(DEPS_DIR)</font><font color="#990000">/</font><font color="#009900">$(</font>call dep_name<font color="#990000">,</font><font color="#009900">$1</font><font color="#990000">)</font> <font color="#990000">&amp;&amp;</font> git checkout -q <font color="#009900">$(</font>call dep_commit<font color="#990000">,</font><font color="#009900">$1</font><font color="#990000">);</font>
endef</tt></pre>
</div></div>
<p>Note that, like dependency information, this custom fetch method must be written before including <em>erlang.mk</em>.</p>
<h2 id="_how_deps_are_fetched_and_built">How deps are fetched and built</h2>
<p>The order in which dependencies are fetched and built is well defined. This means that Erlang.mk will get the same applications regardless of the command or options being used.</p>
<p>In tree traversal terms, where the list of dependencies is a tree, Erlang.mk fetches everything using the pre-order traversal method. The steps can be summarized like this, starting from the root application:</p>
<ol><li>Fetch all dependencies for the application
</li>
<li>Build first dependency
</li>
<li>Build Nth dependency
</li>
<li>Build last dependency
</li>
</ol>
<p>Every time a dependency is built, these same steps are followed, recursively.</p>
<p>Do note that the first step, fetching all dependencies of an application, is not guaranteed to be ordered. The reason for this is that it is not possible to have the same dependency listed twice in a single application, and therefore there can be no conflicts. Remember, this step only fetches, at no point are different applications built in parallel.</p>
<p>What about conflicts between the dependencies of different applications? Simple. Since builds are ordered, this means that the first version of an application that is fetched will be the one that wins.</p>
<p>This means that if project A depends on projects B and C, in this order, and that both B and C depend on a different version of D, it will always be B&apos;s version of D that wins, because we fetch the dependencies of B before fetching those from C.</p>
<p>Similarly, if project A depends on projects B, C and D, regardless of the order, and A, B and C depend on a different version of D, it will always be A&apos;s version that wins, because we fetch all dependencies of A before fetching those from B or C.</p>
<p>Once a dependency is built, it will not be built again by default. Typically dependencies do not need to be recompiled and this speeds up building immensely. There are a few ways to force recompiling a dependency however:</p>
<ul><li>The dependency directory is a symbolic link; the dependency will always be recompiled.
</li>
<li>The dependency is built directly, for example with a command like <code>make -C deps/cowlib</code>, or <code>make</code> in the dependency&apos;s directory.
</li>
<li>The variable <code>FULL</code> is set, for example <code>make FULL=1</code>. This will force building of all dependencies. This can be added to your Makefile before including <em>erlang.mk</em>.
</li>
<li>The file <code>ebin/dep_built</code> in the dependency is removed.
</li>
</ul>
<h2 id="_fetching_and_listing_dependencies_only">Fetching and listing dependencies only</h2>
<p>You can fetch all dependencies recursively without building anything, with the <code>make fetch-deps</code> command. It follows the same rules described in the section above.</p>
<p>You can list all dependencies recursively, again without building anything, with the <code>make list-deps</code> command. It will obviously need to fetch all dependencies exactly like <code>make fetch-deps</code>. Once everything is fetched, it prints a sorted list of absolute paths to the dependencies.</p>
<p>By default, <code>fetch-deps</code> and <code>list-deps</code> work on the <code>BUILD_DEPS</code> and <code>DEPS</code> lists only. To also fetch/list <code>TEST_DEPS</code>, <code>DOC_DEPS</code>, <code>REL_DEPS</code> and/or <code>SHELL_DEPS</code>, you have two possibilities:</p>
<ul><li>You can use <code>make fetch-test-deps</code>, <code>make fetch-doc-deps</code>, <code>make
fetch-rel-deps</code> and <code>make fetch-shell-deps</code> commands respectively. If you want to list them, you can use <code>make list-test-deps</code>, <code>make
list-doc-deps</code>, <code>make list-rel-deps</code> and <code>make list-shell-deps</code> respectively.
</li>
<li>You can use <code>make fetch-deps</code> or <code>make list-deps</code> with the Makefile variable <code>DEP_TYPES</code> set to a list of dependency types you want. The types are <code>test</code>, <code>doc</code>, <code>rel</code> and <code>shell</code> respectively. For example, you can list test and doc dependencies with <code>make list-deps
DEP_TYPES=&apos;test doc&apos;</code>.
</li>
</ul>
<p>Note that only first level <code>TEST_DEPS</code>, <code>DOC_DEPS</code>, <code>REL_DEPS</code> and <code>SHELL_DEPS</code> are included, not dependencies&apos; one. In other word, <code>make list-test-deps</code> lists the <code>TEST_DEPS</code> of your project, but not <code>TEST_DEPS</code> of the projects yours depend on.</p>
<p>No matter which method you use, <code>BUILD_DEPS</code> and <code>DEPS</code> are always included.</p>
<p>Internally, the <code>make fetch-*</code> commands store the complete list of dependencies in files named <code>$(ERLANG_MK_RECURSIVE_DEPS_LIST)</code>, <code>$(ERLANG_MK_RECURSIVE_TEST_DEPS_LIST)</code>, <code>$(ERLANG_MK_RECURSIVE_DOC_DEPS_LIST)</code>, <code>$(ERLANG_MK_RECURSIVE_REL_DEPS_LIST)</code> and <code>$(ERLANG_MK_RECURSIVE_SHELL_DEPS_LIST)</code>. Those files are simply printed by the <code>make list-*</code> commands.</p>
<p><code>make list-*</code> commands are made for human beings. If you need the list of dependencies in a Makefile or a script, you should use the content of those files directly instead. The reason is that <code>make fetch-*</code> and <code>make list-*</code> may have unwanted content in their output, such as actual fetching of dependencies.</p>
<h2 id="_ignoring_unwanted_dependencies">Ignoring unwanted dependencies</h2>
<p>Sometimes, you may want to ignore dependencies entirely. Not even fetch them. You may want to do this because a project you depend on depends on an application you do not need (like a dependency for building documentation or testing). Or maybe the dependency is already installed on your system.</p>
<p>To ignore a dependency, simply add it to the <code>IGNORE_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>IGNORE_DEPS <font color="#990000">+=</font> edown proper</tt></pre>
</div></div>
<p>This will only ignore dependencies that are needed for building. It is therefore safe to write:</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>IGNORE_DEPS <font color="#990000">+=</font> edown proper
<font color="#009900">TEST_DEPS =</font> proper</tt></pre>
</div></div>
<p>The PropEr application will be fetched as intended when running <code>make tests</code> or <code>make check</code>. It will however not be fetched when running <code>make</code> or <code>make deps</code>.</p>
<h2 id="_dependencies_directory">Dependencies directory</h2>
<p>Dependencies are fetched in <em>$(DEPS_DIR)</em>. By default this is the <em>deps</em> directory. You can change this default, but you should only do so if it was not defined previously. Erlang.mk uses this variable to tell dependencies where to fetch their own dependencies.</p>
<p>You will therefore need to use <code>?=</code> instead of <code>=</code>. Of course, if you know you will never use this project as a dependency, <code>=</code> will work. But to avoid it biting you later on, do this:</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>DEPS_DIR <font color="#990000">?=</font> <font color="#009900">$(CURDIR)</font>/libs</tt></pre>
</div></div>
<p>The <code>$(CURDIR)</code> part is important, otherwise dependencies of dependencies will be fetched in the wrong directory.</p>
<p>Erlang.mk will also export the <code>REBAR_DEPS_DIR</code> variable for compatibility with Rebar build tools, as long as they are recent enough.</p>
<h2 id="_many_applications_in_one_repository">Many applications in one repository</h2>
<p>In addition to the dependencies that are fetched, Erlang.mk also allows you to have dependencies local to your repository. This kind of layout is sometimes called multi-application repositories, or repositories with multiple applications.</p>
<p>They work exactly the same as remote dependencies, except:</p>
<ul><li>They are not fetched
</li>
<li>They are not autopatched
</li>
<li>They are not deleted on <code>make distclean</code>
</li>
<li>They are not automatically added to the application resource file
</li>
</ul>
<p>To properly fill the application resource file and compile apps in the right order, you will need to define the <code>LOCAL_DEPS</code> variable for each relevant application, the same as for OTP applications. Apps can depend on each other in this way, and their compilation order will follow the same rules as regular dependencies in <code>DEPS</code>.</p>
<p>The top-level <code>LOCAL_DEPS</code> variable, if defined, will determine which apps (along with their dependencies) to build, and also which apps should be added to the top-level application resource file, if there is one. This may be useful, for example, for specifying a different set of apps to build for different releases. If <code>LOCAL_DEPS</code> is not defined, then all apps in the <em>$(APPS_DIR)</em> will be built, but none will be automatically added to the top-level application resource file.</p>
<p>If there is a conflict between a local dependency and a remote dependency, then the local dependency always wins; an error will be triggered when trying to fetch the conflicting remote dependency.</p>
<p>To start using dependencies local to the repository, simply create a folder named <em>$(APPS_DIR)</em>. By default, this folder is the <em>apps/</em> directory.</p>
<p>You can use Erlang.mk to bootstrap local dependencies by using the command <code>make new-app</code> or <code>make new-lib</code>. This command will create the necessary directories and bootstrap the application.</p>
<p>For example, to create a full fledged OTP application as a local dependency:</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 new-app <b><font color="#0000FF">in</font></b><font color="#990000">=</font>webchat</tt></pre>
</div></div>
<p>Or, the same as an OTP library:</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 new-lib <b><font color="#0000FF">in</font></b><font color="#990000">=</font>webchat</tt></pre>
</div></div>
<p>Templates also work with local dependencies, from the root directory of the project. You do need however to tell Erlang.mk to create the files in the correct application:</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 new <font color="#009900">t</font><font color="#990000">=</font>gen_server <font color="#009900">n</font><font color="#990000">=</font>my_server <b><font color="#0000FF">in</font></b><font color="#990000">=</font>webchat</tt></pre>
</div></div>
<h2 id="_repositories_with_no_application_at_the_root_level">Repositories with no application at the root level</h2>
<p>It&apos;s possible to use Erlang.mk with only applications in <em>$(APPS_DIR)</em>, and nothing at the root of the repository. Just create a folder, put the <em>erlang.mk</em> file in it, write a Makefile that includes it, and start creating your applications.</p>
<p>Similarly, it&apos;s possible to have a repository with only dependencies found in <em>$(DEPS_DIR)</em>. You just need to create a Makefile and specify the dependencies you want. This allows you to create a repository for handling the building of releases, for example.</p>
<h2 id="_autopatch">Autopatch</h2>
<p>Erlang.mk will automatically patch all the dependencies it fetches. It needs to do this to ensure that the dependencies become compatible with not only Erlang.mk, but also with the version of Erlang.mk that is currently used.</p>
<p>When fetching a dependency, the following operations are performed:</p>
<ul><li>Fetch the dependency using the configured fetch method
</li>
<li>If it contains a <em>configure.ac</em> or <em>configure.in</em> file, run <code>autoreconf -Wall -vif -I m4</code>
</li>
<li>If it contains a <em>configure</em> script, run it
</li>
<li>Run autopatch on the project
</li>
</ul>
<p>Autopatch first checks if there is any project-specific patch enabled. There are currently three: <code>RABBITMQ_CLIENT_PATCH</code> for the <code>amqp_client</code> dependency (before 3.6.0), <code>RABBITMQ_SERVER_PATCH</code> for the <code>rabbit</code> dependency (before 3.6.0) and <code>ELIXIR_PATCH</code> for the <code>elixir</code> dependency.</p>
<p>Otherwise, autopatch performs different operations depending on the kind of project it finds the dependency to be.</p>
<ul><li>Rebar projects are automatically converted to use Erlang.mk as their build tool. This essentially patches Rebar out, and fixes and converts the project to be compatible with Erlang.mk.
</li>
<li>Erlang.mk projects have their <em>Makefile</em> patched, if necessary, to include the top-level project&apos;s Erlang.mk. This is to ensure that functionality works across all dependencies, even if the dependency&apos;s Erlang.mk is outdated. The patched Makefile can be safely committed if necessary.
</li>
<li>Other Erlang projects get a small Erlang.mk Makefile generated automatically.
</li>
<li>Projects with no source directory and no Makefile get an empty Makefile generated, for compatibility purposes.
</li>
<li>Other projects with no Makefile are left untouched.
</li>
</ul>
<p>You can add additional commands to be run immediately before or after autopatch is done by extending the target <code>autopatch-$(dep)::</code>, for example this would remove a module:</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="#990000">autopatch-ranch::</font>
	rm -f <font color="#009900">$(DEPS_DIR)</font>/ranch/src/ranch_proxy_header.erl</tt></pre>
</div></div>
<p>A common use case for this feature is to apply a PATCH file on the dependency immediately after fetching it. It can also be used to add compiler options, for 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="#990000">autopatch-couchbeam::</font>
	<b><font color="#0000FF">printf</font></b> <font color="#FF0000">"</font><font color="#CC33CC">\n</font><font color="#FF0000">ERLC_OPTS += -DWITH_JIFFY</font><font color="#CC33CC">\n</font><font color="#FF0000">"</font> <font color="#990000">&gt;&gt;</font> <font color="#009900">$(DEPS_DIR)</font>/couchbeam/Makefile</tt></pre>
</div></div>
<p>The commands will run before autopatch when the target is defined before including <em>erlang.mk</em>, and after otherwise.</p>
<p>You can disable the replacing of the <em>erlang.mk</em> file by defining the <code>NO_AUTOPATCH_ERLANG_MK</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="#009900">NO_AUTOPATCH_ERLANG_MK =</font> <font color="#993399">1</font></tt></pre>
</div></div>
<p>You can also disable autopatch entirely for a few select projects using the <code>NO_AUTOPATCH</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="#009900">NO_AUTOPATCH =</font> cowboy ranch cowlib</tt></pre>
</div></div>
<h2 id="_dealing_with_duplicate_modules">Dealing with duplicate modules</h2>
<p>When there are duplicate modules found in both applications and their dependencies, some tasks may fail. Erlang expects modules to be unique in general.</p>
<p>When the duplicates are found in dependencies, you will need to remove one of the duplicates at fetch time. To do so, you can add a rule similar to this to your Makefile before including <em>erlang.mk</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><font color="#009900">DEPS_DIR =</font> <font color="#009900">$(CURDIR)</font>/deps

<font color="#990000">deps::</font> <font color="#009900">$(DEPS_DIR)</font>/cowlib
	<font color="#009900">$(verbose)</font> rm -f <font color="#009900">$(DEPS_DIR)</font>/cowlib/src/cow_ws.erl</tt></pre>
</div></div>
<p>This must be done from the application that has this dependency. Only define the <code>DEPS_DIR</code> variable if necessary.</p>
<h2 id="_skipping_deps">Skipping deps</h2>
<p>It is possible to temporarily skip all dependency operations. This is done by defining the <code>SKIP_DEPS</code> variable. Use cases include being somewhere with no connection to download them, or perhaps a peculiar setup.</p>
<p>A typical usage would be:</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 <font color="#009900">SKIP_DEPS</font><font color="#990000">=</font><font color="#993399">1</font></tt></pre>
</div></div>
<p>When the variable is defined:</p>
<ul><li>Dependencies will not be compiled or downloaded when required
</li>
<li>The dependency directory <em>$(DEPS_DIR)</em> will not be removed on <code>make distclean</code>
</li>
</ul>
<p>This variable only applies to remote dependencies.</p>




	
		
		
		
		
		

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

			
				<a style="float:right" href="https://ninenines.eu/docs/en/erlang.mk/1/guide/ports/">
					NIFs and port drivers
				</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>