Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use environment variable in gyp

Tags:

gyp

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?

like image 559
John Avatar asked Aug 18 '15 11:08

John


2 Answers

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).

like image 143
vladon Avatar answered Sep 26 '22 15:09

vladon


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

like image 43
lexa-b Avatar answered Sep 24 '22 15:09

lexa-b