blob: 5ac948cca70078db17484b8247fbc00f534c052a [file] [log] [blame]
Daniel Dunbar9c199a02009-01-11 23:13:15 +00001import sys # FIXME: Shouldn't be needed.
2
Daniel Dunbara5677512009-01-05 19:53:30 +00003import Arguments
4import Jobs
5import Types
6
7class Tool(object):
Daniel Dunbarba6e3232009-01-06 06:12:13 +00008 """Tool - A concrete implementation of an action."""
Daniel Dunbara5677512009-01-05 19:53:30 +00009
10 eFlagsPipedInput = 1 << 0
11 eFlagsPipedOutput = 1 << 1
12 eFlagsIntegratedCPP = 1 << 2
13
14 def __init__(self, name, flags = 0):
15 self.name = name
16 self.flags = flags
17
18 def acceptsPipedInput(self):
19 return not not (self.flags & Tool.eFlagsPipedInput)
20 def canPipeOutput(self):
21 return not not (self.flags & Tool.eFlagsPipedOutput)
22 def hasIntegratedCPP(self):
23 return not not (self.flags & Tool.eFlagsIntegratedCPP)
24
25class GCC_Common_Tool(Tool):
26 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000027 output, outputType, args, arglist,
Daniel Dunbara5677512009-01-05 19:53:30 +000028 extraArgs):
Daniel Dunbardb439902009-01-07 18:40:45 +000029 cmd_args = sum(map(arglist.render, args),[]) + extraArgs
Daniel Dunbara5677512009-01-05 19:53:30 +000030 if arch:
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +000031 cmd_args.extend(arglist.render(arch))
Daniel Dunbara5677512009-01-05 19:53:30 +000032 if isinstance(output, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +000033 cmd_args.extend(['-o', '-'])
Daniel Dunbara5677512009-01-05 19:53:30 +000034 elif output is None:
Daniel Dunbardb439902009-01-07 18:40:45 +000035 cmd_args.append('-fsyntax-only')
Daniel Dunbara5677512009-01-05 19:53:30 +000036 else:
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +000037 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +000038
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000039 # Only pass -x if gcc will understand it; otherwise hope gcc
40 # understands the suffix correctly. The main use case this
Daniel Dunbar9c199a02009-01-11 23:13:15 +000041 # would go wrong in is for linker inputs if they happened to
42 # have an odd suffix; really the only way to get this to
43 # happen is a command like '-x foobar a.c' which will treat
44 # a.c like a linker input.
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000045 #
46 # FIXME: For the linker case specifically, can we safely
47 # convert inputs into '-Wl,' options?
48 for input in inputs:
49 if input.type.canBeUserSpecified:
50 cmd_args.extend(['-x', input.type.name])
51
52 if isinstance(input.source, Jobs.PipedJob):
53 cmd_args.append('-')
54 else:
55 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +000056
57 jobs.addJob(Jobs.Command('gcc', cmd_args))
58
59class GCC_PreprocessTool(GCC_Common_Tool):
60 def __init__(self):
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000061 super(GCC_PreprocessTool, self).__init__('gcc (cpp)',
Daniel Dunbara5677512009-01-05 19:53:30 +000062 (Tool.eFlagsPipedInput |
63 Tool.eFlagsPipedOutput))
64
65 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000066 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000067 return super(GCC_PreprocessTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000068 output, outputType, args, arglist,
69 ['-E'])
Daniel Dunbara5677512009-01-05 19:53:30 +000070
71class GCC_CompileTool(GCC_Common_Tool):
72 def __init__(self):
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000073 super(GCC_CompileTool, self).__init__('gcc (cc1)',
Daniel Dunbara5677512009-01-05 19:53:30 +000074 (Tool.eFlagsPipedInput |
75 Tool.eFlagsPipedOutput |
76 Tool.eFlagsIntegratedCPP))
77
78 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000079 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000080 return super(GCC_CompileTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000081 output, outputType, args, arglist,
82 ['-S'])
Daniel Dunbara5677512009-01-05 19:53:30 +000083
84class GCC_PrecompileTool(GCC_Common_Tool):
85 def __init__(self):
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000086 super(GCC_PrecompileTool, self).__init__('gcc (pch)',
Daniel Dunbara5677512009-01-05 19:53:30 +000087 (Tool.eFlagsPipedInput |
88 Tool.eFlagsIntegratedCPP))
89
90 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000091 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000092 return super(GCC_PrecompileTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000093 output, outputType, args, arglist,
Daniel Dunbara5677512009-01-05 19:53:30 +000094 [])
95
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000096class DarwinAssembleTool(Tool):
Daniel Dunbara5677512009-01-05 19:53:30 +000097 def __init__(self):
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000098 super(DarwinAssembleTool, self).__init__('as',
99 Tool.eFlagsPipedInput)
Daniel Dunbara5677512009-01-05 19:53:30 +0000100
101 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000102 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000103 assert len(inputs) == 1
104 assert outputType is Types.ObjectType
105
106 input = inputs[0]
107
108 cmd_args = []
109 if arch:
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000110 cmd_args.extend(arglist.render(arch))
Daniel Dunbardb439902009-01-07 18:40:45 +0000111 cmd_args.append('-force_cpusubtype_ALL')
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000112 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000113 if isinstance(input.source, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +0000114 cmd_args.append('-')
Daniel Dunbara5677512009-01-05 19:53:30 +0000115 else:
Daniel Dunbardb439902009-01-07 18:40:45 +0000116 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000117 jobs.addJob(Jobs.Command('as', cmd_args))
118
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +0000119class GCC_AssembleTool(GCC_Common_Tool):
120 def __init__(self):
121 # We can't generally assume the assembler can take or output
122 # on pipes.
123 super(GCC_AssembleTool, self).__init__('gcc (as)')
124
125 def constructJob(self, phase, arch, jobs, inputs,
126 output, outputType, args, arglist):
127 return super(GCC_AssembleTool, self).constructJob(phase, arch, jobs, inputs,
128 output, outputType, args, arglist,
129 ['-c'])
130
131class GCC_LinkTool(GCC_Common_Tool):
132 def __init__(self):
133 super(GCC_LinkTool, self).__init__('gcc (ld)')
134
135 def constructJob(self, phase, arch, jobs, inputs,
136 output, outputType, args, arglist):
137 return super(GCC_LinkTool, self).constructJob(phase, arch, jobs, inputs,
138 output, outputType, args, arglist,
139 [])
140
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000141class Darwin10_X86_LinkTool(Tool):
Daniel Dunbara5677512009-01-05 19:53:30 +0000142 kCollect2Path = '/usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2'
143 def __init__(self):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000144 super(Darwin10_X86_LinkTool, self).__init__('collect2')
145
146 def addDarwinArch(self, cmd_args, arch, arglist):
147 # Derived from darwin_arch spec.
148 cmd_args.append('-arch')
149 # FIXME: The actual spec uses -m64 for this, but we want to
150 # respect arch. Figure out what exactly gcc is doing.
151 #if arglist.getLastArg(arglist.parser.m_64Option):
152 if arglist.getValue(arch) == 'x86_64':
153 cmd_args.append('x86_64')
154 else:
155 cmd_args.append('i386')
156
157 def addDarwinSubArch(self, cmd_args, arch, arglist):
158 # Derived from darwin_subarch spec, not sure what the
159 # distinction exists for but at least for this chain it is the same.
160 return self.addDarwinArch(cmd_args, arch, arglist)
161
162 def addLinkArgs(self, cmd_args, arch, arglist):
163 # Derived from link spec.
164 if arglist.getLastArg(arglist.parser.staticOption):
165 cmd_args.append('-static')
166 else:
167 cmd_args.append('-dynamic')
168 if arglist.getLastArg(arglist.parser.f_gnuRuntimeOption):
169 # FIXME: Replace -lobjc in forward args with
170 # -lobjc-gnu. How do we wish to handle such things?
171 pass
172
173 if not arglist.getLastArg(arglist.parser.ZdynamiclibOption):
174 if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption):
175 self.addDarwinArch(cmd_args, arch, arglist)
176 cmd_args.append('-force_cpusubtype_all')
177 else:
178 self.addDarwinSubArch(cmd_args, arch, arglist)
179
180 if arglist.getLastArg(arglist.parser.ZbundleOption):
181 cmd_args.append('-bundle')
182 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zbundle_loaderOption,
183 '-bundle_loader')
184 arglist.addAllArgs(cmd_args, arglist.parser.client_nameOption)
185 if arglist.getLastArg(arglist.parser.compatibility_versionOption):
186 # FIXME: Where should diagnostics go?
187 print >>sys.stderr, "-compatibility_version only allowed with -dynamiclib"
188 sys.exit(1)
189 if arglist.getLastArg(arglist.parser.current_versionOption):
190 print >>sys.stderr, "-current_version only allowed with -dynamiclib"
191 sys.exit(1)
192 if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption):
193 cmd_args.append('-force_flat_namespace')
194 if arglist.getLastArg(arglist.parser.Zinstall_nameOption):
195 print >>sys.stderr, "-install_name only allowed with -dynamiclib"
196 sys.exit(1)
197 arglist.addLastArg(cmd_args, arglist.parser.keep_private_externsOption)
198 arglist.addLastArg(cmd_args, arglist.parser.private_bundleOption)
199 else:
200 cmd_args.append('-dylib')
201 if arglist.getLastArg(arglist.parser.ZbundleOption):
202 print >>sys.stderr, "-bundle not allowed with -dynamiclib"
203 sys.exit(1)
204 if arglist.getLastArg(arglist.parser.Zbundle_loaderOption):
205 print >>sys.stderr, "-bundle_loader not allowed with -dynamiclib"
206 sys.exit(1)
207 if arglist.getLastArg(arglist.parser.client_nameOption):
208 print >>sys.stderr, "-client_name not allowed with -dynamiclib"
209 sys.exit(1)
210 arglist.addAllArgsTranslated(cmd_args, arglist.parser.compatibility_versionOption,
211 '-dylib_compatibility_version')
212 arglist.addAllArgsTranslated(cmd_args, arglist.parser.current_versionOption,
213 '-dylib_current_version')
214
215 if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption):
216 self.addDarwinArch(cmd_args, arch, arglist)
217 # NOTE: We don't add -force_cpusubtype_ALL on this path. Ok.
218 else:
219 self.addDarwinSubArch(cmd_args, arch, arglist)
220
221 if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption):
222 print >>sys.stderr, "-force_flat_namespace not allowed with -dynamiclib"
223 sys.exit(1)
224
225 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zinstall_nameOption,
226 '-dylib_install_name')
227
228 if arglist.getLastArg(arglist.parser.keep_private_externsOption):
229 print >>sys.stderr, "-keep_private_externs not allowed with -dynamiclib"
230 sys.exit(1)
231 if arglist.getLastArg(arglist.parser.private_bundleOption):
232 print >>sys.stderr, "-private_bundle not allowed with -dynamiclib"
233 sys.exit(1)
234
235 if arglist.getLastArg(arglist.parser.Zall_loadOption):
236 cmd_args.append('-all_load')
237
238 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zallowable_clientOption,
239 '-allowable_client')
240
241 if arglist.getLastArg(arglist.parser.Zbind_at_loadOption):
242 cmd_args.append('-bind_at_load')
243
244 if arglist.getLastArg(arglist.parser.Zdead_stripOption):
245 cmd_args.append('-dead_strip')
246
247 if arglist.getLastArg(arglist.parser.Zno_dead_strip_inits_and_termsOption):
248 cmd_args.append('-no_dead_strip_inits_and_terms')
249
250 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zdylib_fileOption,
251 '-dylib_file')
252
253 if arglist.getLastArg(arglist.parser.ZdynamicOption):
254 cmd_args.append('-dynamic')
255
256 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zexported_symbols_listOption,
257 '-exported_symbols_list')
258
259 if arglist.getLastArg(arglist.parser.Zflat_namespaceOption):
260 cmd_args.append('-flat_namespace')
261
262 arglist.addAllArgs(cmd_args, arglist.parser.headerpad_max_install_namesOption)
263 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zimage_baseOption,
264 '-image_base')
265 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZinitOption,
266 '-init')
267
268 if not arglist.getLastArg(arglist.parser.m_macosxVersionMinOption):
269 if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
270 # FIXME: I don't understand what is going on
271 # here. This is supposed to come from
272 # darwin_ld_minversion, but gcc doesn't seem to be
273 # following that; it must be getting over-ridden
274 # somewhere.
275 cmd_args.append('-macosx_version_min')
276 # FIXME: De-hardcode.
277 cmd_args.append('10.6.0')
278 pass
279 else:
280 # addAll doesn't make sense here but this is what gcc
281 # does.
282 arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_macosxVersionMinOption,
283 '-macosx_version_min')
284
285 arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_iphoneosVersionMinOption,
286 '-iphoneos_version_min')
287 arglist.addLastArg(cmd_args, arglist.parser.nomultidefsOption)
288
289 if arglist.getLastArg(arglist.parser.Zmulti_moduleOption):
290 cmd_args.append('-multi_module')
291
292 if arglist.getLastArg(arglist.parser.Zsingle_moduleOption):
293 cmd_args.append('-single_module')
294
295 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zmultiply_definedOption,
296 '-multiply_defined')
297
298 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZmultiplydefinedunusedOption,
299 '-multiply_defined_unused')
300
301 if arglist.getLastArg(arglist.parser.f_pieOption):
302 cmd_args.append('-pie')
303
304 arglist.addLastArg(cmd_args, arglist.parser.prebindOption)
305 arglist.addLastArg(cmd_args, arglist.parser.noprebindOption)
306 arglist.addLastArg(cmd_args, arglist.parser.nofixprebindingOption)
307 arglist.addLastArg(cmd_args, arglist.parser.prebind_all_twolevel_modulesOption)
308 arglist.addLastArg(cmd_args, arglist.parser.read_only_relocsOption)
309 arglist.addAllArgs(cmd_args, arglist.parser.sectcreateOption)
310 arglist.addAllArgs(cmd_args, arglist.parser.sectorderOption)
311 arglist.addAllArgs(cmd_args, arglist.parser.seg1addrOption)
312 arglist.addAllArgs(cmd_args, arglist.parser.segprotOption)
313 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZsegaddrOption,
314 '-segaddr')
315 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_only_addrOption,
316 '-segs_read_only_addr')
317 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_write_addrOption,
318 '-segs_read_write_addr')
319 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zseg_addr_tableOption,
320 '-seg_addr_table')
321 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zfn_seg_addr_table_filenameOption,
322 '-fn_seg_addr_table_filename')
323 arglist.addAllArgs(cmd_args, arglist.parser.sub_libraryOption)
324 arglist.addAllArgs(cmd_args, arglist.parser.sub_umbrellaOption)
325 arglist.addAllArgsTranslated(cmd_args, arglist.parser.isysrootOption,
326 '-syslibroot')
327 arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespaceOption)
328 arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespace_hintsOption)
329 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZumbrellaOption,
330 '-umbrella')
331 arglist.addAllArgs(cmd_args, arglist.parser.undefinedOption)
332 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zunexported_symbols_listOption,
333 '-unexported_symbols_list')
334 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zweak_reference_mismatchesOption,
335 '-weak_reference_mismatches')
336
337 if not arglist.getLastArg(arglist.parser.Zweak_reference_mismatchesOption):
338 cmd_args.append('-weak_reference_mismatches')
339 cmd_args.append('non-weak')
340
341 arglist.addLastArg(cmd_args, arglist.parser.XOption)
342 arglist.addAllArgs(cmd_args, arglist.parser.yOption)
343 arglist.addLastArg(cmd_args, arglist.parser.wOption)
344 arglist.addAllArgs(cmd_args, arglist.parser.pagezero_sizeOption)
345 arglist.addAllArgs(cmd_args, arglist.parser.segs_read_Option)
346 arglist.addLastArg(cmd_args, arglist.parser.seglinkeditOption)
347 arglist.addLastArg(cmd_args, arglist.parser.noseglinkeditOption)
348 arglist.addAllArgs(cmd_args, arglist.parser.sectalignOption)
349 arglist.addAllArgs(cmd_args, arglist.parser.sectobjectsymbolsOption)
350 arglist.addAllArgs(cmd_args, arglist.parser.segcreateOption)
351 arglist.addLastArg(cmd_args, arglist.parser.whyloadOption)
352 arglist.addLastArg(cmd_args, arglist.parser.whatsloadedOption)
353 arglist.addAllArgs(cmd_args, arglist.parser.dylinker_install_nameOption)
354 arglist.addLastArg(cmd_args, arglist.parser.dylinkerOption)
355 arglist.addLastArg(cmd_args, arglist.parser.MachOption)
Daniel Dunbara5677512009-01-05 19:53:30 +0000356
357 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000358 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000359 assert outputType is Types.ImageType
360
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000361 # The logic here is derived from gcc's behavior; most of which
362 # comes from specs (link_command). Consult gcc for more information.
363
364 # FIXME: gcc's spec controls when this is done; certain things
365 # like -filelist or -Wl, still trigger a link stage. I don't
366 # quite understand how gcc decides to execute the linker,
367 # investigate. Also, the spec references -fdump= which seems
368 # to have disappeared?
Daniel Dunbara5677512009-01-05 19:53:30 +0000369 cmd_args = []
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000370
371 # Not sure why this particular decomposition exists in gcc.
372 self.addLinkArgs(cmd_args, arch, arglist)
373
374 # FIXME: Need to insert "additional linker options accumulated
375 # from compilation". What does this mean precisely? And where
376 # do -Wl, options and -Xlinker options come in?
377
378 # FIXME: gcc has %{x} in here. How could this ever happen?
379 # Cruft?
380 arglist.addLastArg(cmd_args, arglist.parser.dOption)
381 arglist.addLastArg(cmd_args, arglist.parser.tOption)
382 arglist.addLastArg(cmd_args, arglist.parser.ZOption)
383 arglist.addLastArg(cmd_args, arglist.parser.uOption)
384 arglist.addLastArg(cmd_args, arglist.parser.AOption)
385 arglist.addLastArg(cmd_args, arglist.parser.eOption)
386 arglist.addLastArg(cmd_args, arglist.parser.mOption)
387 arglist.addLastArg(cmd_args, arglist.parser.rOption)
388
389 cmd_args.extend(arglist.render(output))
390
391 if (not arglist.getLastArg(arglist.parser.AOption) and
392 not arglist.getLastArg(arglist.parser.nostdlibOption) and
393 not arglist.getLastArg(arglist.parser.nostartfilesOption)):
394 # Derived from startfile spec.
395 if arglist.getLastArg(arglist.parser.ZdynamiclibOption):
396 # Derived from darwin_dylib1 spec.
397 if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
398 cmd_args.append('-ldylib1.o')
399 else:
400 if self.macosxVersionCmp('<', '10.5', arglist):
401 cmd_args.append('-ldylib1.o')
402 else:
403 cmd_args.append('-ldylib1.10.5.o')
404 else:
405 if arglist.getLastArg(arglist.parser.ZbundleOption):
406 if not arglist.getLastArg(arglist.parser.staticOption):
407 cmd_args.append('-lbundle1.o')
408 else:
409 if arglist.getLastArg(arglist.parser.pgOption):
410 if arglist.getLastArg(arglist.parser.staticOption):
411 cmd_args.append('-lgcrt0.o')
412 else:
413 if arglist.getLastArg(arglist.parser.objectOption):
414 cmd_args.append('-lgcrt0.o')
415 else:
416 if arglist.getLastArg(arglist.parser.preloadOption):
417 cmd_args.append('-lgcrt0.o')
418 else:
419 cmd_args.append('-lgcrt1.o')
420
421 # darwin_crt2 spec is empty.
422 pass
423 else:
424 if arglist.getLastArg(arglist.parser.staticOption):
425 cmd_args.append('-lcrt0.o')
426 else:
427 if arglist.getLastArg(arglist.parser.objectOption):
428 cmd_args.append('-lcrt0.o')
429 else:
430 if arglist.getLastArg(arglist.parser.preloadOption):
431 cmd_args.append('-lcrt0.o')
432 else:
433 # Derived from darwin_crt1 spec.
434 if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
435 cmd_args.append('-lcrt1.o')
436 else:
437 if self.macosxVersionCmp('<', '10.5', arglist):
438 cmd_args.append('-lcrt1.o')
439 else:
440 cmd_args.append('-lcrt1.10.5.o')
441
442 # darwin_crt2 spec is empty.
443 pass
444
445 if arglist.getLastArg(arglist.parser.sharedLibgccOption):
446 if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
447 if self.macosxVersionCmp('<', '10.5', arglist):
448 # FIXME: gcc does a library search for this
449 # file, this will be be broken currently.
450 cmd_args.append('crt3.o')
451
452 arglist.addAllArgs(cmd_args, arglist.parser.LOption)
453
454 if arglist.getLastArg(arglist.parser.f_openmpOption):
455 # This is more complicated in gcc...
456 cmd_args.append('-lgomp')
457
458 # FIXME: Derive these correctly.
459 if arglist.getValue(arch) == 'x86_64':
460 cmd_args.extend(["-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64",
461 "-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64"])
462 cmd_args.extend(["-L/usr/lib/i686-apple-darwin10/4.2.1",
463 "-L/usr/lib/gcc/i686-apple-darwin10/4.2.1",
464 "-L/usr/lib/gcc/i686-apple-darwin10/4.2.1",
465 "-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1",
466 "-L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.."])
467
Daniel Dunbara5677512009-01-05 19:53:30 +0000468 for input in inputs:
Daniel Dunbardb439902009-01-07 18:40:45 +0000469 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000470
471 if (arglist.getLastArg(arglist.parser.f_profileArcsOption) or
472 arglist.getLastArg(arglist.parser.f_profileGenerateOption) or
473 arglist.getLastArg(arglist.parser.f_createProfileOption) or
474 arglist.getLastArg(arglist.parser.coverageOption)):
475 cmd_args.append('-lgcov')
476
477 if arglist.getLastArg(arglist.parser.f_nestedFunctionsOption):
478 cmd_args.append('-allow_stack_execute')
479
480 if (not arglist.getLastArg(arglist.parser.nostdlibOption) and
481 not arglist.getLastArg(arglist.parser.nodefaultlibsOption)):
482 # link_ssp spec is empty.
483
484 # Derived from libgcc spec.
485 if arglist.getLastArg(arglist.parser.staticOption):
486 cmd_args.append('-lgcc_static')
487 elif arglist.getLastArg(arglist.parser.staticLibgccOption):
488 cmd_args.append('-lgcc_eh')
489 cmd_args.append('-lgcc')
490 elif arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
491 # Derived from darwin_iphoneos_libgcc spec.
492 cmd_args.append('-lgcc_s.10.5')
493 cmd_args.append('-lgcc')
494 elif (arglist.getLastArg(arglist.parser.sharedLibgccOption) or
495 arglist.getLastArg(arglist.parser.f_exceptionsOption) or
496 arglist.getLastArg(arglist.parser.f_gnuRuntimeOption)):
497 if self.macosxVersionCmp('<', '10.5', arglist):
498 cmd_args.append('-lgcc_s.10.4')
499 else:
500 cmd_args.append('-lgcc_s.10.5')
501 cmd_args.append('-lgcc')
502 else:
503 if (self.macosxVersionCmp('<', '10.5', arglist) and
504 self.macosxVersionCmp('>=', '10.3.9', arglist)):
505 cmd_args.append('-lgcc_s.10.4')
506 else:
507 cmd_args.append('-lgcc_s.10.5')
508 cmd_args.append('-lgcc')
509
510 # Derived from lib spec.
511 if not arglist.getLastArg(arglist.parser.staticOption):
512 cmd_args.append('-lSystem')
513
514 if (not arglist.getLastArg(arglist.parser.AOption) and
515 not arglist.getLastArg(arglist.parser.nostdlibOption) and
516 not arglist.getLastArg(arglist.parser.nostartfilesOption)):
517 # endfile_spec is empty.
518 pass
519
520 arglist.addAllArgs(cmd_args, arglist.parser.TOption)
521 arglist.addAllArgs(cmd_args, arglist.parser.FOption)
522
Daniel Dunbara5677512009-01-05 19:53:30 +0000523 jobs.addJob(Jobs.Command(self.kCollect2Path, cmd_args))
524
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000525 # FIXME: We need to add a dsymutil job here in some particular
526 # cases (basically whenever we have a c-family input we are
527 # compiling, I think). Find out why this is the condition, and
528 # implement. See link_command spec for more details.
529
530 def macosxVersionCmp(self, cmp, version, arglist):
531 import sys
532 print >>sys.stderr, 'FIXME: macosxVersionCmp unimplemented.'
533 return False
534
Daniel Dunbara5677512009-01-05 19:53:30 +0000535class LipoTool(Tool):
536 def __init__(self):
537 super(LipoTool, self).__init__('lipo')
538
539 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000540 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000541 assert outputType is Types.ImageType
542
Daniel Dunbardb439902009-01-07 18:40:45 +0000543 cmd_args = ['-create']
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000544 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000545 for input in inputs:
Daniel Dunbardb439902009-01-07 18:40:45 +0000546 cmd_args.append(arglist.getValue(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000547 jobs.addJob(Jobs.Command('lipo', cmd_args))