aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-03-31 20:31:43 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-03-31 20:31:43 +0300
commitbf6157d7684fde7a2127d7d548d58576529daef8 (patch)
tree2d50a12115e8d9ddf07d78b9bed707413c55144f
parentmakefile_escaping: best practices (diff)
downloadblog-bf6157d7684fde7a2127d7d548d58576529daef8.tar.gz
blog-bf6157d7684fde7a2127d7d548d58576529daef8.zip
makefile_escaping: escape_arg -> noexpand
Diffstat (limited to '')
-rw-r--r--_posts/2020-05-20-makefile-escaping.md18
1 files changed, 9 insertions, 9 deletions
diff --git a/_posts/2020-05-20-makefile-escaping.md b/_posts/2020-05-20-makefile-escaping.md
index faa3754..4308467 100644
--- a/_posts/2020-05-20-makefile-escaping.md
+++ b/_posts/2020-05-20-makefile-escaping.md
@@ -50,7 +50,7 @@ your-command arg1 arg2)'` with `'$(call escape,$(dangerous_variable))'` and
on the command line), add the following lengthy snippet to prevent the values
from being expanded:
- define escape_arg
+ define noexpand
ifeq ($$(origin $(1)),environment)
$(1) := $$(value $(1))
endif
@@ -67,9 +67,9 @@ environment variable contains `$` as in `Accidental $variable reference`) are
not expanded if you use the following pattern in the Makefile:
param1 ?= Default value
- $(eval $(call escape_arg,param1))
+ $(eval $(call noexpand,param1))
- $(eval $(call escape_arg,param2))
+ $(eval $(call noexpand,param2))
Quoting arguments
-----------------
@@ -342,7 +342,7 @@ The snippet above can be generalized by defining a custom function that
produces the required `make` code, and then calling `eval`.
```
-define escape_arg
+define noexpand
ifeq ($$(origin $(1)),environment)
$(1) := $$(value $(1))
endif
@@ -357,11 +357,11 @@ endef
test_var ?= This is safe.
test_var2 ?= This is safe - 2.
-$(eval $(call escape_arg,test_var))
-$(eval $(call escape_arg,test_var2))
+$(eval $(call noexpand,test_var))
+$(eval $(call noexpand,test_var2))
```
-I couldn't find a case where the combination of `escape` and `escape_arg`
+I couldn't find a case where the combination of `escape` and `noexpand`
wouldn't work.
You can even safely use other variable as the default value of `test_var`, and
it works:
@@ -372,7 +372,7 @@ it works:
escape = $(subst ','\'',$(1))
-define escape_arg
+define noexpand
ifeq ($$(origin $(1)),environment)
$(1) := $$(value $(1))
endif
@@ -387,7 +387,7 @@ endef
simple_var := Simple value
test_var ?= $(simple_var) in test_var
-$(eval $(call escape_arg,test_var))
+$(eval $(call noexpand,test_var))
simple_var := New simple value
composite_var := Composite value - $(simple_var) - $(test_var)