]> sigrok.org Git - libsigrok.git/blame - bindings/python/setup.py
setup.py: Do VPATH search for swig/enums.i
[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
758b01ad 24import subprocess
f7740954
ML
25import os
26
0e1a7fe9
MC
27srcdir = os.path.split(__file__)[0]
28
91bea31f
ML
29sr_includes, sr_lib_dirs, sr_libs, (sr_version,) = [
30 subprocess.check_output(
f7740954
ML
31 ["pkg-config", option, "glib-2.0", "glibmm-2.4", "pygobject-3.0"]
32 ).decode().rstrip().split(' ')
91bea31f
ML
33 for option in
34 ("--cflags-only-I", "--libs-only-L", "--libs-only-l", "--modversion")]
758b01ad 35
0e1a7fe9
MC
36includes = ['../../include', '../cxx/include']
37includes += [os.path.join(srcdir, path) for path in includes]
5a3e3428 38includes += ['../..']
0e1a7fe9 39includes += [i[2:] for i in sr_includes]
cd5623ca 40includes += [np.get_include(), ]
f7740954 41libdirs = ['../../.libs', '../cxx/.libs'] + [l[2:] for l in sr_lib_dirs]
52ff4f6a 42libs = [l[2:] for l in sr_libs] + ['sigrokcxx']
f7740954 43
0e1a7fe9
MC
44def vpath(file):
45 vfile = os.path.join(srcdir, file)
46 return vfile if os.path.exists(vfile) else file
47
48def unvpath(file):
49 return os.path.relpath(file, srcdir) if file.startswith(srcdir) else file
50
51class build_py(_build_py):
52 def find_package_modules(self, package, pkg_dir):
53 mods = _build_py.find_package_modules(self, package, pkg_dir)
54 vmods = _build_py.find_package_modules(self, package, vpath(pkg_dir))
55 mods.extend([mod for mod in vmods if mod not in mods])
56 return mods
57 def check_package(self, package, package_dir):
58 return _build_py.check_package(self, package, vpath(package_dir))
59
60class build_ext(_build_ext):
61 def spawn (self, cmd):
62 cmd[1:-1] = [arg if arg.startswith('-') else unvpath(arg) for arg in
63 cmd[1:-1]]
64 _build_ext.spawn(self, cmd)
65 def swig_sources (self, sources, extension):
66 return [unvpath(src) for src in
67 _build_ext.swig_sources(self, sources, extension)]
68
758b01ad
ML
69setup(
70 name = 'libsigrok',
02206269 71 namespace_packages = ['sigrok'],
0e1a7fe9 72 packages = find_packages(srcdir),
758b01ad
ML
73 version = sr_version,
74 description = "libsigrok API wrapper",
9ae3eb12 75 zip_safe = False,
0e1a7fe9 76 script_name = __file__,
758b01ad 77 ext_modules = [
f7740954 78 Extension('sigrok.core._classes',
0e1a7fe9 79 sources = [vpath('sigrok/core/classes.i')],
5a3e3428
DE
80 swig_opts = ['-c++', '-threads', '-Isigrok/core',
81 '-I..', '-I%s' % os.path.join(srcdir, '..')] +
f7740954 82 ['-I%s' % i for i in includes],
5fcc5909 83 extra_compile_args = ['-std=c++11', '-Wno-uninitialized'],
f0f1d90d
ML
84 include_dirs = includes,
85 library_dirs = libdirs,
86 libraries = libs)
758b01ad 87 ],
0e1a7fe9 88 cmdclass = {'build_py': build_py, 'build_ext': build_ext},
758b01ad 89)