0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

First attempt at node.dlopen

Compiled first working 'hello world' module with this config
This commit is contained in:
Ryan 2009-06-20 15:07:10 +02:00
parent 31db4f1ed8
commit 2b6d72431b
6 changed files with 70 additions and 9 deletions

1
deps/libeio/wscript vendored
View File

@ -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');

1
deps/libev/wscript vendored
View File

@ -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');

7
src/main.cc Normal file
View File

@ -0,0 +1,7 @@
#include "node.h"
int
main (int argc, char *argv[])
{
return node::start(argc, argv);
}

View File

@ -16,6 +16,7 @@
#include <stdlib.h>
#include <strings.h>
#include <assert.h>
#include <dlfcn.h> /* dlopen(), dlsym() */
#include <string>
#include <list>
@ -100,6 +101,36 @@ node_exit (const v8::Arguments& args)
return Undefined();
}
typedef void (*extInit)(Handle<Object> exports);
Handle<Value>
node_dlopen (const v8::Arguments& args)
{
if (args.Length() < 2) return Undefined();
HandleScope scope;
String::Utf8Value filename(args[0]->ToString());
Local<Object> 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<extInit>(init_handle);
init(target);
return Undefined();
}
v8::Handle<v8::Value>
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.

View File

@ -32,6 +32,7 @@ do { \
enum encoding {ASCII, UTF8, RAW};
enum encoding ParseEncoding (v8::Handle<v8::Value> encoding_v);
void FatalException (v8::TryCatch &try_catch);
int start (int argc, char *argv[]);
} // namespace node
#endif // node_h

35
wscript
View File

@ -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"