m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <m@m-chrzan.xyz>2022-12-21 01:05:26 +0100
committerMarcin Chrzanowski <m@m-chrzan.xyz>2022-12-21 01:05:26 +0100
commit7fd8c95dc1bc360e09aa155c03bfc6213401285f (patch)
tree07e6088d5e4b5fa99de9f8b62b4075d3c7ab59bf
parentc82346e161a607b0f7a8fcbbce87095a2d41cb2e (diff)
Add Makefile tips
-rw-r--r--makefile.md30
1 files changed, 30 insertions, 0 deletions
diff --git a/makefile.md b/makefile.md
new file mode 100644
index 0000000..a7a3ab8
--- /dev/null
+++ b/makefile.md
@@ -0,0 +1,30 @@
+# Writing Makefiles
+
+## Pattern rules
+
+In prerequesite, use exactly one `%`. Can then be used in requirements. E.g.
+
+ %.o: %.c
+ # compile .c file to .o
+
+Details: <https://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html>
+
+## Automatic variables
+
+* `$@`: current target
+* `$<`: first prerequisite
+* `$^`: all prerequisites, separated by spaces
+* `$(@F)`: file-within-directory part of target path
+
+More: <https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html>
+
+## Text functions
+
+* `$(var:suffix=replacement)`, syntax sugar for
+ `$(patsubst %suffix, $replacement, $(var))`
+
+More: <https://www.gnu.org/software/make/manual/html_node/Text-Functions.html>
+
+## Quiet commands
+
+By default, `make` prints the command being run. Prepend `@` to silence this.