diff --git a/deps/libeio/wscript b/deps/libeio/wscript index 90be7cce49..5023d96a7d 100644 --- a/deps/libeio/wscript +++ b/deps/libeio/wscript @@ -113,4 +113,5 @@ def build(bld): libeio.install_path = None if bld.env["USE_DEBUG"]: libeio.clone("debug"); + bld.install_files('${PREFIX}/include/node/', 'eio.h'); diff --git a/deps/libev/wscript b/deps/libev/wscript index 27b1f01f2a..c1cf1e894c 100644 --- a/deps/libev/wscript +++ b/deps/libev/wscript @@ -56,4 +56,5 @@ def build(bld): libev.install_path = None if bld.env["USE_DEBUG"]: libev.clone("debug"); + bld.install_files('${PREFIX}/include/node/', 'ev.h'); diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000000..5e2f53773b --- /dev/null +++ b/src/main.cc @@ -0,0 +1,7 @@ +#include "node.h" + +int +main (int argc, char *argv[]) +{ + return node::start(argc, argv); +} diff --git a/src/node.cc b/src/node.cc index 8f46dcf7c0..c96dbaa763 100644 --- a/src/node.cc +++ b/src/node.cc @@ -16,6 +16,7 @@ #include #include #include +#include /* dlopen(), dlsym() */ #include #include @@ -100,6 +101,36 @@ node_exit (const v8::Arguments& args) return Undefined(); } +typedef void (*extInit)(Handle exports); + +Handle +node_dlopen (const v8::Arguments& args) +{ + if (args.Length() < 2) return Undefined(); + + HandleScope scope; + + String::Utf8Value filename(args[0]->ToString()); + Local target = args[1]->ToObject(); + + void *handle = dlopen(*filename, RTLD_LAZY); + if (handle == NULL) { + ThrowException(String::New("dlopen() failed.")); + return Undefined(); + } + + void *init_handle = dlsym(handle, "init"); + if (init_handle == NULL) { + ThrowException(String::New("No 'init' symbol found in module.")); + return Undefined(); + } + extInit init = reinterpret_cast(init_handle); + + init(target); + + return Undefined(); +} + v8::Handle compile (const v8::Arguments& args) { @@ -206,6 +237,7 @@ Load (int argc, char *argv[]) NODE_SET_METHOD(node_obj, "compile", compile); NODE_SET_METHOD(node_obj, "reallyExit", node_exit); + NODE_SET_METHOD(node_obj, "dlopen", node_dlopen); node_obj->Set(String::NewSymbol("EventEmitter"), EventEmitter::constructor_template->GetFunction()); @@ -283,7 +315,7 @@ ParseArgs (int *argc, char **argv) } int -main (int argc, char *argv[]) +node::start (int argc, char *argv[]) { evcom_ignore_sigpipe(); ev_default_loop(EVFLAG_AUTO); // initialize the default ev loop. diff --git a/src/node.h b/src/node.h index 6462bc45b7..1dc473d5dc 100644 --- a/src/node.h +++ b/src/node.h @@ -32,6 +32,7 @@ do { \ enum encoding {ASCII, UTF8, RAW}; enum encoding ParseEncoding (v8::Handle encoding_v); void FatalException (v8::TryCatch &try_catch); +int start (int argc, char *argv[]); } // namespace node #endif // node_h diff --git a/wscript b/wscript index e4f01c4cd7..096652fc8c 100644 --- a/wscript +++ b/wscript @@ -56,6 +56,7 @@ def configure(conf): conf.env["USE_DEBUG"] = Options.options.debug + conf.check(lib='dl', uselib_store='DL') if Options.options.debug: conf.check(lib='profiler', uselib_store='PROFILER') @@ -127,6 +128,7 @@ def build_udns(bld): #debug.target = join(debug_dir, static_lib) bld.env_of_name('debug')["STATICLIB_UDNS"] = "udns" bld.env_of_name('debug')["LIBPATH_UDNS"] = debug_dir + bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h'); def build_v8(bld): @@ -162,6 +164,8 @@ def build_v8(bld): v8_debug.rule = v8rule % (v8dir_tgt, scons, "debug") v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g") + bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/v8*'); + def build(bld): bld.add_subdirs('deps/libeio deps/libev') @@ -178,6 +182,7 @@ def build(bld): evcom.install_path = None if bld.env["USE_DEBUG"]: evcom.clone("debug") + bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h'); ### http_parser http_parser = bld.new_task_gen("cc", "staticlib") @@ -222,10 +227,11 @@ def build(bld): if bld.env["USE_DEBUG"]: native_cc.clone("debug") - ### node - node = bld.new_task_gen("cxx", "program") - node.target = 'node' - node.source = """ + ### node lib + libnode = bld.new_task_gen("cxx", "shlib") + libnode.name = "node" + libnode.target = "node" + libnode.source = """ src/node.cc src/events.cc src/http.cc @@ -237,7 +243,7 @@ def build(bld): src/child_process.cc src/constants.cc """ - node.includes = """ + libnode.includes = """ src/ deps/v8/include deps/libev @@ -247,11 +253,24 @@ def build(bld): deps/http_parser deps/coupling """ - node.uselib_local = "evcom ev eio http_parser coupling" - node.uselib = "UDNS V8 EXECINFO PROFILER EFENCE" + libnode.uselib_local = "evcom ev eio http_parser coupling" + libnode.uselib = "UDNS V8 EXECINFO PROFILER EFENCE DL" + libnode.install_path = '${PREFIX}/lib' + bld.install_files('${PREFIX}/include/node/', 'config.h src/node.h src/object_wrap.h'); + + ### node + node = bld.new_task_gen("cxx", "program") + node.target = 'node' + node.source = "src/main.cc" + node.includes = libnode.includes + node.uselib_local = "node" node.install_path = '${PREFIX}/bin' node.chmod = 0755 if bld.env["USE_DEBUG"]: - node.clone("debug") + node_g = node.clone("debug") + node_g.target = "node_g" + + libnode_g = libnode.clone("debug") + libnode_g.target = "node_g"