I'm totally new to gyp, so please excuse any ignorance on the subject -- I'm trying to incorporate a project which uses gyp into a larger environment generated by make. The .gyp file in question has a -L option for a C file, and it points to a hardcoded directory. I'd like to change it to point to a directory based on a variable set in the parent project's makefile.
I can use sed to do a search and replace of the string before I build the project, but this seems messy. I'm wondering if it's possible to access an environmental variable from within a gyp file?
Asked
Active
Viewed 1,731 times
6
![](../../users/profiles/1228628.webp)
John
- 2,910
- 2
- 23
- 41
2 Answers
5
Yes, you can use shell command, for example:
...
'include_dirs': [
'<!(echo %OPENSSL_DIR%)/include',
'<!(echo %BOOST_DIR%)',
'<!(echo %SQLITE_DIR%)',
],
...
(this syntax is for Windows, for Linux use $
in env vars, like echo $OPENSSL_DIR
).
![](../../users/profiles/1555823.webp)
vladon
- 7,412
- 1
- 35
- 75
4
for crossplatform definition, use 'conditions' directive
'include_dirs': [
...
],
'conditions': [
['OS=="win"', {
'include_dirs': [
'<!(echo %OPENSSL_DIR%)/include',
'<!(echo %BOOST_DIR%)',
'<!(echo %SQLITE_DIR%)'
]
}],
['OS!="win"', {
'include_dirs': [
'<!(echo $OPENSSL_DIR)/include',
'<!(echo $BOOST_DIR)',
'<!(echo $SQLITE_DIR)'
]
}]
]
for details see Variable Expansions and Conditionals
![](../../users/profiles/3263174.webp)
lexa-b
- 1,261
- 12
- 15