Преглед изворни кода

Experimental support for duktape (Step 5/?)

bel2125 пре 9 година
родитељ
комит
b806e83762
4 измењених фајлова са 98 додато и 2 уклоњено
  1. 16 0
      Makefile
  2. 60 0
      resources/Makefile.in-duktape
  3. 19 0
      test/page.ssjs
  4. 3 2
      test/prime.ssjs

+ 16 - 0
Makefile

@@ -91,6 +91,18 @@ ifdef WITH_LUA
   include resources/Makefile.in-lua
   include resources/Makefile.in-lua
 endif
 endif
 
 
+ifdef WITH_SSJS
+  WITH_DUKTAPE = 1
+endif
+
+ifdef WITH_DUKTAPE_SHARED
+  WITH_DUKTAPE = 1
+endif
+
+ifdef WITH_DUKTAPE
+  include resources/Makefile.in-duktape
+endif
+
 ifdef WITH_IPV6
 ifdef WITH_IPV6
   CFLAGS += -DUSE_IPV6
   CFLAGS += -DUSE_IPV6
 endif
 endif
@@ -161,6 +173,10 @@ help:
 	@echo " Make Options"
 	@echo " Make Options"
 	@echo "   WITH_LUA=1            build with Lua support; include Lua as static library"
 	@echo "   WITH_LUA=1            build with Lua support; include Lua as static library"
 	@echo "   WITH_LUA_SHARED=1     build with Lua support; use dynamic linking to liblua5.2.so"
 	@echo "   WITH_LUA_SHARED=1     build with Lua support; use dynamic linking to liblua5.2.so"
+	@echo "   WITH_LUA_VERSION=502  build with Lua 5.2.x (501 for Lua 5.1.x to 503 for 5.3.x)"
+	@echo "   WITH_DUKTAPE=1        build with Duktape support; include as static library"
+	@echo "   WITH_DUKTAPE_SHARED=1 build with Duktape support; use libduktape1.3.so"
+#	@echo "   WITH_DUKTAPE_VERSION=103 build with Duktape 1.3.x"
 	@echo "   WITH_DEBUG=1          build with GDB debug support"
 	@echo "   WITH_DEBUG=1          build with GDB debug support"
 	@echo "   WITH_IPV6=1           with IPV6 support"
 	@echo "   WITH_IPV6=1           with IPV6 support"
 	@echo "   WITH_WEBSOCKET=1      build with web socket support"
 	@echo "   WITH_WEBSOCKET=1      build with web socket support"

+ 60 - 0
resources/Makefile.in-duktape

@@ -0,0 +1,60 @@
+#
+# Copyright (c) 2015 the Civetweb developers
+#
+# License http://opensource.org/licenses/mit-license.php MIT License
+#
+
+ifndef WITH_DUKTAPE
+  $(error WITH_DUKTAPE is not defined)
+endif
+
+# Duktape default version is 1.3.0 (103)
+WITH_DUKTAPE_VERSION ?= 103
+DUKTAPE_VERSION_KNOWN = 0
+
+# Select src and header according to the Duktape version
+ifeq ($(WITH_DUKTAPE_VERSION), 103)
+  $(info Duktape: Using version 1.3.0)
+  DUKTAPE_DIR = src/third_party/duktape-1.3.0/src
+  DUKTAPE_SHARED_LIB_FLAG = -lduktape1.3
+  DUKTAPE_CFLAGS = -DDUKTAPE_VERSION_MAKEFILE=501
+  DUKTAPE_VERSION_KNOWN = 1
+endif
+
+ifneq ($(DUKTAPE_VERSION_KNOWN), 1)
+  $(error Duktape: Unknwon version - $(WITH_DUKTAPE_VERSION))
+endif
+
+
+# Add flags for all Duktape versions
+DUKTAPE_CFLAGS += -I$(DUKTAPE_DIR) -DUSE_DUKTAPE
+
+ifneq ($(TARGET_OS),WIN32)
+#  DUKTAPE_CFLAGS += 
+endif
+
+ifdef WITH_DUKTAPE_SHARED
+
+  DUKTAPE_SOURCE_FILES =
+
+  $(info Duktape: using dynamic linking)
+
+else
+
+  DUKTAPE_SOURCE_FILES = duktape.c
+
+ifeq ($(WITH_DUKTAPE_VERSION), 104)
+#    DUKTAPE_SOURCE_FILES +=
+endif
+
+  $(info Duktape: using static library)
+
+endif
+
+DUKTAPE_SOURCES = $(addprefix $(DUKTAPE_DIR)/, $(DUKTAPE_SOURCE_FILES))
+DUKTAPE_OBJECTS = $(DUKTAPE_SOURCES:.c=.o)
+
+OBJECTS += $(DUKTAPE_OBJECTS)
+CFLAGS += $(DUKTAPE_CFLAGS)
+SOURCE_DIRS = $(DUKTAPE_DIR)
+

+ 19 - 0
test/page.ssjs

@@ -0,0 +1,19 @@
+print = this.send || print
+
+// send a header
+print('HTTP/1.0 200 OK\r\n');
+print('Content-Type: text/html\r\n');
+print('\r\n');
+
+print("<html><body>\n");
+print("<p>This example page is generated by the ");
+print('<a href="https://github.com/civetweb/civetweb">CivetWeb web server</a>');
+print(" with server side javascript.</p>\n");
+
+var d = new Date();
+var n = d.toString(); 
+
+print("<p>Server time: " + n + "</p>\n");
+
+print("</body></html>\n");
+

+ 3 - 2
test/prime.ssjs

@@ -1,4 +1,4 @@
-// prime.js
+// prime.js - a test from the Duktape home page (with minimal modifications)
 
 
 // Pure Ecmascript version of low level helper
 // Pure Ecmascript version of low level helper
 function primeCheckEcmascript(val, limit) {
 function primeCheckEcmascript(val, limit) {
@@ -22,7 +22,7 @@ function primeCheck(val) {
 function primeTest() {
 function primeTest() {
     var res = [];
     var res = [];
 
 
-    print('Have native helper: ' + (primeCheckHelper !== primeCheckEcmascript));
+    print('Have native helper: ' + (primeCheckHelper !== primeCheckEcmascript) + '\n');
     for (var i = 2; i <= 1000; i++) {
     for (var i = 2; i <= 1000; i++) {
         if (primeCheck(i)) { res.push(i); }
         if (primeCheck(i)) { res.push(i); }
     } 
     } 
@@ -34,3 +34,4 @@ print = this.send || print
 print('HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\n');
 print('HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\n');
 
 
 primeTest();
 primeTest();
+