[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check for the existance of variable.
From: |
Paul D. Smith |
Subject: |
Re: Check for the existance of variable. |
Date: |
Tue, 11 Apr 2006 11:38:55 -0400 |
%% "PATTON, BILLY \(SBCSI\)" <address@hidden> writes:
pb> commands are shell syntax and make file is for make syntax. I
pb> cannot check for the existence of a make variable in the commands
pb> of a rule.
Again, you haven't defined "existence". It can mean different things:
it can mean the variable was never set at all, or it can mean the
variable was set but has an empty value. These are distinct states and
depending on which one you want, the solutions are very different.
pb> So with that said I must check for the existence of the variable
pb> before I create the rule.
No, that's not the only solution.
The traditional solution is to put the contents of the make variable
into a shell variable, then use shell syntax to test it. Something like
this:
foo:
@shellvar='$(MAKEVAR)'; \
if [ -z "$$shellvar" ]; then \
echo "empty"; \
else \
echo "not empty"; \
fi
This is portable to any make. As an alternative, you can use GNU make's
$(if ...) function so that the condition is tested in make before the
shell is even invoked:
foo:
@echo "$(if $(MAKEVAR),not )empty"
pb> Steps I would need to create this
pb> 2. find the origin of the string
pb> $(origin $(call merge,+,$(call uc,$(flow)) $(proj) $(bb) $(sub))
pb> 3. find the string "file"
pb> $(findstring file,$(origin $(call merge,+,$(call uc,$(flow)) $(proj)
pb> $(bb) $(sub))
I've said in the past: I really discourage use of findstring and subst
unless you REALLY need them. They're dangerous because they match any
substring, anywhere. Everywhere possible you should use patsubst,
filter, and filter-out as they match only entire words; they won't be
fooled by things like "somefile" etc.
Also, why do you want to test for "file"? What if someone sets one of
these variables on the command line? Then this test won't match.
I think this is the wrong approach. You should test directly for what
you care about (whether the value exists or not), not what you don't
really care about (where the value originates from).
--
-------------------------------------------------------------------------------
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