Best way to do conditionals ?
David Chase
david.r.chase at oracle.com
Fri Apr 12 13:39:46 UTC 2013
Sanity check -- this is make 3.81, right?
I checked on both MacOS 10.8 and Ubuntu
Because (as is always the case) "it works for me":
--------------
JVM_VARIANT_SERVER := true
JVM_VARIANT_CLIENT := true
CLIENT_AND_SERVER1 := $(and $(findstring true, $(JVM_VARIANT_SERVER)), $(findstring true, $(JVM_VARIANT_CLIENT)))
CLIENT_AND_SERVER2 := $(and $(JVM_VARIANT_SERVER), $(JVM_VARIANT_CLIENT))
ifeq ($(CLIENT_AND_SERVER1), true)
one: two
@echo one then C=$(JVM_VARIANT_CLIENT) S=$(JVM_VARIANT_SERVER) BOTH1=$(CLIENT_AND_SERVER1) BOTH2=$(CLIENT_AND_SERVER2)
else
one: two
@echo one else C=$(JVM_VARIANT_CLIENT) S=$(JVM_VARIANT_SERVER) BOTH1=$(CLIENT_AND_SERVER1) BOTH2=$(CLIENT_AND_SERVER2)
endif
ifeq ($(CLIENT_AND_SERVER2), true)
two:
@echo two then C=$(JVM_VARIANT_CLIENT) S=$(JVM_VARIANT_SERVER) BOTH1=$(CLIENT_AND_SERVER1) BOTH2=$(CLIENT_AND_SERVER2)
else
two:
@echo two else C=$(JVM_VARIANT_CLIENT) S=$(JVM_VARIANT_SERVER) BOTH1=$(CLIENT_AND_SERVER1) BOTH2=$(CLIENT_AND_SERVER2)
endif
-----------------
"make one" yields
two then C=true S=true BOTH1=true BOTH2=true
one then C=true S=true BOTH1=true BOTH2=true
I experimented with string "true" instead of true and with " true "
and got the expected results (findstring true, as-boolean false).
So what's different about our glorious Makefiles?
Is it possibly indentation-related? No, only if the indent is a tab, and then it gets noisy:
make
Makefile:11: warning: overriding commands for target `one'
Makefile:8: warning: ignoring old commands for target `one'
two then C=true S=true BOTH1=true BOTH2=true
one else C=true S=true BOTH1=true BOTH2=true
David
On 2013-04-12, at 8:33 AM, David Holmes <david.holmes at oracle.com> wrote:
> On 12/04/2013 7:02 PM, David Holmes wrote:
>> I need to examine the JVM_VARIANT(S) variables and logically I want to do:
>>
>> if (client and server)
>> ...
>> else
>> ...
>> endif
>>
>>
>> Nesting if blocks doesn't work - I need a conjunction, or a way to
>> define a single variable using a conjunction.
>>
>> Suggestions?
>
> So I re-discovered the "and" operation
>
> CLIENT_AND_SERVER := $(and $(findstring true, $(JVM_VARIANT_SERVER)), $(findstring true, $(JVM_VARIANT_CLIENT)))
> ifeq ($(CLIENT_AND_SERVER), true)
> # Use the committed jvm.cfg for this 32 bit setup but add
> # minimal if needed
> $(JVMCFG): $(JVMCFG_SRC)
> $(call install-file)
> ifeq ($(JVM_VARIANT_MINIMAL1), true)
> $(PRINTF) "-minimal KNOWN\n">>$(@)
> endif
> else
> $(JVMCFG):
> @$(ECHO) C=$(JVM_VARIANT_CLIENT) S=$(JVM_VARIANT_SERVER) BOTH=$(CLIENT_AND_SERVER)
>
> Yet I always execute the else but print:
>
> C=true S=true BOTH=true
>
>
> I'm stumped! :(
>
> Thanks,
> David
More information about the build-dev
mailing list