forked from gvalkov/python-evdev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·98 lines (77 loc) · 3.21 KB
/
setup.py
File metadata and controls
executable file
·98 lines (77 loc) · 3.21 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
87
88
89
90
91
92
93
94
95
96
97
98
import os
import sys
import textwrap
from pathlib import Path
from setuptools import setup, Extension, Command
from setuptools.command import build_ext as _build_ext
from subprocess import run, CalledProcessError
curdir = Path(__file__).resolve().parent
ecodes_path = curdir / "evdev/ecodes.c"
def create_ecodes(headers=None):
if not headers:
include_paths = set()
cpath = os.environ.get("CPATH", "").strip()
c_inc_path = os.environ.get("C_INCLUDE_PATH", "").strip()
if cpath:
include_paths.update(cpath.split(":"))
if c_inc_path:
include_paths.update(c_inc_path.split(":"))
include_paths.add("/usr/include")
files = ["linux/input.h", "linux/input-event-codes.h", "linux/uinput.h"]
headers = [os.path.join(path, file) for path in include_paths for file in files]
# Filtrele ve mevcut başlık dosyalarını bul
headers = [header for header in headers if os.path.isfile(header)]
if not headers:
msg = """\
The 'linux/input.h' and 'linux/input-event-codes.h' include files
are missing. You will have to install the kernel header files in
order to continue:
dnf install kernel-headers-$(uname -r)
apt-get install linux-headers-$(uname -r)
emerge sys-kernel/linux-headers
pacman -S kernel-headers
If they are installed in a non-standard location, use the '--evdev-headers' option.
"""
sys.stderr.write(textwrap.dedent(msg))
sys.exit(1)
# Komutu çalıştır ve hata yönetimi ekle
try:
print(f"Writing {ecodes_path} using headers: {' '.join(headers)}")
with ecodes_path.open("w") as fh:
cmd = [sys.executable, "evdev/genecodes.py", *headers]
run(cmd, check=True, stdout=fh)
except CalledProcessError as e:
sys.stderr.write(f"Error during code generation: {e}\n")
sys.exit(1)
class build_ecodes(Command):
description = "Generate ecodes.c"
user_options = [("evdev-headers=", None, "Paths to input subsystem headers")]
def initialize_options(self):
self.evdev_headers = None
def finalize_options(self):
if self.evdev_headers:
self.evdev_headers = self.evdev_headers.split(":")
def run(self):
create_ecodes(self.evdev_headers)
class build_ext(_build_ext.build_ext):
def has_ecodes(self):
if ecodes_path.exists():
print("ecodes.c already exists ... skipping build_ecodes")
return not ecodes_path.exists()
def run(self):
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
_build_ext.build_ext.run(self)
sub_commands = [("build_ecodes", has_ecodes)] + _build_ext.build_ext.sub_commands
cflags = ["-std=c++23", "-Wno-error=declaration-after-statement"]
setup(
ext_modules=[
Extension("evdev._input", sources=["evdev/input.c"], extra_compile_args=cflags),
Extension("evdev._uinput", sources=["evdev/uinput.c"], extra_compile_args=cflags),
Extension("evdev._ecodes", sources=["evdev/ecodes.c"], extra_compile_args=cflags),
],
cmdclass={
"build_ext": build_ext,
"build_ecodes": build_ecodes,
},
)