Permalink
Browse files

Linux, 32-bit, and node v0.2.x support

Added support for linux and 32-bit builds via makefile madness. I should
probably be using waf, but I don't really care about learning that, so
here we are. Also it was only a 2-line change to fix support for earlier
versions of node, so why not?
  • Loading branch information...
1 parent 906b73a commit 32ab75f4b21cec0b6b883a800f0a8015ec1bf2bc @laverdet committed Jan 16, 2011
Showing with 48 additions and 12 deletions.
  1. +37 −8 Makefile
  2. +2 −0 coroutine.h
  3. +6 −1 fiber-shim
  4. +3 −3 node-fibers.cc
View
@@ -1,15 +1,44 @@
+# I know nothing about scons, waf, or autoconf. Sorry.
NODE_PREFIX := $(shell node --vars | egrep ^NODE_PREFIX: | cut -c14-)
-# CPPFLAGS = -ggdb -O0 -Wall -I$(NODE_PREFIX)/include -I$(NODE_PREFIX)/include/node -I/Users/marcel/code/v8/include
-CPPFLAGS = -m64 -ggdb -O0 -Wall -I$(NODE_PREFIX)/include -I$(NODE_PREFIX)/include/node
+NODE_PLATFORM := $(shell node --vars | egrep -o 'DPLATFORM="[^"]+' | cut -c12-)
+NODE_BITS := $(shell file `which node` | egrep -o '[0-9]{2}-bit' | cut -c-2)
-all: node-fibers.node
+CPPFLAGS = -Wall -I$(NODE_PREFIX)/include -I$(NODE_PREFIX)/include/node
+ifdef DEBUG
+ CPPFLAGS += -ggdb -O0
+else
+ CPPFLAGS += -g -O3
+endif
-coroutine.dylib: coroutine.cc
- $(CXX) $(CPPFLAGS) -dynamiclib -o $@ $^
+ifeq ($(NODE_BITS), 32)
+ CPPFLAGS += -m32
+endif
+ifeq ($(NODE_BITS), 64)
+ CPPFLAGS += -m64
+endif
-node-fibers.node: node-fibers.cc coroutine.dylib
- $(CXX) $(CPPFLAGS) -bundle -undefined dynamic_lookup -o $@ $^
+ifeq ($(NODE_PLATFORM), linux)
+ CPP_DYFLAGS = -fPIC -shared
+ CPP_NODEFLAGS = -fPIC -shared -Wl,-Bdynamic
+ COROUTINE_SO = coroutine.so
+endif
+ifeq ($(NODE_PLATFORM), darwin)
+ CPP_DYFLAGS = -dynamiclib
+ CPP_NODEFLAGS = -bundle -undefined dynamic_lookup
+ COROUTINE_SO = coroutine.dylib
+endif
+COROUTINE_SO_FULL = `pwd`/$(COROUTINE_SO)
+
+all: $(COROUTINE_SO) node-fibers.node
+
+$(COROUTINE_SO_FULL): $(COROUTINE_SO)
+
+$(COROUTINE_SO): coroutine.cc
+ $(CXX) $(CPPFLAGS) $(CPP_DYFLAGS) -o $@ $^ -lpthread
+
+node-fibers.node: node-fibers.cc $(COROUTINE_SO_FULL)
+ $(CXX) $(CPPFLAGS) $(CPP_NODEFLAGS) -o $@ $^
clean:
- -$(RM) node-fibers.node coroutine.dylib
+ -$(RM) node-fibers.node $(COROUTINE_SO)
-$(RM) -r *.dSYM
View
@@ -1,4 +1,6 @@
+#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE
+#endif
#include <stdlib.h>
#include <ucontext.h>
#include <memory>
View
@@ -1,2 +1,7 @@
#!/bin/sh
-DYLD_INSERT_LIBRARIES=`pwd`/coroutine.dylib DYLD_FORCE_FLAT_NAMESPACE=1 $@
+UNAME=`uname`
+if [[ "$UNAME" == "Linux" ]]; then
+ LD_PRELOAD=`pwd`/coroutine.so $@
+elif [[ "$UNAME" == "Darwin" ]]; then
+ DYLD_INSERT_LIBRARIES=`pwd`/coroutine.dylib DYLD_FORCE_FLAT_NAMESPACE=1 $@
+fi
View
@@ -67,15 +67,15 @@ class Fiber: ObjectWrap {
* callback; it doesn't create any new contexts until run() is called.
*/
static Handle<Value> New(const Arguments& args) {
- if (!args.IsConstructCall()) {
- return FromConstructorTemplate(tmpl, args);
- }
HandleScope scope;
if (args.Length() != 1) {
THROW(Exception::TypeError, "Fiber expects 1 argument");
} else if (!args[0]->IsFunction()) {
THROW(Exception::TypeError, "Fiber expects a function");
+ } else if (!args.IsConstructCall()) {
+ Local<Value> argv[1] = { Local<Value>::New(args[0]) };
+ return tmpl->GetFunction()->NewInstance(1, argv);
}
Handle<Function> fn = Local<Function>::Cast(args[0]);

0 comments on commit 32ab75f

Please sign in to comment.