|
1 Index: setuptools/extension.py |
|
2 =================================================================== |
|
3 --- setuptools/extension.py (revision 75864) |
|
4 +++ setuptools/extension.py (working copy) |
|
5 @@ -28,6 +28,11 @@ |
|
6 class Library(Extension): |
|
7 """Just like a regular Extension, but built as a library instead""" |
|
8 |
|
9 + def __init__(self, *args, **kwds): |
|
10 + self.force_shared = kwds.pop('force_shared', False) |
|
11 + Extension.__init__(self, *args, **kwds) |
|
12 + |
|
13 + |
|
14 import sys, distutils.core, distutils.extension |
|
15 distutils.core.Extension = Extension |
|
16 distutils.extension.Extension = Extension |
|
17 Index: setuptools/command/build_ext.py |
|
18 =================================================================== |
|
19 --- setuptools/command/build_ext.py (revision 75864) |
|
20 +++ setuptools/command/build_ext.py (working copy) |
|
21 @@ -85,8 +85,12 @@ |
|
22 if fullname in self.ext_map: |
|
23 ext = self.ext_map[fullname] |
|
24 if isinstance(ext,Library): |
|
25 + if ext.force_shared and not use_stubs: |
|
26 + _libtype = 'shared' |
|
27 + else: |
|
28 + _libtype = libtype |
|
29 fn, ext = os.path.splitext(filename) |
|
30 - return self.shlib_compiler.library_filename(fn,libtype) |
|
31 + return self.shlib_compiler.library_filename(fn,_libtype) |
|
32 elif use_stubs and ext._links_to_dynamic: |
|
33 d,fn = os.path.split(filename) |
|
34 return os.path.join(d,'dl-'+fn) |
|
35 @@ -170,14 +174,22 @@ |
|
36 def build_extension(self, ext): |
|
37 _compiler = self.compiler |
|
38 try: |
|
39 + force_shared = False |
|
40 if isinstance(ext,Library): |
|
41 self.compiler = self.shlib_compiler |
|
42 + force_shared = ext.force_shared and not use_stubs |
|
43 + if force_shared: |
|
44 + self.compiler.link_shared_object = \ |
|
45 + sh_link_shared_object.__get__(self.compiler) |
|
46 _build_ext.build_extension(self,ext) |
|
47 if ext._needs_stub: |
|
48 self.write_stub( |
|
49 self.get_finalized_command('build_py').build_lib, ext |
|
50 ) |
|
51 finally: |
|
52 + if force_shared: |
|
53 + self.compiler.link_shared_object = \ |
|
54 + link_shared_object.__get__(self.compiler) |
|
55 self.compiler = _compiler |
|
56 |
|
57 def links_to_dynamic(self, ext): |
|
58 @@ -244,44 +256,41 @@ |
|
59 os.unlink(stub_file) |
|
60 |
|
61 |
|
62 -if use_stubs or os.name=='nt': |
|
63 - # Build shared libraries |
|
64 - # |
|
65 - def link_shared_object(self, objects, output_libname, output_dir=None, |
|
66 - libraries=None, library_dirs=None, runtime_library_dirs=None, |
|
67 - export_symbols=None, debug=0, extra_preargs=None, |
|
68 - extra_postargs=None, build_temp=None, target_lang=None |
|
69 - ): self.link( |
|
70 - self.SHARED_LIBRARY, objects, output_libname, |
|
71 - output_dir, libraries, library_dirs, runtime_library_dirs, |
|
72 - export_symbols, debug, extra_preargs, extra_postargs, |
|
73 - build_temp, target_lang |
|
74 - ) |
|
75 -else: |
|
76 - # Build static libraries everywhere else |
|
77 - libtype = 'static' |
|
78 +def sh_link_shared_object(self, objects, output_libname, output_dir=None, |
|
79 + libraries=None, library_dirs=None, runtime_library_dirs=None, |
|
80 + export_symbols=None, debug=0, extra_preargs=None, |
|
81 + extra_postargs=None, build_temp=None, target_lang=None |
|
82 +): self.link(self.SHARED_LIBRARY, objects, output_libname, |
|
83 + output_dir, libraries, library_dirs, runtime_library_dirs, |
|
84 + export_symbols, debug, extra_preargs, extra_postargs, |
|
85 + build_temp, target_lang) |
|
86 |
|
87 - def link_shared_object(self, objects, output_libname, output_dir=None, |
|
88 - libraries=None, library_dirs=None, runtime_library_dirs=None, |
|
89 - export_symbols=None, debug=0, extra_preargs=None, |
|
90 - extra_postargs=None, build_temp=None, target_lang=None |
|
91 - ): |
|
92 - # XXX we need to either disallow these attrs on Library instances, |
|
93 - # or warn/abort here if set, or something... |
|
94 - #libraries=None, library_dirs=None, runtime_library_dirs=None, |
|
95 - #export_symbols=None, extra_preargs=None, extra_postargs=None, |
|
96 - #build_temp=None |
|
97 +def st_link_shared_object(self, objects, output_libname, output_dir=None, |
|
98 + libraries=None, library_dirs=None, runtime_library_dirs=None, |
|
99 + export_symbols=None, debug=0, extra_preargs=None, |
|
100 + extra_postargs=None, build_temp=None, target_lang=None |
|
101 +): |
|
102 + # XXX we need to either disallow these attrs on Library instances, |
|
103 + # or warn/abort here if set, or something... |
|
104 + #libraries=None, library_dirs=None, runtime_library_dirs=None, |
|
105 + #export_symbols=None, extra_preargs=None, extra_postargs=None, |
|
106 + #build_temp=None |
|
107 |
|
108 - assert output_dir is None # distutils build_ext doesn't pass this |
|
109 - output_dir,filename = os.path.split(output_libname) |
|
110 - basename, ext = os.path.splitext(filename) |
|
111 - if self.library_filename("x").startswith('lib'): |
|
112 - # strip 'lib' prefix; this is kludgy if some platform uses |
|
113 - # a different prefix |
|
114 - basename = basename[3:] |
|
115 + assert output_dir is None # distutils build_ext doesn't pass this |
|
116 + output_dir,filename = os.path.split(output_libname) |
|
117 + basename, ext = os.path.splitext(filename) |
|
118 + if self.library_filename("x").startswith('lib'): |
|
119 + # strip 'lib' prefix; this is kludgy if some platform uses |
|
120 + # a different prefix |
|
121 + basename = basename[3:] |
|
122 |
|
123 - self.create_static_lib( |
|
124 - objects, basename, output_dir, debug, target_lang |
|
125 - ) |
|
126 + self.create_static_lib(objects, basename, output_dir, debug, target_lang) |
|
127 |
|
128 |
|
129 +if use_stubs or os.name=='nt': |
|
130 + # Build shared libraries |
|
131 + link_shared_object = sh_link_shared_object |
|
132 +else: |
|
133 + # Build static libraries everywhere else (unless force_shared) |
|
134 + libtype = 'static' |
|
135 + link_shared_object = st_link_shared_object |