Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython-config.py
More file actions
Latest commit
157 lines (112 loc) · 3.87 KB
/
Copy pathpython-config.py
File metadata and controls
157 lines (112 loc) · 3.87 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# python-config.py
#
# This script tries to find the correct ldflags and cflags through python3
# introspection. See CPython's Misc/python-config.in and configure.ac for
# details.
importsys
importsysconfig
importplatform
importpathlib
classMSVC:
def__init__(self):
self.name="cl"
self.cflags= []
self.ldflags= ["-link"]
defadd_library_path(self, path):
self.ldflags.append('-LIBPATH:"'+path+'"')
defadd_library(self, lib):
self.ldflags.append(lib+".lib")
defadd_libraries(self, libs):
forlibinlibs:
self.add_library(lib)
defadd_include_path(self, path):
self.cflags.append('-I"'+path+'"')
classGnuLikeCompiler:
def__init__(self, name):
self.name=name
self.cflags= []
self.ldflags= []
defadd_library_path(self, path):
self.ldflags.append('-L"'+path+'"')
defadd_library(self, lib):
self.ldflags.append('-l'+lib)
defadd_libraries(self, libs):
forlibinlibs:
self.add_library(lib)
defadd_include_path(self, path):
self.cflags.append('-I"'+path+'"')
getvar=sysconfig.get_config_var
defextend_with_config_var(array, name):
var=getvar(name)
ifvarisnotNone:
array.extend(var.split())
deffind_compiler():
try:
CC=getvar("CC").lower()
if"clang"inCC:
compiler=GnuLikeCompiler("clang")
elif"gcc"inCC:
compiler=GnuLikeCompiler("gcc")
else:
raiseRuntimeError("Unknown compiler")
exceptException:
pycompiler=platform.python_compiler().lower()
if"msc"inpycompiler:
compiler=MSVC()
elif"clang"inpycompiler:
compiler=GnuLikeCompiler("clang")
elif"gcc"inpycompiler:
compiler=GnuLikeCompiler("gcc")
else:
raiseRuntimeError("Unknown compiler")
returncompiler
# Detect the platform/system
system=platform.system().lower()
ifsystemnotin ["linux", "darwin", "windows"]:
raiseRuntimeError("Unsupported system")
# Detect the compiler
compiler=find_compiler()
# Get common Python configuration variables
VERSION=getvar("VERSION")
LIBDIR=getvar("LIBDIR")
CONFINCLUDEDIR=getvar("CONFINCLUDEDIR")
try:
abiflags=sys.abiflags
exceptException:
abiflags=getvar("abiflags") or""
# Configure system specific variables
ifsystem=="windows"andLIBDIRisNone:
# Assume libpath is %PYTHONPREFIX%\\libs on Windows
prefix=pathlib.Path(sysconfig.get_config_var("prefix"))
libs=prefix/"libs"
ifnotlibs.exists():
raiseRuntimeError("Unable to find python C libraries")
LIBDIR=str(libs)
elifsystem=="darwin":
# Set @rpath when using clang
PYTHONFRAMEWORKPREFIX=getvar("PYTHONFRAMEWORKPREFIX")
ifPYTHONFRAMEWORKPREFIX!="":
compiler.cflags.append("-Wl,-rpath -Wl,"+PYTHONFRAMEWORKPREFIX)
# Configure ldflags
compiler.add_library_path(LIBDIR)
compiler.add_library("python"+VERSION+abiflags)
extend_with_config_var(compiler.ldflags, "LIBS")
extend_with_config_var(compiler.ldflags, "SYSLIBS")
ifnotgetvar("Py_ENABLE_SHARED"):
LIBPL=getvar("LIBPL")
ifLIBPLisnotNone:
compiler.add_library_path(LIBPL)
ifnotgetvar("PYTHONFRAMEWORK"):
extend_with_config_var(compiler.ldflags, "LINKFORSHARED")
# Configure cflags
compiler.add_include_path(sysconfig.get_path("include"))
compiler.add_include_path(sysconfig.get_path("platinclude"))
ifCONFINCLUDEDIRisnotNone: # Can be None on Windows
compiler.add_include_path(CONFINCLUDEDIR+"/python"+VERSION+abiflags)
extend_with_config_var(compiler.cflags, "CFLAGS")
# The output is parsed by gsc, one line at a time:
print(VERSION)
print(compiler.name)
print(" ".join(compiler.ldflags))
print(" ".join(compiler.cflags))
print(LIBDIR)