@@ -19,16 +19,17 @@ def dequote(s):
1919
2020
2121def 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 )
2525 data = f .read ().strip ().split ()
2626 ret = f .close ()
2727 if ret :
2828 if ret / 256 :
2929 data = []
3030 if ret / 256 > 1 :
3131 raise OSError ("{} not found" .format (_mysql_config_path ))
32+ print (data )
3233 return data
3334
3435
@@ -62,26 +63,41 @@ def get_config():
6263 static = True
6364 sys .argv .remove ("--static" )
6465
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" )
6671 library_dirs = [dequote (i [2 :]) for i in libs if i .startswith ("-L" )]
6772 libraries = [dequote (i [2 :]) for i in libs if i .startswith ("-l" )]
6873 extra_link_args = [x for x in libs if not x .startswith (("-l" , "-L" ))]
6974
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 ("%" , "%%" ))
7693
7794 # 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 :
8098 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
85101
86102 if static :
87103 # properly handle mysql client libraries that are not called libmysqlclient
@@ -109,11 +125,12 @@ def get_config():
109125 if client in libraries :
110126 libraries .remove (client )
111127 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 )
117134
118135 name = "mysqlclient"
119136 metadata ["name" ] = name
@@ -138,6 +155,10 @@ def get_config():
138155 if static :
139156 ext_options ["language" ] = "c++"
140157
158+ print ("ext_options:" )
159+ for k , v in ext_options .items ():
160+ print (" {}: {}" .format (k , v ))
161+
141162 return metadata , ext_options
142163
143164
0 commit comments