Can i use the environment variable in gyp

I am completely new to gyp, so please excuse my ignorance of the subject - I am trying to incorporate a project that uses gyp into the larger environment created by make. The .gyp file has the -L option for the C file, and it points to hard code. I would like to modify it to point to a directory based on the variable specified in the parent make file of the project.
I can use sed to find and replace the string before I build the project, but that seems messy. I am wondering if it is possible to access the environment variable from the gyp file?

+4
source share
2 answers

Yes, you can use the 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, e.g. echo $OPENSSL_DIR ).

+4
source

to determine cross-platform, use the "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 more details see Variable Extensions and Conditional Parameters.

+4
source

All Articles