Reputation: 4926
A variable in my makefile contains a long list of files, separated by space. I need to look through this list, but since the filenames are separated by space it's not very easy to do. So I'd like to print out the list, but where each filename separated by a new line.
Here's my attempt:
SOME_VARIABLE := I want this to be on separate lines
SOME_VARIABLE_SPLIT := $(subst ' ','\n',$(SOME_VARIABLE))
$(info $(SOME_VARIABLE_SPLIT))
Output:
I want this to be on separate lines
How do I print a variable containing space-separated filenames, with each filename on a separate line?
Upvotes: 0
Views: 327
Reputation: 29260
Your problem comes from the way subst
works: your quotes and backslashes are taken literally.
A solution consists in first defining two variables containing a space and a newline:
# $(NULL) is empty string
NULL :=
# $(SPACE) is one space
SPACE := $(NULL) $(NULL)
# $(\n) is new line
define \n
endef
and then using them in your substitution:
SOME_VARIABLE := I want this to be on separate lines
SOME_VARIABLE_SPLIT := $(subst $(SPACE),$(\n),$(SOME_VARIABLE))
$(info $(SOME_VARIABLE_SPLIT))
Notes:
NULL
variable to define a variable which value is a space,\n
; maybe not the best thing to do for readability (readers could be puzzled) but funny enough to use it anyway,Upvotes: 1