Commits

Anonymous committed d08bab7

added node.js support to build addons and run tests

Comments (0)

Files changed (2)

 # $(2): source files to include in the library
 # $(3): libraries to link with
 # $(4): output name; default lib$(1)
+# $(5): output extension; default .so
+# $(6): build name; default SO
 
 define library
 $$(if $(trace),$$(warning called library "$(1)" "$(2)" "$(3)"))
 $$(eval $$(call add_sources,$(2)))
 
 $$(eval tmpLIBNAME := $(if $(4),$(4),lib$(1)))
+$$(eval so := $(if $(5),$(5),.so))
+
+LIB_$(1)_BUILD_NAME := $(if $(6),$(6),[SO])
 
 OBJFILES_$(1):=$$(foreach file,$(addsuffix .lo,$(basename $(2:%=$(CWD)/%))),$$(BUILD_$$(file)_OBJ))
 
-LINK_$(1)_COMMAND:=$$(CXX) $$(CXXFLAGS) $$(CXXLIBRARYFLAGS) -o $(BIN)/$$(tmpLIBNAME).so $$(OBJFILES_$(1)) $$(foreach lib,$(3), -l$$(lib))
+LINK_$(1)_COMMAND:=$$(CXX) $$(CXXFLAGS) $$(CXXLIBRARYFLAGS) -o $(BIN)/$$(tmpLIBNAME)$$(so) $$(OBJFILES_$(1)) $$(foreach lib,$(3), -l$$(lib))
 
 LINK_$(1)_HASH := $$(call hash_command,$$(LINK_$(1)_COMMAND))
-LIB_$(1)_SO   := $(BIN)/$$(tmpLIBNAME).$$(LINK_$(1)_HASH).so
+LIB_$(1)_SO   := $(BIN)/$$(tmpLIBNAME).$$(LINK_$(1)_HASH)$$(so)
 
-LIB_$(1)_CURRENT_VERSION := $$(shell cat $(BIN)/$$(tmpLIBNAME).so.version 2>/dev/null)
+LIB_$(1)_CURRENT_VERSION := $$(shell cat $(BIN)/$$(tmpLIBNAME)$$(so).version 2>/dev/null)
 
 # We need the library so names to stay the same, so we copy the correct one
 # into our version
-$(BIN)/$$(tmpLIBNAME).so: $$(LIB_$(1)_SO) $$(if $$(findstring $$(LINK_$(1)_HASH),$$(LIB_$(1)_CURRENT_VERSION)),,redo)
+$(BIN)/$$(tmpLIBNAME)$$(so): $$(LIB_$(1)_SO) $$(if $$(findstring $$(LINK_$(1)_HASH),$$(LIB_$(1)_CURRENT_VERSION)),,redo)
 	$$(if $$(findstring,redo,$$^),$$(warning $(1) version mismatch (relink required): current $$(LIB_$(1)_CURRENT_VERSION) required: $$(LINK_$(1)_HASH)))
 	@cp $$< $$@
 	@echo $$(LINK_$(1)_HASH) > $$@.version
 redo:
 .PHONY: redo
 
-LINK_$(1)_COMMAND2 := $$(subst $(BIN)/$$(tmpLIBNAME).so,$$(LIB_$(1)_SO),$$(LINK_$(1)_COMMAND))
+LINK_$(1)_COMMAND2 := $$(subst $(BIN)/$$(tmpLIBNAME)$$(so),$$(LIB_$(1)_SO),$$(LINK_$(1)_COMMAND))
+
+LIB_$(1)_FILENAME := $$(tmpLIBNAME)$$(so)
 
 $$(LIB_$(1)_SO):	$(BIN)/.dir_exists $$(OBJFILES_$(1)) $$(foreach lib,$(3),$$(LIB_$$(lib)_DEPS))
-	$$(if $(verbose_build),@echo $$(LINK_$(1)_COMMAND2),@echo "[SO] $(if $(4),$(4),lib$(1)).so")
+	$$(if $(verbose_build),@echo $$(LINK_$(1)_COMMAND2),@echo $$(LIB_$(1)_BUILD_NAME) $$(LIB_$(1)_FILENAME))
 	@$$(LINK_$(1)_COMMAND2) || (echo "FAILED += $$@" >> .target.mk && false)
 
-LIB_$(1)_DEPS := $(BIN)/$$(tmpLIBNAME).so
+LIB_$(1)_DEPS := $(BIN)/$$(tmpLIBNAME)$$(so)
 
-libraries: $(BIN)/$$(tmpLIBNAME).so
+libraries: $(BIN)/$$(tmpLIBNAME)$$(so)
 
 endef
 
+ifeq ($(NODEJS_ENABLED),1)
+
+NODE ?= node
+NODE_PATH := $(if $(NODE_PATH),$(NODE_PATH):)$(BIN)
+
+# add a node.js addon
+# $(1): name of the addon
+# $(2): source files to include in the addon
+# $(3): libraries to link with
+
+define nodejs_addon
+$$(eval $$(call library,$(1),$(2),$(3),$(1),.node,[NODEJS]))
+endef
+
+# node test case
+
+# $(1) name of the test (the javascript file that contains the test case)
+# $(2) node.js modules on which it depends
+# $(3) test style.  Currently unused.
+
+define nodejs_test
+$$(if $(trace),$$(warning called nodejs_test "$(1)" "$(2)" "$(3)"))
+
+TEST_$(1)_COMMAND := rm -f $(TESTS)/$(1).{passed,failed} && ((set -o pipefail && NODE_PATH=$(NODE_PATH) $(NODE) $(CWD)/$(1).js > $(TESTS)/$(1).running 2>&1 && mv $(TESTS)/$(1).running $(TESTS)/$(1).passed) || (mv $(TESTS)/$(1).running $(TESTS)/$(1).failed && echo "           $(1) FAILED" && cat $(TESTS)/$(1).failed && false))
+
+$(TESTS)/$(1).passed:	$(CWD)/$(1).js $$(foreach lib,$(2),$$(LIB_$$(lib)_DEPS))
+	$$(if $(verbose_build),@echo '$$(TEST_$(1)_COMMAND)',@echo "[TESTCASE] $(1)")
+	@$$(TEST_$(1)_COMMAND)
+
+$(1):	$(CWD)/$(1).js $$(foreach lib,$(2),$$(PYTHON_$$(lib)_DEPS))
+	NODE_PATH=$(NODE_PATH) $(NODE) $(CWD)/$(1).js
+
+.PHONY: $(1)
+
+test $(CURRENT_TEST_TARGETS) $(4):	$(TESTS)/$(1).passed
+
+endef
+
+endif