Skip to content

Commit bcb3f7f

Browse files
committed
Use post_config.gypi to use shared libraries
Node can be compiled with external shared libraries; in this case append their compile and linker flags last.
1 parent 7245415 commit bcb3f7f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

lib/configure.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function configure (gyp, argv, callback) {
3333
, buildDir = path.resolve('build')
3434
, configNames = [ 'config.gypi', 'common.gypi' ]
3535
, configs = []
36+
, post_configs = []
3637
, nodeDir
3738
, release = processRelease(argv, gyp, process.version, process.release)
3839

@@ -110,20 +111,35 @@ function configure (gyp, argv, callback) {
110111

111112
var configFilename = 'config.gypi'
112113
var configPath = path.resolve(buildDir, configFilename)
114+
var postConfigFilename = 'post_config.gypi'
115+
var postConfigPath = path.resolve(buildDir, postConfigFilename)
113116

114117
log.verbose('build/' + configFilename, 'creating config file')
115118

116119
var config = process.config || {}
117120
, defaults = config.target_defaults
118121
, variables = config.variables
122+
, fallback_target_defaults = {}
119123

120124
// default "config.variables"
121125
if (!variables) variables = config.variables = {}
122126

123127
// default "config.defaults"
124128
if (!defaults) defaults = config.target_defaults = {}
125129

126-
// don't inherit the "defaults" from node's `process.config` object.
130+
if ( variables.node_shared_cares ||
131+
variables.node_shared_http_parser ||
132+
variables.node_shared_libuv ||
133+
variables.node_shared_openssl ||
134+
variables.node_shared_zlib ) {
135+
Object.keys(defaults).forEach(function (entry) {
136+
if (entry in {'cflags': 1, 'defines': 1, 'include_dirs': 1, 'libraries': 1}) {
137+
fallback_target_defaults[entry] = defaults[entry]
138+
}
139+
})
140+
}
141+
// if node engine does not have to rely on shared libraries in the system
142+
// do not inherit the "defaults" from node's `process.config` object.
127143
// doing so could cause problems in cases where the `node` executable was
128144
// compiled on a different machine (with different lib/include paths) than
129145
// the machine where the addon is being built to
@@ -186,7 +202,17 @@ function configure (gyp, argv, callback) {
186202
, json = JSON.stringify(config, boolsToString, 2)
187203
log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
188204
configs.push(configPath)
189-
fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs)
205+
fs.writeFile(configPath, [prefix, json, ''].join('\n'), function() {
206+
207+
var config = {
208+
"target_defaults": fallback_target_defaults
209+
}
210+
, prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
211+
, json = JSON.stringify(config, boolsToString, 2)
212+
log.verbose('build/' + postConfigFilename, 'writing out config file: %s', postConfigPath)
213+
post_configs.push(postConfigPath)
214+
fs.writeFile(postConfigPath, [prefix, json, ''].join('\n'), findConfigs)
215+
})
190216
}
191217

192218
function findConfigs (err) {
@@ -291,6 +317,9 @@ function configure (gyp, argv, callback) {
291317

292318
argv.push('-I', addon_gypi)
293319
argv.push('-I', common_gypi)
320+
post_configs.forEach(function (config) {
321+
argv.push('-I', config)
322+
})
294323
argv.push('-Dlibrary=shared_library')
295324
argv.push('-Dvisibility=default')
296325
argv.push('-Dnode_root_dir=' + nodeDir)

0 commit comments

Comments
 (0)