[packages/libsigrok] - added python patch, compile also optimized modules - added missing patch (missing file for Ruby bi

qboosh qboosh at pld-linux.org
Sat Jul 2 10:05:11 CEST 2016


commit 96fc3c0561c3f9ba317a03fcf4cdee60d9bb59ac
Author: Jakub Bogusz <qboosh at pld-linux.org>
Date:   Sat Jul 2 10:05:13 2016 +0200

    - added python patch, compile also optimized modules
    - added missing patch (missing file for Ruby bindings)
    - added ruby patch (fix ruby module build and install path), build ruby module
    - added java patch (adjust jni module install path), build java module)
    - updated dependencies

 libsigrok-java.patch    |  16 ++
 libsigrok-missing.patch | 431 ++++++++++++++++++++++++++++++++++++++++++++++++
 libsigrok-python.patch  |  11 ++
 libsigrok-ruby.patch    |  34 ++++
 libsigrok.spec          | 206 ++++++++++++++++-------
 5 files changed, 640 insertions(+), 58 deletions(-)
---
diff --git a/libsigrok.spec b/libsigrok.spec
index f7e540b..e707f38 100644
--- a/libsigrok.spec
+++ b/libsigrok.spec
@@ -1,12 +1,10 @@
-# TODO:
-# - bindings (ruby, java)
 #
 # Conditional build:
 %bcond_without	static_libs	# static library
-%bcond_without	python2 # CPython 2.x module
-%bcond_without	python3 # CPython 3.x module
-
-%define	module	sigrok
+%bcond_without	java		# Java bindings
+%bcond_without	python2		# CPython 2.x module
+%bcond_without	python3		# CPython 3.x module
+%bcond_without	ruby		# Ruby module
 
 Summary:	Basic hardware access drivers for logic analyzers
 Summary(pl.UTF-8):	Podstawowe sterowniki dostępu do sprzętu dla analizatorów logicznych
@@ -17,6 +15,10 @@ License:	GPL v3+
 Group:		Libraries
 Source0:	http://sigrok.org/download/source/libsigrok/%{name}-%{version}.tar.gz
 # Source0-md5:	6cd64b94be0b8ce7224de8c823f735aa
+Patch0:		%{name}-python.patch
+Patch1:		%{name}-missing.patch
+Patch2:		%{name}-ruby.patch
+Patch3:		%{name}-java.patch
 URL:		http://www.sigrok.org/
 BuildRequires:	autoconf >= 2.63
 BuildRequires:	automake >= 1:1.11
@@ -24,28 +26,46 @@ BuildRequires:	automake >= 1:1.11
 BuildRequires:	doxygen
 BuildRequires:	gcc >= 6:4.0
 BuildRequires:	glib2-devel >= 1:2.32.0
+BuildRequires:	glibmm-devel >= 2.32.0
 BuildRequires:	graphviz
-BuildRequires:	libftdi-devel >= 0.16
+%{?with_java:BuildRequires:	jdk}
+BuildRequires:	libftdi1-devel >= 1.0
+# TODO:
+#BuildRequires:	libgpib-devel
+BuildRequires:	libieee1284-devel
 BuildRequires:	librevisa-devel >= 0.0.20130812
 BuildRequires:	libserialport-devel >= 0.1.1
+BuildRequires:	libstdc++-devel >= 6:4.7
 BuildRequires:	libtool >= 2:2
 BuildRequires:	libusb-devel >= 1.0.16
 BuildRequires:	libzip-devel >= 0.10
 BuildRequires:	pkgconfig >= 1:0.22
+# required also for C++ binding
+BuildRequires:	python >= 1:2.7
 %if %{with python2}
-BuildRequires:	python-modules
+BuildRequires:	python-modules >= 1:2.7
 BuildRequires:	python-numpy-devel
+BuildRequires:	python-pygobject3-devel >= 3.0.0
 BuildRequires:	python-setuptools
 %endif
 %if %{with python3}
-BuildRequires:	python3-modules
+BuildRequires:	python3-modules >= 1:3.2
 BuildRequires:	python3-numpy-devel
+BuildRequires:	python3-pygobject3-devel >= 3.0.0
 BuildRequires:	python3-setuptools
 %endif
+BuildRequires:	rpm-pythonprov
+BuildRequires:	rpmbuild(macros) >= 1.612
+%{?with_ruby:BuildRequires:	ruby-devel}
+%{?with_java:BuildRequires:	swig}
+%if %{with python2} || %{with python3}
+BuildRequires:	swig-python
+%endif
+%{?with_ruby:BuildRequires:	swig-ruby >= 3.0.8}
 Requires:	glib2 >= 1:2.32.0
-Requires:	libftdi >= 0.16
+Requires:	libftdi1 >= 1.0
 Requires:	librevisa >= 0.0.20130812
-Requires:	libserialport >= 0.1.0
+Requires:	libserialport >= 0.1.1
 Requires:	libusb >= 1.0.16
 Requires:	libzip >= 0.10
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
@@ -67,8 +87,10 @@ Summary(pl.UTF-8):	Pliki programistyczne biblioteki libsigrok
 Group:		Development/Libraries
 Requires:	%{name} = %{version}-%{release}
 Requires:	glib2-devel >= 1:2.32.0
-Requires:	libftdi-devel >= 0.16
+Requires:	libftdi1-devel >= 1.0
+Requires:	libieee1284-devel
 Requires:	librevisa-devel >= 0.0.20130812
+Requires:	libserialport-devel >= 0.1.1
 Requires:	libusb-devel >= 1.0.16
 Requires:	libzip-devel >= 0.10
 
@@ -93,65 +115,108 @@ Static libsigrok library.
 Statyczna biblioteka libsigrok.
 
 %package c++
-Summary:	C++ libsigrok library
-Summary(pl.UTF-8):	Biblioteka C++ libsigrok
-Group:		Development/Libraries
+Summary:	C++ bindings for libsigrok library
+Summary(pl.UTF-8):	Wiązania C++ do biblioteki libsigrok
+Group:		Libraries
 Requires:	%{name} = %{version}-%{release}
+Requires:	glibmm >= 2.32.0
 
 %description c++
-C++ libsigrok library.
+C++ bindings for libsigrok library.
 
 %description c++ -l pl.UTF-8
-Biblioteka C++ libsigrok.
+Wiązania C++ do biblioteki libsigrok.
 
 %package c++-devel
-Summary:	Header files for develop C++ libsigrok based application
-Summary(pl.UTF-8):	Pliki nagłówkowe do biblioteki C++ libsigrok
+Summary:	Header files for libsigrokcxx based applications
+Summary(pl.UTF-8):	Pliki nagłówkowe biblioteki libsigrokcxx
 Group:		Development/Libraries
 Requires:	%{name}-c++ = %{version}-%{release}
+Requires:	%{name}-devel = %{version}-%{release}
+Requires:	glibmm-devel >= 2.32.0
+Requires:	libstdc++-devel
 
 %description c++-devel
-This package includes the header files and libraries necessary to
-develop applications that use C++ libsigrok.
+This package includes the header files necessary to develop
+applications that use libsigrokcxx library.
 
 %description c++-devel -l pl.UTF-8
 Pakiet ten zawiera pliki nagłówkowe niezbędne do kompilacji programów
-z wykorzystaniem biblioteki c++-libsigrok.
+z wykorzystaniem biblioteki libsigrokcxx.
 
 %package c++-static
-Summary:	Static libraries for C++ libsigrok
-Summary(pl.UTF-8):	Biblioteki statyczne C++ libsigrok
+Summary:	Static libsigrokcxx library
+Summary(pl.UTF-8):	Biblioteka statyczna libsigrokcxx
 Group:		Development/Libraries
 Requires:	%{name}-c++-devel = %{version}-%{release}
 
 %description c++-static
-This package includes the static libraries necessary to develop
-applications that use C++ libsigrok.
+Static libsigrokcxx library.
 
 %description c++-static -l pl.UTF-8
-Pakiet ten zawiera biblioteki statyczne C++ libsigrok.
+Biblioteka statyczna libsigrokcxx.
+
+%package -n java-sigrok
+Summary:	Java bindings for libsigrok library
+Summary(pl.UTF-8):	Wiązania Javy do biblioteki libsigrok
+Group:		Libraries/Java
+Requires:	%{name}-c++ = %{version}-%{release}
+Requires:	jre
+
+%description -n java-sigrok
+Java bindings for libsigrok library.
 
-%package -n python-%{module}
-Summary:	libsigrok python bindings
+%description -n java-sigrok -l pl.UTF-8
+Wiązania Javy do biblioteki libsigrok.
+
+%package -n python-sigrok
+Summary:	Python 2 bindings for libsigrok library
+Summary(pl.UTF-8):	Wiązania Pythona 2 do biblioteki libsigrok
 Group:		Libraries/Python
-Requires:	python-modules
+Requires:	%{name}-c++ = %{version}-%{release}
+Requires:	python-modules >= 1:2.7
+
+%description -n python-sigrok
+Python 2 bindings for libsigrok library.
 
-%description -n python-%{module}
-libsigrok python bindings.
+%description -n python-sigrok -l pl.UTF-8
+Wiązania Pythona 2 do biblioteki libsigrok.
 
-%package -n python3-%{module}
-Summary:	libsigrok python bindings
+%package -n python3-sigrok
+Summary:	Python 3 bindings for libsigrok library
+Summary(pl.UTF-8):	Wiązania Pythona 3 do biblioteki libsigrok
 Group:		Libraries/Python
-Requires:	python3-modules
+Requires:	%{name}-c++ = %{version}-%{release}
+Requires:	python3-modules >= 1:3.2
+
+%description -n python3-sigrok
+Python 3 bindings for libsigrok library.
+
+%description -n python3-sigrok -l pl.UTF-8
+Wiązania Pythona 3 do biblioteki libsigrok.
+
+%package -n ruby-sigrok
+Summary:	Ruby bindings for libsigrok library
+Summary(pl.UTF-8):	Wiązania języka Ruby do biblioteki libsigrok
+Group:		Libraries/Java
+Requires:	%{name}-c++ = %{version}-%{release}
+Requires:	ruby
+
+%description -n ruby-sigrok
+Ruby bindings for libsigrok library.
 
-%description -n python3-%{module}
-libsigrok python bindings.
+%description -n ruby-sigrok -l pl.UTF-8
+Wiązania języka Ruby do biblioteki libsigrok.
 
 %prep
 %setup -q
+%patch0 -p1
+%patch1 -p1
+%patch2 -p1
+%patch3 -p1
 
 %build
-install -d autostuff
+#install -d autostuff
 %{__libtoolize}
 %{__aclocal} -I m4
 %{__autoconf}
@@ -159,16 +224,18 @@ install -d autostuff
 %{__automake}
 
 %if %{with python3}
-install -d .py3-bindings
-cp -a * .py3-bindings
+install -d build-py3
+cd build-py3
+#install -d .py3-bindings
+#cp -a * .py3-bindings
 
-cd .py3-bindings
-%configure \
+#cd .py3-bindings
+../%configure \
 	PYTHON="%{__python3}" \
 	--disable-all-drivers \
-	--disable-silent-rules \
-	--disable-ruby \
 	--disable-java \
+	--disable-ruby \
+	--disable-silent-rules \
 	--disable-static \
 	--enable-python
 %{__make} python-build
@@ -178,10 +245,10 @@ cd ..
 %configure \
 	PYTHON="%{__python}" \
 	--enable-all-drivers \
+	--enable-java%{!?with_java:=no} \
+	--enable-python%{!?with_python2:=no} \
+	--enable-ruby%{!?with_ruby:=no} \
 	--disable-silent-rules \
-	--disable-ruby \
-	--disable-java \
-	--%{?with_python2:en}%{!?with_python2:dis}able-python \
 	%{!?with_static_libs:--disable-static}
 
 %{__make}
@@ -193,7 +260,8 @@ rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT{/lib/udev/rules.d,%{_datadir}/sigrok-firmware}
 
 %if %{with python3}
-%{__make} -C .py3-bindings python-install \
+#%{__make} -C .py3-bindings python-install
+%{__make} -C build-py3 python-install \
 	DESTDIR=$RPM_BUILD_ROOT
 %endif
 
@@ -205,6 +273,10 @@ sed -e 's#plugdev#usb#g' contrib/z60_libsigrok.rules > $RPM_BUILD_ROOT/lib/udev/
 # obsoleted by pkg-config
 %{__rm} $RPM_BUILD_ROOT%{_libdir}/libsigrok{,cxx}.la
 
+%if %{with python2}
+%py_postclean
+%endif
+
 %clean
 rm -rf $RPM_BUILD_ROOT
 
@@ -252,20 +324,38 @@ rm -rf $RPM_BUILD_ROOT
 %{_libdir}/libsigrokcxx.a
 %endif
 
-%if %{with python2}
-%files -n python-%{module}
+%if %{with java}
+%files -n java-sigrok
 %defattr(644,root,root,755)
-%{py_sitedir}/%{module}
-%if "%{py_ver}" > "2.4"
-%{py_sitedir}/*%{module}-%{version}-py*.egg-info
-%{py_sitedir}/*%{module}-%{version}-py*.pth
+%attr(755,root,root) %{_libdir}/libsigrok_java_core_classes.so
+%{_javadir}/sigrok-core.jar
 %endif
+
+%if %{with python2}
+%files -n python-sigrok
+%defattr(644,root,root,755)
+%dir %{py_sitedir}/sigrok
+%dir %{py_sitedir}/sigrok/core
+%attr(755,root,root) %{py_sitedir}/sigrok/core/_classes.so
+%{py_sitedir}/sigrok/core/*.py[co]
+%{py_sitedir}/libsigrok-%{version}-py*.egg-info
+%{py_sitedir}/libsigrok-%{version}-py*.pth
 %endif
 
 %if %{with python3}
-%files -n python3-%{module}
+%files -n python3-sigrok
+%defattr(644,root,root,755)
+%dir %{py3_sitedir}/sigrok
+%dir %{py3_sitedir}/sigrok/core
+%attr(755,root,root) %{py3_sitedir}/sigrok/core/_classes.cpython-*.so
+%{py3_sitedir}/sigrok/core/*.py
+%{py3_sitedir}/sigrok/core/__pycache__
+%{py3_sitedir}/libsigrok-%{version}-py*.egg-info
+%{py3_sitedir}/libsigrok-%{version}-py*.pth
+%endif
+
+%if %{with ruby}
+%files -n ruby-sigrok
 %defattr(644,root,root,755)
-%{py3_sitedir}/%{module}
-%{py3_sitedir}/*%{module}-%{version}-py*.egg-info
-%{py3_sitedir}/*%{module}-%{version}-py*.pth
+%attr(755,root,root) %{ruby_vendorarchdir}/sigrok.so
 %endif
diff --git a/libsigrok-java.patch b/libsigrok-java.patch
new file mode 100644
index 0000000..55dce9c
--- /dev/null
+++ b/libsigrok-java.patch
@@ -0,0 +1,16 @@
+--- libsigrok-0.4.0/Makefile.am.orig	2016-07-02 08:54:03.332196411 +0200
++++ libsigrok-0.4.0/Makefile.am	2016-07-02 08:54:51.591934967 +0200
+@@ -743,9 +743,11 @@
+ 		-fno-strict-aliasing -fPIC -shared $(JCLS)/classes_wrap.cxx \
+ 		-lsigrokcxx $(LIBSIGROKCXX_LIBS) -o $(JLIB)
+ 
++jnilibdir = $(libdir)
++
+ java-install:
+-	$(INSTALL) -d $(DESTDIR)$(libdir)/jni
+-	$(INSTALL) $(JLIB) $(DESTDIR)$(libdir)/jni
++	$(INSTALL) -d $(DESTDIR)$(jnilibdir)
++	$(INSTALL) $(JLIB) $(DESTDIR)$(jnilibdir)
+ 	$(INSTALL) -d $(DESTDIR)$(datadir)/java
+ 	$(INSTALL) $(JJAR) $(DESTDIR)$(datadir)/java
+ 
diff --git a/libsigrok-missing.patch b/libsigrok-missing.patch
new file mode 100644
index 0000000..7044855
--- /dev/null
+++ b/libsigrok-missing.patch
@@ -0,0 +1,431 @@
+--- libsigrok-0.4.0/bindings/ruby/classes.i.orig	1970-01-01 01:00:00.000000000 +0100
++++ libsigrok-0.4.0/bindings/ruby/classes.i	2016-06-30 21:17:12.340108319 +0200
+@@ -0,0 +1,428 @@
++/*
++ * This file is part of the libsigrok project.
++ *
++ * Copyright (C) 2016 Aurelien Jacobs <aurel at gnuage.org>
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++
++%define DOCSTRING
++"
++= Introduction
++
++The sigrok Ruby API provides an object-oriented Ruby interface to the
++functionality in libsigrok. It is built on top of the libsigrokcxx C++ API.
++
++= Getting started
++
++Usage of the sigrok Ruby API needs to begin with a call to Context.create().
++This will create the global libsigrok context and returns a Context object.
++Methods on this object provide access to the hardware drivers, input and output
++formats supported by the library, as well as means of creating other objects
++such as sessions and triggers.
++
++= Error handling
++
++When any libsigrok C API call returns an error, an Error exception is raised,
++which provides access to the error code and description."
++%enddef
++
++%module(docstring=DOCSTRING) sigrok
++
++%{
++#include <stdio.h>
++#include <glibmm.h>
++
++#include "config.h"
++%}
++
++%include "../swig/templates.i"
++
++%{
++static const char *string_from_ruby(VALUE obj)
++{
++    switch (TYPE(obj)) {
++    case T_STRING:
++        return StringValueCStr(obj);
++    case T_SYMBOL:
++        return rb_id2name(SYM2ID(obj));
++    default:
++        throw sigrok::Error(SR_ERR_ARG);
++    }
++}
++
++/* Convert from Glib::Variant to native Ruby types. */
++static VALUE variant_to_ruby(Glib::VariantBase variant)
++{
++    if (variant.is_of_type(Glib::VARIANT_TYPE_BOOL)) {
++        return Glib::VariantBase::cast_dynamic< Glib::Variant<bool> >(variant).get() ? Qtrue : Qfalse;
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_BYTE)) {
++        return UINT2NUM(Glib::VariantBase::cast_dynamic< Glib::Variant<unsigned char> >(variant).get());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_INT16)) {
++        return INT2NUM(Glib::VariantBase::cast_dynamic< Glib::Variant<gint16> >(variant).get());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_UINT16)) {
++        return UINT2NUM(Glib::VariantBase::cast_dynamic< Glib::Variant<guint16> >(variant).get());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_INT32)) {
++        return INT2NUM(Glib::VariantBase::cast_dynamic< Glib::Variant<gint32> >(variant).get());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_UINT32)) {
++        return UINT2NUM(Glib::VariantBase::cast_dynamic< Glib::Variant<guint32> >(variant).get());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_INT64)) {
++        return LL2NUM(Glib::VariantBase::cast_dynamic< Glib::Variant<gint64> >(variant).get());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_UINT64)) {
++        return ULL2NUM(Glib::VariantBase::cast_dynamic< Glib::Variant<guint64> >(variant).get());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_DOUBLE)) {
++        return DBL2NUM(Glib::VariantBase::cast_dynamic< Glib::Variant<double> >(variant).get());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_STRING)) {
++        auto str = Glib::VariantBase::cast_dynamic< Glib::Variant<std::string> >(variant).get();
++        return rb_str_new(str.c_str(), str.length());
++    } else if (variant.is_of_type(Glib::VARIANT_TYPE_VARIANT)) {
++        auto var = Glib::VariantBase::cast_dynamic< Glib::Variant<Glib::VariantBase> >(variant).get();
++        return variant_to_ruby(var);
++    } else if (variant.is_container()) {
++        Glib::VariantContainerBase container = Glib::VariantBase::cast_dynamic< Glib::VariantContainerBase > (variant);
++        gsize count = container.get_n_children();
++        if (container.is_of_type(Glib::VARIANT_TYPE_DICTIONARY)) {
++            VALUE hash = rb_hash_new();
++            for (gsize i = 0; i < count; i++) {
++                Glib::VariantContainerBase entry = Glib::VariantBase::cast_dynamic< Glib::VariantContainerBase > (container.get_child(i));
++                VALUE key = variant_to_ruby(entry.get_child(0));
++                VALUE val = variant_to_ruby(entry.get_child(1));
++                rb_hash_aset(hash, key, val);
++            }
++            return hash;
++        } else if (container.is_of_type(Glib::VARIANT_TYPE_ARRAY) ||
++                   container.is_of_type(Glib::VARIANT_TYPE_TUPLE)) {
++            VALUE array = rb_ary_new2(count);
++            for (gsize i = 0; i < count; i++) {
++                VALUE val = variant_to_ruby(container.get_child(i));
++                rb_ary_store(array, i, val);
++            }
++            return array;
++        }
++    } else {
++        SWIG_exception(SWIG_TypeError, ("TODO: GVariant(" + variant.get_type().get_string() + ") -> Ruby").c_str());
++    }
++}
++%}
++
++/* Map from Glib::Variant to native Ruby types. */
++%typemap(out) Glib::VariantBase {
++    $result = variant_to_ruby($1);
++}
++
++/* Map from Glib::VariantContainer to native Ruby types. */
++%typemap(out) Glib::VariantContainerBase {
++    $result = variant_to_ruby($1);
++}
++
++/* Map from callable Ruby Proc to LogCallbackFunction */
++%typemap(in) sigrok::LogCallbackFunction {
++    if (!rb_obj_is_proc($input))
++        SWIG_exception(SWIG_TypeError, "Expected a callable Ruby object");
++
++    std::shared_ptr<VALUE> proc(new VALUE($input), rb_gc_unregister_address);
++    rb_gc_register_address(proc.get());
++
++    $1 = [=] (const sigrok::LogLevel *loglevel, std::string message) {
++        VALUE log_obj = SWIG_NewPointerObj(
++                SWIG_as_voidptr(loglevel), SWIGTYPE_p_sigrok__LogLevel, 0);
++
++        VALUE string_obj = rb_external_str_new_with_enc(message.c_str(), message.length(), rb_utf8_encoding());
++
++        VALUE args = rb_ary_new_from_args(2, log_obj, string_obj);
++        rb_proc_call(*proc.get(), args);
++    };
++}
++
++/* Map from callable Ruby Proc to SessionStoppedCallback */
++%typemap(in) sigrok::SessionStoppedCallback {
++    if (!rb_obj_is_proc($input))
++        SWIG_exception(SWIG_TypeError, "Expected a callable Ruby object");
++
++    std::shared_ptr<VALUE> proc(new VALUE($input), rb_gc_unregister_address);
++    rb_gc_register_address(proc.get());
++
++    $1 = [=] () {
++        rb_proc_call(*proc.get(), rb_ary_new());
++    };
++}
++
++/* Map from callable Ruby Proc to DatafeedCallbackFunction */
++%typemap(in) sigrok::DatafeedCallbackFunction {
++    if (!rb_obj_is_proc($input))
++        SWIG_exception(SWIG_TypeError, "Expected a callable Ruby object");
++
++    std::shared_ptr<VALUE> proc(new VALUE($input), rb_gc_unregister_address);
++    rb_gc_register_address(proc.get());
++
++    $1 = [=] (std::shared_ptr<sigrok::Device> device,
++            std::shared_ptr<sigrok::Packet> packet) {
++        VALUE device_obj = SWIG_NewPointerObj(
++            SWIG_as_voidptr(new std::shared_ptr<sigrok::Device>(device)),
++            SWIGTYPE_p_std__shared_ptrT_sigrok__Device_t, SWIG_POINTER_OWN);
++
++        VALUE packet_obj = SWIG_NewPointerObj(
++            SWIG_as_voidptr(new std::shared_ptr<sigrok::Packet>(packet)),
++            SWIGTYPE_p_std__shared_ptrT_sigrok__Packet_t, SWIG_POINTER_OWN);
++
++        VALUE args = rb_ary_new_from_args(2, device_obj, packet_obj);
++        rb_proc_call(*proc.get(), args);
++    };
++}
++
++/* Cast PacketPayload pointers to correct subclass type. */
++%ignore sigrok::Packet::payload;
++%rename sigrok::Packet::_payload payload;
++%extend sigrok::Packet
++{
++    VALUE _payload()
++    {
++        if ($self->type() == sigrok::PacketType::HEADER) {
++            return SWIG_NewPointerObj(
++                SWIG_as_voidptr(new std::shared_ptr<sigrok::Header>(dynamic_pointer_cast<sigrok::Header>($self->payload()))),
++                SWIGTYPE_p_std__shared_ptrT_sigrok__Header_t, SWIG_POINTER_OWN);
++        } else if ($self->type() == sigrok::PacketType::META) {
++            return SWIG_NewPointerObj(
++                SWIG_as_voidptr(new std::shared_ptr<sigrok::Meta>(dynamic_pointer_cast<sigrok::Meta>($self->payload()))),
++                SWIGTYPE_p_std__shared_ptrT_sigrok__Meta_t, SWIG_POINTER_OWN);
++        } else if ($self->type() == sigrok::PacketType::ANALOG) {
++            return SWIG_NewPointerObj(
++                SWIG_as_voidptr(new std::shared_ptr<sigrok::Analog>(dynamic_pointer_cast<sigrok::Analog>($self->payload()))),
++                SWIGTYPE_p_std__shared_ptrT_sigrok__Analog_t, SWIG_POINTER_OWN);
++        } else if ($self->type() == sigrok::PacketType::LOGIC) {
++            return SWIG_NewPointerObj(
++                SWIG_as_voidptr(new std::shared_ptr<sigrok::Logic>(dynamic_pointer_cast<sigrok::Logic>($self->payload()))),
++                SWIGTYPE_p_std__shared_ptrT_sigrok__Logic_t, SWIG_POINTER_OWN);
++        } else {
++            return Qnil;
++        }
++    }
++}
++
++%{
++
++#include "libsigrokcxx/libsigrokcxx.hpp"
++
++/* Convert from a Ruby type to Glib::Variant, according to config key data type. */
++Glib::VariantBase ruby_to_variant_by_key(VALUE input, const sigrok::ConfigKey *key)
++{
++    enum sr_datatype type = (enum sr_datatype) key->data_type()->id();
++
++    if (type == SR_T_UINT64 && RB_TYPE_P(input, T_FIXNUM))
++        return Glib::Variant<guint64>::create(NUM2ULL(input));
++    if (type == SR_T_UINT64 && RB_TYPE_P(input, T_BIGNUM))
++        return Glib::Variant<guint64>::create(NUM2ULL(input));
++    else if (type == SR_T_STRING && RB_TYPE_P(input, T_STRING))
++        return Glib::Variant<Glib::ustring>::create(string_from_ruby(input));
++    else if (type == SR_T_STRING && RB_TYPE_P(input, T_SYMBOL))
++        return Glib::Variant<Glib::ustring>::create(string_from_ruby(input));
++    else if (type == SR_T_BOOL && RB_TYPE_P(input, T_TRUE))
++        return Glib::Variant<bool>::create(true);
++    else if (type == SR_T_BOOL && RB_TYPE_P(input, T_FALSE))
++        return Glib::Variant<bool>::create(false);
++    else if (type == SR_T_FLOAT && RB_TYPE_P(input, T_FLOAT))
++        return Glib::Variant<double>::create(RFLOAT_VALUE(input));
++    else if (type == SR_T_INT32 && RB_TYPE_P(input, T_FIXNUM))
++        return Glib::Variant<gint32>::create(NUM2INT(input));
++    else
++        throw sigrok::Error(SR_ERR_ARG);
++}
++
++/* Convert from a Ruby type to Glib::Variant, according to Option data type. */
++Glib::VariantBase ruby_to_variant_by_option(VALUE input, std::shared_ptr<sigrok::Option> option)
++{
++    Glib::VariantBase variant = option->default_value();
++
++    if (variant.is_of_type(Glib::VARIANT_TYPE_UINT64) && RB_TYPE_P(input, T_FIXNUM))
++        return Glib::Variant<guint64>::create(NUM2ULL(input));
++    else if (variant.is_of_type(Glib::VARIANT_TYPE_UINT64) && RB_TYPE_P(input, T_BIGNUM))
++        return Glib::Variant<guint64>::create(NUM2ULL(input));
++    else if (variant.is_of_type(Glib::VARIANT_TYPE_STRING) && RB_TYPE_P(input, T_STRING))
++        return Glib::Variant<Glib::ustring>::create(string_from_ruby(input));
++    else if (variant.is_of_type(Glib::VARIANT_TYPE_STRING) && RB_TYPE_P(input, T_SYMBOL))
++        return Glib::Variant<Glib::ustring>::create(string_from_ruby(input));
++    else if (variant.is_of_type(Glib::VARIANT_TYPE_BOOL) && RB_TYPE_P(input, T_TRUE))
++        return Glib::Variant<bool>::create(true);
++    else if (variant.is_of_type(Glib::VARIANT_TYPE_BOOL) && RB_TYPE_P(input, T_FALSE))
++        return Glib::Variant<bool>::create(false);
++    else if (variant.is_of_type(Glib::VARIANT_TYPE_DOUBLE) && RB_TYPE_P(input, T_FLOAT))
++        return Glib::Variant<double>::create(RFLOAT_VALUE(input));
++    else if (variant.is_of_type(Glib::VARIANT_TYPE_INT32) && RB_TYPE_P(input, T_FIXNUM))
++        return Glib::Variant<gint32>::create(NUM2INT(input));
++    else
++        throw sigrok::Error(SR_ERR_ARG);
++}
++
++struct hash_to_map_options_params {
++    std::map<std::string, std::shared_ptr<sigrok::Option> > options;
++    std::map<std::string, Glib::VariantBase> output;
++};
++
++int convert_option(VALUE key, VALUE val, VALUE in) {
++    struct hash_to_map_options_params *params;
++    params = (struct hash_to_map_options_params *)in;
++
++    auto k = string_from_ruby(key);
++    auto v = ruby_to_variant_by_option(val, params->options[k]);
++    params->output[k] = v;
++
++    return ST_CONTINUE;
++}
++
++/* Convert from a Ruby hash to a std::map<std::string, Glib::VariantBase> */
++std::map<std::string, Glib::VariantBase> hash_to_map_options(VALUE hash,
++    std::map<std::string, std::shared_ptr<sigrok::Option> > options)
++{
++    if (!RB_TYPE_P(hash, T_HASH))
++        throw sigrok::Error(SR_ERR_ARG);
++
++    struct hash_to_map_options_params params = { options };
++    rb_hash_foreach(hash, (int (*)(ANYARGS))convert_option, (VALUE)&params);
++
++    return params.output;
++}
++
++int convert_option_by_key(VALUE key, VALUE val, VALUE in) {
++    std::map<const sigrok::ConfigKey *, Glib::VariantBase> *options;
++    options = (std::map<const sigrok::ConfigKey *, Glib::VariantBase> *)in;
++
++    auto k = sigrok::ConfigKey::get_by_identifier(string_from_ruby(key));
++    auto v = ruby_to_variant_by_key(val, k);
++    (*options)[k] = v;
++
++    return ST_CONTINUE;
++}
++
++%}
++
++/* Ignore these methods, we will override them below. */
++%ignore sigrok::Analog::data;
++%ignore sigrok::Driver::scan;
++%ignore sigrok::Input::send;
++%ignore sigrok::InputFormat::create_input;
++%ignore sigrok::OutputFormat::create_output;
++
++%include "doc.i"
++
++%define %attributevector(Class, Type, Name, Get)
++%alias sigrok::Class::_ ## Get #Name;
++%enddef
++
++%define %attributemap(Class, Type, Name, Get)
++%alias sigrok::Class::_ ## Get #Name;
++%enddef
++
++%define %enumextras(Class)
++%extend sigrok::Class
++{
++    VALUE to_s()
++    {
++        std::string str = $self->name();
++        return rb_external_str_new_with_enc(str.c_str(), str.length(), rb_utf8_encoding());
++    }
++
++    bool operator==(void *other)
++    {
++        return (long) $self == (long) other;
++    }
++}
++%enddef
++
++%include "../swig/classes.i"
++
++/* Replace the original Driver.scan with a keyword arguments version. */
++%rename sigrok::Driver::_scan scan;
++%extend sigrok::Driver
++{
++    std::vector<std::shared_ptr<sigrok::HardwareDevice> > _scan(VALUE kwargs = rb_hash_new())
++    {
++        if (!RB_TYPE_P(kwargs, T_HASH))
++            throw sigrok::Error(SR_ERR_ARG);
++
++        std::map<const sigrok::ConfigKey *, Glib::VariantBase> options;
++        rb_hash_foreach(kwargs, (int (*)(ANYARGS))convert_option_by_key, (VALUE)&options);
++
++        return $self->scan(options);
++    }
++}
++
++/* Support Input.send() with string argument. */
++%rename sigrok::Input::_send send;
++%extend sigrok::Input
++{
++    void _send(VALUE data)
++    {
++        data = StringValue(data);
++        return $self->send(RSTRING_PTR(data), RSTRING_LEN(data));
++    }
++}
++
++/* Support InputFormat.create_input() with keyword arguments. */
++%rename sigrok::InputFormat::_create_input create_input;
++%extend sigrok::InputFormat
++{
++    std::shared_ptr<sigrok::Input> _create_input(VALUE hash = rb_hash_new())
++    {
++        return $self->create_input(hash_to_map_options(hash, $self->options()));
++    }
++}
++
++/* Support OutputFormat.create_output() with keyword arguments. */
++%rename sigrok::OutputFormat::_create_output create_output;
++%extend sigrok::OutputFormat
++{
++    std::shared_ptr<sigrok::Output> _create_output(
++        std::shared_ptr<sigrok::Device> device, VALUE hash = rb_hash_new())
++    {
++        return $self->create_output(device,
++            hash_to_map_options(hash, $self->options()));
++    }
++
++    std::shared_ptr<sigrok::Output> _create_output(string filename,
++        std::shared_ptr<sigrok::Device> device, VALUE hash = rb_hash_new())
++    {
++        return $self->create_output(filename, device,
++            hash_to_map_options(hash, $self->options()));
++    }
++}
++
++/* Support config_set() with Ruby input types. */
++%extend sigrok::Configurable
++{
++    void config_set(const ConfigKey *key, VALUE input)
++    {
++        $self->config_set(key, ruby_to_variant_by_key(input, key));
++    }
++}
++
++/* Return Ruby array from Analog::data(). */
++%rename sigrok::Analog::_data data;
++%extend sigrok::Analog
++{
++    VALUE _data()
++    {
++        int num_channels = $self->channels().size();
++        int num_samples  = $self->num_samples();
++        float *data = (float *) $self->data_pointer();
++        VALUE channels = rb_ary_new2(num_channels);
++        for(int i = 0; i < num_channels; i++) {
++            VALUE samples = rb_ary_new2(num_samples);
++            for (int j = 0; j < num_samples; j++) {
++                rb_ary_store(samples, j, DBL2NUM(data[i*num_samples+j]));
++            }
++            rb_ary_store(channels, i, samples);
++        }
++        return channels;
++    }
++}
diff --git a/libsigrok-python.patch b/libsigrok-python.patch
new file mode 100644
index 0000000..b596896
--- /dev/null
+++ b/libsigrok-python.patch
@@ -0,0 +1,11 @@
+--- libsigrok-0.4.0/Makefile.am.orig	2016-01-29 23:44:34.000000000 +0100
++++ libsigrok-0.4.0/Makefile.am	2016-06-30 19:57:26.586034973 +0200
+@@ -638,7 +638,7 @@
+ python-install:
+ 	$(AM_V_at)$(MKDIR_P) "$(DESTDIR)$(prefix)" "$(DESTDIR)$(exec_prefix)"
+ 	destdir='$(DESTDIR)'; $(setup_py) install $${destdir:+"--root=$$destdir"} \
+-		--prefix "$(prefix)" --exec-prefix "$(exec_prefix)"
++		--prefix "$(prefix)" --exec-prefix "$(exec_prefix)" --install-purelib="$(pythondir)" --optimize=2
+ 
+ python-clean:
+ 	-$(AM_V_at)rm -f $(PDIR)/timestamp
diff --git a/libsigrok-ruby.patch b/libsigrok-ruby.patch
new file mode 100644
index 0000000..5ceaaa4
--- /dev/null
+++ b/libsigrok-ruby.patch
@@ -0,0 +1,34 @@
+--- libsigrok-0.4.0/Makefile.am.orig	2016-06-30 21:35:37.630787111 +0200
++++ libsigrok-0.4.0/Makefile.am	2016-07-01 05:59:31.576995763 +0200
+@@ -675,16 +675,16 @@
+ 		$(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 $<
++	$(AM_V_CXX)$(CXX) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) $(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)
++	$(AM_V_CXXLD)$(CXX) $(AM_CXXFLAGS) $(CXXFLAGS) -shared -std=c++11 -o $@ $< -lsigrokcxx -Lbindings/cxx/.libs $(RBSIGROK_LIBS)
+ 
+ ruby-build: $(REXT)
+ 
+ ruby-install: $(REXT)
+-	$(INSTALL) -d $(DESTDIR)$(prefix)/$(RBSIGROK_EXTDIR)
+-	$(INSTALL) $< $(DESTDIR)$(prefix)/$(RBSIGROK_EXTDIR)
++	$(INSTALL) -d $(DESTDIR)$(RBSIGROK_EXTDIR)
++	$(INSTALL) $< $(DESTDIR)$(RBSIGROK_EXTDIR)
+ 
+ ruby-clean:
+ 	-$(AM_V_at)rm -fr $(RDIR)/doc
+--- libsigrok-0.4.0/configure.ac.orig	2016-01-29 23:44:34.000000000 +0100
++++ libsigrok-0.4.0/configure.ac	2016-07-02 08:53:49.128940025 +0200
+@@ -506,7 +506,7 @@
+ 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)")])
++	PKG_CHECK_MODULES([RBSIGROK], [$SR_PKGLIBS_RUBY $SR_PKGLIBS_CXX], [AC_SUBST(RBSIGROK_EXTDIR, "$($PKG_CONFIG --variable=vendorarchdir $SR_PKGLIBS_RUBY)")])
+ ])
+ 
+ # Check for specific libusb features, now that we know the CFLAGS.
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/libsigrok.git/commitdiff/96fc3c0561c3f9ba317a03fcf4cdee60d9bb59ac



More information about the pld-cvs-commit mailing list