From f30ef63fd29b968af6495fdb4603eb14583aa208 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 21 Mar 2022 08:44:53 +0300 Subject: makefile_escaping: terser TL;DR --- _posts/2020-05-20-makefile-escaping.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to '_posts') diff --git a/_posts/2020-05-20-makefile-escaping.md b/_posts/2020-05-20-makefile-escaping.md index 70bf802..d16e3b5 100644 --- a/_posts/2020-05-20-makefile-escaping.md +++ b/_posts/2020-05-20-makefile-escaping.md @@ -43,8 +43,7 @@ and you're pretty much good to go. escape = $(subst ','\'',$(1)) - Use it to safeguard against single quote characters in your variables/function -outputs. + It protects against quite characters in command arguments. You can then replace things like `'$(dangerous_variable)'` or `'$(shell your-command arg1 arg2)'` with `'$(call escape,$(dangerous_variable))'` and `'$(call escape,$(shell your-command arg1 arg2))'`. @@ -64,14 +63,13 @@ from being expanded: endif endef - You can then be sure any accidental variables references (like if the -environment variable contains `$` as in `Accidental $variable reference`) are -not expanded if you use the following pattern in the Makefile: + Then `eval` the `noexpand` function output for every possibly overridden +variable or a used environment variable: - param1 ?= Default value - $(eval $(call noexpand,param1)) + param_with_default_value ?= Default value + $(eval $(call noexpand,param_with_default_value)) - $(eval $(call noexpand,param2)) + $(eval $(call noexpand,used_environment_variable)) Quoting arguments ----------------- -- cgit v1.2.3