@@ -33,6 +33,7 @@ function configure (gyp, argv, callback) {
33
33
, buildDir = path . resolve ( 'build' )
34
34
, configNames = [ 'config.gypi' , 'common.gypi' ]
35
35
, configs = [ ]
36
+ , post_configs = [ ]
36
37
, nodeDir
37
38
, release = processRelease ( argv , gyp , process . version , process . release )
38
39
@@ -110,27 +111,42 @@ function configure (gyp, argv, callback) {
110
111
111
112
var configFilename = 'config.gypi'
112
113
var configPath = path . resolve ( buildDir , configFilename )
114
+ var postConfigFilename = 'post_config.gypi'
115
+ var postConfigPath = path . resolve ( buildDir , postConfigFilename )
113
116
114
117
log . verbose ( 'build/' + configFilename , 'creating config file' )
115
118
116
119
var config = process . config || { }
117
120
, defaults = config . target_defaults
118
121
, variables = config . variables
122
+ , fallback_target_defaults = { }
123
+ , post_variables = [ 'cflags' , 'defines' , 'include_dirs' , 'libraries' ]
119
124
120
125
// default "config.variables"
121
126
if ( ! variables ) variables = config . variables = { }
122
127
123
128
// default "config.defaults"
124
129
if ( ! defaults ) defaults = config . target_defaults = { }
125
130
126
- // don't inherit the "defaults" from node's `process.config` object.
131
+ if ( variables . node_shared_cares ||
132
+ variables . node_shared_http_parser ||
133
+ variables . node_shared_libuv ||
134
+ variables . node_shared_openssl ||
135
+ variables . node_shared_zlib ) {
136
+ Object . keys ( defaults ) . forEach ( function ( entry ) {
137
+ if ( post_variables . indexOf ( entry ) > 0 ) {
138
+ fallback_target_defaults [ entry ] = defaults [ entry ]
139
+ }
140
+ } )
141
+ }
142
+ // if node engine does not have to rely on shared libraries in the system
143
+ // do not inherit the "defaults" from node's `process.config` object.
127
144
// doing so could cause problems in cases where the `node` executable was
128
145
// compiled on a different machine (with different lib/include paths) than
129
146
// the machine where the addon is being built to
130
- defaults . cflags = [ ]
131
- defaults . defines = [ ]
132
- defaults . include_dirs = [ ]
133
- defaults . libraries = [ ]
147
+ post_variables . forEach ( function ( post_var ) {
148
+ defaults [ post_var ] = [ ]
149
+ } )
134
150
135
151
// set the default_configuration prop
136
152
if ( 'debug' in gyp . opts ) {
@@ -186,7 +202,17 @@ function configure (gyp, argv, callback) {
186
202
, json = JSON . stringify ( config , boolsToString , 2 )
187
203
log . verbose ( 'build/' + configFilename , 'writing out config file: %s' , configPath )
188
204
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
+ } )
190
216
}
191
217
192
218
function findConfigs ( err ) {
@@ -291,6 +317,9 @@ function configure (gyp, argv, callback) {
291
317
292
318
argv . push ( '-I' , addon_gypi )
293
319
argv . push ( '-I' , common_gypi )
320
+ post_configs . forEach ( function ( config ) {
321
+ argv . push ( '-I' , config )
322
+ } )
294
323
argv . push ( '-Dlibrary=shared_library' )
295
324
argv . push ( '-Dvisibility=default' )
296
325
argv . push ( '-Dnode_root_dir=' + nodeDir )
0 commit comments