Changeset 391 for python/trunk/Lib/distutils/extension.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/distutils/extension.py
r2 r391 4 4 modules in setup scripts.""" 5 5 6 __revision__ = "$Id : extension.py 37623 2004-10-14 10:02:08Z anthonybaxter$"6 __revision__ = "$Id$" 7 7 8 8 import os, string, sys … … 151 151 strip_comments=1, skip_blanks=1, join_lines=1, 152 152 lstrip_ws=1, rstrip_ws=1) 153 extensions = [] 154 155 while 1: 156 line = file.readline() 157 if line is None: # eof 158 break 159 if _variable_rx.match(line): # VAR=VALUE, handled in first pass 160 continue 161 162 if line[0] == line[-1] == "*": 163 file.warn("'%s' lines not handled yet" % line) 164 continue 165 166 #print "original line: " + line 167 line = expand_makefile_vars(line, vars) 168 words = split_quoted(line) 169 #print "expanded line: " + line 170 171 # NB. this parses a slightly different syntax than the old 172 # makesetup script: here, there must be exactly one extension per 173 # line, and it must be the first word of the line. I have no idea 174 # why the old syntax supported multiple extensions per line, as 175 # they all wind up being the same. 176 177 module = words[0] 178 ext = Extension(module, []) 179 append_next_word = None 180 181 for word in words[1:]: 182 if append_next_word is not None: 183 append_next_word.append(word) 184 append_next_word = None 153 try: 154 extensions = [] 155 156 while 1: 157 line = file.readline() 158 if line is None: # eof 159 break 160 if _variable_rx.match(line): # VAR=VALUE, handled in first pass 185 161 continue 186 162 187 suffix = os.path.splitext(word)[1] 188 switch = word[0:2] ; value = word[2:] 189 190 if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"): 191 # hmm, should we do something about C vs. C++ sources? 192 # or leave it up to the CCompiler implementation to 193 # worry about? 194 ext.sources.append(word) 195 elif switch == "-I": 196 ext.include_dirs.append(value) 197 elif switch == "-D": 198 equals = string.find(value, "=") 199 if equals == -1: # bare "-DFOO" -- no value 200 ext.define_macros.append((value, None)) 201 else: # "-DFOO=blah" 202 ext.define_macros.append((value[0:equals], 203 value[equals+2:])) 204 elif switch == "-U": 205 ext.undef_macros.append(value) 206 elif switch == "-C": # only here 'cause makesetup has it! 207 ext.extra_compile_args.append(word) 208 elif switch == "-l": 209 ext.libraries.append(value) 210 elif switch == "-L": 211 ext.library_dirs.append(value) 212 elif switch == "-R": 213 ext.runtime_library_dirs.append(value) 214 elif word == "-rpath": 215 append_next_word = ext.runtime_library_dirs 216 elif word == "-Xlinker": 217 append_next_word = ext.extra_link_args 218 elif word == "-Xcompiler": 219 append_next_word = ext.extra_compile_args 220 elif switch == "-u": 221 ext.extra_link_args.append(word) 222 if not value: 163 if line[0] == line[-1] == "*": 164 file.warn("'%s' lines not handled yet" % line) 165 continue 166 167 #print "original line: " + line 168 line = expand_makefile_vars(line, vars) 169 words = split_quoted(line) 170 #print "expanded line: " + line 171 172 # NB. this parses a slightly different syntax than the old 173 # makesetup script: here, there must be exactly one extension per 174 # line, and it must be the first word of the line. I have no idea 175 # why the old syntax supported multiple extensions per line, as 176 # they all wind up being the same. 177 178 module = words[0] 179 ext = Extension(module, []) 180 append_next_word = None 181 182 for word in words[1:]: 183 if append_next_word is not None: 184 append_next_word.append(word) 185 append_next_word = None 186 continue 187 188 suffix = os.path.splitext(word)[1] 189 switch = word[0:2] ; value = word[2:] 190 191 if suffix in (".c", ".cc", ".cpp", ".cxx", ".c++", ".m", ".mm"): 192 # hmm, should we do something about C vs. C++ sources? 193 # or leave it up to the CCompiler implementation to 194 # worry about? 195 ext.sources.append(word) 196 elif switch == "-I": 197 ext.include_dirs.append(value) 198 elif switch == "-D": 199 equals = string.find(value, "=") 200 if equals == -1: # bare "-DFOO" -- no value 201 ext.define_macros.append((value, None)) 202 else: # "-DFOO=blah" 203 ext.define_macros.append((value[0:equals], 204 value[equals+2:])) 205 elif switch == "-U": 206 ext.undef_macros.append(value) 207 elif switch == "-C": # only here 'cause makesetup has it! 208 ext.extra_compile_args.append(word) 209 elif switch == "-l": 210 ext.libraries.append(value) 211 elif switch == "-L": 212 ext.library_dirs.append(value) 213 elif switch == "-R": 214 ext.runtime_library_dirs.append(value) 215 elif word == "-rpath": 216 append_next_word = ext.runtime_library_dirs 217 elif word == "-Xlinker": 223 218 append_next_word = ext.extra_link_args 224 elif suffix in (".a", ".so", ".sl", ".o", ".dylib"): 225 # NB. a really faithful emulation of makesetup would 226 # append a .o file to extra_objects only if it 227 # had a slash in it; otherwise, it would s/.o/.c/ 228 # and append it to sources. Hmmmm. 229 ext.extra_objects.append(word) 230 else: 231 file.warn("unrecognized argument '%s'" % word) 232 233 extensions.append(ext) 219 elif word == "-Xcompiler": 220 append_next_word = ext.extra_compile_args 221 elif switch == "-u": 222 ext.extra_link_args.append(word) 223 if not value: 224 append_next_word = ext.extra_link_args 225 elif word == "-Xcompiler": 226 append_next_word = ext.extra_compile_args 227 elif switch == "-u": 228 ext.extra_link_args.append(word) 229 if not value: 230 append_next_word = ext.extra_link_args 231 elif suffix in (".a", ".so", ".sl", ".o", ".dylib"): 232 # NB. a really faithful emulation of makesetup would 233 # append a .o file to extra_objects only if it 234 # had a slash in it; otherwise, it would s/.o/.c/ 235 # and append it to sources. Hmmmm. 236 ext.extra_objects.append(word) 237 else: 238 file.warn("unrecognized argument '%s'" % word) 239 240 extensions.append(ext) 241 finally: 242 file.close() 234 243 235 244 #print "module:", module
Note:
See TracChangeset
for help on using the changeset viewer.