]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | |
23 | import numpy as np | |
24 | import subprocess | |
25 | import os | |
26 | ||
27 | srcdir = os.path.split(__file__)[0] | |
28 | ||
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(' ') | |
33 | for option in | |
34 | ("--cflags-only-I", "--libs-only-L", "--libs-only-l", "--modversion")] | |
35 | ||
36 | includes = ['../../include', '../cxx/include'] | |
37 | includes += [os.path.join(srcdir, path) for path in includes] | |
38 | includes += ['../..'] | |
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'] | |
43 | ||
44 | def vpath(file): | |
45 | vfile = os.path.join(srcdir, file) | |
46 | return vfile if os.path.exists(vfile) else file | |
47 | ||
48 | def unvpath(file): | |
49 | return os.path.relpath(file, srcdir) if file.startswith(srcdir) else file | |
50 | ||
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]) | |
56 | return mods | |
57 | def check_package(self, package, package_dir): | |
58 | return _build_py.check_package(self, package, vpath(package_dir)) | |
59 | ||
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 | |
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 | ||
69 | setup( | |
70 | name = 'libsigrok', | |
71 | namespace_packages = ['sigrok'], | |
72 | packages = find_packages(srcdir), | |
73 | version = sr_version, | |
74 | description = "libsigrok API wrapper", | |
75 | zip_safe = False, | |
76 | script_name = __file__, | |
77 | ext_modules = [ | |
78 | Extension('sigrok.core._classes', | |
79 | sources = [vpath('sigrok/core/classes.i')], | |
80 | swig_opts = ['-c++', '-threads', '-Isigrok/core', | |
81 | '-I..', '-I%s' % os.path.join(srcdir, '..')] + | |
82 | ['-I%s' % i for i in includes], | |
83 | extra_compile_args = ['-std=c++11', '-Wno-uninitialized'], | |
84 | include_dirs = includes, | |
85 | library_dirs = libdirs, | |
86 | libraries = libs) | |
87 | ], | |
88 | cmdclass = {'build_py': build_py, 'build_ext': build_ext}, | |
89 | ) |