Browse Source

Support addons with gyp

Initial pass.
v0.7.4-release
Ryan Dahl 13 years ago
parent
commit
18b92201be
  1. 17
      test/addons/hello-world/binding.cc
  2. 8
      test/addons/hello-world/binding.gyp
  3. 4
      test/addons/hello-world/test.js
  4. 17
      tools/addon.gypi
  5. 26
      tools/gyp_addon

17
test/addons/hello-world/binding.cc

@ -0,0 +1,17 @@
#include <node.h>
#include <v8.h>
using namespace v8;
extern "C" {
void init(Handle<Object> target);
}
Handle<Value> Method(const Arguments& args) {
HandleScope scope;
return scope.Close(String::New("world"));
}
void init(Handle<Object> target) {
NODE_SET_METHOD(target, "hello", Method);
}

8
test/addons/hello-world/binding.gyp

@ -0,0 +1,8 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ]
}
]
}

4
test/addons/hello-world/test.js

@ -0,0 +1,4 @@
var assert = require('assert');
var binding = require('./out/Release/binding');
assert.equal('world', binding.hello());
console.log('binding.hello() =', binding.hello());

17
tools/addon.gypi

@ -0,0 +1,17 @@
{
'target_defaults': {
'type': 'loadable_module',
'product_extension': 'node',
'include_dirs': [
'../src',
'../deps/uv/include',
'../deps/v8/include'
],
'conditions': [
[ 'OS=="mac"', {
'libraries': [ '-undefined dynamic_lookup' ],
}]
]
}
}

26
tools/gyp_addon

@ -0,0 +1,26 @@
#!/usr/bin/env python
import os
import sys
script_dir = os.path.dirname(__file__)
node_root = os.path.normpath(os.path.join(script_dir, os.pardir))
sys.path.insert(0, os.path.join(node_root, 'tools', 'gyp', 'pylib'))
import gyp
if __name__ == '__main__':
args = sys.argv[1:]
addon_gypi = os.path.join(node_root, 'tools', 'addon.gypi')
common_gypi = os.path.join(node_root, 'common.gypi')
args.extend(['-I', addon_gypi])
args.extend(['-I', common_gypi])
args.extend(['-Dlibrary=shared_library'])
args.extend(['-Dvisibility=default'])
args.extend(['--depth=.']);
gyp_args = list(args)
rc = gyp.main(gyp_args)
if rc != 0:
print 'Error running GYP'
sys.exit(rc)
Loading…
Cancel
Save