@@ -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,27 +111,42 @@ 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 = { }
123+ , post_variables = [ 'cflags' , 'defines' , 'include_dirs' , 'libraries' ]
119124
120125 // default "config.variables"
121126 if ( ! variables ) variables = config . variables = { }
122127
123128 // default "config.defaults"
124129 if ( ! defaults ) defaults = config . target_defaults = { }
125130
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.
127144 // doing so could cause problems in cases where the `node` executable was
128145 // compiled on a different machine (with different lib/include paths) than
129146 // 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+ } )
134150
135151 // set the default_configuration prop
136152 if ( 'debug' in gyp . opts ) {
@@ -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