forked from birdstakes/quatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
115 lines (94 loc) · 3.01 KB
/
setup.py
File metadata and controls
115 lines (94 loc) · 3.01 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import subprocess
import sys
from glob import glob
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
# This abuses build_ext to build executables instead of extension modules because it
# already does most of what we need and a bunch of things (bdist_* commands, for
# instance) seem to assume binary extensions are the only way you can end up with a
# platform-specific binary distribution.
WINDOWS = sys.platform == "win32"
lburg = Extension(
"quatch.bin.lburg",
glob("lcc/lburg/*.c"),
)
cpp = Extension(
"quatch.bin.q3cpp",
glob("lcc/cpp/*.c"),
)
lcc = Extension(
"quatch.bin.q3lcc",
glob("lcc/etc/*.c"),
)
rcc = Extension(
"quatch.bin.q3rcc",
glob("lcc/src/*.c") + glob("lcc/src/*.md"),
include_dirs=["lcc/src"],
)
class build_ext(_build_ext):
def run(self):
from distutils.ccompiler import new_compiler, CCompiler
compiler = new_compiler(
compiler=self.compiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force,
)
macros = [("WIN32", None)] if WINDOWS else []
for ext in self.extensions:
sources = []
for source in ext.sources:
_, suffix = os.path.splitext(source)
if suffix == ".md":
sources.append(self.lburg(source))
else:
sources.append(source)
objects = compiler.compile(
sources,
macros=macros + ext.define_macros,
include_dirs=ext.include_dirs,
output_dir=self.build_temp,
)
# using compiler.link_executable duplicates the file extension on windows
compiler.link(
CCompiler.EXECUTABLE, objects, self.get_ext_fullpath(ext.name)
)
def lburg(self, source):
name, _ = os.path.splitext(source)
output = os.path.join(self.build_temp, name + ".c")
os.makedirs(os.path.dirname(output), exist_ok=True)
subprocess.run(
[
self.get_ext_fullpath(lburg.name),
source,
output,
]
)
return output
def get_ext_filename(self, ext_name):
suffix = ".exe" if WINDOWS else ""
return os.path.join(*ext_name.split(".")) + suffix
cmdclass = {"build_ext": build_ext}
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
class bdist_wheel(_bdist_wheel):
def get_tag(self):
if "WINDOWS_HACK" in os.environ:
# if everything is compiled with mingw32 the wheel should work
# with any windows version of python
return "py3", "none", "win32.win_amd64"
else:
return super().get_tag()
cmdclass["bdist_wheel"] = bdist_wheel
except ImportError:
pass
setup(
cmdclass=cmdclass,
ext_modules=[
lburg,
cpp,
lcc,
rcc,
],
)