[Rake-devel] make like variables?
Ittay Dror
ittay.dror at gmail.com
Sun Sep 7 01:20:45 EDT 2008
Ittay Dror wrote:
>
>
> Jim Weirich wrote:
>>
>> On Sep 6, 2008, at 2:21 AM, Ittay Dror wrote:
>>
>>> in make, if in my Makefile I have
>>> FOO = 1
>>> FOO += 2
>>> test:
>>> echo $(FOO)
>>>
>>> then running:
>>> > make
>>> 1 2
>>> > make FOO=3
>>> 3
>>>
>>> That is, if passed in the command line, any assignments to FOO are
>>> ignored. In Makefile, this can be changed by using the 'override'
>>> method. It is not that important, just an idiom that people coming
>>> from Make expect. Obviously, Rakefile being Ruby this sort of
>>> behavior can be done.
>>
>>
>> I think if I had to do this, I would use an idiom like:
>>
>> ENV['FOO'] ||= 1
> yes, but then ENV['FOO'] += 1 will increase FOO by one, which is not
> the Make behavior.
>>
>> I really don't have control over how ruby variables are assigned.
>> I'm not sure how to do it in rake for any arbitrary variable.
>>
> I didn't mean to do it for arbitrary variables, instead, accessing
> variables through an object that controls the behavior.
>
> I don't think this in itself (mimicking the exact behavior of Make) is
> worth the hassle, but providing a nicer interface to dealing with
> command line variables might be, for example, if the object
> controlling variables also knows how to handle 'FOO+=a' and 'FOO-=b'
> in the command line, it could be a nice feature, mainly for C/C++ builds.
unfortunately, this cannot be done currently, since rake uses the Regexp
/^(\w+)=(.*)$/ to match command line variables, which doesn't apply to
things like F+++=a or FOO-=b. Instead, they are interpreted as task
names. This is also the case for 'foo.bar=val' (dotted variables are
common in java)
In general, I think it is better to use the regexp /^(.+)=(.*)$/,
restricting task names to not use '=' and allowing more characters in
variable names.
Ittay
>
> If you like, since I need such behavior anyway, I can post it when it
> is ready.
>
> Ittay
>
--
--
Ittay Dror <ittay.dror at gmail.com>
More information about the Rake-devel
mailing list