2 ## This file is part of the libsigrok project.
4 ## Copyright (C) 2013 Martin Ling <martin-sigrok@earth.li>
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.
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.
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/>.
20 from setuptools import setup, find_packages, Extension
21 from distutils.command.build_py import build_py as _build_py
22 from distutils.command.build_ext import build_ext as _build_ext
27 srcdir = os.path.split(__file__)[0]
29 sr_includes, sr_lib_dirs, sr_libs, (sr_version,) = [
30 subprocess.check_output(
31 ["pkg-config", option, "glib-2.0", "glibmm-2.4", "pygobject-3.0"]
32 ).decode().rstrip().split(' ')
34 ("--cflags-only-I", "--libs-only-L", "--libs-only-l", "--modversion")]
36 includes = ['../../include', '../cxx/include']
37 includes += [os.path.join(srcdir, path) for path in includes]
38 includes += ['../..', '../../include/libsigrok', '../cxx/include/libsigrokcxx']
39 includes += [i[2:] for i in sr_includes]
40 includes += [np.get_include(), ]
41 libdirs = ['../../.libs', '../cxx/.libs'] + [l[2:] for l in sr_lib_dirs]
42 libs = [l[2:] for l in sr_libs] + ['sigrokcxx']
45 vfile = os.path.join(srcdir, file)
46 return vfile if os.path.exists(vfile) else file
49 return os.path.relpath(file, srcdir) if file.startswith(srcdir) else file
51 class 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])
57 def check_package(self, package, package_dir):
58 return _build_py.check_package(self, package, vpath(package_dir))
60 class build_ext(_build_ext):
61 def spawn (self, cmd):
62 cmd[1:-1] = [arg if arg.startswith('-') else unvpath(arg) for arg in
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)]
71 namespace_packages = ['sigrok'],
72 packages = find_packages(srcdir),
74 description = "libsigrok API wrapper",
76 script_name = __file__,
78 Extension('sigrok.core._classes',
79 sources = [vpath('sigrok/core/classes.i')],
80 swig_opts = ['-c++', '-threads', '-Isigrok/core'] +
81 ['-I%s' % i for i in includes],
82 extra_compile_args = ['-std=c++11', '-Wno-uninitialized'],
83 include_dirs = includes,
84 library_dirs = libdirs,
87 cmdclass = {'build_py': build_py, 'build_ext': build_ext},