here I am again with another m开发者_JS百科ake issue Im trying to handle (hardly), I have set several values I want make to read, but when I try to change inside a loop it does not work; $(FOUND) stills being the same as it was first, what could I being doing bad? is other way to set variables or to change them into?
here's a part of my code related to this question:
$(shell for d in $(INPUT); \
do \
$(if $(FOUND) -eq 1, REL=$(REL)../); \
$(if $(findstring $(WORD),$(INPUT)), \
echo '$(WORD)../'; FOUND=1)\
done)
$(FOUND) variable is defined outside but want it to change when it gets $(WORD)
any suggestion for that???
thank you so much
There are several things wrong with the code above, so much so that it is difficult to understand your intention. Here is a partial list (sorry if I sound like Microsoft clippy)
- The code
$(if $(FOUND) -eq 1, REL=$(REL)../)
, looks like a mix between gnu-make syntax and shell syntax. - Your loop seems to be superfluous. You are not using the loop variable
d
, and you are using a construct that process the entire sequence. E.g.:$(findstring $(WORD),$(INPUT)
- It seems that you are trying to generate code like
echo '$(WORD)../'
, but the context of this code is unclear. If it is outside a rule, the code has no meaning. If it is inside a rule, it will evaluate too late to set a makefile variable. There is a way to work around this problem, but first you need to clarify your intention better. - I can only suspect you intended to have
REL=$(REL)/..
orREL=../$(REL)
but I can be mistaken. - Lastly it is important to understand that what you really should do in a Makefile is to describe a dependency graph, and let make figure out the order of operation needed to be performed. So a procedural approach such as may inferred from your code above should be minimized.
Edit:
If I read you correctly, you are trying to achieve a tricky goal in Makefile. Let me assure you that your inexperience is not the only stumbling block you have. Writing good Makefiles is hard. If you have any control over this, I strongly suggest to have a look at some other build solutions. For example, cmake can write good Makefiles for you.
If you are trying to calculate a base-dir or a relative-dir, please note that the concept of current-working-directory as saved in $(CURDIR)
might or might not be what you expect.
For your question, you can indeed use a GNU make $(foreach ...)
construct, but there are several functions that are designed to handle sequences without iterations, that might serve you better.
精彩评论