summaryrefslogtreecommitdiffstats
path: root/docs/en/erlang.mk/1/guide/getting_started/index.html
blob: 0504e949291af54cc6b8a24c43a60e0249493115 (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
<!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">

    <meta name="generator" content="Hugo 0.16" />

    <title>Nine Nines: Getting started</title>

    <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
	
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/99s.css" 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="Keep in touch!" href="http://twitter.com/lhoguin"><img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png"></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>Getting started</span></h1>

<div class="paragraph"><p>This chapter explains how to get started using Erlang.mk.</p></div>
<div class="sect1">
<h2 id="_creating_a_folder_for_your_project">Creating a folder for your project</h2>
<div class="sectionbody">
<div class="paragraph"><p>The first step is always to create a new folder that will
contain your project.</p></div>
<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>$ mkdir hello_joe
$ cd hello_joe</tt></pre></div></div>
<div class="paragraph"><p>Most people tend to put all their projects side by side in
a common folder. We recommend keeping an organization similar
to your remote repositories. For example, for GitHub users,
put all your projects in a common folder with the same name
as your username. For example <em>$HOME/ninenines/cowboy</em> for
the Cowboy project.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_downloading_erlang_mk">Downloading Erlang.mk</h2>
<div class="sectionbody">
<div class="paragraph"><p>At the time of writing, Erlang.mk is unlikely to be present
in your Erlang distribution, or even in your OS packages.</p></div>
<div class="paragraph"><p>The next step is therefore to download it:</p></div>
<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>$ wget https<span style="color: #990000">:</span>//erlang<span style="color: #990000">.</span>mk/erlang<span style="color: #990000">.</span>mk</tt></pre></div></div>
<div class="paragraph"><p>Or:</p></div>
<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>$ curl https<span style="color: #990000">:</span>//erlang<span style="color: #990000">.</span>mk/erlang<span style="color: #990000">.</span>mk -o erlang<span style="color: #990000">.</span>mk</tt></pre></div></div>
<div class="paragraph"><p>Alternatively, just <a href="https://erlang.mk/erlang.mk">click on this link</a>.</p></div>
<div class="paragraph"><p>Make sure you put the file inside the folder we created previously.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_getting_started_with_otp_applications">Getting started with OTP applications</h2>
<div class="sectionbody">
<div class="paragraph"><p>An OTP application is an Erlang application that has a supervision
tree. In other words, it will always have processes running.</p></div>
<div class="paragraph"><p>This kind of project can be automatically generated by Erlang.mk.
All you need to do is use the <code>bootstrap</code> target:</p></div>
<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<span style="color: #990000">.</span>mk bootstrap</tt></pre></div></div>
<div class="paragraph"><p>Something similar to the following snippet will then appear
on your screen:</p></div>
<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>git clone https<span style="color: #990000">:</span>//github<span style="color: #990000">.</span>com/ninenines/erlang<span style="color: #990000">.</span>mk <span style="color: #990000">.</span>erlang<span style="color: #990000">.</span>mk<span style="color: #990000">.</span>build
Cloning into <span style="color: #FF0000">'.erlang.mk.build'</span><span style="color: #990000">...</span>
remote<span style="color: #990000">:</span> Counting objects<span style="color: #990000">:</span> <span style="color: #993399">4035</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
remote<span style="color: #990000">:</span> Compressing objects<span style="color: #990000">:</span> <span style="color: #993399">100</span><span style="color: #990000">%</span> <span style="color: #990000">(</span><span style="color: #993399">12</span><span style="color: #990000">/</span><span style="color: #993399">12</span><span style="color: #990000">),</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
remote<span style="color: #990000">:</span> Total <span style="color: #993399">4035</span> <span style="color: #990000">(</span>delta <span style="color: #993399">8</span><span style="color: #990000">),</span> reused <span style="color: #993399">4</span> <span style="color: #990000">(</span>delta <span style="color: #993399">4</span><span style="color: #990000">),</span> pack-reused <span style="color: #993399">4019</span>
Receiving objects<span style="color: #990000">:</span> <span style="color: #993399">100</span><span style="color: #990000">%</span> <span style="color: #990000">(</span><span style="color: #993399">4035</span><span style="color: #990000">/</span><span style="color: #993399">4035</span><span style="color: #990000">),</span> <span style="color: #993399">1.10</span> MiB <span style="color: #990000">|</span> <span style="color: #993399">784.00</span> KiB/s<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
Resolving deltas<span style="color: #990000">:</span> <span style="color: #993399">100</span><span style="color: #990000">%</span> <span style="color: #990000">(</span><span style="color: #993399">2442</span><span style="color: #990000">/</span><span style="color: #993399">2442</span><span style="color: #990000">),</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
Checking connectivity<span style="color: #990000">...</span> <span style="font-weight: bold"><span style="color: #0000FF">done</span></span><span style="color: #990000">.</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">[</span> -f build<span style="color: #990000">.</span>config <span style="color: #990000">];</span> <span style="font-weight: bold"><span style="color: #0000FF">then</span></span> cp build<span style="color: #990000">.</span>config <span style="color: #990000">.</span>erlang<span style="color: #990000">.</span>mk<span style="color: #990000">.</span>build<span style="color: #990000">;</span> <span style="font-weight: bold"><span style="color: #0000FF">fi</span></span>
cd <span style="color: #990000">.</span>erlang<span style="color: #990000">.</span>mk<span style="color: #990000">.</span>build <span style="color: #990000">&amp;&amp;</span> make
make<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">]:</span> Entering directory <span style="color: #FF0000">'/home/essen/tmp/hello_joe/.erlang.mk.build'</span>
awk <span style="color: #FF0000">'FNR==1 &amp;&amp; NR!=1{print ""}1'</span> core/core<span style="color: #990000">.</span>mk index<span style="color: #990000">/*.</span>mk core/index<span style="color: #990000">.</span>mk core/deps<span style="color: #990000">.</span>mk plugins/protobuffs<span style="color: #990000">.</span>mk core/erlc<span style="color: #990000">.</span>mk core/docs<span style="color: #990000">.</span>mk core/test<span style="color: #990000">.</span>mk plugins/asciidoc<span style="color: #990000">.</span>mk plugins/bootstrap<span style="color: #990000">.</span>mk plugins/c_src<span style="color: #990000">.</span>mk plugins/ci<span style="color: #990000">.</span>mk plugins/ct<span style="color: #990000">.</span>mk plugins/dialyzer<span style="color: #990000">.</span>mk plugins/edoc<span style="color: #990000">.</span>mk plugins/elvis<span style="color: #990000">.</span>mk plugins/erlydtl<span style="color: #990000">.</span>mk plugins/escript<span style="color: #990000">.</span>mk plugins/eunit<span style="color: #990000">.</span>mk plugins/relx<span style="color: #990000">.</span>mk plugins/shell<span style="color: #990000">.</span>mk plugins/triq<span style="color: #990000">.</span>mk plugins/xref<span style="color: #990000">.</span>mk plugins/cover<span style="color: #990000">.</span>mk <span style="color: #990000">\</span>
        <span style="color: #990000">|</span> sed <span style="color: #FF0000">'s/^ERLANG_MK_VERSION = .*/ERLANG_MK_VERSION = 1.2.0-642-gccd2b9f/'</span> <span style="color: #990000">&gt;</span> erlang<span style="color: #990000">.</span>mk
make<span style="color: #990000">[</span><span style="color: #993399">1</span><span style="color: #990000">]:</span> Leaving directory <span style="color: #FF0000">'/home/essen/tmp/hello_joe/.erlang.mk.build'</span>
cp <span style="color: #990000">.</span>erlang<span style="color: #990000">.</span>mk<span style="color: #990000">.</span>build/erlang<span style="color: #990000">.</span>mk <span style="color: #990000">.</span>/erlang<span style="color: #990000">.</span>mk
rm -rf <span style="color: #990000">.</span>erlang<span style="color: #990000">.</span>mk<span style="color: #990000">.</span>build</tt></pre></div></div>
<div class="paragraph"><p>This is Erlang.mk bootstrapping itself. Indeed, the file you
initially downloaded contains nothing more than the code needed
to bootstrap. This operation is done only once. Consult the
<a href="../updating">Updating Erlang.mk</a> chapter for more
information.</p></div>
<div class="paragraph"><p>Of course, the generated project can now be compiled:</p></div>
<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>
<div class="paragraph"><p>Cheers!</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_getting_started_with_otp_libraries">Getting started with OTP libraries</h2>
<div class="sectionbody">
<div class="paragraph"><p>An OTP library is an Erlang application that has no supervision
tree. In other words, it is nothing but modules.</p></div>
<div class="paragraph"><p>This kind of project can also be generated by Erlang.mk, using
the <code>bootstrap-lib</code> target:</p></div>
<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<span style="color: #990000">.</span>mk bootstrap-lib</tt></pre></div></div>
<div class="paragraph"><p>Erlang.mk will once again bootstrap itself and generate all
the files for your project. You can now compile it:</p></div>
<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>
<div class="paragraph"><p>Enjoy!</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_getting_started_with_otp_releases">Getting started with OTP releases</h2>
<div class="sectionbody">
<div class="paragraph"><p>An OTP release is the combination of the Erlang RunTime System (ERTS)
along with all the libraries and files that your node will need
to run. It is entirely self contained, and can often be sent as-is
to your production system and run without any extra setup.</p></div>
<div class="paragraph"><p>Erlang.mk can of course bootstrap your project to generate releases.
You can use the <code>bootstrap-rel</code> target for this purpose:</p></div>
<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 bootstrap-rel</tt></pre></div></div>
<div class="paragraph"><p>This target can be combined with <code>bootstrap</code> or <code>bootstrap-lib</code> to
create a project that will build a release:</p></div>
<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<span style="color: #990000">.</span>mk bootstrap-lib bootstrap-rel</tt></pre></div></div>
<div class="paragraph"><p>It is often very useful to keep the top-level project for
commands useful during operations, and put the components
of the system in separate applications that you will then
depend on. Consult the <a href="../deps">Packages and dependencies</a>
chapter for more information.</p></div>
<div class="paragraph"><p>When you run <code>make</code> from now on, Erlang.mk will compile your
project and build the release:</p></div>
<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    hello_joe<span style="color: #990000">.</span>app<span style="color: #990000">.</span>src
 GEN    distclean-relx-rel
 GEN    /home/essen/tmp/hello_joe/relx
<span style="color: #990000">===&gt;</span> Starting relx build process <span style="color: #990000">...</span>
<span style="color: #990000">===&gt;</span> Resolving OTP Applications from directories<span style="color: #990000">:</span>
          /home/essen/tmp/hello_joe/ebin
          /usr/lib/erlang/lib
          /home/essen/tmp/hello_joe/deps
<span style="color: #990000">===&gt;</span> Resolved hello_joe_release-<span style="color: #993399">1</span>
<span style="color: #990000">===&gt;</span> Including Erts from /usr/lib/erlang
<span style="color: #990000">===&gt;</span> release successfully created<span style="color: #990000">!</span></tt></pre></div></div>
<div class="paragraph"><p>The first time you run this command, Erlang.mk will download
<em>relx</em>, the release building tool. So don&#8217;t worry if you see
more output than above.</p></div>
<div class="paragraph"><p>If building the release is slow, no need to upgrade your
hardware just yet. Just consult the <a href="../relx">Releases</a>
chapter for various tips to speed up build time during
development.</p></div>
<div class="paragraph"><p>You can start the release using the <em>./_rel/hello_joe_release/bin/hello_joe_release</em>
script, or simply run <code>make run</code>. The latter will also compile
your project and build the release if it wasn&#8217;t already:</p></div>
<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 run
 APP    hello_joe<span style="color: #990000">.</span>app<span style="color: #990000">.</span>src
 GEN    distclean-relx-rel
<span style="color: #990000">===&gt;</span> Starting relx build process <span style="color: #990000">...</span>
<span style="color: #990000">===&gt;</span> Resolving OTP Applications from directories<span style="color: #990000">:</span>
          /home/essen/tmp/hello_joe/ebin
          /usr/lib/erlang/lib
          /home/essen/tmp/hello_joe/deps
<span style="color: #990000">===&gt;</span> Resolved hello_joe_release-<span style="color: #993399">1</span>
<span style="color: #990000">===&gt;</span> Including Erts from /usr/lib/erlang
<span style="color: #990000">===&gt;</span> release successfully created<span style="color: #990000">!</span>
Exec<span style="color: #990000">:</span> /home/essen/tmp/hello_joe<span style="color: #990000">/</span>_rel/hello_joe_release/erts-<span style="color: #993399">7.0</span>/bin/erlexec -boot /home/essen/tmp/hello_joe<span style="color: #990000">/</span>_rel/hello_joe_release/releases<span style="color: #990000">/</span><span style="color: #993399">1</span>/hello_joe_release -boot_var ERTS_LIB_DIR /home/essen/tmp/hello_joe<span style="color: #990000">/</span>_rel/hello_joe_release/erts-<span style="color: #993399">7.0</span><span style="color: #990000">/..</span>/lib -env ERL_LIBS /home/essen/tmp/hello_joe<span style="color: #990000">/</span>_rel/hello_joe_release/releases<span style="color: #990000">/</span><span style="color: #993399">1</span>/lib -config /home/essen/tmp/hello_joe<span style="color: #990000">/</span>_rel/hello_joe_release/releases<span style="color: #990000">/</span><span style="color: #993399">1</span>/sys<span style="color: #990000">.</span>config -args_file /home/essen/tmp/hello_joe<span style="color: #990000">/</span>_rel/hello_joe_release/releases<span style="color: #990000">/</span><span style="color: #993399">1</span>/vm<span style="color: #990000">.</span>args -- console
Root<span style="color: #990000">:</span> /home/essen/tmp/hello_joe<span style="color: #990000">/</span>_rel/hello_joe_release
/home/essen/tmp/hello_joe<span style="color: #990000">/</span>_rel/hello_joe_release
heart_beat_kill_pid <span style="color: #990000">=</span> <span style="color: #993399">16389</span>
Erlang/OTP <span style="color: #993399">18</span> <span style="color: #990000">[</span>erts-<span style="color: #993399">7.0</span><span style="color: #990000">]</span> <span style="color: #990000">[</span><span style="font-weight: bold"><span style="color: #0000FF">source</span></span><span style="color: #990000">]</span> <span style="color: #990000">[</span><span style="color: #993399">64</span>-bit<span style="color: #990000">]</span> <span style="color: #990000">[</span>smp<span style="color: #990000">:</span><span style="color: #993399">4</span><span style="color: #990000">:</span><span style="color: #993399">4</span><span style="color: #990000">]</span> <span style="color: #990000">[</span>async-threads<span style="color: #990000">:</span><span style="color: #993399">10</span><span style="color: #990000">]</span> <span style="color: #990000">[</span>hipe<span style="color: #990000">]</span> <span style="color: #990000">[</span>kernel-poll<span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">false</span></span><span style="color: #990000">]</span>

Eshell V7<span style="color: #990000">.</span><span style="color: #993399">0</span>  <span style="color: #990000">(</span>abort with <span style="color: #990000">^</span>G<span style="color: #990000">)</span>
<span style="color: #990000">(</span>hello_joe@<span style="color: #993399">127.0</span><span style="color: #990000">.</span><span style="color: #993399">0.1</span><span style="color: #990000">)</span><span style="color: #993399">1</span><span style="color: #990000">&gt;</span></tt></pre></div></div>
<div class="paragraph"><p>Simple as that!</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_getting_started_from_scratch">Getting started from scratch</h2>
<div class="sectionbody">
<div class="paragraph"><p>If you already have an application, or you want to have full
control over what files will be created, you can setup Erlang.mk
manually.</p></div>
<div class="paragraph"><p>Erlang.mk is very easy to setup: all that you need to do is to
create a folder, put Erlang.mk in it, and write a one line
Makefile containing:</p></div>
<div class="listingblock">
<div class="content"></div></div>
<div class="paragraph"><p>For a step by step:</p></div>
<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>$ mkdir hello_joe
$ cd hello_joe
$ curl https<span style="color: #990000">:</span>//erlang<span style="color: #990000">.</span>mk/erlang<span style="color: #990000">.</span>mk -o erlang<span style="color: #990000">.</span>mk
$ echo <span style="color: #FF0000">"include erlang.mk"</span> <span style="color: #990000">&gt;</span> Makefile
$ make</tt></pre></div></div>
<div class="paragraph"><p>From that point onward you can create an <code>src/</code> folder or start
using templates.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_using_spaces_instead_of_tabs">Using spaces instead of tabs</h2>
<div class="sectionbody">
<div class="paragraph"><p>Erlang.mk defaults to tabs when creating files from templates.
This is in part because of a personal preference, and in part
because it is much easier to convert tabs to spaces than the
opposite.</p></div>
<div class="paragraph"><p>Use the <code>SP</code> variable if you prefer spaces. Set it to the number
of spaces per indentation level you want.</p></div>
<div class="paragraph"><p>For example, if you prefer two spaces per indentation level:</p></div>
<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<span style="color: #990000">.</span>mk bootstrap <span style="color: #009900">SP</span><span style="color: #990000">=</span><span style="color: #993399">2</span></tt></pre></div></div>
<div class="paragraph"><p>When you bootstrap the project initially, the variable automatically
gets added to the Makefile, so you only need to provide it when
you get started.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_using_templates">Using templates</h2>
<div class="sectionbody">
<div class="paragraph"><p>It is no secret that Erlang&#8217;s OTP behaviors tend to have some
boilerplate. It is rarely an issue of course, except when
creating new modules. That&#8217;s why Erlang.mk not only comes with
templates for generating projects, but also individual modules!</p></div>
<div class="paragraph"><p>You can list all available templates with the <code>list-templates</code>
target:</p></div>
<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 list-templates
Available templates<span style="color: #990000">:</span> cowboy_http cowboy_loop cowboy_rest cowboy_ws gen_fsm gen_server ranch_protocol supervisor</tt></pre></div></div>
<div class="paragraph"><p>To generate a module, let&#8217;s say a <code>gen_server</code>, all you need to
do is to call <code>make new</code> with the appropriate arguments:</p></div>
<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 <span style="color: #009900">t</span><span style="color: #990000">=</span>gen_server <span style="color: #009900">n</span><span style="color: #990000">=</span>my_server</tt></pre></div></div>
<div class="paragraph"><p>This will create a module located in <em>src/my_server.erl</em>
using the <code>gen_server</code> template.</p></div>
<div class="paragraph"><p>This module is automatically compiled the next time you run
<code>make</code>:</p></div>
<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
 ERLC   my_server<span style="color: #990000">.</span>erl
 APP    hello_joe<span style="color: #990000">.</span>app<span style="color: #990000">.</span>src</tt></pre></div></div>
<div class="paragraph"><p>All that&#8217;s left to do is to open it in your favorite editor
and make it do something!</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_hiding_erlang_mk_from_git">Hiding Erlang.mk from git</h2>
<div class="sectionbody">
<div class="paragraph"><p>Erlang.mk is a large text file. It can easily take a large part of
a <code>git diff</code> or a <code>git grep</code> command. You can avoid this by telling
Git that <em>erlang.mk</em> is a binary file.</p></div>
<div class="paragraph"><p>Add this to your <em>.gitattributes</em> file. This is a file that you
can create at the root of your repository:</p></div>
<div class="listingblock">
<div class="content">
<pre><code>erlang.mk -diff</code></pre>
</div></div>
<div class="paragraph"><p>The <em>erlang.mk</em> file will still appear in diffs and greps, but
as a binary file, meaning its contents won&#8217;t be shown by default
anymore.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_getting_help">Getting help</h2>
<div class="sectionbody">
<div class="paragraph"><p>During development, if you don&#8217;t remember the name of a target,
you can always run <code>make help</code>:</p></div>
<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 <span style="font-weight: bold"><span style="color: #0000FF">help</span></span>
erlang<span style="color: #990000">.</span>mk <span style="color: #990000">(</span>version <span style="color: #993399">1.2</span><span style="color: #990000">.</span><span style="color: #993399">0</span>-<span style="color: #993399">642</span>-gccd2b9f<span style="color: #990000">)</span> is distributed under the terms of the ISC License<span style="color: #990000">.</span>
Copyright <span style="color: #990000">(</span>c<span style="color: #990000">)</span> <span style="color: #993399">2013</span>-<span style="color: #993399">2015</span> Loïc Hoguin <span style="color: #990000">&lt;</span>essen@ninenines<span style="color: #990000">.</span>eu<span style="color: #990000">&gt;</span>

Usage<span style="color: #990000">:</span> <span style="color: #990000">[</span><span style="color: #009900">V</span><span style="color: #990000">=</span><span style="color: #993399">1</span><span style="color: #990000">]</span> make <span style="color: #990000">[</span>target<span style="color: #990000">]...</span>

Core targets<span style="color: #990000">:</span>
  all           Run deps<span style="color: #990000">,</span> app and rel targets <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> that order
  app           Compile the project
  deps          Fetch dependencies <span style="color: #990000">(</span><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> needed<span style="color: #990000">)</span> and compile them
  search <span style="color: #009900">q</span><span style="color: #990000">=...</span>  Search <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> a package <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> the built-in index
  rel           Build a release <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> this project<span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> applicable
  docs          Build the documentation <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> this project
  install-docs  Install the man pages <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> this project
  check         Compile and run all tests and analysis <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> this project
  tests         Run the tests <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> this project
  clean         Delete temporary and output files from most targets
  distclean     Delete all temporary and output files
  <span style="font-weight: bold"><span style="color: #0000FF">help</span></span>          Display this <span style="font-weight: bold"><span style="color: #0000FF">help</span></span> and <span style="font-weight: bold"><span style="color: #0000FF">exit</span></span>
  erlang-mk     Update erlang<span style="color: #990000">.</span>mk to the latest version

Bootstrap targets<span style="color: #990000">:</span>
  bootstrap          Generate a skeleton of an OTP application
  bootstrap-lib      Generate a skeleton of an OTP library
  bootstrap-rel      Generate the files needed to build a release
  new <span style="color: #009900">t</span><span style="color: #990000">=</span>TPL <span style="color: #009900">n</span><span style="color: #990000">=</span>NAME   Generate a module NAME based on the template TPL
  list-templates     List available templates
<span style="color: #990000">...</span></tt></pre></div></div>
<div class="paragraph"><p>This guide should provide any other answer. If not, please
open a ticket on <a href="https://github.com/ninenines/erlang.mk/issues">the official repository</a>
and we will work on improving the guide.</p></div>
<div class="paragraph"><p>Commercial support is available through Nine Nines. Please contact
Loïc Hoguin by sending an email to <a href="mailto:[email protected]">[email protected]</a>.</p></div>
</div>
</div>



	
		
		

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

			
				<a style="float:right" href="https://ninenines.eu/docs/en/erlang.mk/1/guide/overview/">
					Overview
				</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>

</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-2016</p>
            </div>
          </div>
        </div>
      </footer>

    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="/js/bootstrap-carousel.js"></script>
    <script src="/js/bootstrap-dropdown.js"></script>
    <script src="/js/custom.js"></script>
  </body>
</html>