[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: defining variables in canned sequences
From: |
Paul D. Smith |
Subject: |
Re: defining variables in canned sequences |
Date: |
Tue, 14 Oct 2003 14:58:45 -0400 |
%% Robert Mecklenburg <address@hidden> writes:
rm> define make-variables
rm> FOO = foo
rm> BAR = bar
rm> endef
rm> $(make-variables)
rm> echo:
rm> # $(FOO)
rm> # $(BAR)
rm> When executed make reports
rm> Makefile:5: *** missing separator. Stop.
rm> Why?
A variable cannot expand into multiple lines.
rm> I know I can resolve the issue by wrapping the variable expansion
rm> in $(eval ), but that isn't my question. I just want to know why
rm> the expansion generates the error. The define construct
rm> explicitly preserves newlines in the expansion so I would think
rm> the parser would simply see two assignments separated by a
rm> newline. Evidently not.
No. The parser parses _line-by-line_. When it reads in one line, it
expands it, and expects and interprets the results to continue to be a
single line. The results of the expansion are still parsed in that way.
It doesn't do anything like "push" the expansion back into the parser
stack and restart the read.
When I was implementing the eval functionality that is the first way I
tried to implement it: without requiring an extra function but just
making something like what you wrote above work. It turns out that
given the complexities of the make parser, this is actually quite
difficult.
And, eval is more powerful anyway because it can be used anywhere that a
variable expansion is used.
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist