Debian Codegraph @

tests/integration/testdependencies/setup.py

raw
1 from __future__ import annotations
2
3 import subprocess
4 from os import getenv, path
5
6 from setuptools import Extension, setup
7 from setuptools.command.build_ext import build_ext
8
9 define_macros = [("_GNU_SOURCE", None)]
10 libraries = []
11 library_dirs = []
12 extra_compile_args = []
13
14 if getenv("WITH_DEPENDENCY", "0") == "1":
15 libraries.append("dependency")
16 library_dirs.append(path.abspath(path.dirname(__file__)))
17 define_macros.append(("WITH_DEPENDENCY", "1"))
18
19 if getenv("WITH_ARCH", "") != "":
20 extra_compile_args.extend((f"-march={getenv('WITH_ARCH')}", "-mneeded"))
21
22 libraries.extend(["m", "c"])
23
24
25 class BuildExt(build_ext):
26 def run(self) -> None:
27 cflags = ("-shared", "-fPIC", "-D_GNU_SOURCE", *extra_compile_args)
28 cmd = f"gcc {' '.join(cflags)} dependency.c -o libdependency.so -lm -lc"
29 subprocess.check_call(cmd.split())
30 super().run()
31
32
33 setup(
34 name="testdependencies",
35 version="0.0.1",
36 cmdclass={"build_ext": BuildExt},
37 ext_modules=[
38 Extension(
39 "testdependencies",
40 sources=["testdependencies.c"],
41 extra_compile_args=extra_compile_args,
42 define_macros=define_macros,
43 libraries=libraries,
44 library_dirs=library_dirs,
45 ),
46 ],
47 )