Skip to content

Commit ef57808

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 d3478d7 commit ef57808

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

Diff for: lib/configure.js

+35-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function configure (gyp, argv, callback) {
2828
, buildDir = path.resolve('build')
2929
, configNames = [ 'config.gypi', 'common.gypi' ]
3030
, configs = []
31+
, post_configs = []
3132
, nodeDir
3233
, release = processRelease(argv, gyp, process.version, process.release)
3334

@@ -97,27 +98,42 @@ function configure (gyp, argv, callback) {
9798

9899
var configFilename = 'config.gypi'
99100
var configPath = path.resolve(buildDir, configFilename)
101+
var postConfigFilename = 'post_config.gypi'
102+
var postConfigPath = path.resolve(buildDir, postConfigFilename)
100103

101104
log.verbose('build/' + configFilename, 'creating config file')
102105

103106
var config = process.config || {}
104107
, defaults = config.target_defaults
105108
, variables = config.variables
109+
, fallback_target_defaults = {}
110+
, post_variables = ['cflags', 'defines', 'include_dirs', 'libraries']
106111

107112
// default "config.variables"
108113
if (!variables) variables = config.variables = {}
109114

110115
// default "config.defaults"
111116
if (!defaults) defaults = config.target_defaults = {}
112117

113-
// don't inherit the "defaults" from node's `process.config` object.
118+
if ( variables.node_shared_cares ||
119+
variables.node_shared_http_parser ||
120+
variables.node_shared_libuv ||
121+
variables.node_shared_openssl ||
122+
variables.node_shared_zlib ) {
123+
Object.keys(defaults).forEach(function (entry) {
124+
if (post_variables.indexOf(entry) > 0) {
125+
fallback_target_defaults[entry] = defaults[entry]
126+
}
127+
})
128+
}
129+
// if node engine does not have to rely on shared libraries in the system
130+
// do not inherit the "defaults" from node's `process.config` object.
114131
// doing so could cause problems in cases where the `node` executable was
115132
// compiled on a different machine (with different lib/include paths) than
116133
// the machine where the addon is being built to
117-
defaults.cflags = []
118-
defaults.defines = []
119-
defaults.include_dirs = []
120-
defaults.libraries = []
134+
post_variables.forEach(function (post_var) {
135+
defaults[post_var] = []
136+
})
121137

122138
// set the default_configuration prop
123139
if ('debug' in gyp.opts) {
@@ -182,7 +198,17 @@ function configure (gyp, argv, callback) {
182198
, json = JSON.stringify(config, boolsToString, 2)
183199
log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
184200
configs.push(configPath)
185-
fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs)
201+
fs.writeFile(configPath, [prefix, json, ''].join('\n'), function() {
202+
203+
var config = {
204+
"target_defaults": fallback_target_defaults
205+
}
206+
, prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
207+
, json = JSON.stringify(config, boolsToString, 2)
208+
log.verbose('build/' + postConfigFilename, 'writing out config file: %s', postConfigPath)
209+
post_configs.push(postConfigPath)
210+
fs.writeFile(postConfigPath, [prefix, json, ''].join('\n'), findConfigs)
211+
})
186212
}
187213

188214
function findConfigs (err) {
@@ -280,6 +306,9 @@ function configure (gyp, argv, callback) {
280306

281307
argv.push('-I', addon_gypi)
282308
argv.push('-I', common_gypi)
309+
post_configs.forEach(function (config) {
310+
argv.push('-I', config)
311+
})
283312
argv.push('-Dlibrary=shared_library')
284313
argv.push('-Dvisibility=default')
285314
argv.push('-Dnode_root_dir=' + nodeDir)

0 commit comments

Comments
 (0)