blob: c5568e3c91fce24c0ed75cd6238dca50524f852d [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:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +000055 assert isinstance(input.source, Arguments.Arg)
56 # If this is a linker input then assume we can forward
57 # just by rendering.
58 if input.source.opt.isLinkerInput:
59 cmd_args.extend(arglist.render(input.source))
60 else:
61 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +000062
63 jobs.addJob(Jobs.Command('gcc', cmd_args))
64
65class GCC_PreprocessTool(GCC_Common_Tool):
66 def __init__(self):
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000067 super(GCC_PreprocessTool, self).__init__('gcc (cpp)',
Daniel Dunbara5677512009-01-05 19:53:30 +000068 (Tool.eFlagsPipedInput |
69 Tool.eFlagsPipedOutput))
70
71 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000072 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000073 return super(GCC_PreprocessTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000074 output, outputType, args, arglist,
75 ['-E'])
Daniel Dunbara5677512009-01-05 19:53:30 +000076
77class GCC_CompileTool(GCC_Common_Tool):
78 def __init__(self):
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000079 super(GCC_CompileTool, self).__init__('gcc (cc1)',
Daniel Dunbara5677512009-01-05 19:53:30 +000080 (Tool.eFlagsPipedInput |
81 Tool.eFlagsPipedOutput |
82 Tool.eFlagsIntegratedCPP))
83
84 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000085 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000086 return super(GCC_CompileTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000087 output, outputType, args, arglist,
88 ['-S'])
Daniel Dunbara5677512009-01-05 19:53:30 +000089
90class GCC_PrecompileTool(GCC_Common_Tool):
91 def __init__(self):
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +000092 super(GCC_PrecompileTool, self).__init__('gcc (pch)',
Daniel Dunbara5677512009-01-05 19:53:30 +000093 (Tool.eFlagsPipedInput |
94 Tool.eFlagsIntegratedCPP))
95
96 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000097 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +000098 return super(GCC_PrecompileTool, self).constructJob(phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +000099 output, outputType, args, arglist,
Daniel Dunbara5677512009-01-05 19:53:30 +0000100 [])
101
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +0000102class DarwinAssembleTool(Tool):
Daniel Dunbara5677512009-01-05 19:53:30 +0000103 def __init__(self):
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +0000104 super(DarwinAssembleTool, self).__init__('as',
105 Tool.eFlagsPipedInput)
Daniel Dunbara5677512009-01-05 19:53:30 +0000106
107 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000108 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000109 assert len(inputs) == 1
110 assert outputType is Types.ObjectType
111
112 input = inputs[0]
113
114 cmd_args = []
115 if arch:
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000116 cmd_args.extend(arglist.render(arch))
Daniel Dunbardb439902009-01-07 18:40:45 +0000117 cmd_args.append('-force_cpusubtype_ALL')
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000118 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000119 if isinstance(input.source, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +0000120 cmd_args.append('-')
Daniel Dunbara5677512009-01-05 19:53:30 +0000121 else:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000122 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000123 jobs.addJob(Jobs.Command('as', cmd_args))
124
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +0000125class GCC_AssembleTool(GCC_Common_Tool):
126 def __init__(self):
127 # We can't generally assume the assembler can take or output
128 # on pipes.
129 super(GCC_AssembleTool, self).__init__('gcc (as)')
130
131 def constructJob(self, phase, arch, jobs, inputs,
132 output, outputType, args, arglist):
133 return super(GCC_AssembleTool, self).constructJob(phase, arch, jobs, inputs,
134 output, outputType, args, arglist,
135 ['-c'])
136
137class GCC_LinkTool(GCC_Common_Tool):
138 def __init__(self):
139 super(GCC_LinkTool, self).__init__('gcc (ld)')
140
141 def constructJob(self, phase, arch, jobs, inputs,
142 output, outputType, args, arglist):
143 return super(GCC_LinkTool, self).constructJob(phase, arch, jobs, inputs,
144 output, outputType, args, arglist,
145 [])
146
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000147class Darwin_X86_LinkTool(Tool):
148 def __init__(self, darwinVersion, gccVersion):
149 super(Darwin_X86_LinkTool, self).__init__('collect2')
150 assert isinstance(darwinVersion, tuple) and len(darwinVersion) == 3
151 assert isinstance(gccVersion, tuple) and len(gccVersion) == 3
152 self.darwinVersion = darwinVersion
153 self.gccVersion = gccVersion
154
155 def getCollect2Path(self):
156 return '/usr/libexec/gcc/%s/collect2' % self.getToolChainDir()
157
158 def getToolChainDir(self):
159 return 'i686-apple-darwin%d/%s' % (self.darwinVersion[0],
160 '.'.join(map(str,self.gccVersion)))
161
162 def getMacosxVersionMin(self):
163 major,minor,minorminor = self.darwinVersion
164 return '%d.%d.%d' % (10, major-4, minor)
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000165
166 def addDarwinArch(self, cmd_args, arch, arglist):
167 # Derived from darwin_arch spec.
168 cmd_args.append('-arch')
169 # FIXME: The actual spec uses -m64 for this, but we want to
170 # respect arch. Figure out what exactly gcc is doing.
171 #if arglist.getLastArg(arglist.parser.m_64Option):
172 if arglist.getValue(arch) == 'x86_64':
173 cmd_args.append('x86_64')
174 else:
175 cmd_args.append('i386')
176
177 def addDarwinSubArch(self, cmd_args, arch, arglist):
178 # Derived from darwin_subarch spec, not sure what the
179 # distinction exists for but at least for this chain it is the same.
180 return self.addDarwinArch(cmd_args, arch, arglist)
181
182 def addLinkArgs(self, cmd_args, arch, arglist):
183 # Derived from link spec.
184 if arglist.getLastArg(arglist.parser.staticOption):
185 cmd_args.append('-static')
186 else:
187 cmd_args.append('-dynamic')
188 if arglist.getLastArg(arglist.parser.f_gnuRuntimeOption):
189 # FIXME: Replace -lobjc in forward args with
190 # -lobjc-gnu. How do we wish to handle such things?
191 pass
192
193 if not arglist.getLastArg(arglist.parser.ZdynamiclibOption):
194 if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption):
195 self.addDarwinArch(cmd_args, arch, arglist)
196 cmd_args.append('-force_cpusubtype_all')
197 else:
198 self.addDarwinSubArch(cmd_args, arch, arglist)
199
200 if arglist.getLastArg(arglist.parser.ZbundleOption):
201 cmd_args.append('-bundle')
202 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zbundle_loaderOption,
203 '-bundle_loader')
204 arglist.addAllArgs(cmd_args, arglist.parser.client_nameOption)
205 if arglist.getLastArg(arglist.parser.compatibility_versionOption):
206 # FIXME: Where should diagnostics go?
207 print >>sys.stderr, "-compatibility_version only allowed with -dynamiclib"
208 sys.exit(1)
209 if arglist.getLastArg(arglist.parser.current_versionOption):
210 print >>sys.stderr, "-current_version only allowed with -dynamiclib"
211 sys.exit(1)
212 if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption):
213 cmd_args.append('-force_flat_namespace')
214 if arglist.getLastArg(arglist.parser.Zinstall_nameOption):
215 print >>sys.stderr, "-install_name only allowed with -dynamiclib"
216 sys.exit(1)
217 arglist.addLastArg(cmd_args, arglist.parser.keep_private_externsOption)
218 arglist.addLastArg(cmd_args, arglist.parser.private_bundleOption)
219 else:
220 cmd_args.append('-dylib')
221 if arglist.getLastArg(arglist.parser.ZbundleOption):
222 print >>sys.stderr, "-bundle not allowed with -dynamiclib"
223 sys.exit(1)
224 if arglist.getLastArg(arglist.parser.Zbundle_loaderOption):
225 print >>sys.stderr, "-bundle_loader not allowed with -dynamiclib"
226 sys.exit(1)
227 if arglist.getLastArg(arglist.parser.client_nameOption):
228 print >>sys.stderr, "-client_name not allowed with -dynamiclib"
229 sys.exit(1)
230 arglist.addAllArgsTranslated(cmd_args, arglist.parser.compatibility_versionOption,
231 '-dylib_compatibility_version')
232 arglist.addAllArgsTranslated(cmd_args, arglist.parser.current_versionOption,
233 '-dylib_current_version')
234
235 if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption):
236 self.addDarwinArch(cmd_args, arch, arglist)
237 # NOTE: We don't add -force_cpusubtype_ALL on this path. Ok.
238 else:
239 self.addDarwinSubArch(cmd_args, arch, arglist)
240
241 if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption):
242 print >>sys.stderr, "-force_flat_namespace not allowed with -dynamiclib"
243 sys.exit(1)
244
245 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zinstall_nameOption,
246 '-dylib_install_name')
247
248 if arglist.getLastArg(arglist.parser.keep_private_externsOption):
249 print >>sys.stderr, "-keep_private_externs not allowed with -dynamiclib"
250 sys.exit(1)
251 if arglist.getLastArg(arglist.parser.private_bundleOption):
252 print >>sys.stderr, "-private_bundle not allowed with -dynamiclib"
253 sys.exit(1)
254
255 if arglist.getLastArg(arglist.parser.Zall_loadOption):
256 cmd_args.append('-all_load')
257
258 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zallowable_clientOption,
259 '-allowable_client')
260
261 if arglist.getLastArg(arglist.parser.Zbind_at_loadOption):
262 cmd_args.append('-bind_at_load')
263
264 if arglist.getLastArg(arglist.parser.Zdead_stripOption):
265 cmd_args.append('-dead_strip')
266
267 if arglist.getLastArg(arglist.parser.Zno_dead_strip_inits_and_termsOption):
268 cmd_args.append('-no_dead_strip_inits_and_terms')
269
270 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zdylib_fileOption,
271 '-dylib_file')
272
273 if arglist.getLastArg(arglist.parser.ZdynamicOption):
274 cmd_args.append('-dynamic')
275
276 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zexported_symbols_listOption,
277 '-exported_symbols_list')
278
279 if arglist.getLastArg(arglist.parser.Zflat_namespaceOption):
280 cmd_args.append('-flat_namespace')
281
282 arglist.addAllArgs(cmd_args, arglist.parser.headerpad_max_install_namesOption)
283 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zimage_baseOption,
284 '-image_base')
285 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZinitOption,
286 '-init')
287
288 if not arglist.getLastArg(arglist.parser.m_macosxVersionMinOption):
289 if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
290 # FIXME: I don't understand what is going on
291 # here. This is supposed to come from
292 # darwin_ld_minversion, but gcc doesn't seem to be
293 # following that; it must be getting over-ridden
294 # somewhere.
295 cmd_args.append('-macosx_version_min')
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000296 cmd_args.append(self.getMacosxVersionMin())
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000297 else:
298 # addAll doesn't make sense here but this is what gcc
299 # does.
300 arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_macosxVersionMinOption,
301 '-macosx_version_min')
302
303 arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_iphoneosVersionMinOption,
304 '-iphoneos_version_min')
305 arglist.addLastArg(cmd_args, arglist.parser.nomultidefsOption)
306
307 if arglist.getLastArg(arglist.parser.Zmulti_moduleOption):
308 cmd_args.append('-multi_module')
309
310 if arglist.getLastArg(arglist.parser.Zsingle_moduleOption):
311 cmd_args.append('-single_module')
312
313 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zmultiply_definedOption,
314 '-multiply_defined')
315
316 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZmultiplydefinedunusedOption,
317 '-multiply_defined_unused')
318
319 if arglist.getLastArg(arglist.parser.f_pieOption):
320 cmd_args.append('-pie')
321
322 arglist.addLastArg(cmd_args, arglist.parser.prebindOption)
323 arglist.addLastArg(cmd_args, arglist.parser.noprebindOption)
324 arglist.addLastArg(cmd_args, arglist.parser.nofixprebindingOption)
325 arglist.addLastArg(cmd_args, arglist.parser.prebind_all_twolevel_modulesOption)
326 arglist.addLastArg(cmd_args, arglist.parser.read_only_relocsOption)
327 arglist.addAllArgs(cmd_args, arglist.parser.sectcreateOption)
328 arglist.addAllArgs(cmd_args, arglist.parser.sectorderOption)
329 arglist.addAllArgs(cmd_args, arglist.parser.seg1addrOption)
330 arglist.addAllArgs(cmd_args, arglist.parser.segprotOption)
331 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZsegaddrOption,
332 '-segaddr')
333 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_only_addrOption,
334 '-segs_read_only_addr')
335 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_write_addrOption,
336 '-segs_read_write_addr')
337 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zseg_addr_tableOption,
338 '-seg_addr_table')
339 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zfn_seg_addr_table_filenameOption,
340 '-fn_seg_addr_table_filename')
341 arglist.addAllArgs(cmd_args, arglist.parser.sub_libraryOption)
342 arglist.addAllArgs(cmd_args, arglist.parser.sub_umbrellaOption)
343 arglist.addAllArgsTranslated(cmd_args, arglist.parser.isysrootOption,
344 '-syslibroot')
345 arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespaceOption)
346 arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespace_hintsOption)
347 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZumbrellaOption,
348 '-umbrella')
349 arglist.addAllArgs(cmd_args, arglist.parser.undefinedOption)
350 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zunexported_symbols_listOption,
351 '-unexported_symbols_list')
352 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zweak_reference_mismatchesOption,
353 '-weak_reference_mismatches')
354
355 if not arglist.getLastArg(arglist.parser.Zweak_reference_mismatchesOption):
356 cmd_args.append('-weak_reference_mismatches')
357 cmd_args.append('non-weak')
358
359 arglist.addLastArg(cmd_args, arglist.parser.XOption)
360 arglist.addAllArgs(cmd_args, arglist.parser.yOption)
361 arglist.addLastArg(cmd_args, arglist.parser.wOption)
362 arglist.addAllArgs(cmd_args, arglist.parser.pagezero_sizeOption)
363 arglist.addAllArgs(cmd_args, arglist.parser.segs_read_Option)
364 arglist.addLastArg(cmd_args, arglist.parser.seglinkeditOption)
365 arglist.addLastArg(cmd_args, arglist.parser.noseglinkeditOption)
366 arglist.addAllArgs(cmd_args, arglist.parser.sectalignOption)
367 arglist.addAllArgs(cmd_args, arglist.parser.sectobjectsymbolsOption)
368 arglist.addAllArgs(cmd_args, arglist.parser.segcreateOption)
369 arglist.addLastArg(cmd_args, arglist.parser.whyloadOption)
370 arglist.addLastArg(cmd_args, arglist.parser.whatsloadedOption)
371 arglist.addAllArgs(cmd_args, arglist.parser.dylinker_install_nameOption)
372 arglist.addLastArg(cmd_args, arglist.parser.dylinkerOption)
373 arglist.addLastArg(cmd_args, arglist.parser.MachOption)
Daniel Dunbara5677512009-01-05 19:53:30 +0000374
375 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000376 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000377 assert outputType is Types.ImageType
378
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000379 # The logic here is derived from gcc's behavior; most of which
Daniel Dunbaree8cc262009-01-12 02:24:21 +0000380 # comes from specs (starting with link_command). Consult gcc
381 # for more information.
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000382
383 # FIXME: gcc's spec controls when this is done; certain things
384 # like -filelist or -Wl, still trigger a link stage. I don't
385 # quite understand how gcc decides to execute the linker,
386 # investigate. Also, the spec references -fdump= which seems
387 # to have disappeared?
Daniel Dunbara5677512009-01-05 19:53:30 +0000388 cmd_args = []
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000389
390 # Not sure why this particular decomposition exists in gcc.
391 self.addLinkArgs(cmd_args, arch, arglist)
392
Daniel Dunbaree8cc262009-01-12 02:24:21 +0000393 # This toolchain never accumlates options in specs, the only
394 # place this gets used is to add -ObjC.
395 if (arglist.getLastArg(arglist.parser.ObjCOption) or
396 arglist.getLastArg(arglist.parser.f_objcOption)):
397 cmd_args.append('-ObjC')
398 if arglist.getLastArg(arglist.parser.ObjCXXOption):
399 cmd_args.append('-ObjC')
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000400
401 # FIXME: gcc has %{x} in here. How could this ever happen?
402 # Cruft?
403 arglist.addLastArg(cmd_args, arglist.parser.dOption)
404 arglist.addLastArg(cmd_args, arglist.parser.tOption)
405 arglist.addLastArg(cmd_args, arglist.parser.ZOption)
406 arglist.addLastArg(cmd_args, arglist.parser.uOption)
407 arglist.addLastArg(cmd_args, arglist.parser.AOption)
408 arglist.addLastArg(cmd_args, arglist.parser.eOption)
409 arglist.addLastArg(cmd_args, arglist.parser.mOption)
410 arglist.addLastArg(cmd_args, arglist.parser.rOption)
411
412 cmd_args.extend(arglist.render(output))
413
414 if (not arglist.getLastArg(arglist.parser.AOption) and
415 not arglist.getLastArg(arglist.parser.nostdlibOption) and
416 not arglist.getLastArg(arglist.parser.nostartfilesOption)):
417 # Derived from startfile spec.
418 if arglist.getLastArg(arglist.parser.ZdynamiclibOption):
419 # Derived from darwin_dylib1 spec.
420 if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
421 cmd_args.append('-ldylib1.o')
422 else:
423 if self.macosxVersionCmp('<', '10.5', arglist):
424 cmd_args.append('-ldylib1.o')
425 else:
426 cmd_args.append('-ldylib1.10.5.o')
427 else:
428 if arglist.getLastArg(arglist.parser.ZbundleOption):
429 if not arglist.getLastArg(arglist.parser.staticOption):
430 cmd_args.append('-lbundle1.o')
431 else:
432 if arglist.getLastArg(arglist.parser.pgOption):
433 if arglist.getLastArg(arglist.parser.staticOption):
434 cmd_args.append('-lgcrt0.o')
435 else:
436 if arglist.getLastArg(arglist.parser.objectOption):
437 cmd_args.append('-lgcrt0.o')
438 else:
439 if arglist.getLastArg(arglist.parser.preloadOption):
440 cmd_args.append('-lgcrt0.o')
441 else:
442 cmd_args.append('-lgcrt1.o')
443
444 # darwin_crt2 spec is empty.
445 pass
446 else:
447 if arglist.getLastArg(arglist.parser.staticOption):
448 cmd_args.append('-lcrt0.o')
449 else:
450 if arglist.getLastArg(arglist.parser.objectOption):
451 cmd_args.append('-lcrt0.o')
452 else:
453 if arglist.getLastArg(arglist.parser.preloadOption):
454 cmd_args.append('-lcrt0.o')
455 else:
456 # Derived from darwin_crt1 spec.
457 if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
458 cmd_args.append('-lcrt1.o')
459 else:
460 if self.macosxVersionCmp('<', '10.5', arglist):
461 cmd_args.append('-lcrt1.o')
462 else:
463 cmd_args.append('-lcrt1.10.5.o')
464
465 # darwin_crt2 spec is empty.
466 pass
467
468 if arglist.getLastArg(arglist.parser.sharedLibgccOption):
469 if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
470 if self.macosxVersionCmp('<', '10.5', arglist):
471 # FIXME: gcc does a library search for this
472 # file, this will be be broken currently.
473 cmd_args.append('crt3.o')
474
475 arglist.addAllArgs(cmd_args, arglist.parser.LOption)
476
477 if arglist.getLastArg(arglist.parser.f_openmpOption):
478 # This is more complicated in gcc...
479 cmd_args.append('-lgomp')
480
481 # FIXME: Derive these correctly.
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000482 tcDir = self.getToolChainDir()
483 if arglist.getValue(arch) == 'x86_64':
484 cmd_args.extend(["-L/usr/lib/gcc/%s/x86_64" % tcDir,
485 "-L/usr/lib/gcc/%s/x86_64" % tcDir])
486 cmd_args.extend(["-L/usr/lib/%s" % tcDir,
487 "-L/usr/lib/gcc/%s" % tcDir,
488 "-L/usr/lib/gcc/%s" % tcDir,
489 "-L/usr/lib/gcc/%s/../../../%s" % (tcDir,tcDir),
490 "-L/usr/lib/gcc/%s/../../.." % tcDir])
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000491
Daniel Dunbara5677512009-01-05 19:53:30 +0000492 for input in inputs:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000493 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000494
495 if (arglist.getLastArg(arglist.parser.f_profileArcsOption) or
496 arglist.getLastArg(arglist.parser.f_profileGenerateOption) or
497 arglist.getLastArg(arglist.parser.f_createProfileOption) or
498 arglist.getLastArg(arglist.parser.coverageOption)):
499 cmd_args.append('-lgcov')
500
501 if arglist.getLastArg(arglist.parser.f_nestedFunctionsOption):
502 cmd_args.append('-allow_stack_execute')
503
504 if (not arglist.getLastArg(arglist.parser.nostdlibOption) and
505 not arglist.getLastArg(arglist.parser.nodefaultlibsOption)):
506 # link_ssp spec is empty.
507
508 # Derived from libgcc spec.
509 if arglist.getLastArg(arglist.parser.staticOption):
510 cmd_args.append('-lgcc_static')
511 elif arglist.getLastArg(arglist.parser.staticLibgccOption):
512 cmd_args.append('-lgcc_eh')
513 cmd_args.append('-lgcc')
514 elif arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
515 # Derived from darwin_iphoneos_libgcc spec.
516 cmd_args.append('-lgcc_s.10.5')
517 cmd_args.append('-lgcc')
518 elif (arglist.getLastArg(arglist.parser.sharedLibgccOption) or
519 arglist.getLastArg(arglist.parser.f_exceptionsOption) or
520 arglist.getLastArg(arglist.parser.f_gnuRuntimeOption)):
521 if self.macosxVersionCmp('<', '10.5', arglist):
522 cmd_args.append('-lgcc_s.10.4')
523 else:
524 cmd_args.append('-lgcc_s.10.5')
525 cmd_args.append('-lgcc')
526 else:
527 if (self.macosxVersionCmp('<', '10.5', arglist) and
528 self.macosxVersionCmp('>=', '10.3.9', arglist)):
529 cmd_args.append('-lgcc_s.10.4')
530 else:
531 cmd_args.append('-lgcc_s.10.5')
532 cmd_args.append('-lgcc')
533
534 # Derived from lib spec.
535 if not arglist.getLastArg(arglist.parser.staticOption):
536 cmd_args.append('-lSystem')
537
538 if (not arglist.getLastArg(arglist.parser.AOption) and
539 not arglist.getLastArg(arglist.parser.nostdlibOption) and
540 not arglist.getLastArg(arglist.parser.nostartfilesOption)):
541 # endfile_spec is empty.
542 pass
543
544 arglist.addAllArgs(cmd_args, arglist.parser.TOption)
545 arglist.addAllArgs(cmd_args, arglist.parser.FOption)
546
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000547 jobs.addJob(Jobs.Command(self.getCollect2Path(), cmd_args))
Daniel Dunbara5677512009-01-05 19:53:30 +0000548
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000549 # FIXME: We need to add a dsymutil job here in some particular
550 # cases (basically whenever we have a c-family input we are
551 # compiling, I think). Find out why this is the condition, and
552 # implement. See link_command spec for more details.
553
554 def macosxVersionCmp(self, cmp, version, arglist):
555 import sys
556 print >>sys.stderr, 'FIXME: macosxVersionCmp unimplemented.'
557 return False
558
Daniel Dunbara5677512009-01-05 19:53:30 +0000559class LipoTool(Tool):
560 def __init__(self):
561 super(LipoTool, self).__init__('lipo')
562
563 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000564 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000565 assert outputType is Types.ImageType
566
Daniel Dunbardb439902009-01-07 18:40:45 +0000567 cmd_args = ['-create']
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000568 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000569 for input in inputs:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000570 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000571 jobs.addJob(Jobs.Command('lipo', cmd_args))