@@ -149,84 +149,87 @@ def read_setup_file(filename):
149149 file = TextFile (filename ,
150150 strip_comments = 1 , skip_blanks = 1 , join_lines = 1 ,
151151 lstrip_ws = 1 , rstrip_ws = 1 )
152- extensions = []
153-
154- while True :
155- line = file .readline ()
156- if line is None : # eof
157- break
158- if _variable_rx .match (line ): # VAR=VALUE, handled in first pass
159- continue
160-
161- if line [0 ] == line [- 1 ] == "*" :
162- file .warn ("'%s' lines not handled yet" % line )
163- continue
164-
165- line = expand_makefile_vars (line , vars )
166- words = split_quoted (line )
167-
168- # NB. this parses a slightly different syntax than the old
169- # makesetup script: here, there must be exactly one extension per
170- # line, and it must be the first word of the line. I have no idea
171- # why the old syntax supported multiple extensions per line, as
172- # they all wind up being the same.
173-
174- module = words [0 ]
175- ext = Extension (module , [])
176- append_next_word = None
177-
178- for word in words [1 :]:
179- if append_next_word is not None :
180- append_next_word .append (word )
181- append_next_word = None
152+ try :
153+ extensions = []
154+
155+ while True :
156+ line = file .readline ()
157+ if line is None : # eof
158+ break
159+ if _variable_rx .match (line ): # VAR=VALUE, handled in first pass
182160 continue
183161
184- suffix = os .path .splitext (word )[1 ]
185- switch = word [0 :2 ] ; value = word [2 :]
186-
187- if suffix in (".c" , ".cc" , ".cpp" , ".cxx" , ".c++" , ".m" , ".mm" ):
188- # hmm, should we do something about C vs. C++ sources?
189- # or leave it up to the CCompiler implementation to
190- # worry about?
191- ext .sources .append (word )
192- elif switch == "-I" :
193- ext .include_dirs .append (value )
194- elif switch == "-D" :
195- equals = value .find ("=" )
196- if equals == - 1 : # bare "-DFOO" -- no value
197- ext .define_macros .append ((value , None ))
198- else : # "-DFOO=blah"
199- ext .define_macros .append ((value [0 :equals ],
200- value [equals + 2 :]))
201- elif switch == "-U" :
202- ext .undef_macros .append (value )
203- elif switch == "-C" : # only here 'cause makesetup has it!
204- ext .extra_compile_args .append (word )
205- elif switch == "-l" :
206- ext .libraries .append (value )
207- elif switch == "-L" :
208- ext .library_dirs .append (value )
209- elif switch == "-R" :
210- ext .runtime_library_dirs .append (value )
211- elif word == "-rpath" :
212- append_next_word = ext .runtime_library_dirs
213- elif word == "-Xlinker" :
214- append_next_word = ext .extra_link_args
215- elif word == "-Xcompiler" :
216- append_next_word = ext .extra_compile_args
217- elif switch == "-u" :
218- ext .extra_link_args .append (word )
219- if not value :
162+ if line [0 ] == line [- 1 ] == "*" :
163+ file .warn ("'%s' lines not handled yet" % line )
164+ continue
165+
166+ line = expand_makefile_vars (line , vars )
167+ words = split_quoted (line )
168+
169+ # NB. this parses a slightly different syntax than the old
170+ # makesetup script: here, there must be exactly one extension per
171+ # line, and it must be the first word of the line. I have no idea
172+ # why the old syntax supported multiple extensions per line, as
173+ # they all wind up being the same.
174+
175+ module = words [0 ]
176+ ext = Extension (module , [])
177+ append_next_word = None
178+
179+ for word in words [1 :]:
180+ if append_next_word is not None :
181+ append_next_word .append (word )
182+ append_next_word = None
183+ continue
184+
185+ suffix = os .path .splitext (word )[1 ]
186+ switch = word [0 :2 ] ; value = word [2 :]
187+
188+ if suffix in (".c" , ".cc" , ".cpp" , ".cxx" , ".c++" , ".m" , ".mm" ):
189+ # hmm, should we do something about C vs. C++ sources?
190+ # or leave it up to the CCompiler implementation to
191+ # worry about?
192+ ext .sources .append (word )
193+ elif switch == "-I" :
194+ ext .include_dirs .append (value )
195+ elif switch == "-D" :
196+ equals = value .find ("=" )
197+ if equals == - 1 : # bare "-DFOO" -- no value
198+ ext .define_macros .append ((value , None ))
199+ else : # "-DFOO=blah"
200+ ext .define_macros .append ((value [0 :equals ],
201+ value [equals + 2 :]))
202+ elif switch == "-U" :
203+ ext .undef_macros .append (value )
204+ elif switch == "-C" : # only here 'cause makesetup has it!
205+ ext .extra_compile_args .append (word )
206+ elif switch == "-l" :
207+ ext .libraries .append (value )
208+ elif switch == "-L" :
209+ ext .library_dirs .append (value )
210+ elif switch == "-R" :
211+ ext .runtime_library_dirs .append (value )
212+ elif word == "-rpath" :
213+ append_next_word = ext .runtime_library_dirs
214+ elif word == "-Xlinker" :
220215 append_next_word = ext .extra_link_args
221- elif suffix in (".a" , ".so" , ".sl" , ".o" , ".dylib" ):
222- # NB. a really faithful emulation of makesetup would
223- # append a .o file to extra_objects only if it
224- # had a slash in it; otherwise, it would s/.o/.c/
225- # and append it to sources. Hmmmm.
226- ext .extra_objects .append (word )
227- else :
228- file .warn ("unrecognized argument '%s'" % word )
229-
230- extensions .append (ext )
216+ elif word == "-Xcompiler" :
217+ append_next_word = ext .extra_compile_args
218+ elif switch == "-u" :
219+ ext .extra_link_args .append (word )
220+ if not value :
221+ append_next_word = ext .extra_link_args
222+ elif suffix in (".a" , ".so" , ".sl" , ".o" , ".dylib" ):
223+ # NB. a really faithful emulation of makesetup would
224+ # append a .o file to extra_objects only if it
225+ # had a slash in it; otherwise, it would s/.o/.c/
226+ # and append it to sources. Hmmmm.
227+ ext .extra_objects .append (word )
228+ else :
229+ file .warn ("unrecognized argument '%s'" % word )
230+
231+ extensions .append (ext )
232+ finally :
233+ file .close ()
231234
232235 return extensions
0 commit comments