@@ -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
316316entirely 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
13561356absolute path in < code > LIB_M</ code > and print it. If the library is not
13571357found, 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 > &{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 "> ^{&{1} ' ' &{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 "> 'foo bar'</ 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 "> 'baz gaz'</ 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 > &{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 > &{}</ 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
13961448necessary). File permissions from the original files are preserved
13971449during 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
14031455pkgconfig directory, and public headers into the include directory under
14041456the chosen prefix.</ p >
0 commit comments