[build2] Access to environment variables

Moldmann Max (DC-MH/ENG52-NA) Max.Moldmann at boschrexroth-us.com
Mon Aug 28 20:44:17 UTC 2017


Hello Boris,

Thanks this works! 
...Unfortunately only for one directory. So I currently have to do this in the config.build file:

config.c.poptions = "-I$getenv(HEADERS_1)" "-I$getenv(HEADERS_2)" "-I$getenv(HEADERS_3)" "-I$getenv(HEADERS_4)"
config.c.libs = $getenv(LIBRARY_1) $getenv(LIBRARY_2) $getenv(LIBRARY_3) $getenv(LIBRARY_4)

instead of just one list that contains them all:

config.c.poptions = "$getenv(HEADERS)"
config.c.libs = "$getenv(LIBRARIES)"

But when I try this and add this line in the buildfile:

print $config.c.poptions

I get this for the separate headers:

-Ic:/dir1 -IC:/dir2 -IC:/dir3 -IC:/dir4

And this for the all in one environment variable:

"-Ic:/dir1" "-IC:/dir2" "-IC:/dir3" "-IC:/dir4"

But the compiler considers this as an invalid argument and thus doesn't find the header files.

Removing the quotes around getenv() yields:

error: type mismatch in variable config.c.poptions
  info: value type is string
  info: variable type is strings

Would be awesome if you could find a way for this to work for multiple options at one!


Max


-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Friday, June 23, 2017 4:10 AM
To: Moldmann Max (DC-MA/ENG52-NA) <Max.Moldmann at boschrexroth-us.com>
Cc: users at build2.org
Subject: Re: [build2] Access to environment variables

Moldmann Max (DC-MA/ENG52-NA) <Max.Moldmann at boschrexroth-us.com> writes:

> Is it possible to access environment variables in config.build?

If you get the latest staged[1] toolchain, then you can use the getenv() function. For example:

print $getenv(PATH)

cxx.poptions += "-I$getenv(MY_HEADER_DIR)"

[1] https://stage.build2.org/0/

Boris



More information about the users mailing list