From 7fd8c95dc1bc360e09aa155c03bfc6213401285f Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 21 Dec 2022 01:05:26 +0100 Subject: Add Makefile tips --- makefile.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 makefile.md 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: + +## Automatic variables + +* `$@`: current target +* `$<`: first prerequisite +* `$^`: all prerequisites, separated by spaces +* `$(@F)`: file-within-directory part of target path + +More: + +## Text functions + +* `$(var:suffix=replacement)`, syntax sugar for + `$(patsubst %suffix, $replacement, $(var))` + +More: + +## Quiet commands + +By default, `make` prints the command being run. Prepend `@` to silence this. -- cgit v1.2.3