help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there any value in a lisp-like $(cond ...) function?


From: Eric Melski
Subject: Re: Is there any value in a lisp-like $(cond ...) function?
Date: Thu, 16 Dec 2010 19:09:50 -0800
User-agent: Thunderbird 2.0.0.24 (X11/20100623)

J.T. Conklin wrote:
While testing my implementation, I realized that using $(or ...) can
mostly approximate this:

        t:
                $(or $(if ${COND1},${RESULTS1}), \
                     $(if ${COND2},${RESULTS2}), \
                     $(if ${COND3},${RESULTS3}), \
                     ${RESULTS4})


The significant difference is that if ${CONDN} is true but ${RESULTN}
expands to false, $(or ...) will continue on where $(cond ...) would have stopped. Accidently adding an else-part to an $(if ...) would
cause problems too.

You don't show what CONDN or RESULTSN are in your case, but generally speaking at least, you can address your first concern above by appending a space character _after_ the reference to each RESULTSN variable. For example:

        t:
                $(or $(if ${COND1},${RESULTS1} ), \
                     $(if ${COND2},${RESULTS2} ), \
                    $(if ${COND3},${RESULTS3} ), \
                    ${RESULTS4})


That's sufficient to make the expression evaluate to "true" for purposes of gmake and short-circuit out of the evaluation of the other expressions. You can trace which expressions are evaluated by inserting a $(info) call into them, like this:

        COND1=$(info COND1)
        COND2=$(info COND2)
        COND3=$(info COND3)
        RESULTS1=$(info RESULTS1)
        RESULTS2=$(info RESULTS2)
        RESULTS3=$(info RESULTS3)
        RESULTS4=$(info RESULTS4)


With this set of values, you'll see that COND1, COND2, COND3 and RESULTS4 are evaluated; change COND2 to "$(info COND2)x" (again, the x is enough to make it "true") and instead you get COND1, COND2 and RESULTS2 evaluated.

Hope that helps,

Eric Melski
Electric Cloud, Inc.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]