]> sigrok.org Git - libsigrok.git/blame - bindings/python/setup.py
Makefile.am: Fix out-of-tree build for Python bindings
[libsigrok.git] / bindings / python / setup.py
CommitLineData
8dc93c84 1##
50985c20 2## This file is part of the libsigrok project.
8dc93c84
UH
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##
758b01ad 19
02206269 20from setuptools import setup, find_packages, Extension
0e1a7fe9
MC
21from distutils.command.build_py import build_py as _build_py
22from distutils.command.build_ext import build_ext as _build_ext
758b01ad 23import subprocess
f7740954
ML
24import os
25
0e1a7fe9
MC
26srcdir = os.path.split(__file__)[0]
27
91bea31f
ML
28sr_includes, sr_lib_dirs, sr_libs, (sr_version,) = [
29 subprocess.check_output(
f7740954
ML
30 ["pkg-config", option, "glib-2.0", "glibmm-2.4", "pygobject-3.0"]
31 ).decode().rstrip().split(' ')
91bea31f
ML
32 for option in
33 ("--cflags-only-I", "--libs-only-L", "--libs-only-l", "--modversion")]
758b01ad 34
0e1a7fe9
MC
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]
f7740954 39libdirs = ['../../.libs', '../cxx/.libs'] + [l[2:] for l in sr_lib_dirs]
f0f1d90d 40libs = [l[2:] for l in sr_libs] + ['sigrokxx']
f7740954 41
0e1a7fe9
MC
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
758b01ad
ML
67setup(
68 name = 'libsigrok',
02206269 69 namespace_packages = ['sigrok'],
0e1a7fe9 70 packages = find_packages(srcdir),
758b01ad
ML
71 version = sr_version,
72 description = "libsigrok API wrapper",
9ae3eb12 73 zip_safe = False,
0e1a7fe9 74 script_name = __file__,
758b01ad 75 ext_modules = [
f7740954 76 Extension('sigrok.core._classes',
0e1a7fe9
MC
77 sources = [vpath('sigrok/core/classes.i')],
78 swig_opts = ['-c++', '-threads', '-Isigrok/core'] +
f7740954
ML
79 ['-I%s' % i for i in includes],
80 extra_compile_args = ['-std=c++11'],
f0f1d90d
ML
81 include_dirs = includes,
82 library_dirs = libdirs,
83 libraries = libs)
758b01ad 84 ],
0e1a7fe9 85 cmdclass = {'build_py': build_py, 'build_ext': build_ext},
758b01ad 86)