6

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?

John
  • 2,910
  • 2
  • 23
  • 41

2 Answers2

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

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

lexa-b
  • 1,261
  • 12
  • 15