]> sigrok.org Git - libsigrok.git/blame - bindings/python/setup.py
kingst-la2016: fix segfault that often occurs when a capture is aborted
[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
cd5623ca 23import numpy as np
f7740954 24import os
c05a0ba5
DE
25import sys
26import re
27import shlex
f7740954 28
c05a0ba5
DE
29srcdir = os.path.dirname(os.path.abspath(__file__))
30os.chdir('bindings/python')
31srcdir = os.path.relpath(srcdir)
32srcdir_parent = os.path.normpath(os.path.join(srcdir, '..'))
0e1a7fe9 33
c05a0ba5
DE
34# Override the default compile flags used by distutils.
35os.environ['OPT'] = ''
36
37# Parse the command line arguments for VAR=value assignments,
38# and apply them as environment variables.
39while len(sys.argv) > 1:
40 match = re.match(r'([A-Z]+)=(.*)', sys.argv[1])
41 if match is None:
42 break
43 os.environ[match.group(1)] = match.group(2)
44 del sys.argv[1]
758b01ad 45
0e1a7fe9 46includes = ['../../include', '../cxx/include']
c05a0ba5
DE
47includes += [os.path.normpath(os.path.join(srcdir, path)) for path in includes]
48includes += ['../..', np.get_include()]
49
50ldadd = shlex.split(os.environ.get('LDADD', ''))
51libdirs = ['../../.libs', '../cxx/.libs'] + \
52 [l[2:] for l in ldadd if l.startswith('-L')]
53libs = [l[2:] for l in ldadd if l.startswith('-l')] + ['sigrokcxx']
f7740954 54
0e1a7fe9
MC
55def vpath(file):
56 vfile = os.path.join(srcdir, file)
57 return vfile if os.path.exists(vfile) else file
58
59def unvpath(file):
60 return os.path.relpath(file, srcdir) if file.startswith(srcdir) else file
61
62class build_py(_build_py):
63 def find_package_modules(self, package, pkg_dir):
64 mods = _build_py.find_package_modules(self, package, pkg_dir)
65 vmods = _build_py.find_package_modules(self, package, vpath(pkg_dir))
66 mods.extend([mod for mod in vmods if mod not in mods])
67 return mods
68 def check_package(self, package, package_dir):
69 return _build_py.check_package(self, package, vpath(package_dir))
70
71class build_ext(_build_ext):
8ebf1469
DE
72 def finalize_options(self):
73 _build_ext.finalize_options(self)
74 self.swig_opts = ['-c++', '-threads', '-Isigrok/core', '-I..',
75 '-I' + srcdir_parent] + ['-I%s' % i for i in includes] + self.swig_opts
0e1a7fe9
MC
76 def spawn (self, cmd):
77 cmd[1:-1] = [arg if arg.startswith('-') else unvpath(arg) for arg in
78 cmd[1:-1]]
79 _build_ext.spawn(self, cmd)
80 def swig_sources (self, sources, extension):
81 return [unvpath(src) for src in
82 _build_ext.swig_sources(self, sources, extension)]
83
758b01ad
ML
84setup(
85 name = 'libsigrok',
02206269 86 namespace_packages = ['sigrok'],
0e1a7fe9 87 packages = find_packages(srcdir),
c05a0ba5 88 version = os.environ.get('VERSION'),
758b01ad 89 description = "libsigrok API wrapper",
9ae3eb12 90 zip_safe = False,
758b01ad 91 ext_modules = [
f7740954 92 Extension('sigrok.core._classes',
0e1a7fe9 93 sources = [vpath('sigrok/core/classes.i')],
c05a0ba5 94 extra_compile_args = ['-Wno-uninitialized'],
f0f1d90d
ML
95 include_dirs = includes,
96 library_dirs = libdirs,
97 libraries = libs)
758b01ad 98 ],
0e1a7fe9 99 cmdclass = {'build_py': build_py, 'build_ext': build_ext},
758b01ad 100)