[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Iterating through multi-line variable
From: |
Hambridge, Philip J (ODP) |
Subject: |
RE: Iterating through multi-line variable |
Date: |
Wed, 30 Jun 2010 11:49:25 +0100 |
I think this does the trick...
# Define a var containing one space character.
SPACE :=
SPACE +=
# Define a substitute for space.
SPACESUB := __SPACE__
# Define a var containing one new-line character (there are two blank
lines in this).
define NEWLINE
endef
# The multi-line var under test.
define FOO
foo abc
bar xyz
quux
endef
# Replace each space in FOO with a substitute, then replace each
new-line with a space so
# make sees each line as a word. The foreach function will then loop
through all words
# and it's just necessary to undo the space substitution in the body of
the loop - in this
# cas just a call to the info function.
$(foreach line,$(subst $(NEWLINE),$(SPACE),$(subst
$(SPACE),$(SPACESUB),$(FOO))),\
$(info line: '$(subst $(SPACESUB),$(SPACE),$(line))')\
)
Regards,
Philip.
-----Original Message-----
From: J.T. Conklin [mailto:address@hidden
Sent: 28 June 2010 23:49
To: address@hidden
Subject: Iterating through multi-line variable
Suppose you have a multi-line variable where each line may have spaces.
define FOO
foo abc
bar xyz
quux
endef
Is there a way to iterate through the variable line-by-line instead of
word-by-word (as with $(foreach ...)) ?
--jtc
--
J.T. Conklin