[Omake] environments & export

Aleksey Nogin nogin at metaprl.org
Tue Sep 19 14:04:38 PDT 2006


On 19.09.2006 13:07, Janne Hellsten wrote:

> I'm a little confused.  I'm sorry if this is a FAQ..
> 
> I have the following code in my OMakefile:
> 
> 8<
> TESTS=\
>     test_cache_speed test_samples \
>     test_arm_asm
> 
> if $(equal $(ARM_ELF_TOOLCHAIN),true)
>     TESTS+=test_arm_interp
> 8<
> 
> However, if ARM_ELF_TOOLCHAIN is equal to true, TESTS doesn't get
> added the value "test_arm_interp".  This happens only if I rewrite the
> if like so:
> 
> 8<
> if $(equal $(ARM_ELF_TOOLCHAIN),true)
>     TESTS+=test_arm_interp
>       export
> 8<
> 
> I would've expected TESTS in the enclosing environment to become
> updated.  Apparently what happens now is that TESTS becomes a fresh
> variable inside the "if" and never gets exported to the upper scope.
> 
> Is this the expected behaviour? 

Yes. By default, every time you enter any kind of indented section, you 
are creating a private variable scope. If you want the values to escape, 
you need to export them explicitly.

Consider:

if $(FOO_REQUIRES_EXTRA_CFLAGS)
    CFLAGS+=...
    CProgram(foo)

Here, it is intentional that the CFLAGS changes stay private. In 
general, OMake is fairly conservative - there were cases where OMake 
used to export automatically, but in each of those would always ended up 
realizing that this created problems, so we always ended up changing 
things so that an explicit export is required.

P.S. Unrelated - for things like lists of files (like your TESTS 
variable above), it may be a good idea to use an array instead of a 
space-separated string:

TESTS[] =
    test_cache_speed
    test_samples
    test_arm_asm

P.P.S. You do not need to compare things to "true" - the following 
should also work:

if $(ARM_ELF_TOOLCHAIN)
    TESTS += ...
    ...

See also http://omake.metaprl.org/omake-base.html#section:logic


More information about the Omake mailing list