Commit 27d44cf6 authored by Aurelien Jacobs's avatar Aurelien Jacobs Committed by Uwe Hermann

Implement Ruby bindings on top of SWIG/C++ bindings.

parent 0441038e
......@@ -654,6 +654,51 @@ CLEAN_EXTRA += python-clean
endif
if BINDINGS_RUBY
RDIR = bindings/ruby
RDOC = $(RDIR)/doc.i
RWRAP = $(RDIR)/classes_wrap.cpp
ROBJ = $(RWRAP:.cpp=.o)
REXT = $(RDIR)/sigrok.so
$(RDOC): $(srcdir)/bindings/swig/doc.py $(CPPXMLDOC)
$(AM_V_GEN)$(PYTHON) $(srcdir)/bindings/swig/doc.py ruby $(CPPXMLDOC) > $@
$(RWRAP): $(RDIR)/classes.i $(RDOC) \
bindings/swig/classes.i bindings/swig/templates.i \
bindings/swig/enums.i
$(AM_V_GEN)$(SWIG) -ruby -c++ -Ibindings -Ibindings/cxx/include $(swig_defs) -o $@ $<
$(ROBJ): $(RWRAP) \
$(library_include_HEADERS) \
$(nodist_library_include_HEADERS) \
$(bindings_cxx_libsigrokcxx_la_include_HEADERS) \
$(nodist_bindings_cxx_libsigrokcxx_la_include_HEADERS)
$(AM_V_CXX)$(CXX) $(RBSIGROK_CFLAGS) -I. -Iinclude -Ibindings/cxx/include -fPIC -o $@ -c $<
$(REXT): $(ROBJ) @ORDER@ bindings/cxx/libsigrokcxx.la
$(AM_V_CXXLD)$(CXX) -shared -std=c++11 -o $@ $< -lsigrokcxx -Lbindings/cxx/.libs $(RBSIGROK_LIBS)
ruby-build: $(REXT)
ruby-install: $(REXT)
$(INSTALL) -d $(prefix)/$(RBSIGROK_EXTDIR)
$(INSTALL) $< $(prefix)/$(RBSIGROK_EXTDIR)
ruby-clean:
-$(AM_V_at)rm -fr $(RDIR)/doc
-$(AM_V_at)rm $(REXT) $(ROBJ) $(RWRAP) $(RDOC)
ruby-doc: $(RWRAP)
$(AM_V_at)yard doc -o $(RDIR)/doc $<
BUILD_EXTRA += ruby-build
INSTALL_EXTRA += ruby-install
CLEAN_EXTRA += ruby-clean
endif
if BINDINGS_JAVA
JDIR = bindings/java
......
......@@ -71,6 +71,13 @@ Requirements for the Python bindings:
- graphviz (optional, only needed for the Python API docs)
- doxypy (optional, only needed for the Python API docs)
Requirements for the Ruby bindings:
- libsigrokcxx >= 0.3.0 (the libsigrok C++ bindings, see above)
- Ruby >= 1.9.3 (including development files!)
- SWIG >= 3.0.8
- YARD (optional, only needed for the Ruby API docs)
Requirements for the Java bindings:
- libsigrokcxx >= 0.3.0 (the libsigrok C++ bindings, see above)
......
This diff is collapsed.
......@@ -45,6 +45,8 @@ for compound in index.findall('compound'):
if brief:
if language == 'python':
print('%%feature("docstring") %s "%s";' % (class_name, brief))
elif language == 'ruby':
print('%%feature("docstring") %s "/* Document-class: %s\\n%s */\\n";' % (class_name, class_name.replace("sigrok", "Sigrok", 1), brief))
elif language == 'java':
print('%%typemap(javaclassmodifiers) %s "/** %s */\npublic class"' % (
class_name, brief))
......@@ -73,6 +75,12 @@ for compound in index.findall('compound'):
class_name, member_name, brief)] + [
'@param %s %s' % (name, desc)
for name, desc in parameters.items()]) + '";')
if language == 'ruby' and kind == 'public-func':
print(str.join('\n', [
'%%feature("docstring") %s::%s "/* %s' % (
class_name, member_name, brief)] + [
'@param %s %s' % (name, desc)
for name, desc in parameters.items()]) + ' */\\n";')
elif language == 'java' and kind == 'public-func':
print(str.join('\n', [
'%%javamethodmodifiers %s::%s "/** %s' % (
......@@ -101,3 +109,6 @@ for compound in index.findall('compound'):
print('%s.%s.__doc__ = """%s"""' % (
trimmed_name, member_name, brief))
print('%}')
elif language == 'ruby' and constants:
for member_name, brief in constants:
print('%%feature("docstring") %s::%s "/* %s */\\n";' % (class_name, member_name, brief))
......@@ -91,6 +91,7 @@ SR_VAR_OPT_PKG([SR_PKGLIBS], [sr_deps_avail])
SR_PKGLIBS_TESTS=
SR_PKGLIBS_CXX=
SR_PKGLIBS_PYTHON=
SR_PKGLIBS_RUBY=
SR_EXTRA_LIBS=
SR_ARG_OPT_PKG([libserialport], [LIBSERIALPORT], [NEED_SERIAL],
......@@ -282,6 +283,10 @@ AC_ARG_ENABLE([python],
[AS_HELP_STRING([--enable-python], [build Python bindings [default=yes]])],
[], [enable_python=$enable_bindings])
AC_ARG_ENABLE([ruby],
[AS_HELP_STRING([--enable-ruby], [build Ruby bindings [default=yes]])],
[], [enable_ruby=$enable_bindings])
AC_ARG_ENABLE([java],
[AS_HELP_STRING([--enable-java], [build Java bindings [default=yes]])],
[], [enable_java=$enable_bindings])
......@@ -386,6 +391,41 @@ AS_IF([test -z "$sr_python_missing"],
[BINDINGS_PYTHON=$enable_python], [BINDINGS_PYTHON=no])
AM_CONDITIONAL([BINDINGS_PYTHON], [test "x$BINDINGS_PYTHON" = xyes])
#####################
## Ruby bindings ##
#####################
AS_IF([test "x$BINDINGS_CXX" = xyes],
[sr_ruby_missing=],
[sr_ruby_missing='C++ bindings'])
AX_RUBY_EXT
AS_IF([test "x$RUBY" = x],
[SR_APPEND([sr_ruby_missing], [', '], ['Ruby'])])
# Extract major and minor version number of the Ruby interpreter.
sr_rbmajor=${RUBY_VERSION%%.*}
sr_rbminor=${RUBY_VERSION#*.}
sr_rbminor=${sr_rbminor%%.*}
# The Ruby bindings need Ruby development files.
SR_PKG_CHECK([ruby_dev], [SR_PKGLIBS_RUBY],
[ruby],
[ruby-$sr_rbmajor.$sr_rbminor])
AS_IF([test "x$sr_have_ruby_dev" != xyes],
[SR_APPEND([sr_ruby_missing], [', '], [Headers])])
# The Ruby bindings use SWIG to generate code.
AS_IF([test "x$SWIG" = x],
[SR_APPEND([sr_ruby_missing], [', '], [SWIG])])
AS_IF([test -z "$sr_ruby_missing"],
[BINDINGS_RUBY=$enable_ruby], [BINDINGS_RUBY=no])
AM_CONDITIONAL([BINDINGS_RUBY], [test "x$BINDINGS_RUBY" = xyes])
# AC_SUBST(RUBY_EXT_DLEXT, $RUBY_EXT_DLEXT)
####################
## Java bindings ##
####################
......@@ -454,6 +494,7 @@ PKG_CHECK_MODULES([TESTS], [$SR_PKGLIBS_TESTS glib-2.0 $SR_PKGLIBS])
AM_COND_IF([BINDINGS_CXX], [
PKG_CHECK_MODULES([LIBSIGROKCXX], [$SR_PKGLIBS_CXX])
PKG_CHECK_MODULES([PYSIGROK], [$SR_PKGLIBS_PYTHON $SR_PKGLIBS_CXX])
PKG_CHECK_MODULES([RBSIGROK], [$SR_PKGLIBS_RUBY $SR_PKGLIBS_CXX], [AC_SUBST(RBSIGROK_EXTDIR, "lib/$($PKG_CONFIG --variable=sitearch $SR_PKGLIBS_RUBY)/$($PKG_CONFIG --variable=RUBY_BASE_NAME $SR_PKGLIBS_RUBY)/vendor_ruby/$($PKG_CONFIG --variable=ruby_version $SR_PKGLIBS_RUBY)")])
])
# Check for specific libusb features, now that we know the CFLAGS.
......@@ -490,7 +531,7 @@ m4_define([SR_PREPARE_BINDING_REPORT], [
test -z "$sr_$1_missing" || sr_report_$1=" (missing: $sr_$1_missing)"
test "x$enable_$1" = xyes || sr_report_$1=' (disabled)'
])
m4_map_args([SR_PREPARE_BINDING_REPORT], [cxx], [python], [java])
m4_map_args([SR_PREPARE_BINDING_REPORT], [cxx], [python], [ruby], [java])
cat >&AS_MESSAGE_FD <<_EOF
......@@ -531,6 +572,7 @@ Enabled SCPI backends:
Enabled language bindings:
- C++............................. $BINDINGS_CXX$sr_report_cxx
- Python.......................... $BINDINGS_PYTHON$sr_report_python
- Ruby............................ $BINDINGS_RUBY$sr_report_ruby
- Java............................ $BINDINGS_JAVA$sr_report_java
_EOF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment