]> sigrok.org Git - libsigrok.git/blame_incremental - bindings/python/setup.py
Makefile.am: Fix out-of-tree build for Python bindings
[libsigrok.git] / bindings / python / setup.py
... / ...
CommitLineData
1##
2## This file is part of the libsigrok project.
3##
4## Copyright (C) 2013 Martin Ling <martin-sigrok@earth.li>
5##
6## This program is free software: you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation, either version 3 of the License, or
9## (at your option) any later version.
10##
11## This program is distributed in the hope that it will be useful,
12## but WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14## GNU General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with this program. If not, see <http://www.gnu.org/licenses/>.
18##
19
20from setuptools import setup, find_packages, Extension
21from distutils.command.build_py import build_py as _build_py
22from distutils.command.build_ext import build_ext as _build_ext
23import subprocess
24import os
25
26srcdir = os.path.split(__file__)[0]
27
28sr_includes, sr_lib_dirs, sr_libs, (sr_version,) = [
29 subprocess.check_output(
30 ["pkg-config", option, "glib-2.0", "glibmm-2.4", "pygobject-3.0"]
31 ).decode().rstrip().split(' ')
32 for option in
33 ("--cflags-only-I", "--libs-only-L", "--libs-only-l", "--modversion")]
34
35includes = ['../../include', '../cxx/include']
36includes += [os.path.join(srcdir, path) for path in includes]
37includes += ['../..', '../../include/libsigrok', '../cxx/include/libsigrok']
38includes += [i[2:] for i in sr_includes]
39libdirs = ['../../.libs', '../cxx/.libs'] + [l[2:] for l in sr_lib_dirs]
40libs = [l[2:] for l in sr_libs] + ['sigrokxx']
41
42def vpath(file):
43 vfile = os.path.join(srcdir, file)
44 return vfile if os.path.exists(vfile) else file
45
46def unvpath(file):
47 return os.path.relpath(file, srcdir) if file.startswith(srcdir) else file
48
49class build_py(_build_py):
50 def find_package_modules(self, package, pkg_dir):
51 mods = _build_py.find_package_modules(self, package, pkg_dir)
52 vmods = _build_py.find_package_modules(self, package, vpath(pkg_dir))
53 mods.extend([mod for mod in vmods if mod not in mods])
54 return mods
55 def check_package(self, package, package_dir):
56 return _build_py.check_package(self, package, vpath(package_dir))
57
58class build_ext(_build_ext):
59 def spawn (self, cmd):
60 cmd[1:-1] = [arg if arg.startswith('-') else unvpath(arg) for arg in
61 cmd[1:-1]]
62 _build_ext.spawn(self, cmd)
63 def swig_sources (self, sources, extension):
64 return [unvpath(src) for src in
65 _build_ext.swig_sources(self, sources, extension)]
66
67setup(
68 name = 'libsigrok',
69 namespace_packages = ['sigrok'],
70 packages = find_packages(srcdir),
71 version = sr_version,
72 description = "libsigrok API wrapper",
73 zip_safe = False,
74 script_name = __file__,
75 ext_modules = [
76 Extension('sigrok.core._classes',
77 sources = [vpath('sigrok/core/classes.i')],
78 swig_opts = ['-c++', '-threads', '-Isigrok/core'] +
79 ['-I%s' % i for i in includes],
80 extra_compile_args = ['-std=c++11'],
81 include_dirs = includes,
82 library_dirs = libdirs,
83 libraries = libs)
84 ],
85 cmdclass = {'build_py': build_py, 'build_ext': build_ext},
86)