This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsetup.py
111 lines (81 loc) · 2.72 KB
/
setup.py
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
#!/usr/bin/env python
#
# When modifying this file, always keep in mind that it has to work on both
# Python 2.x and 3.x.
#
from __future__ import print_function
import contextlib
import os
import setuptools
import subprocess
import sys
DIR = os.path.dirname(os.path.abspath(__file__))
XED_BUILD_DIR = os.path.join(DIR, "build")
XED_KITS_DIR = os.path.join(XED_BUILD_DIR, "kits")
XED_CURRENT_KIT_DIR = os.getenv("XED_CURRENT_KIT_DIR")
def get_sources():
return [
name
for name in os.listdir(DIR)
if os.path.isfile(os.path.join(DIR, name)) and name.endswith(".c")
]
def get_extra_link_args():
if sys.platform.startswith("linux"):
return ["-Wl,--whole-archive", "-lxed", "-Wl,--no-whole-archive"]
elif sys.platform.startswith("darwin"):
return ["-Wl,-force_load", os.path.join(XED_CURRENT_KIT_DIR, "lib", "libxed.a")]
else:
raise EnvironmentError(
"Don't know how to link static XED to pyxed on platform %s" % sys.platform
)
def build_xed():
mfile = os.path.join(DIR, "external", "xed", "mfile.py")
if not os.path.exists(mfile):
raise EnvironmentError(
"XED directory not initialized, run: git submodule update --init --recursive"
)
if not os.path.exists(XED_KITS_DIR):
subprocess.check_call(
"%s --static --extra-flags=-fPIC install" % mfile, shell=True
)
@contextlib.contextmanager
def mkchdir(wd):
cwd = os.getcwd()
if not os.path.exists(wd):
os.makedirs(wd)
try:
os.chdir(wd)
yield wd
finally:
os.chdir(cwd)
def main(argv):
global XED_CURRENT_KIT_DIR
if XED_CURRENT_KIT_DIR is None:
with mkchdir(XED_BUILD_DIR):
build_xed()
for name in os.listdir(XED_KITS_DIR):
if "xed-install-base" in name:
XED_CURRENT_KIT_DIR = os.path.join(XED_KITS_DIR, name)
if XED_CURRENT_KIT_DIR is None:
raise EnvironmentError("Could not find compiled Intel XED kit")
pyxed_mod = setuptools.Extension(
"pyxed",
include_dirs=[os.path.join(XED_CURRENT_KIT_DIR, "include", "xed")],
library_dirs=[os.path.join(XED_CURRENT_KIT_DIR, "lib")],
extra_compile_args=["-fPIC"],
extra_link_args=get_extra_link_args(),
sources=[os.path.join(DIR, name) for name in get_sources()],
)
setuptools.setup(
name="pyxed",
version="1.1",
description="pyxed",
author="huku",
author_email="[email protected]",
url="https://github.com/huku-/pyxed",
ext_modules=[pyxed_mod],
extras_require={"dev": ["pytest"]},
)
return os.EX_OK
if __name__ == "__main__":
sys.exit(main(sys.argv))