From d3b17437b12625bd31118f40e06a3bb28b6c5fda Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 3 Dec 2022 14:16:28 +1300 Subject: [js] Stop using swig -c++ for C examples --- Examples/Makefile.in | 12 +++- Examples/javascript/class/Makefile | 3 +- Examples/javascript/constant/Makefile | 2 - Examples/javascript/enum/Makefile | 3 +- Examples/javascript/example.mk | 18 ++++-- Examples/javascript/exception/Makefile | 3 +- Examples/javascript/functor/Makefile | 2 +- Examples/javascript/native/Makefile | 2 +- Examples/javascript/nspace/Makefile | 2 +- Examples/javascript/operator/Makefile | 2 +- Examples/javascript/overload/Makefile | 2 +- Examples/javascript/pointer/Makefile | 2 +- Examples/javascript/pointer/binding.gyp.in | 2 +- Examples/javascript/pointer/example.c | 16 +++++ Examples/javascript/pointer/example.cxx | 16 ----- Examples/javascript/reference/Makefile | 3 +- Examples/javascript/simple/Makefile | 2 +- Examples/javascript/simple/binding.gyp.in | 2 +- Examples/javascript/simple/example.c | 18 ++++++ Examples/javascript/simple/example.cxx | 18 ------ Examples/javascript/template/Makefile | 2 +- Examples/javascript/variables/Makefile | 2 +- Examples/javascript/variables/binding.gyp.in | 2 +- Examples/javascript/variables/example.c | 96 ++++++++++++++++++++++++++++ Examples/javascript/variables/example.cxx | 96 ---------------------------- 25 files changed, 171 insertions(+), 157 deletions(-) create mode 100644 Examples/javascript/pointer/example.c delete mode 100644 Examples/javascript/pointer/example.cxx create mode 100644 Examples/javascript/simple/example.c delete mode 100644 Examples/javascript/simple/example.cxx create mode 100644 Examples/javascript/variables/example.c delete mode 100644 Examples/javascript/variables/example.cxx (limited to 'Examples') diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 0849597a9..5a4639076 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -711,14 +711,23 @@ endif # ---------------------------------------------------------------- javascript_wrapper: +ifeq (node,$(JSENGINE)) + $(SWIG) -javascript $(SWIGOPT) -$(JSENGINE) -o $(INTERFACEDIR)$(TARGET)_wrap.cxx $(INTERFACEPATH) +else $(SWIG) -javascript $(SWIGOPT) -$(JSENGINE) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH) +endif javascript_wrapper_cpp: $(SRCDIR_SRCS) $(SWIG) -javascript -c++ $(SWIGOPT) -$(JSENGINE) -o $(INTERFACEDIR)$(TARGET)_wrap.cxx $(INTERFACEPATH) javascript_build: $(SRCDIR_SRCS) +ifeq (node,$(JSENGINE)) + sed -e 's|$$srcdir|./$(SRCDIR)|g' $(SRCDIR)binding.gyp.in > binding.gyp + MAKEFLAGS= $(NODEGYP) --loglevel=silent configure build 1>>/dev/null +else $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES) $(JSINCLUDES) - $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) + $(LDSHARED) $(CCSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO) +endif javascript_build_cpp: $(SRCDIR_SRCS) ifeq (node,$(JSENGINE)) @@ -727,7 +736,6 @@ ifeq (node,$(JSENGINE)) else $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(INCLUDES) $(JSINCLUDES) $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO) - endif # These targets are used by the test-suite: diff --git a/Examples/javascript/class/Makefile b/Examples/javascript/class/Makefile index 54a8f7b03..b6805576e 100644 --- a/Examples/javascript/class/Makefile +++ b/Examples/javascript/class/Makefile @@ -1,3 +1,4 @@ -SRCS = example.cxx +CXXSRCS = example.cxx +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/constant/Makefile b/Examples/javascript/constant/Makefile index 0402f8d09..a80ecf16f 100644 --- a/Examples/javascript/constant/Makefile +++ b/Examples/javascript/constant/Makefile @@ -1,3 +1 @@ -SRCS = - include $(SRCDIR)../example.mk diff --git a/Examples/javascript/enum/Makefile b/Examples/javascript/enum/Makefile index 54a8f7b03..b6805576e 100644 --- a/Examples/javascript/enum/Makefile +++ b/Examples/javascript/enum/Makefile @@ -1,3 +1,4 @@ -SRCS = example.cxx +CXXSRCS = example.cxx +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/example.mk b/Examples/javascript/example.mk index cce99fa25..5a9ba8a99 100644 --- a/Examples/javascript/example.mk +++ b/Examples/javascript/example.mk @@ -13,18 +13,22 @@ SWIGEXE = $(SWIG_TOP)/swig SWIG_LIB_DIR = $(SWIG_TOP)/$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib TARGET = example INTERFACE = example.i -SWIGOPT = -DV8_VERSION=$(JSV8_VERSION) +SWIGOPT = + +ifneq (jsc, $(ENGINE)) +SWIGOPT += -DV8_VERSION=$(JSV8_VERSION) +endif check: build $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' javascript_run build: - $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp - $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' \ - SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build_cpp + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SRCS='$(SRCS)' SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper$(_CPP) + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \ + SRCS='$(SRCS)' SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build$(_CPP) clean: $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' javascript_clean diff --git a/Examples/javascript/exception/Makefile b/Examples/javascript/exception/Makefile index 54a8f7b03..b6805576e 100644 --- a/Examples/javascript/exception/Makefile +++ b/Examples/javascript/exception/Makefile @@ -1,3 +1,4 @@ -SRCS = example.cxx +CXXSRCS = example.cxx +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/functor/Makefile b/Examples/javascript/functor/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/functor/Makefile +++ b/Examples/javascript/functor/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/native/Makefile b/Examples/javascript/native/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/native/Makefile +++ b/Examples/javascript/native/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/nspace/Makefile b/Examples/javascript/nspace/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/nspace/Makefile +++ b/Examples/javascript/nspace/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/operator/Makefile b/Examples/javascript/operator/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/operator/Makefile +++ b/Examples/javascript/operator/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/overload/Makefile b/Examples/javascript/overload/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/overload/Makefile +++ b/Examples/javascript/overload/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/pointer/Makefile b/Examples/javascript/pointer/Makefile index 54a8f7b03..413b64bbd 100644 --- a/Examples/javascript/pointer/Makefile +++ b/Examples/javascript/pointer/Makefile @@ -1,3 +1,3 @@ -SRCS = example.cxx +SRCS = example.c include $(SRCDIR)../example.mk diff --git a/Examples/javascript/pointer/binding.gyp.in b/Examples/javascript/pointer/binding.gyp.in index cb2b45e8f..cfd4854b0 100644 --- a/Examples/javascript/pointer/binding.gyp.in +++ b/Examples/javascript/pointer/binding.gyp.in @@ -2,7 +2,7 @@ "targets": [ { "target_name": "example", - "sources": [ " 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + + diff --git a/Examples/javascript/simple/example.cxx b/Examples/javascript/simple/example.cxx deleted file mode 100644 index 1c2af789c..000000000 --- a/Examples/javascript/simple/example.cxx +++ /dev/null @@ -1,18 +0,0 @@ -/* File : example.c */ - -/* A global variable */ -double Foo = 3.0; - -/* Compute the greatest common divisor of positive integers */ -int gcd(int x, int y) { - int g; - g = y; - while (x > 0) { - g = x; - x = y % x; - y = g; - } - return g; -} - - diff --git a/Examples/javascript/template/Makefile b/Examples/javascript/template/Makefile index 0402f8d09..8085356b1 100644 --- a/Examples/javascript/template/Makefile +++ b/Examples/javascript/template/Makefile @@ -1,3 +1,3 @@ -SRCS = +_CPP = _cpp include $(SRCDIR)../example.mk diff --git a/Examples/javascript/variables/Makefile b/Examples/javascript/variables/Makefile index 54a8f7b03..413b64bbd 100644 --- a/Examples/javascript/variables/Makefile +++ b/Examples/javascript/variables/Makefile @@ -1,3 +1,3 @@ -SRCS = example.cxx +SRCS = example.c include $(SRCDIR)../example.mk diff --git a/Examples/javascript/variables/binding.gyp.in b/Examples/javascript/variables/binding.gyp.in index cb2b45e8f..cfd4854b0 100644 --- a/Examples/javascript/variables/binding.gyp.in +++ b/Examples/javascript/variables/binding.gyp.in @@ -2,7 +2,7 @@ "targets": [ { "target_name": "example", - "sources": [ " +#include +#include "example.h" + +int ivar = 0; +short svar = 0; +long lvar = 0; +unsigned int uivar = 0; +unsigned short usvar = 0; +unsigned long ulvar = 0; +signed char scvar = 0; +unsigned char ucvar = 0; +char cvar = 0; +float fvar = 0; +double dvar = 0; +char *strvar = 0; +#ifdef __cplusplus // Note: for v8 this must be linkable with g++, without extern cstrvar is mangled +extern const char cstrvar[] = "Goodbye"; +#else +const char cstrvar[] = "Goodbye"; +#endif +const +int *iptrvar = 0; +char name[256] = "Dave"; +char path[256] = "/home/beazley"; + + +/* Global variables involving a structure */ +Point *ptptr = 0; +Point pt = { 10, 20 }; + +/* A variable that we will make read-only in the interface */ +int status = 1; + +/* A debugging function to print out their values */ + +void print_vars() { + printf("ivar = %d\n", ivar); + printf("svar = %d\n", svar); + printf("lvar = %ld\n", lvar); + printf("uivar = %u\n", uivar); + printf("usvar = %u\n", usvar); + printf("ulvar = %lu\n", ulvar); + printf("scvar = %d\n", scvar); + printf("ucvar = %u\n", ucvar); + printf("fvar = %g\n", fvar); + printf("dvar = %g\n", dvar); + printf("cvar = %c\n", cvar); + printf("strvar = %s\n", strvar ? strvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); + printf("name = %s\n", name); + printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("pt = (%d, %d)\n", pt.x, pt.y); + printf("status = %d\n", status); +} + +/* A function to create an integer (to test iptrvar) */ + +int *new_int(int value) { + int *ip = (int *) malloc(sizeof(int)); + *ip = value; + return ip; +} + +/* A function to create a point */ + +Point *new_Point(int x, int y) { + Point *p = (Point *) malloc(sizeof(Point)); + p->x = x; + p->y = y; + return p; +} + +char * Point_print(Point *p) { + static char buffer[256]; + if (p) { + sprintf(buffer,"(%d,%d)", p->x,p->y); + } else { + sprintf(buffer,"null"); + } + return buffer; +} + +void pt_print() { + printf("(%d, %d)\n", pt.x, pt.y); +} diff --git a/Examples/javascript/variables/example.cxx b/Examples/javascript/variables/example.cxx deleted file mode 100644 index 15314b383..000000000 --- a/Examples/javascript/variables/example.cxx +++ /dev/null @@ -1,96 +0,0 @@ -/* File : example.c */ - -/* I'm a file containing some C global variables */ - -/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ -#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) -# define _CRT_SECURE_NO_DEPRECATE -#endif - -#include -#include -#include "example.h" - -int ivar = 0; -short svar = 0; -long lvar = 0; -unsigned int uivar = 0; -unsigned short usvar = 0; -unsigned long ulvar = 0; -signed char scvar = 0; -unsigned char ucvar = 0; -char cvar = 0; -float fvar = 0; -double dvar = 0; -char *strvar = 0; -#ifdef __cplusplus // Note: for v8 this must be linkable with g++, without extern cstrvar is mangled -extern const char cstrvar[] = "Goodbye"; -#else -const char cstrvar[] = "Goodbye"; -#endif -const -int *iptrvar = 0; -char name[256] = "Dave"; -char path[256] = "/home/beazley"; - - -/* Global variables involving a structure */ -Point *ptptr = 0; -Point pt = { 10, 20 }; - -/* A variable that we will make read-only in the interface */ -int status = 1; - -/* A debugging function to print out their values */ - -void print_vars() { - printf("ivar = %d\n", ivar); - printf("svar = %d\n", svar); - printf("lvar = %ld\n", lvar); - printf("uivar = %u\n", uivar); - printf("usvar = %u\n", usvar); - printf("ulvar = %lu\n", ulvar); - printf("scvar = %d\n", scvar); - printf("ucvar = %u\n", ucvar); - printf("fvar = %g\n", fvar); - printf("dvar = %g\n", dvar); - printf("cvar = %c\n", cvar); - printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar); - printf("iptrvar = %p\n", (void *)iptrvar); - printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); - printf("pt = (%d, %d)\n", pt.x, pt.y); - printf("status = %d\n", status); -} - -/* A function to create an integer (to test iptrvar) */ - -int *new_int(int value) { - int *ip = (int *) malloc(sizeof(int)); - *ip = value; - return ip; -} - -/* A function to create a point */ - -Point *new_Point(int x, int y) { - Point *p = (Point *) malloc(sizeof(Point)); - p->x = x; - p->y = y; - return p; -} - -char * Point_print(Point *p) { - static char buffer[256]; - if (p) { - sprintf(buffer,"(%d,%d)", p->x,p->y); - } else { - sprintf(buffer,"null"); - } - return buffer; -} - -void pt_print() { - printf("(%d, %d)\n", pt.x, pt.y); -} -- cgit v1.2.1