configure: port the gyp_addon login into the "configure" step

Now `tools/gyp_addon` can be removed from the node repo.
Part of joyent/node#3760.
This commit is contained in:
Nathan Rajlich 2012-08-12 14:27:59 -07:00
parent 11808b4397
commit d770292b99
2 changed files with 57 additions and 12 deletions

24
addon.gypi Normal file
View file

@ -0,0 +1,24 @@
{
'target_defaults': {
'type': 'loadable_module',
'product_extension': 'node',
'product_prefix': '',
'include_dirs': [
'<(node_root_dir)/src',
'<(node_root_dir)/deps/uv/include',
'<(node_root_dir)/deps/v8/include'
],
'conditions': [
[ 'OS=="mac"', {
'libraries': [ '-undefined dynamic_lookup' ],
}],
[ 'OS=="win"', {
'libraries': [ '-l<(node_root_dir)/$(Configuration)/node.lib' ],
}],
[ 'OS=="freebsd" or OS=="openbsd" or OS=="solaris" or (OS=="linux" and target_arch!="ia32")', {
'cflags': [ '-fPIC' ],
}]
]
}
}

View file

@ -274,22 +274,19 @@ function configure (gyp, argv, callback) {
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'), runGypAddon)
fs.writeFile(configPath, [prefix, json, ''].join('\n'), runGyp)
}
function runGypAddon (err) {
function runGyp (err) {
if (err) return callback(err)
// location of the `gyp_addon` python script for the target nodedir
var gyp_addon = path.resolve(nodeDir, 'tools', 'gyp_addon')
if (!~argv.indexOf('-f') && !~argv.indexOf('--format')) {
if (win) {
log.verbose('gyp_addon', 'gyp format was not specified; forcing "msvs"')
log.verbose('gyp', 'gyp format was not specified; forcing "msvs"')
// force the 'make' target for non-Windows
argv.push('-f', 'msvs')
} else {
log.verbose('gyp_addon', 'gyp format was not specified; forcing "make"')
log.verbose('gyp', 'gyp format was not specified; forcing "make"')
// force the 'make' target for non-Windows
argv.push('-f', 'make')
}
@ -310,25 +307,49 @@ function configure (gyp, argv, callback) {
}
// include the "config.gypi" file that was generated
argv.unshift('-I' + configPath)
argv.push('-I', configPath)
// this logic ported from the old `gyp_addon` python file
var gyp_script = path.resolve(nodeDir, 'tools', 'gyp', 'gyp')
var addon_gypi = path.resolve(__dirname, '..', 'addon.gypi')
var common_gypi = path.resolve(nodeDir, 'common.gypi')
var output_dir = 'build'
if (win) {
// Windows expects an absolute path
output_dir = buildDir
}
argv.push('-I', addon_gypi)
argv.push('-I', common_gypi)
argv.push('-Dlibrary=shared_library')
argv.push('-Dvisibility=default')
argv.push('-Dnode_root_dir=' + nodeDir)
argv.push('-Dmodule_root_dir=' + process.cwd())
argv.push('--depth=.');
// tell gyp to write the Makefile/Solution files into output_dir
argv.push('--generator-output', output_dir)
// tell make to write its output into the same dir
argv.push('-Goutput_dir=.')
// enforce use of the "binding.gyp" file
argv.unshift('binding.gyp')
// execute `gyp_addon` from the current target nodedir
argv.unshift(gyp_addon)
// execute `gyp` from the current target nodedir
argv.unshift(gyp_script)
var cp = gyp.spawn(python, argv)
cp.on('exit', onCpExit)
}
/**
* Called when the `gyp_addon` child process exits.
* Called when the `gyp` child process exits.
*/
function onCpExit (code, signal) {
if (code !== 0) {
callback(new Error('`gyp_addon` failed with exit code: ' + code))
callback(new Error('`gyp` failed with exit code: ' + code))
} else {
// we're done
callback()