'How to encode a string with a space at the end in a protected manner in a makefile?
Suppose I define a runners.mk file:
run=./
valgrind=valgrind --this --or --that-option
And intentionally put a space at the end of the valgrind line.
The idea is to use any "runner" in the same way:
valgrind-foo-bar-executable: foo-bar-executable
$(valgrind)$<
run-foo-bar-executable: foo-bar-executable
$(run)$<
So that I can eventually abstract everything into a runner pattern with matching (once I get a few more examples).
However, this is a public repo and it is standard practice to clear out all blanks at the end of lines.
In order to do this pattern, it would be ideal to put some kind of protected blank at the end of the valgrind command. However, in a makefile quotes are interpreted literally.
Is there some way to protect this suffixed blank in the makefile?
Solution 1:[1]
You can add an empty var on the end of the valgrind line to "protect" the space before it:
empty=
run=./
valgrind=valgrind --this --or --that-option $(empty)
Now the space between --that-option and $(empty) will be clearly visible and not removed as a trailing space.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chris Dodd |
