Browse Source

Simple wrappers for Python and Lua

Load by setting the PATH variables and "import open62541" and "require('open62541')" respectively
Julius Pfrommer 10 years ago
parent
commit
88c8cb1a08
5 changed files with 107 additions and 10 deletions
  1. 14 7
      Makefile.am
  2. 30 3
      configure.ac
  3. 20 0
      wrappers/lua/Makefile.am
  4. 23 0
      wrappers/open62541.i
  5. 20 0
      wrappers/python/Makefile.am

+ 14 - 7
Makefile.am

@@ -1,5 +1,4 @@
-#AM_CFLAGS  = -std=c99 -pedantic -pipe -fPIC -fno-exceptions -fstack-protector -Wl,-z,relro -Wl,-z,now -fvisibility=hidden -W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -Werror
-AM_CFLAGS  = -std=c99 -pedantic -pipe -funsigned-char -Wno-pointer-sign -fno-exceptions -fstack-protector -fvisibility=hidden -W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -Werror
+AM_CFLAGS  = -std=c99 -pedantic -pipe -funsigned-char -Wno-pointer-sign -fno-exceptions -fstack-protector -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -Werror
 AM_LDFLAGS =
 AM_LDADD =
 
@@ -27,16 +26,24 @@ endif
 export GLOBAL_AM_CFLAGS = $(AM_CFLAGS)
 export GLOBAL_AM_LDADD = $(AM_LDADD)
 
-SUBS=src
+SUBDIRS=src
 if HAVE_CHECK
-	SUBS+= tests
+	SUBDIRS+= tests
 endif
 
 if ENABLE_DOXYGEN
-	SUBS+= doc
+	SUBDIRS+= doc
 endif
-	
+
 if TARGET_WIN
 else
-SUBDIRS = $(SUBS) examples/src	
+SUBDIRS += examples/src	
+endif
+
+if PYTHON_WRAPPER
+SUBDIRS += wrappers/python
+endif
+
+if LUA_WRAPPER
+SUBDIRS += wrappers/lua
 endif

+ 30 - 3
configure.ac

@@ -29,6 +29,7 @@ AM_COND_IF([TARGET_WIN],
 AM_COND_IF([TARGET_LINUX],
     AC_DEFINE([LINUX]))
    
+#debugging
 AC_ARG_ENABLE(debug,
 AS_HELP_STRING([--enable-debug],
                [enable debugging, default: no]),
@@ -46,6 +47,7 @@ AM_CONDITIONAL(VERBOSE, test x"$verbose" = x"true")
 AM_COND_IF([VERBOSE],
     AC_DEFINE([VERBOSE])) #define VERBOSE is accessible from pre-processor
 
+#multithreading
 AC_ARG_ENABLE(multithreading,
 AS_HELP_STRING([--enable-multithreading],
                [enable multithreading, default: yes]),
@@ -58,6 +60,7 @@ AM_CONDITIONAL(MULTITHREADING, test x"$multithreading" = x"true")
 AM_COND_IF([MULTITHREADING],
     AC_DEFINE([MULTITHREADING])) #define MULTITHREADING is accessible from pre-processor
 
+#coverage
 AC_ARG_ENABLE(coverage,
 AS_HELP_STRING([--enable-coverage],
                [enable coverage, default: no]),
@@ -81,7 +84,7 @@ AS_HELP_STRING([--enable-raspi],
 	esac],[raspi=false])
 AM_CONDITIONAL(RASPI, test x"$raspi" = x"true")
 AM_COND_IF([RASPI],
-    AC_DEFINE([RASPI])) #define MULTITHREADING is accessible from pre-processor
+    AC_DEFINE([RASPI]))
 
 #doxygen start
 AC_ARG_ENABLE(doxygen,
@@ -109,10 +112,34 @@ fi
 AM_COND_IF([ENABLE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
 #doxygen end
 
-   
+#language wrappers
+AC_ARG_ENABLE(python_wrapper,
+AS_HELP_STRING([--enable-python-wrapper],
+               [build python-wrapper, default: no]),
+	[case "${enableval}" in
+		yes) python_wrapper=true ;;
+		no)  python_wrapper=false ;;
+		*)   AC_MSG_ERROR([bad value ${enableval} for --enable-python-wrapper]) ;; 
+	esac],[python_wrapper=false])
+AM_CONDITIONAL(PYTHON_WRAPPER, test x"$python_wrapper" = x"true")
+AM_COND_IF([PYTHON_WRAPPER],
+    AC_DEFINE([PYTHON_WRAPPER]))
+
+AC_ARG_ENABLE(lua_wrapper,
+AS_HELP_STRING([--enable-lua-wrapper],
+               [build lua-wrapper, default: no]),
+	[case "${enableval}" in
+		yes) lua_wrapper=true ;;
+		no)  lua_wrapper=false ;;
+		*)   AC_MSG_ERROR([bad value ${enableval} for --enable-lua-wrapper]) ;; 
+	esac],[lua_wrapper=false])
+AM_CONDITIONAL(LUA_WRAPPER, test x"$lua_wrapper" = x"true")
+AM_COND_IF([LUA_WRAPPER],
+    AC_DEFINE([LUA_WRAPPER]))
+
 AC_LIBTOOL_WIN32_DLL
 AC_PROG_LIBTOOL
 AC_CONFIG_MACRO_DIR([m4])
-AC_CONFIG_FILES(Makefile src/Makefile tests/Makefile examples/src/Makefile doc/Makefile)
+AC_CONFIG_FILES(Makefile src/Makefile tests/Makefile examples/src/Makefile doc/Makefile wrappers/python/Makefile wrappers/lua/Makefile)
 AC_OUTPUT
 

+ 20 - 0
wrappers/lua/Makefile.am

@@ -0,0 +1,20 @@
+INCLUDEDIRS = -I$(top_builddir)/src -I$(top_builddir)/src/util -I$(top_builddir)/examples/src
+AM_CFLAGS = $(GLOBAL_AM_CFLAGS) $(INCLUDEDIRS)
+WRAPPER_DIR = $(top_builddir)/wrappers
+
+open62541.lua open62541_wrap_lua.c:
+	swig -lua $(INCLUDEDIRS) -o ./open62541_wrap_lua.c $(WRAPPER_DIR)/open62541.i
+
+networklayer.so:
+	gcc -c $(AM_CFLAGS) $(top_builddir)/examples/src/networklayer.c -o networklayer.so
+
+open62541_wrap_lua.o: open62541_wrap_lua.c
+	gcc -c $(subst -Wall, ,$(subst -Wreturn-type, ,$(subst -pedantic, , $(AM_CFLAGS)))) -I/usr/include/lua5.2 open62541_wrap_lua.c
+
+open62541.so: networklayer.so open62541_wrap_lua.o
+	ld -shared open62541_wrap_lua.o networklayer.so $(top_builddir)/lib/libopen62541.so -o open62541.so
+
+all: open62541.lua open62541.so
+
+clean:
+	rm networklayer.so open62541.lua open62541.so open62541_wrap_lua.c open62541_wrap_lua.o

+ 23 - 0
wrappers/open62541.i

@@ -0,0 +1,23 @@
+/*
+ swig -python -I../src -I../examples/src open62541.i
+ gcc -c open62541_wrap.c -I/usr/include/python2.7 -I../examples/src -I../src -fPIC
+ ld -shared open62541_wrap.o ../lib/libopen62541.so ../examples/src/networklayer.so -o _open62541.so
+*/
+
+%module open62541
+%{
+/* Includes the header in the wrapper code */
+#include "networklayer.h"
+#include "ua_application.h"
+%}
+
+/* Parse the header file to generate wrappers */
+typedef int UA_Int32;
+//%include "stdint.i"
+//%include "ua_types.h"
+%include "networklayer.h"
+%include "ua_application.h"
+
+extern NL_Description NL_Description_TcpBinary;
+extern Application appMockup;
+void appMockup_init();

+ 20 - 0
wrappers/python/Makefile.am

@@ -0,0 +1,20 @@
+INCLUDEDIRS = -I$(top_builddir)/src -I$(top_builddir)/src/util -I$(top_builddir)/examples/src
+AM_CFLAGS = $(GLOBAL_AM_CFLAGS) $(INCLUDEDIRS)
+WRAPPER_DIR = $(top_builddir)/wrappers
+
+open62541.py open62541_wrap_python.c:
+	swig -python $(INCLUDEDIRS) -o ./open62541_wrap_python.c $(WRAPPER_DIR)/open62541.i
+
+networklayer.so:
+	gcc -c $(AM_CFLAGS) $(top_builddir)/examples/src/networklayer.c -o networklayer.so
+
+open62541_wrap_python.o: open62541_wrap_python.c
+	gcc -c $(subst -pedantic, , $(AM_CFLAGS)) -I/usr/include/python2.7 open62541_wrap_python.c
+
+_open62541.so: networklayer.so open62541_wrap_python.o
+	ld -shared open62541_wrap_python.o networklayer.so $(top_builddir)/lib/libopen62541.so -o _open62541.so
+
+all: open62541.py _open62541.so
+
+clean:
+	rm networklayer.so open62541.py open62541.pyc _open62541.so open62541_wrap_python.c open62541_wrap_python.o