mirror of
https://github.com/electron/node-gyp.git
synced 2025-09-15 13:43:40 +02:00
configure: create and use a 'config.gypi' file
This is like how node does it with its ./configure script. Closes #32.
This commit is contained in:
parent
f20a84364b
commit
d4431b2da2
1 changed files with 42 additions and 21 deletions
|
@ -9,6 +9,7 @@ var fs = require('fs')
|
|||
, path = require('path')
|
||||
, glob = require('glob')
|
||||
, semver = require('semver')
|
||||
, mkdirp = require('./util/mkdirp')
|
||||
, createHook = require('./util/hook')
|
||||
, asyncEmit = require('./util/asyncEmit')
|
||||
, win = process.platform == 'win32'
|
||||
|
@ -18,6 +19,8 @@ exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' f
|
|||
function configure (gyp, argv, callback) {
|
||||
|
||||
var python = gyp.opts.python || 'python'
|
||||
, buildDir = path.resolve('build')
|
||||
, configPath
|
||||
, emitter
|
||||
, versionStr
|
||||
, version
|
||||
|
@ -46,10 +49,45 @@ function configure (gyp, argv, callback) {
|
|||
}
|
||||
version = version.slice(1, 4).join('.')
|
||||
gyp.opts.ensure = true
|
||||
gyp.commands.install([ version ], go)
|
||||
gyp.commands.install([ version ], createBuildDir)
|
||||
}
|
||||
|
||||
function go (err) {
|
||||
function createBuildDir (err) {
|
||||
if (err) return callback(err)
|
||||
gyp.verbose('attempting to create "build" dir', buildDir)
|
||||
mkdirp(buildDir, function (err, isNew) {
|
||||
if (err) return callback(err)
|
||||
gyp.verbose('"build" dir needed to be created?', isNew)
|
||||
createConfigFile()
|
||||
})
|
||||
}
|
||||
|
||||
function createConfigFile (err) {
|
||||
if (err) return callback(err)
|
||||
gyp.verbose('creating build/config.gypi file')
|
||||
|
||||
var config = {}
|
||||
configPath = path.resolve(buildDir, 'config.gypi')
|
||||
|
||||
config.target_defaults = {
|
||||
cflags: []
|
||||
, default_configuration: gyp.opts.debug ? 'Debug' : 'Release'
|
||||
, defines: []
|
||||
, include_dirs: []
|
||||
, libraries: []
|
||||
}
|
||||
|
||||
config.variables = {
|
||||
target_arch: gyp.opts.arch || process.arch || 'ia32'
|
||||
}
|
||||
|
||||
var prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
|
||||
, json = JSON.stringify(config, null, 2)
|
||||
gyp.verbose('writing out config file', configPath)
|
||||
fs.writeFile(configPath, [prefix, json, ''].join('\n'), runGypAddon)
|
||||
}
|
||||
|
||||
function runGypAddon (err) {
|
||||
if (err) return callback(err)
|
||||
|
||||
var devDir = path.resolve(process.env.HOME, '.node-gyp', version)
|
||||
|
@ -61,25 +99,8 @@ function configure (gyp, argv, callback) {
|
|||
argv.push('-f', 'make')
|
||||
}
|
||||
|
||||
var hasArch = argv.some(function (arg) {
|
||||
return arg.indexOf('-Dtarget_arch') === 0
|
||||
})
|
||||
// was --arch specified?
|
||||
if (!hasArch && gyp.opts.arch) {
|
||||
gyp.verbose('using the architecture specified by --arch', gyp.opts.arch)
|
||||
argv.push('-Dtarget_arch=' + gyp.opts.arch)
|
||||
hasArch = true
|
||||
}
|
||||
|
||||
// this may need to be tweaked for windows and stuff, we'll see...
|
||||
if (!hasArch) {
|
||||
// on < 0.8 the target_arch variable is set to ia32 by default unless
|
||||
// overridden, so we have to explicitly specify the arch here
|
||||
gyp.verbose('target arch not specified, using the current host architecture', process.arch)
|
||||
argv.push('-Dtarget_arch=' + process.arch)
|
||||
gyp.opts.arch = process.arch
|
||||
hasArch = true
|
||||
}
|
||||
// include the "config.gypi" file that was generated
|
||||
argv.unshift('-I' + configPath)
|
||||
|
||||
// enforce use of the "binding.gyp" file
|
||||
argv.unshift('binding.gyp')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue