@@ -28,6 +28,7 @@ function configure (gyp, argv, callback) {
28
28
, buildDir = path . resolve ( 'build' )
29
29
, configNames = [ 'config.gypi' , 'common.gypi' ]
30
30
, configs = [ ]
31
+ , post_configs = [ ]
31
32
, nodeDir
32
33
, release = processRelease ( argv , gyp , process . version , process . release )
33
34
@@ -97,27 +98,42 @@ function configure (gyp, argv, callback) {
97
98
98
99
var configFilename = 'config.gypi'
99
100
var configPath = path . resolve ( buildDir , configFilename )
101
+ var postConfigFilename = 'post_config.gypi'
102
+ var postConfigPath = path . resolve ( buildDir , postConfigFilename )
100
103
101
104
log . verbose ( 'build/' + configFilename , 'creating config file' )
102
105
103
106
var config = process . config || { }
104
107
, defaults = config . target_defaults
105
108
, variables = config . variables
109
+ , fallback_target_defaults = { }
110
+ , post_variables = [ 'cflags' , 'defines' , 'include_dirs' , 'libraries' ]
106
111
107
112
// default "config.variables"
108
113
if ( ! variables ) variables = config . variables = { }
109
114
110
115
// default "config.defaults"
111
116
if ( ! defaults ) defaults = config . target_defaults = { }
112
117
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.
114
131
// doing so could cause problems in cases where the `node` executable was
115
132
// compiled on a different machine (with different lib/include paths) than
116
133
// 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
+ } )
121
137
122
138
// set the default_configuration prop
123
139
if ( 'debug' in gyp . opts ) {
@@ -182,7 +198,17 @@ function configure (gyp, argv, callback) {
182
198
, json = JSON . stringify ( config , boolsToString , 2 )
183
199
log . verbose ( 'build/' + configFilename , 'writing out config file: %s' , configPath )
184
200
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
+ } )
186
212
}
187
213
188
214
function findConfigs ( err ) {
@@ -280,6 +306,9 @@ function configure (gyp, argv, callback) {
280
306
281
307
argv . push ( '-I' , addon_gypi )
282
308
argv . push ( '-I' , common_gypi )
309
+ post_configs . forEach ( function ( config ) {
310
+ argv . push ( '-I' , config )
311
+ } )
283
312
argv . push ( '-Dlibrary=shared_library' )
284
313
argv . push ( '-Dvisibility=default' )
285
314
argv . push ( '-Dnode_root_dir=' + nodeDir )
0 commit comments