comparison setup_posix.py @ 5:b70cce9bd065 MySQLdb

Merge changes from 1.2 branch r456-468
author adustman
date Sun, 11 Feb 2007 04:37:29 +0000
parents
children fa8974a41c76
comparison
equal deleted inserted replaced
4:b5a377255eea 5:b70cce9bd065
1 from ConfigParser import SafeConfigParser
2
3 # This dequote() business is required for some older versions
4 # of mysql_config
5
6 def dequote(s):
7 if s[0] in "\"'" and s[0] == s[-1]:
8 s = s[1:-1]
9 return s
10
11 def compiler_flag(f):
12 return "-%s" % f
13
14 def mysql_config(what):
15 from os import popen
16
17 f = popen("mysql_config --%s" % what)
18 data = f.read().strip().split()
19 ret = f.close()
20 if ret:
21 if ret/256:
22 data = []
23 if ret/256 > 1:
24 raise EnvironmentError, "mysql_config is not on your PATH"
25 return data
26
27 def get_config():
28 import os, sys
29 from setup_common import get_metadata_and_options, enabled, create_release_file
30
31 metadata, options = get_metadata_and_options()
32
33 extra_objects = []
34 static = enabled(options, 'static')
35 if enabled(options, 'embedded'):
36 libs = mysql_config("libmysqld-libs")
37 client = "mysqld"
38 elif enabled(options, 'threadsafe'):
39 libs = mysql_config("libs_r")
40 client = "mysqlclient_r"
41 if not libs:
42 libs = mysql_config("libs")
43 client = "mysqlclient"
44 else:
45 libs = mysql_config("libs")
46 client = "mysqlclient"
47
48 library_dirs = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("L")) ]
49 libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
50
51 removable_compile_args = [ compiler_flag(f) for f in "ILl" ]
52 extra_compile_args = [ i for i in mysql_config("cflags")
53 if i[:2] not in removable_compile_args ]
54 include_dirs = [ dequote(i[2:])
55 for i in mysql_config('include')
56 if i.startswith(compiler_flag('I')) ]
57 if not include_dirs: # fix for MySQL-3.23
58 include_dirs = [ dequote(i[2:])
59 for i in mysql_config('cflags')
60 if i.startswith(compiler_flag('I')) ]
61
62 if static:
63 extra_objects.append(os.path.join(
64 library_dirs[0],'lib%s.a' % client))
65
66 name = "MySQL-%s" % os.path.basename(sys.executable)
67 if enabled(options, 'embedded'):
68 name = name + "-embedded"
69 metadata['name'] = name
70
71 define_macros = [
72 ('version_info', metadata['version_info']),
73 ('__version__', metadata['version']),
74 ]
75 create_release_file(metadata)
76 del metadata['version_info']
77 ext_options = dict(
78 name = "_mysql",
79 library_dirs = library_dirs,
80 libraries = libraries,
81 extra_compile_args = extra_compile_args,
82 include_dirs = include_dirs,
83 extra_objects = extra_objects,
84 define_macros = define_macros,
85 )
86 return metadata, ext_options
87
88 if __name__ == "__main__":
89 print """You shouldn't be running this directly; it is used by setup.py."""
90