Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
86 lines (73 loc) · 2.54 KB
/
Copy pathsetup.py
File metadata and controls
86 lines (73 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
#
# Copyright (C) 2021 Sean D'Epagnier
#
# This Program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
# This setup.py only handles C/SWIG extension builds.
# All metadata, dependencies, and entry points are in pyproject.toml.
import os
from setuptools import Extension, setup
from setuptools.command.install import install
# Workaround: ensure SWIG-generated Python wrappers exist before
# setuptools scans for packages.
class build_ext_first(install):
def run(self):
self.run_command("build_ext")
return install.run(self)
linebuffer_module = Extension(
"pypilot/linebuffer/_linebuffer",
sources=[
"pypilot/linebuffer/linebuffer.cpp",
"pypilot/linebuffer/linebuffer.i",
],
extra_compile_args=["-Wno-unused-result"],
swig_opts=["-c++"],
)
arduino_servo_module = Extension(
"pypilot/arduino_servo/_arduino_servo",
sources=[
"pypilot/arduino_servo/arduino_servo.cpp",
"pypilot/arduino_servo/arduino_servo_eeprom.cpp",
"pypilot/arduino_servo/arduino_servo.i",
],
extra_compile_args=["-Wno-unused-result"],
swig_opts=["-c++"],
)
ret = os.system('pkg-config --cflags libgpiod')
if ret == 0:
print('detected libgpiod')
ugfx_libraries=['gpiod']
import subprocess
ver = subprocess.check_output(
["pkg-config", "--modversion", "libgpiod"],
text=True
).strip()
ugfx_defs = ['-DGPIOD_VERSION_MAJOR=' + ver.split(".")[0]]
else:
print('no gpiod library for ugfx')
ugfx_libraries=[]
ugfx_defs = []
ugfx_module = Extension(
"pypilot/hat/ugfx/_ugfx",
sources=["hat/ugfx/ugfx.cpp",
"hat/ugfx/ugfx.i"],
extra_compile_args=["-Wno-unused-result"] + ugfx_defs,
libraries=ugfx_libraries,
swig_opts=["-c++"] + ugfx_defs,
)
spireader_module = Extension('pypilot/hat/spireader/_spireader',
sources=['hat/spireader/spireader.cpp',
'hat/spireader/spireader.i'],
extra_compile_args=['-Wno-unused-result'],
libraries=ugfx_libraries,
swig_opts=['-c++'])
ext_modules = [arduino_servo_module, linebuffer_module, ugfx_module]
if spireader_module:
ext_modules.append(spireader_module)
setup(
ext_modules=ext_modules,
cmdclass={"install": build_ext_first},
)