diff --git a/lib/configure.js b/lib/configure.js index 19374b7275..9644897d31 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -33,6 +33,7 @@ function configure (gyp, argv, callback) { , buildDir = path.resolve('build') , configNames = [ 'config.gypi', 'common.gypi' ] , configs = [] + , post_configs = [] , nodeDir , release = processRelease(argv, gyp, process.version, process.release) @@ -110,12 +111,16 @@ function configure (gyp, argv, callback) { var configFilename = 'config.gypi' var configPath = path.resolve(buildDir, configFilename) + var postConfigFilename = 'post_config.gypi' + var postConfigPath = path.resolve(buildDir, postConfigFilename) log.verbose('build/' + configFilename, 'creating config file') var config = process.config || {} , defaults = config.target_defaults , variables = config.variables + , fallback_target_defaults = {} + , post_variables = ['cflags', 'defines', 'include_dirs', 'libraries'] // default "config.variables" if (!variables) variables = config.variables = {} @@ -123,14 +128,25 @@ function configure (gyp, argv, callback) { // default "config.defaults" if (!defaults) defaults = config.target_defaults = {} - // don't inherit the "defaults" from node's `process.config` object. + if ( variables.node_shared_cares || + variables.node_shared_http_parser || + variables.node_shared_libuv || + variables.node_shared_openssl || + variables.node_shared_zlib ) { + Object.keys(defaults).forEach(function (entry) { + if (post_variables.indexOf(entry) > 0) { + fallback_target_defaults[entry] = defaults[entry] + } + }) + } + // if node engine does not have to rely on shared libraries in the system + // do not inherit the "defaults" from node's `process.config` object. // doing so could cause problems in cases where the `node` executable was // compiled on a different machine (with different lib/include paths) than // the machine where the addon is being built to - defaults.cflags = [] - defaults.defines = [] - defaults.include_dirs = [] - defaults.libraries = [] + post_variables.forEach(function (post_var) { + defaults[post_var] = [] + }) // set the default_configuration prop if ('debug' in gyp.opts) { @@ -186,7 +202,17 @@ function configure (gyp, argv, callback) { , json = JSON.stringify(config, boolsToString, 2) log.verbose('build/' + configFilename, 'writing out config file: %s', configPath) configs.push(configPath) - fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs) + fs.writeFile(configPath, [prefix, json, ''].join('\n'), function() { + + var config = { + "target_defaults": fallback_target_defaults + } + , prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step' + , json = JSON.stringify(config, boolsToString, 2) + log.verbose('build/' + postConfigFilename, 'writing out config file: %s', postConfigPath) + post_configs.push(postConfigPath) + fs.writeFile(postConfigPath, [prefix, json, ''].join('\n'), findConfigs) + }) } function findConfigs (err) { @@ -291,6 +317,9 @@ function configure (gyp, argv, callback) { argv.push('-I', addon_gypi) argv.push('-I', common_gypi) + post_configs.forEach(function (config) { + argv.push('-I', config) + }) argv.push('-Dlibrary=shared_library') argv.push('-Dvisibility=default') argv.push('-Dnode_root_dir=' + nodeDir)