@@ -19,16 +19,17 @@ def dequote(s):
19
19
20
20
21
21
def mysql_config (what ):
22
- from os import popen
23
-
24
- f = popen ("{} --{}" . format ( _mysql_config_path , what ) )
22
+ cmd = "{} --{}" . format ( _mysql_config_path , what )
23
+ print ( cmd )
24
+ f = os . popen (cmd )
25
25
data = f .read ().strip ().split ()
26
26
ret = f .close ()
27
27
if ret :
28
28
if ret / 256 :
29
29
data = []
30
30
if ret / 256 > 1 :
31
31
raise OSError ("{} not found" .format (_mysql_config_path ))
32
+ print (data )
32
33
return data
33
34
34
35
@@ -62,26 +63,41 @@ def get_config():
62
63
static = True
63
64
sys .argv .remove ("--static" )
64
65
65
- libs = mysql_config ("libs" )
66
+ libs = os .environ .get ("MYSQLCLIENT_LDFLAGS" )
67
+ if libs :
68
+ libs = libs .strip ().split ()
69
+ else :
70
+ libs = mysql_config ("libs" )
66
71
library_dirs = [dequote (i [2 :]) for i in libs if i .startswith ("-L" )]
67
72
libraries = [dequote (i [2 :]) for i in libs if i .startswith ("-l" )]
68
73
extra_link_args = [x for x in libs if not x .startswith (("-l" , "-L" ))]
69
74
70
- removable_compile_args = ("-I" , "-L" , "-l" )
71
- extra_compile_args = [
72
- i .replace ("%" , "%%" )
73
- for i in mysql_config ("cflags" )
74
- if i [:2 ] not in removable_compile_args
75
- ]
75
+ cflags = os .environ .get ("MYSQLCLIENT_CFLAGS" )
76
+ if cflags :
77
+ use_mysqlconfig_cflags = False
78
+ cflags = cflags .strip ().split ()
79
+ else :
80
+ use_mysqlconfig_cflags = True
81
+ cflags = mysql_config ("cflags" )
82
+
83
+ include_dirs = []
84
+ extra_compile_args = ["-std=c99" ]
85
+
86
+ for a in cflags :
87
+ if a .startswith ("-I" ):
88
+ include_dirs .append (dequote (a [2 :]))
89
+ elif a .startswith (("-L" , "-l" )): # This should be LIBS.
90
+ pass
91
+ else :
92
+ extra_compile_args .append (a .replace ("%" , "%%" ))
76
93
77
94
# Copy the arch flags for linking as well
78
- for i in range (len (extra_compile_args )):
79
- if extra_compile_args [i ] == "-arch" :
95
+ try :
96
+ i = extra_compile_args .index ("-arch" )
97
+ if "-arch" not in extra_link_args :
80
98
extra_link_args += ["-arch" , extra_compile_args [i + 1 ]]
81
-
82
- include_dirs = [
83
- dequote (i [2 :]) for i in mysql_config ("include" ) if i .startswith ("-I" )
84
- ]
99
+ except ValueError :
100
+ pass
85
101
86
102
if static :
87
103
# properly handle mysql client libraries that are not called libmysqlclient
@@ -109,11 +125,12 @@ def get_config():
109
125
if client in libraries :
110
126
libraries .remove (client )
111
127
else :
112
- # mysql_config may have "-lmysqlclient -lz -lssl -lcrypto", but zlib and
113
- # ssl is not used by _mysql. They are needed only for static build.
114
- for L in ("crypto" , "ssl" , "z" ):
115
- if L in libraries :
116
- libraries .remove (L )
128
+ if use_mysqlconfig_cflags :
129
+ # mysql_config may have "-lmysqlclient -lz -lssl -lcrypto", but zlib and
130
+ # ssl is not used by _mysql. They are needed only for static build.
131
+ for L in ("crypto" , "ssl" , "z" ):
132
+ if L in libraries :
133
+ libraries .remove (L )
117
134
118
135
name = "mysqlclient"
119
136
metadata ["name" ] = name
@@ -138,6 +155,10 @@ def get_config():
138
155
if static :
139
156
ext_options ["language" ] = "c++"
140
157
158
+ print ("ext_options:" )
159
+ for k , v in ext_options .items ():
160
+ print (" {}: {}" .format (k , v ))
161
+
141
162
return metadata , ext_options
142
163
143
164
0 commit comments