Skip to content

Commit b07ea7e

Browse files
committed
Build with node-gyp
1 parent 64398c5 commit b07ea7e

3 files changed

Lines changed: 117 additions & 2 deletions

File tree

binding.gyp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'nodegit',
5+
'sources': [
6+
'src/base.cc',
7+
'src/blob.cc',
8+
'src/commit.cc',
9+
'src/error.cc',
10+
'src/object.cc',
11+
'src/oid.cc',
12+
'src/reference.cc',
13+
'src/repo.cc',
14+
'src/revwalk.cc',
15+
'src/sig.cc',
16+
'src/tree.cc',
17+
'src/tree_entry.cc'
18+
],
19+
'todosources': [
20+
],
21+
22+
'include_dirs': [
23+
'vendor/libv8-convert',
24+
'vendor/libgit2/include'
25+
],
26+
27+
'libraries': [
28+
'-L<!(pwd)/vendor/libgit2/build',
29+
'-lgit2'
30+
],
31+
32+
'cflags': [
33+
'-Wall'
34+
],
35+
36+
'ldflags': [
37+
'-Wl,-rpath,\$$ORIGIN/../../vendor/libgit2/build'
38+
],
39+
40+
'conditions': [
41+
['OS=="mac"', {
42+
'xcode_settings': {
43+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
44+
}
45+
}]
46+
]
47+
}
48+
]
49+
}

install.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var async = require('async'),
2+
child_process = require('child_process'),
3+
spawn = child_process.spawn,
4+
path = require('path');
5+
6+
function passthru() {
7+
var args = Array.prototype.slice.call(arguments);
8+
var cb = args.splice(-1)[0];
9+
var cmd = args.splice(0, 1)[0];
10+
var opts = {};
11+
if(typeof(args.slice(-1)[0]) === 'object') {
12+
opts = args.splice(-1)[0];
13+
}
14+
var child = spawn(cmd, args, opts);
15+
16+
child.stdout.pipe(process.stdout);
17+
child.stderr.pipe(process.stderr);
18+
child.on('exit', cb);
19+
}
20+
21+
function shpassthru() {
22+
var cmd =
23+
passthru.apply(null, ['/bin/sh', '-c'].concat(Array.prototype.slice.call(arguments)));
24+
}
25+
26+
function envpassthru() {
27+
passthru.apply(null, ['/usr/bin/env'].concat(Array.prototype.slice.call(arguments)));
28+
}
29+
30+
var buildDir = path.join(__dirname, 'vendor/libgit2/build');
31+
async.series([
32+
function(callback) {
33+
console.log('[nodegit] Downloading libgit2 dependency.');
34+
envpassthru('git', 'submodule', 'init', callback);
35+
},
36+
function(callback) {
37+
envpassthru('git', 'submodule', 'update', callback);
38+
},
39+
function(callback) {
40+
console.log('[nodegit] Building libgit2 dependency.');
41+
envpassthru('mkdir', '-p', buildDir, callback);
42+
},
43+
function(callback) {
44+
envpassthru('cmake', '-DTHREADSAFE=1', '-DBUILD_CLAR=0', '..', {
45+
cwd: buildDir
46+
}, callback);
47+
},
48+
function(callback) {
49+
envpassthru('cmake', '--build', '.', {
50+
cwd: buildDir
51+
}, callback);
52+
},
53+
function(callback) {
54+
console.log('[nodegit] Building native module.');
55+
// shpassthru('node-gyp configure --debug', callback);
56+
shpassthru('node-gyp configure', callback);
57+
},
58+
function(callback) {
59+
shpassthru('node-gyp build', callback);
60+
}
61+
], function(err) {
62+
if(err) process.exit(err);
63+
});

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929
"engines": {
3030
"node": "~0.8"
3131
},
32+
"depenencies": {
33+
"async": ">= 0.1.21",
34+
"node-gyp": "~0.8.2"
35+
},
3236
"devDependencies": {
3337
"nodeunit": "0.7.x",
3438
"rimraf": "1.0.x"
3539
},
3640
"scripts": {
37-
"preinstall": "./build.sh",
38-
"install": "",
41+
"install": "node install.js",
3942
"test": "cd test && nodeunit *.js"
4043
}
4144
}

0 commit comments

Comments
 (0)