aboutsummaryrefslogtreecommitdiffhomepage
path: root/print.html
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2024-03-26 23:15:06 +0000
committerjohannst <johannst@users.noreply.github.com>2024-03-26 23:15:06 +0000
commitda792f6afb36c4a03f51e618b64e6bd5e27fb3fd (patch)
tree7bdd11e9cac7b96ab0b470c162e69b2efd29aa9a /print.html
parenta06b9396568441dfe4eef2ff40eac951f8664187 (diff)
downloadnotes-da792f6afb36c4a03f51e618b64e6bd5e27fb3fd.tar.gz
notes-da792f6afb36c4a03f51e618b64e6bd5e27fb3fd.zip
deploy: 0ccba0943d477b71cdccd2505eb81b95f091263a
Diffstat (limited to 'print.html')
-rw-r--r--print.html120
1 files changed, 113 insertions, 7 deletions
diff --git a/print.html b/print.html
index d6958f5..df3cdad 100644
--- a/print.html
+++ b/print.html
@@ -4423,7 +4423,7 @@ target_link_libraries(main liba)
<blockquote>
<p>Use <code>make -p</code> to print all rules and variables (implicitly + explicitly defined).</p>
</blockquote>
-<h2 id="pattern-rules--automatic-variables"><a class="header" href="#pattern-rules--automatic-variables">Pattern rules &amp; Automatic variables</a></h2>
+<h2 id="pattern-rules--variables"><a class="header" href="#pattern-rules--variables">Pattern rules &amp; variables</a></h2>
<h3 id="pattern-rules"><a class="header" href="#pattern-rules">Pattern rules</a></h3>
<p>A pattern rule contains the <code>%</code> char (exactly one of them) and look like this example:</p>
<pre><code class="language-make">%.o : %.c
@@ -4476,6 +4476,19 @@ bbb:
<ul>
<li><code>$(CURDIR)</code>: Path of current working dir after using <code>make -C path</code></li>
</ul>
+<h3 id="multi-line-variables"><a class="header" href="#multi-line-variables">Multi-line variables</a></h3>
+<pre><code class="language-make">define my_var
+@echo foo
+@echo bar
+endef
+
+all:
+ $(my_var)
+</code></pre>
+<p>Running above <code>Makefile</code> gives:</p>
+<pre><code class="language-text">foo
+bar
+</code></pre>
<h2 id="arguments"><a class="header" href="#arguments">Arguments</a></h2>
<p>Arguments specified on the command line <em>override</em> ordinary variable
assignments in the makefile (<a href="https://www.gnu.org/software/make/manual/html_node/Overriding.html">overriding variables</a>).</p>
@@ -4518,12 +4531,105 @@ out := $(filter-out %.b %.c, $(in))
<h3 id="abspath"><a class="header" href="#abspath"><code>abspath</code></a></h3>
<p>Resolve each file name as absolute path (don't resolve symlinks).</p>
<pre><code class="language-make">$(abspath fname1 fname2 ..)
+</code></pre>
+<h3 id="realpath"><a class="header" href="#realpath"><code>realpath</code></a></h3>
+<p>Resolve each file name as canonical path.</p>
+<pre><code class="language-make">$(realpath fname1 fname2 ..)
+</code></pre>
+<h3 id="call--ref"><a class="header" href="#call--ref"><code>call</code> (<a href="https://www.gnu.org/software/make/manual/html_node/Call-Function.html">ref</a>)</a></h3>
+<p>Invoke parametrized function, which is an expression saved in a variable.</p>
+<pre><code class="language-make">swap = $(2) $(1)
+
+all:
+ @echo "call swap first second -&gt; $(call swap,first,second)"
+</code></pre>
+<p>Outputs:</p>
+<pre><code class="language-text">call swap first second -&gt; second first
+</code></pre>
+<h3 id="eval-ref"><a class="header" href="#eval-ref"><code>eval</code> (<a href="https://www.gnu.org/software/make/manual/html_node/Eval-Function.html">ref</a>)</a></h3>
+<p>Allows to define new makefile constructs by evaluating the result of a variable
+or function.</p>
+<pre><code class="language-make">define new_rule
+$(1):
+ @echo "$(1) -&gt; $(2)"
+endef
+
+default: rule1 rule2
-### `realpath`
-Resolve each file name as canonical path.
-```make
-$(realpath fname1 fname2 ..)
+$(eval $(call new_rule,rule1,foo))
+$(eval $(call new_rule,rule2,bar))
</code></pre>
+<p>Outputs:</p>
+<pre><code class="language-text">rule1 -&gt; foo
+rule2 -&gt; bar
+</code></pre>
+<h3 id="foreach-ref"><a class="header" href="#foreach-ref">foreach (<a href="https://www.gnu.org/software/make/manual/html_node/Foreach-Function.html">ref</a>)</a></h3>
+<p>Repeat a piece of text for a list of values, given the syntax <code>$(foreach var,list,text)</code>.</p>
+<pre><code class="language-make">myfn = x$(1)x
+
+default:
+ @echo $(foreach V,foo bar baz,$(call myfn,$(V)))
+</code></pre>
+<p>Outputs:</p>
+<pre><code class="language-text">xfoox xbarx xbazx
+</code></pre>
+<h2 id="examples-11"><a class="header" href="#examples-11">Examples</a></h2>
+<h3 id="config-based-settings"><a class="header" href="#config-based-settings">Config based settings</a></h3>
+<pre><code class="language-make">conf-y := default
+conf-$(FOO) := $(conf-y) foo
+conf-$(BAR) := $(conf-y) bar
+
+libs-y := libdef
+libs-$(FOO) += libfoo
+libs-$(BAR) += libbar
+
+all:
+ @echo "conf-y: $(conf-y)"
+ @echo "libs-y: $(libs-y)"
+</code></pre>
+<p>Yields the following results.</p>
+<pre><code class="language-sh">$ make
+conf-y: default
+libs-y: libdef
+
+$ make FOO=y
+conf-y: default foo
+libs-y: libdef libfoo
+
+$ make BAR=y
+conf-y: default bar
+libs-y: libdef libbar
+
+$ make FOO=y BAR=y
+conf-y: default foo bar
+libs-y: libdef libfoo libbar
+</code></pre>
+<h3 id="using-foreach--eval--call-to-generate-new-rules"><a class="header" href="#using-foreach--eval--call-to-generate-new-rules">Using <code>foreach / eval / call</code> to generate new rules</a></h3>
+<pre><code class="language-make">define new_rule
+$(1):
+ @echo "$(1) -&gt; $(2)"
+endef
+
+arg-rule1 = foo
+arg-rule2 = bar
+
+RULES = rule1 rule2
+
+all: $(RULES)
+
+$(foreach R,$(RULES),$(eval $(call new_rule,$(R),$(arg-$(R)))))
+
+# equivalent to
+# $(eval $(call new_rule,rule1,foo))
+# $(eval $(call new_rule,rule2,bar))
+</code></pre>
+<p>Outputs:</p>
+<pre><code class="language-text">rule1 -&gt; foo
+rule2 -&gt; bar
+</code></pre>
+<blockquote>
+<p>Use <code>make -R -p</code> to print the make database including the rules.</p>
+</blockquote>
<div style="break-before: page; page-break-before: always;"></div><h1 id="ldso8"><a class="header" href="#ldso8">ld.so(8)</a></h1>
<h2 id="environment-variables"><a class="header" href="#environment-variables">Environment Variables</a></h2>
<pre><code class="language-console"> LD_PRELOAD=&lt;l_so&gt; colon separated list of libso's to be pre loaded
@@ -5879,7 +5985,7 @@ tcp/udp/icmp Filter for protocol.
<blockquote>
<p>Use <code>and/or/not</code> and <code>()</code> to build filter expressions.</p>
</blockquote>
-<h1 id="examples-11"><a class="header" href="#examples-11">Examples</a></h1>
+<h1 id="examples-12"><a class="header" href="#examples-12">Examples</a></h1>
<h2 id="capture-packets-from-remote-host"><a class="header" href="#capture-packets-from-remote-host">Capture packets from remote host</a></h2>
<pre><code class="language-makrdown"># -k: Start capturing immediately.
ssh &lt;host&gt; tcpdump -i any -w - | sudo wireshark -k -i -
@@ -5911,7 +6017,7 @@ tcp/udp/ssh/wg/... Filter for protocol.
<blockquote>
<p>Use <code>tshak -G</code> to list all fields that can be used in display filters.</p>
</blockquote>
-<h1 id="examples-12"><a class="header" href="#examples-12">Examples</a></h1>
+<h1 id="examples-13"><a class="header" href="#examples-13">Examples</a></h1>
<h2 id="capture-and-filter-packet-to-file"><a class="header" href="#capture-and-filter-packet-to-file">Capture and filter packet to file</a></h2>
<pre><code class="language-bash"># Capture TCP traffic with port 80 on interface eth0 to file.
sudo tshark -i eht0 -f 'tcp and port 80' -w tx.pcap