[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
$(if-eq ...)
From: |
Stephan Beal |
Subject: |
$(if-eq ...) |
Date: |
Fri, 29 Jun 2007 18:17:52 +0200 |
User-agent: |
KMail/1.9.7 |
Hi, all!
i'm trying to implement an $(if-eq ...) function which goes a little
something like this:
$(call if-eq,LHS,RHS,THEN[,ELSE])
The intention is of course to get an inline equivalent of:
ifeq (LHS,RHS)
...
endif
i've got it working, but of course it's missing the short-circuit
features of built-ins, e.g. so that the $(error) in:
$(if X,,$(error this is an error))
will only be evaluated if !X. That works for built-ins of course, but i
don't see a way to do it with add-on funcs.
The code is trivial:
define if-eq
ifeq ($1,$2)
$3
else
$4
endif
endef
Two tests:
$(eval $(call if-eq,1,2,\
$$(error this should not happen),\
$$(warning this should happen)))
$(eval $(call if-eq,abc,abc,\
$$(warning this should happen),\
$$(error this should not happen)))
That runs correctly, but requires that i use $$ on warning/eval and then
wrap the whole thing in an eval statement.
Does anyone know a way (or kludge) that i can use to get the
short-circuit evaluation of the THEN/ELSE parts, such that i could do:
$(call if-eq,A,B,$(error A does not equal B),$(eval something-else))
without actually running the $(error) or $(eval something-else) when
those parts do not apply?
One of the limitations i'm working with (against?) is that i can't use
features which are new in 3.81 because i'll eventually be targetting
machines where 3.80 can be expected but where an upgrade to 3.81+
cannot be expected.
--
----- stephan beal
http://www.wanderinghorse.net
signature.asc
Description: This is a digitally signed message part.