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?
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
).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With