Skip to content
Browse files

switch to gyp

  • Loading branch information...
1 parent 991eb71 commit d326482c4a6907089382e79f49a29df25b78d3fc @tokuhirom committed Aug 29, 2012
Showing with 53 additions and 32 deletions.
  1. +1 −0 .gitignore
  2. +9 −0 HACKING.mkdn
  3. +25 −0 binding.gyp
  4. +2 −2 index.js
  5. +7 −4 src/perl_bindings.cc
  6. 0 src/{perlxsi.cc → perlxsi.c}
  7. +9 −0 utils/libperl.pl
  8. +0 −26 wscript
View
1 .gitignore
@@ -1,3 +1,4 @@
.lock-wscript
node_modules/
build/
+src/config.h
View
9 HACKING.mkdn
@@ -11,3 +11,12 @@ Manuals
read perlapi, perlcall, perlembed.
+Installing
+----------
+
+You need to compile Perl5 with -fPIC option. I recommend to use following options to install.
+
+ $ PERLBREW_CONFIGURE_FLAGS=-de perlbrew install perl-5.16.1 -Duseshrplib -Duseithreads -Dusethreads -Accflags='-fPIC' -nv
+
+cc -shared -o dllo.so -Wl,--whole-archive -lperl -Wl,--no-whole-archive `perl -MExtUtils::Embed -e ldopts | perl -pe 's/-lperl//'`
+
View
25 binding.gyp
@@ -0,0 +1,25 @@
+{
+ 'targets': [
+ {
+ 'target_name': 'perl',
+ 'sources': [
+ './src/perl_bindings.cc',
+ './src/perlxsi.c'
+ ],
+ 'libraries': [
+ '<!@(perl -MExtUtils::Embed -e ldopts)'
+ ],
+ 'cflags!': [ '-fno-exceptions' ],
+ 'cflags_cc!': [ '-fno-exceptions' ],
+ 'cflags': [
+ '-fexceptions',
+ '-Duseithreads',
+ '-Duseithread',
+ '-Dusethreads',
+ '-Dusethread',
+ '<!@(perl utils/libperl.pl)'
+ '<!@(perl -MExtUtils::Embed -e ccopts)'
+ ]
+ },
+ ]
+}
View
4 index.js
@@ -1,5 +1,5 @@
-var P = require('./build/Release/perl-simple.node');
-// P.InitPerl();
+var P = require('./build/Release/perl.node');
+P.InitPerl();
P.Perl.prototype.use = function (name) {
if (!name.match(/^[A-Za-z0-9_:]+$/)) {
throw new Exception("This is not a valid class name : " + name);
View
11 src/perl_bindings.cc
@@ -1,5 +1,6 @@
#define BUILDING_NODE_EXTENSION
+
#include <node.h>
#include <string>
#include <vector>
@@ -8,7 +9,9 @@
#include <EXTERN.h> /* from the Perl distribution */
#include <perl.h> /* from the Perl distribution */
+#include <embed.h>
#include "ppport.h"
+#include "config.h"
#ifdef New
#undef New
@@ -554,24 +557,24 @@ Persistent<FunctionTemplate> NodePerlClass::constructor_template;
static Handle<Value> InitPerl(const Arguments& args) {
HandleScope scope;
- void *lib = dlopen("libperl.so", RTLD_LAZY|RTLD_GLOBAL);
+ void *lib = dlopen(LIBPERL, RTLD_LAZY|RTLD_GLOBAL);
if (lib) {
dlclose(lib);
return scope.Close(Undefined());
} else {
- return ThrowException(Exception::Error(String::New(dlerror())));
+ std::cerr << dlerror() << std::endl;
+ return scope.Close(Undefined());
+ // return ThrowException(Exception::Error(String::New(dlerror())));
}
}
extern "C" void init(Handle<Object> target) {
HandleScope scope;
- /*
{
Handle<FunctionTemplate> t = FunctionTemplate::New(InitPerl);
target->Set(String::New("InitPerl"), t->GetFunction());
}
- */
NodePerl::Init(target);
NodePerlObject::Init(target);
View
0 src/perlxsi.cc → src/perlxsi.c
File renamed without changes.
View
9 utils/libperl.pl
@@ -0,0 +1,9 @@
+use strict;
+use warnings;
+use utf8;
+use Config;
+
+open my $fh, '>', 'src/config.h' or die "Cannot open config.h: $!";
+print $fh q{#define LIBPERL "} . $Config{libperl}. qq{"\n};
+close $fh;
+
View
26 wscript
@@ -1,26 +0,0 @@
-import Utils
-import Options
-
-srcdir = '.'
-blddir = 'build'
-VERSION = '0.0.1'
-
-def set_options(opt):
- opt.tool_options('compiler_cxx')
- opt.add_option('--perl', action='store', default='perl', help='perl path')
-
-def configure(conf):
- conf.check_tool('compiler_cxx')
- conf.check_tool('node_addon')
- perl = Options.options.perl
- print('→ the value of perl is %r' % perl)
- conf.env.append_unique('CXXFLAGS',Utils.cmd_output(perl + ' -MExtUtils::Embed -e ccopts').split())
- conf.env.append_unique('CXXFLAGS',['-Duseithreads'])
- conf.env.append_unique('LINKFLAGS',Utils.cmd_output(perl + ' -MExtUtils::Embed -e ldopts').split())
- conf.env.append_unique('LDFLAGS',['-static'])
-
-def build(bld):
- obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
- obj.target = 'perl-simple'
- obj.source = './src/perlxsi.cc ./src/perl_bindings.cc'
-

0 comments on commit d326482

Please sign in to comment.
Something went wrong with that request. Please try again.