From: Martin Ling Date: Mon, 15 Apr 2013 19:01:07 +0000 (+0100) Subject: Add SWIG interface file and build script for Python bindings. X-Git-Tag: dsupstream~142 X-Git-Url: http://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=758b01adcbbc2cd4c077281ad06c7bb2ac414391 Add SWIG interface file and build script for Python bindings. --- diff --git a/.gitignore b/.gitignore index f2d4a5e8..5e6015bd 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,8 @@ Makefile.in # KDevelop project files *.kdev4 + +# Files generated by building Python bindings +bindings/python/build +bindings/python/libsigrok.py +bindings/python/libsigrok_python_wrap.c diff --git a/bindings/python/libsigrok_python.i b/bindings/python/libsigrok_python.i new file mode 100644 index 00000000..b3898724 --- /dev/null +++ b/bindings/python/libsigrok_python.i @@ -0,0 +1,20 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2013 Martin Ling + * + * 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 3 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 . + */ + +%include "../swig/libsigrok.i" diff --git a/bindings/python/setup.py b/bindings/python/setup.py new file mode 100644 index 00000000..0d854afd --- /dev/null +++ b/bindings/python/setup.py @@ -0,0 +1,45 @@ +# +# This file is part of the sigrok project. +# +# Copyright (C) 2013 Martin Ling +# +# 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 3 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 . + +from distutils.core import setup, Extension +import subprocess + +sr_includes = subprocess.check_output( + ["pkg-config", "--cflags", "libsigrok"]).rstrip().split(' ') + +sr_libs = subprocess.check_output( + ["pkg-config", "--libs", "libsigrok"]).rstrip().split(' ') + +sr_version = subprocess.check_output( + ["pkg-config", "--version", "libsigrok"]).rstrip() + +setup( + name = 'libsigrok', + version = sr_version, + description = "libsigrok API wrapper", + py_modules = ['libsigrok'], + ext_modules = [ + Extension('_libsigrok', + sources = ['libsigrok_python.i'], + swig_opts = sr_includes, + include_dirs = [i[2:] for i in sr_includes if i.startswith('-I')], + library_dirs = [l[2:] for l in sr_libs if l.startswith('-L')], + libraries = [l[2:] for l in sr_libs if l.startswith('-l')] + ) + ], +) diff --git a/bindings/swig/libsigrok.i b/bindings/swig/libsigrok.i new file mode 100644 index 00000000..73591a12 --- /dev/null +++ b/bindings/swig/libsigrok.i @@ -0,0 +1,47 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2013 Martin Ling + * + * 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 3 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 . + */ + +%module libsigrok +%include "cpointer.i" +%include "carrays.i" + +%{ +#include "libsigrok/libsigrok.h" +%} + +typedef struct _GSList GSList; + +struct _GSList +{ + gpointer data; + GSList *next; +}; + +void g_slist_free(GSList *list); + +%include "libsigrok/libsigrok.h" +#undef SR_API +#define SR_API +%ignore sr_config_info_name_get; +%include "libsigrok/proto.h" +%include "libsigrok/version.h" + +%pointer_functions(struct sr_context *, sr_context_ptr_ptr); +%array_functions(struct sr_dev_driver *, sr_dev_driver_ptr_array); +%pointer_cast(gpointer, struct sr_dev_inst *, gpointer_to_sr_dev_inst_ptr);