Skip to content

Commit 8a3efb0

Browse files
committed
* Macro docs
1 parent 5087d90 commit 8a3efb0

File tree

2 files changed

+121
-11
lines changed

2 files changed

+121
-11
lines changed

README.md

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- [cc/cxx](#cc-----cxx---)
2222
- [library](#library-)
2323
- [install](#install-)
24-
- [macros](#macros)
24+
- [macros](#Macros)
2525

2626
**Autark** is a self-contained build system that resides entirely within
2727
your project and requires only `/bin/sh` and a `C` compiler to work!
@@ -1208,11 +1208,69 @@ if { library { LIB_M libm.a }
12081208
This will search for `libm.a`, and if found, store its absolute path in `LIB_M` and print it.
12091209
If the library is not found, the script will terminate with an error.
12101210

1211+
# Macros
12111212

1212-
# macros
1213+
Macros provide a convenient way to reuse code for implementing repetitive elements in a project’s build script.
1214+
They are especially useful for defining test cases where the build steps differ only by a few parameter values.
12131215

1214-
Макросы являются удобным
1216+
A macro call is similar to a function call, but instead of executing code directly, it rewrites and rebuilds the
1217+
script’s AST (Abstract Syntax Tree) before the build script starts.
12151218

1219+
```cfg
1220+
macro {
1221+
MACRO_NAME
1222+
...
1223+
}
1224+
```
1225+
1226+
The body of a macro directive can contain any valid Autark script elements and may include argument placeholders for macro calls.
1227+
These placeholders have the following format: `&{N}`, where `N` is the argument number starting from one.
1228+
A macro is invoked using the `call` directive:
1229+
1230+
```cfg
1231+
call {
1232+
MACRO_NAME
1233+
ARGS...
1234+
}
1235+
```
1236+
1237+
Example:
1238+
1239+
```cfg
1240+
macro {
1241+
M_ECHO
1242+
set {
1243+
JOIN
1244+
^{&{1} ' ' &{2}}
1245+
}
1246+
echo { JOIN ${JOIN} }
1247+
}
1248+
1249+
call {
1250+
M_ECHO
1251+
'foo bar'
1252+
baz
1253+
}
1254+
1255+
call {
1256+
M_ECHO
1257+
'baz gaz'
1258+
last
1259+
}
1260+
```
1261+
1262+
Console output:
1263+
1264+
```
1265+
foo bar baz
1266+
baz gaz last
1267+
```
1268+
1269+
All `&{N}` placeholders are replaced with the corresponding arguments from the call directive.
1270+
If the argument index `N` is omitted (`&{}`), the arguments are substituted in sequential order starting from `1`.
1271+
1272+
A good real-world example of using macros can be found here:
1273+
https://github.com/Softmotions/protobuf-c/blob/master/t/Issues.autark
12161274

12171275
# install {..}
12181276

dist/docs/index.html

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ <h2 id="quick-links">Quick links</h2>
310310
<li><a href="#cc-----cxx---">cc/cxx</a></li>
311311
<li><a href="#library-">library</a></li>
312312
<li><a href="#install-">install</a></li>
313-
<li><a href="#macros">macros</a></li>
313+
<li><a href="#Macros">macros</a></li>
314314
</ul>
315315
<p><strong>Autark</strong> is a self-contained build system that resides
316316
entirely within your project and requires only <code>/bin/sh</code> and
@@ -1355,8 +1355,60 @@ <h1 id="library-">library {...}</h1>
13551355
<p>This will search for <code>libm.a</code>, and if found, store its
13561356
absolute path in <code>LIB_M</code> and print it. If the library is not
13571357
found, the script will terminate with an error.</p>
1358-
<h1 id="macros">macros</h1>
1359-
<p>Макросы являются удобным</p>
1358+
<h1 id="macros">Macros</h1>
1359+
<p>Macros provide a convenient way to reuse code for implementing
1360+
repetitive elements in a project’s build script. They are especially
1361+
useful for defining test cases where the build steps differ only by a
1362+
few parameter values.</p>
1363+
<p>A macro call is similar to a function call, but instead of executing
1364+
code directly, it rewrites and rebuilds the script’s AST (Abstract
1365+
Syntax Tree) before the build script starts.</p>
1366+
<div class="sourceCode" id="cb57"><pre
1367+
class="sourceCode cfg"><code class="sourceCode ini"><span id="cb57-1"><a href="#cb57-1" aria-hidden="true" tabindex="-1"></a><span class="dt">macro {</span></span>
1368+
<span id="cb57-2"><a href="#cb57-2" aria-hidden="true" tabindex="-1"></a><span class="dt"> MACRO_NAME</span></span>
1369+
<span id="cb57-3"><a href="#cb57-3" aria-hidden="true" tabindex="-1"></a><span class="dt"> ...</span></span>
1370+
<span id="cb57-4"><a href="#cb57-4" aria-hidden="true" tabindex="-1"></a><span class="dt">}</span></span></code></pre></div>
1371+
<p>The body of a macro directive can contain any valid Autark script
1372+
elements and may include argument placeholders for macro calls. These
1373+
placeholders have the following format: <code>&amp;{N}</code>, where
1374+
<code>N</code> is the argument number starting from one. A macro is
1375+
invoked using the <code>call</code> directive:</p>
1376+
<div class="sourceCode" id="cb58"><pre
1377+
class="sourceCode cfg"><code class="sourceCode ini"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a><span class="dt">call {</span></span>
1378+
<span id="cb58-2"><a href="#cb58-2" aria-hidden="true" tabindex="-1"></a><span class="dt"> MACRO_NAME</span></span>
1379+
<span id="cb58-3"><a href="#cb58-3" aria-hidden="true" tabindex="-1"></a><span class="dt"> ARGS...</span></span>
1380+
<span id="cb58-4"><a href="#cb58-4" aria-hidden="true" tabindex="-1"></a><span class="dt">}</span></span></code></pre></div>
1381+
<p>Example:</p>
1382+
<div class="sourceCode" id="cb59"><pre
1383+
class="sourceCode cfg"><code class="sourceCode ini"><span id="cb59-1"><a href="#cb59-1" aria-hidden="true" tabindex="-1"></a><span class="dt">macro {</span></span>
1384+
<span id="cb59-2"><a href="#cb59-2" aria-hidden="true" tabindex="-1"></a><span class="dt"> M_ECHO</span></span>
1385+
<span id="cb59-3"><a href="#cb59-3" aria-hidden="true" tabindex="-1"></a><span class="dt"> set {</span></span>
1386+
<span id="cb59-4"><a href="#cb59-4" aria-hidden="true" tabindex="-1"></a><span class="dt"> JOIN</span></span>
1387+
<span id="cb59-5"><a href="#cb59-5" aria-hidden="true" tabindex="-1"></a><span class="dt"> ^{&amp;{1} &#39; &#39; &amp;{2}}</span></span>
1388+
<span id="cb59-6"><a href="#cb59-6" aria-hidden="true" tabindex="-1"></a><span class="dt"> }</span></span>
1389+
<span id="cb59-7"><a href="#cb59-7" aria-hidden="true" tabindex="-1"></a><span class="dt"> echo { JOIN ${JOIN} }</span></span>
1390+
<span id="cb59-8"><a href="#cb59-8" aria-hidden="true" tabindex="-1"></a><span class="dt">}</span></span>
1391+
<span id="cb59-9"><a href="#cb59-9" aria-hidden="true" tabindex="-1"></a></span>
1392+
<span id="cb59-10"><a href="#cb59-10" aria-hidden="true" tabindex="-1"></a><span class="dt">call {</span></span>
1393+
<span id="cb59-11"><a href="#cb59-11" aria-hidden="true" tabindex="-1"></a><span class="dt"> M_ECHO</span></span>
1394+
<span id="cb59-12"><a href="#cb59-12" aria-hidden="true" tabindex="-1"></a><span class="dt"> &#39;foo bar&#39;</span></span>
1395+
<span id="cb59-13"><a href="#cb59-13" aria-hidden="true" tabindex="-1"></a><span class="dt"> baz</span></span>
1396+
<span id="cb59-14"><a href="#cb59-14" aria-hidden="true" tabindex="-1"></a><span class="dt">}</span></span>
1397+
<span id="cb59-15"><a href="#cb59-15" aria-hidden="true" tabindex="-1"></a></span>
1398+
<span id="cb59-16"><a href="#cb59-16" aria-hidden="true" tabindex="-1"></a><span class="dt">call {</span></span>
1399+
<span id="cb59-17"><a href="#cb59-17" aria-hidden="true" tabindex="-1"></a><span class="dt"> M_ECHO</span></span>
1400+
<span id="cb59-18"><a href="#cb59-18" aria-hidden="true" tabindex="-1"></a><span class="dt"> &#39;baz gaz&#39;</span></span>
1401+
<span id="cb59-19"><a href="#cb59-19" aria-hidden="true" tabindex="-1"></a><span class="dt"> last</span></span>
1402+
<span id="cb59-20"><a href="#cb59-20" aria-hidden="true" tabindex="-1"></a><span class="dt">}</span></span></code></pre></div>
1403+
<p>Console output:</p>
1404+
<pre><code>foo bar baz
1405+
baz gaz last</code></pre>
1406+
<p>All <code>&amp;{N}</code> placeholders are replaced with the
1407+
corresponding arguments from the call directive. If the argument index
1408+
<code>N</code> is omitted (<code>&amp;{}</code>), the arguments are
1409+
substituted in sequential order starting from <code>1</code>.</p>
1410+
<p>A good real-world example of using macros can be found here: <a
1411+
href="https://github.com/Softmotions/protobuf-c/blob/master/t/Issues.autark">https://github.com/Softmotions/protobuf-c/blob/master/t/Issues.autark</a></p>
13601412
<h1 id="install-">install {..}</h1>
13611413
<p>If <code>build.sh</code> is run with the <code>-I</code> or
13621414
<code>--install</code> option (to install all built artifacts), or if an
@@ -1389,16 +1441,16 @@ <h2 id="available-variables-when-install-is-enabled">Available variables
13891441
<code>INSTALL_PREFIX</code> for man pages. <strong>Default:</strong>
13901442
<code>share/man</code></li>
13911443
</ul>
1392-
<div class="sourceCode" id="cb57"><pre
1393-
class="sourceCode cfg"><code class="sourceCode ini"><span id="cb57-1"><a href="#cb57-1" aria-hidden="true" tabindex="-1"></a><span class="dt">install { INSTAL_DIR_EXPR FILES... }</span></span></code></pre></div>
1444+
<div class="sourceCode" id="cb61"><pre
1445+
class="sourceCode cfg"><code class="sourceCode ini"><span id="cb61-1"><a href="#cb61-1" aria-hidden="true" tabindex="-1"></a><span class="dt">install { INSTAL_DIR_EXPR FILES... }</span></span></code></pre></div>
13941446
<p>The install rule copies the specified files into the target directory
13951447
<code>${INSTALL_PREFIX}/${INSTALL_DIR_EXPR}</code> (creating it if
13961448
necessary). File permissions from the original files are preserved
13971449
during the copy.</p>
13981450
<p>Example:</p>
1399-
<div class="sourceCode" id="cb58"><pre
1400-
class="sourceCode cfg"><code class="sourceCode ini"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a><span class="dt">install { ${INSTALL_PKGCONFIG_DIR} libiwnet.pc }</span></span>
1401-
<span id="cb58-2"><a href="#cb58-2" aria-hidden="true" tabindex="-1"></a><span class="dt">install { ${INSTALL_INCLUDE_DIR} ${PUB_HDRS} }</span></span></code></pre></div>
1451+
<div class="sourceCode" id="cb62"><pre
1452+
class="sourceCode cfg"><code class="sourceCode ini"><span id="cb62-1"><a href="#cb62-1" aria-hidden="true" tabindex="-1"></a><span class="dt">install { ${INSTALL_PKGCONFIG_DIR} libiwnet.pc }</span></span>
1453+
<span id="cb62-2"><a href="#cb62-2" aria-hidden="true" tabindex="-1"></a><span class="dt">install { ${INSTALL_INCLUDE_DIR} ${PUB_HDRS} }</span></span></code></pre></div>
14021454
<p>This will install <code>libiwnet.pc</code> into the appropriate
14031455
pkgconfig directory, and public headers into the include directory under
14041456
the chosen prefix.</p>

0 commit comments

Comments
 (0)