diff --git a/lib/configure.js b/lib/configure.js index 44611dc..b07232e 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -29,7 +29,8 @@ function configure (gyp, argv, callback) { , hasVC2012Express = false , hasWin71SDK = false , hasWin8SDK = false - , configPath + , configNames = [ 'config.gypi', 'common.gypi' ] + , configs = [] , nodeDir @@ -241,9 +242,9 @@ function configure (gyp, argv, callback) { if (err) return callback(err) var configFilename = 'config.gypi' - configPath = path.resolve(buildDir, configFilename) + var configPath = path.resolve(buildDir, configFilename) - log.verbose(configFilename, 'creating config file') + log.verbose('build/' + configFilename, 'creating config file') var config = process.config || {} , defaults = config.target_defaults @@ -311,13 +312,34 @@ function configure (gyp, argv, callback) { return v } - log.silly(configFilename, config) + log.silly('build/' + configFilename, config) // now write out the config.gypi file to the build/ dir var prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step' , json = JSON.stringify(config, boolsToString, 2) - log.verbose(configFilename, 'writing out config file: %s', configPath) - fs.writeFile(configPath, [prefix, json, ''].join('\n'), runGyp) + log.verbose('build/' + configFilename, 'writing out config file: %s', configPath) + configs.push(configPath) + fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs) + } + + function findConfigs (err) { + if (err) return callback(err) + var name = configNames.shift(); + if (!name) return runGyp(); + var fullPath = path.resolve(name); + log.verbose(name, 'checking for gypi file: %s', fullPath); + fs.stat(fullPath, function (err, stat) { + if (err) { + if (err.code == 'ENOENT') { + findConfigs() // check next gypi filename + } else { + callback(err) + } + } else { + configs.push(fullPath); + findConfigs() + } + }); } function runGyp (err) { @@ -349,8 +371,10 @@ function configure (gyp, argv, callback) { } } - // include the "config.gypi" file that was generated - argv.push('-I', configPath) + // include all the ".gypi" files that were found + configs.forEach(function (config) { + argv.push('-I', config) + }) // this logic ported from the old `gyp_addon` python file var gyp_script = path.resolve(nodeDir, 'tools', 'gyp', 'gyp')