blob: a9209821488851117a1c7be9af7e9d27327e0d42 [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 = []
Daniel Dunbar996ce962009-01-12 07:40:25 +0000115
116 if arglist.getLastArg(arglist.parser.gOption):
117 cmd_args.append('--gstabs')
118
119 # Derived from asm spec.
Daniel Dunbara5677512009-01-05 19:53:30 +0000120 if arch:
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000121 cmd_args.extend(arglist.render(arch))
Daniel Dunbardb439902009-01-07 18:40:45 +0000122 cmd_args.append('-force_cpusubtype_ALL')
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000123 cmd_args.extend(arglist.render(output))
Daniel Dunbar996ce962009-01-12 07:40:25 +0000124 if (arglist.getLastArg(arglist.parser.m_kernelOption) or
125 arglist.getLastArg(arglist.parser.staticOption) or
126 arglist.getLastArg(arglist.parser.f_appleKextOption)):
127 if not arglist.getLastArg(arglist.parser.ZdynamicOption):
128 cmd_args.append('-static')
129
130 for arg in arglist.getArgs2(arglist.parser.WaOption,
131 arglist.parser.XassemblerOption):
132 cmd_args.extend(arglist.getValues(arg))
133
Daniel Dunbara5677512009-01-05 19:53:30 +0000134 if isinstance(input.source, Jobs.PipedJob):
Daniel Dunbardb439902009-01-07 18:40:45 +0000135 cmd_args.append('-')
Daniel Dunbara5677512009-01-05 19:53:30 +0000136 else:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000137 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbar996ce962009-01-12 07:40:25 +0000138
139 # asm_final spec is empty.
140
Daniel Dunbara5677512009-01-05 19:53:30 +0000141 jobs.addJob(Jobs.Command('as', cmd_args))
142
Daniel Dunbara9ad2bc2009-01-10 02:00:04 +0000143class GCC_AssembleTool(GCC_Common_Tool):
144 def __init__(self):
145 # We can't generally assume the assembler can take or output
146 # on pipes.
147 super(GCC_AssembleTool, self).__init__('gcc (as)')
148
149 def constructJob(self, phase, arch, jobs, inputs,
150 output, outputType, args, arglist):
151 return super(GCC_AssembleTool, self).constructJob(phase, arch, jobs, inputs,
152 output, outputType, args, arglist,
153 ['-c'])
154
155class GCC_LinkTool(GCC_Common_Tool):
156 def __init__(self):
157 super(GCC_LinkTool, self).__init__('gcc (ld)')
158
159 def constructJob(self, phase, arch, jobs, inputs,
160 output, outputType, args, arglist):
161 return super(GCC_LinkTool, self).constructJob(phase, arch, jobs, inputs,
162 output, outputType, args, arglist,
163 [])
164
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000165class Darwin_X86_LinkTool(Tool):
166 def __init__(self, darwinVersion, gccVersion):
167 super(Darwin_X86_LinkTool, self).__init__('collect2')
168 assert isinstance(darwinVersion, tuple) and len(darwinVersion) == 3
169 assert isinstance(gccVersion, tuple) and len(gccVersion) == 3
170 self.darwinVersion = darwinVersion
171 self.gccVersion = gccVersion
172
173 def getCollect2Path(self):
174 return '/usr/libexec/gcc/%s/collect2' % self.getToolChainDir()
175
176 def getToolChainDir(self):
177 return 'i686-apple-darwin%d/%s' % (self.darwinVersion[0],
178 '.'.join(map(str,self.gccVersion)))
179
180 def getMacosxVersionMin(self):
181 major,minor,minorminor = self.darwinVersion
182 return '%d.%d.%d' % (10, major-4, minor)
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000183
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000184 def getMacosxVersionTuple(self, arglist):
185 arg = arglist.getLastArg(arglist.parser.m_macosxVersionMinOption)
186 if arg:
187 version = arglist.getValue(arg)
188 components = version.split('.')
189 try:
190 return tuple(map(int, components))
191 except:
192 raise ArgumentError,"invalid version number %r" % version
193 else:
194 major,minor,minorminor = self.darwinVersion
195 return (10, major-4, minor)
196
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000197 def addDarwinArch(self, cmd_args, arch, arglist):
198 # Derived from darwin_arch spec.
199 cmd_args.append('-arch')
200 # FIXME: The actual spec uses -m64 for this, but we want to
201 # respect arch. Figure out what exactly gcc is doing.
202 #if arglist.getLastArg(arglist.parser.m_64Option):
203 if arglist.getValue(arch) == 'x86_64':
204 cmd_args.append('x86_64')
205 else:
206 cmd_args.append('i386')
207
208 def addDarwinSubArch(self, cmd_args, arch, arglist):
209 # Derived from darwin_subarch spec, not sure what the
210 # distinction exists for but at least for this chain it is the same.
211 return self.addDarwinArch(cmd_args, arch, arglist)
212
213 def addLinkArgs(self, cmd_args, arch, arglist):
214 # Derived from link spec.
215 if arglist.getLastArg(arglist.parser.staticOption):
216 cmd_args.append('-static')
217 else:
218 cmd_args.append('-dynamic')
219 if arglist.getLastArg(arglist.parser.f_gnuRuntimeOption):
220 # FIXME: Replace -lobjc in forward args with
221 # -lobjc-gnu. How do we wish to handle such things?
222 pass
223
224 if not arglist.getLastArg(arglist.parser.ZdynamiclibOption):
225 if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption):
226 self.addDarwinArch(cmd_args, arch, arglist)
227 cmd_args.append('-force_cpusubtype_all')
228 else:
229 self.addDarwinSubArch(cmd_args, arch, arglist)
230
231 if arglist.getLastArg(arglist.parser.ZbundleOption):
232 cmd_args.append('-bundle')
233 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zbundle_loaderOption,
234 '-bundle_loader')
235 arglist.addAllArgs(cmd_args, arglist.parser.client_nameOption)
236 if arglist.getLastArg(arglist.parser.compatibility_versionOption):
237 # FIXME: Where should diagnostics go?
238 print >>sys.stderr, "-compatibility_version only allowed with -dynamiclib"
239 sys.exit(1)
240 if arglist.getLastArg(arglist.parser.current_versionOption):
241 print >>sys.stderr, "-current_version only allowed with -dynamiclib"
242 sys.exit(1)
243 if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption):
244 cmd_args.append('-force_flat_namespace')
245 if arglist.getLastArg(arglist.parser.Zinstall_nameOption):
246 print >>sys.stderr, "-install_name only allowed with -dynamiclib"
247 sys.exit(1)
248 arglist.addLastArg(cmd_args, arglist.parser.keep_private_externsOption)
249 arglist.addLastArg(cmd_args, arglist.parser.private_bundleOption)
250 else:
251 cmd_args.append('-dylib')
252 if arglist.getLastArg(arglist.parser.ZbundleOption):
253 print >>sys.stderr, "-bundle not allowed with -dynamiclib"
254 sys.exit(1)
255 if arglist.getLastArg(arglist.parser.Zbundle_loaderOption):
256 print >>sys.stderr, "-bundle_loader not allowed with -dynamiclib"
257 sys.exit(1)
258 if arglist.getLastArg(arglist.parser.client_nameOption):
259 print >>sys.stderr, "-client_name not allowed with -dynamiclib"
260 sys.exit(1)
261 arglist.addAllArgsTranslated(cmd_args, arglist.parser.compatibility_versionOption,
262 '-dylib_compatibility_version')
263 arglist.addAllArgsTranslated(cmd_args, arglist.parser.current_versionOption,
264 '-dylib_current_version')
265
266 if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption):
267 self.addDarwinArch(cmd_args, arch, arglist)
268 # NOTE: We don't add -force_cpusubtype_ALL on this path. Ok.
269 else:
270 self.addDarwinSubArch(cmd_args, arch, arglist)
271
272 if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption):
273 print >>sys.stderr, "-force_flat_namespace not allowed with -dynamiclib"
274 sys.exit(1)
275
276 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zinstall_nameOption,
277 '-dylib_install_name')
278
279 if arglist.getLastArg(arglist.parser.keep_private_externsOption):
280 print >>sys.stderr, "-keep_private_externs not allowed with -dynamiclib"
281 sys.exit(1)
282 if arglist.getLastArg(arglist.parser.private_bundleOption):
283 print >>sys.stderr, "-private_bundle not allowed with -dynamiclib"
284 sys.exit(1)
285
286 if arglist.getLastArg(arglist.parser.Zall_loadOption):
287 cmd_args.append('-all_load')
288
289 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zallowable_clientOption,
290 '-allowable_client')
291
292 if arglist.getLastArg(arglist.parser.Zbind_at_loadOption):
293 cmd_args.append('-bind_at_load')
294
295 if arglist.getLastArg(arglist.parser.Zdead_stripOption):
296 cmd_args.append('-dead_strip')
297
298 if arglist.getLastArg(arglist.parser.Zno_dead_strip_inits_and_termsOption):
299 cmd_args.append('-no_dead_strip_inits_and_terms')
300
301 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zdylib_fileOption,
302 '-dylib_file')
303
304 if arglist.getLastArg(arglist.parser.ZdynamicOption):
305 cmd_args.append('-dynamic')
306
307 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zexported_symbols_listOption,
308 '-exported_symbols_list')
309
310 if arglist.getLastArg(arglist.parser.Zflat_namespaceOption):
311 cmd_args.append('-flat_namespace')
312
313 arglist.addAllArgs(cmd_args, arglist.parser.headerpad_max_install_namesOption)
314 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zimage_baseOption,
315 '-image_base')
316 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZinitOption,
317 '-init')
318
319 if not arglist.getLastArg(arglist.parser.m_macosxVersionMinOption):
320 if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
321 # FIXME: I don't understand what is going on
322 # here. This is supposed to come from
323 # darwin_ld_minversion, but gcc doesn't seem to be
324 # following that; it must be getting over-ridden
325 # somewhere.
326 cmd_args.append('-macosx_version_min')
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000327 cmd_args.append(self.getMacosxVersionMin())
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000328 else:
329 # addAll doesn't make sense here but this is what gcc
330 # does.
331 arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_macosxVersionMinOption,
332 '-macosx_version_min')
333
334 arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_iphoneosVersionMinOption,
335 '-iphoneos_version_min')
336 arglist.addLastArg(cmd_args, arglist.parser.nomultidefsOption)
337
338 if arglist.getLastArg(arglist.parser.Zmulti_moduleOption):
339 cmd_args.append('-multi_module')
340
341 if arglist.getLastArg(arglist.parser.Zsingle_moduleOption):
342 cmd_args.append('-single_module')
343
344 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zmultiply_definedOption,
345 '-multiply_defined')
346
347 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZmultiplydefinedunusedOption,
348 '-multiply_defined_unused')
349
350 if arglist.getLastArg(arglist.parser.f_pieOption):
351 cmd_args.append('-pie')
352
353 arglist.addLastArg(cmd_args, arglist.parser.prebindOption)
354 arglist.addLastArg(cmd_args, arglist.parser.noprebindOption)
355 arglist.addLastArg(cmd_args, arglist.parser.nofixprebindingOption)
356 arglist.addLastArg(cmd_args, arglist.parser.prebind_all_twolevel_modulesOption)
357 arglist.addLastArg(cmd_args, arglist.parser.read_only_relocsOption)
358 arglist.addAllArgs(cmd_args, arglist.parser.sectcreateOption)
359 arglist.addAllArgs(cmd_args, arglist.parser.sectorderOption)
360 arglist.addAllArgs(cmd_args, arglist.parser.seg1addrOption)
361 arglist.addAllArgs(cmd_args, arglist.parser.segprotOption)
362 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZsegaddrOption,
363 '-segaddr')
364 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_only_addrOption,
365 '-segs_read_only_addr')
366 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_write_addrOption,
367 '-segs_read_write_addr')
368 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zseg_addr_tableOption,
369 '-seg_addr_table')
370 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zfn_seg_addr_table_filenameOption,
371 '-fn_seg_addr_table_filename')
372 arglist.addAllArgs(cmd_args, arglist.parser.sub_libraryOption)
373 arglist.addAllArgs(cmd_args, arglist.parser.sub_umbrellaOption)
374 arglist.addAllArgsTranslated(cmd_args, arglist.parser.isysrootOption,
375 '-syslibroot')
376 arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespaceOption)
377 arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespace_hintsOption)
378 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZumbrellaOption,
379 '-umbrella')
380 arglist.addAllArgs(cmd_args, arglist.parser.undefinedOption)
381 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zunexported_symbols_listOption,
382 '-unexported_symbols_list')
383 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zweak_reference_mismatchesOption,
384 '-weak_reference_mismatches')
385
386 if not arglist.getLastArg(arglist.parser.Zweak_reference_mismatchesOption):
387 cmd_args.append('-weak_reference_mismatches')
388 cmd_args.append('non-weak')
389
390 arglist.addLastArg(cmd_args, arglist.parser.XOption)
391 arglist.addAllArgs(cmd_args, arglist.parser.yOption)
392 arglist.addLastArg(cmd_args, arglist.parser.wOption)
393 arglist.addAllArgs(cmd_args, arglist.parser.pagezero_sizeOption)
394 arglist.addAllArgs(cmd_args, arglist.parser.segs_read_Option)
395 arglist.addLastArg(cmd_args, arglist.parser.seglinkeditOption)
396 arglist.addLastArg(cmd_args, arglist.parser.noseglinkeditOption)
397 arglist.addAllArgs(cmd_args, arglist.parser.sectalignOption)
398 arglist.addAllArgs(cmd_args, arglist.parser.sectobjectsymbolsOption)
399 arglist.addAllArgs(cmd_args, arglist.parser.segcreateOption)
400 arglist.addLastArg(cmd_args, arglist.parser.whyloadOption)
401 arglist.addLastArg(cmd_args, arglist.parser.whatsloadedOption)
402 arglist.addAllArgs(cmd_args, arglist.parser.dylinker_install_nameOption)
403 arglist.addLastArg(cmd_args, arglist.parser.dylinkerOption)
404 arglist.addLastArg(cmd_args, arglist.parser.MachOption)
Daniel Dunbara5677512009-01-05 19:53:30 +0000405
406 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000407 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000408 assert outputType is Types.ImageType
409
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000410 # The logic here is derived from gcc's behavior; most of which
Daniel Dunbaree8cc262009-01-12 02:24:21 +0000411 # comes from specs (starting with link_command). Consult gcc
412 # for more information.
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000413
414 # FIXME: gcc's spec controls when this is done; certain things
415 # like -filelist or -Wl, still trigger a link stage. I don't
416 # quite understand how gcc decides to execute the linker,
417 # investigate. Also, the spec references -fdump= which seems
418 # to have disappeared?
Daniel Dunbara5677512009-01-05 19:53:30 +0000419 cmd_args = []
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000420
421 # Not sure why this particular decomposition exists in gcc.
422 self.addLinkArgs(cmd_args, arch, arglist)
423
Daniel Dunbaree8cc262009-01-12 02:24:21 +0000424 # This toolchain never accumlates options in specs, the only
425 # place this gets used is to add -ObjC.
426 if (arglist.getLastArg(arglist.parser.ObjCOption) or
427 arglist.getLastArg(arglist.parser.f_objcOption)):
428 cmd_args.append('-ObjC')
429 if arglist.getLastArg(arglist.parser.ObjCXXOption):
430 cmd_args.append('-ObjC')
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000431
432 # FIXME: gcc has %{x} in here. How could this ever happen?
433 # Cruft?
434 arglist.addLastArg(cmd_args, arglist.parser.dOption)
435 arglist.addLastArg(cmd_args, arglist.parser.tOption)
436 arglist.addLastArg(cmd_args, arglist.parser.ZOption)
437 arglist.addLastArg(cmd_args, arglist.parser.uOption)
438 arglist.addLastArg(cmd_args, arglist.parser.AOption)
439 arglist.addLastArg(cmd_args, arglist.parser.eOption)
440 arglist.addLastArg(cmd_args, arglist.parser.mOption)
441 arglist.addLastArg(cmd_args, arglist.parser.rOption)
442
443 cmd_args.extend(arglist.render(output))
444
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000445 macosxVersion = self.getMacosxVersionTuple(arglist)
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000446 if (not arglist.getLastArg(arglist.parser.AOption) and
447 not arglist.getLastArg(arglist.parser.nostdlibOption) and
448 not arglist.getLastArg(arglist.parser.nostartfilesOption)):
449 # Derived from startfile spec.
450 if arglist.getLastArg(arglist.parser.ZdynamiclibOption):
451 # Derived from darwin_dylib1 spec.
452 if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
453 cmd_args.append('-ldylib1.o')
454 else:
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000455 if macosxVersion < (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000456 cmd_args.append('-ldylib1.o')
457 else:
458 cmd_args.append('-ldylib1.10.5.o')
459 else:
460 if arglist.getLastArg(arglist.parser.ZbundleOption):
461 if not arglist.getLastArg(arglist.parser.staticOption):
462 cmd_args.append('-lbundle1.o')
463 else:
464 if arglist.getLastArg(arglist.parser.pgOption):
465 if arglist.getLastArg(arglist.parser.staticOption):
466 cmd_args.append('-lgcrt0.o')
467 else:
468 if arglist.getLastArg(arglist.parser.objectOption):
469 cmd_args.append('-lgcrt0.o')
470 else:
471 if arglist.getLastArg(arglist.parser.preloadOption):
472 cmd_args.append('-lgcrt0.o')
473 else:
474 cmd_args.append('-lgcrt1.o')
475
476 # darwin_crt2 spec is empty.
477 pass
478 else:
479 if arglist.getLastArg(arglist.parser.staticOption):
480 cmd_args.append('-lcrt0.o')
481 else:
482 if arglist.getLastArg(arglist.parser.objectOption):
483 cmd_args.append('-lcrt0.o')
484 else:
485 if arglist.getLastArg(arglist.parser.preloadOption):
486 cmd_args.append('-lcrt0.o')
487 else:
488 # Derived from darwin_crt1 spec.
489 if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
490 cmd_args.append('-lcrt1.o')
491 else:
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000492 if macosxVersion < (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000493 cmd_args.append('-lcrt1.o')
494 else:
495 cmd_args.append('-lcrt1.10.5.o')
496
497 # darwin_crt2 spec is empty.
498 pass
499
500 if arglist.getLastArg(arglist.parser.sharedLibgccOption):
501 if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000502 if macosxVersion < (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000503 # FIXME: gcc does a library search for this
504 # file, this will be be broken currently.
505 cmd_args.append('crt3.o')
506
507 arglist.addAllArgs(cmd_args, arglist.parser.LOption)
508
509 if arglist.getLastArg(arglist.parser.f_openmpOption):
510 # This is more complicated in gcc...
511 cmd_args.append('-lgomp')
512
513 # FIXME: Derive these correctly.
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000514 tcDir = self.getToolChainDir()
515 if arglist.getValue(arch) == 'x86_64':
516 cmd_args.extend(["-L/usr/lib/gcc/%s/x86_64" % tcDir,
517 "-L/usr/lib/gcc/%s/x86_64" % tcDir])
518 cmd_args.extend(["-L/usr/lib/%s" % tcDir,
519 "-L/usr/lib/gcc/%s" % tcDir,
520 "-L/usr/lib/gcc/%s" % tcDir,
521 "-L/usr/lib/gcc/%s/../../../%s" % (tcDir,tcDir),
522 "-L/usr/lib/gcc/%s/../../.." % tcDir])
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000523
Daniel Dunbara5677512009-01-05 19:53:30 +0000524 for input in inputs:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000525 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000526
527 if (arglist.getLastArg(arglist.parser.f_profileArcsOption) or
528 arglist.getLastArg(arglist.parser.f_profileGenerateOption) or
529 arglist.getLastArg(arglist.parser.f_createProfileOption) or
530 arglist.getLastArg(arglist.parser.coverageOption)):
531 cmd_args.append('-lgcov')
532
533 if arglist.getLastArg(arglist.parser.f_nestedFunctionsOption):
534 cmd_args.append('-allow_stack_execute')
535
536 if (not arglist.getLastArg(arglist.parser.nostdlibOption) and
537 not arglist.getLastArg(arglist.parser.nodefaultlibsOption)):
538 # link_ssp spec is empty.
539
540 # Derived from libgcc spec.
541 if arglist.getLastArg(arglist.parser.staticOption):
542 cmd_args.append('-lgcc_static')
543 elif arglist.getLastArg(arglist.parser.staticLibgccOption):
544 cmd_args.append('-lgcc_eh')
545 cmd_args.append('-lgcc')
546 elif arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
547 # Derived from darwin_iphoneos_libgcc spec.
548 cmd_args.append('-lgcc_s.10.5')
549 cmd_args.append('-lgcc')
550 elif (arglist.getLastArg(arglist.parser.sharedLibgccOption) or
551 arglist.getLastArg(arglist.parser.f_exceptionsOption) or
552 arglist.getLastArg(arglist.parser.f_gnuRuntimeOption)):
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000553 if macosxVersion < (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000554 cmd_args.append('-lgcc_s.10.4')
555 else:
556 cmd_args.append('-lgcc_s.10.5')
557 cmd_args.append('-lgcc')
558 else:
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000559 if macosxVersion < (10,5) and macosxVersion >= (10,3,9):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000560 cmd_args.append('-lgcc_s.10.4')
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000561 if macosxVersion >= (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000562 cmd_args.append('-lgcc_s.10.5')
563 cmd_args.append('-lgcc')
564
565 # Derived from lib spec.
566 if not arglist.getLastArg(arglist.parser.staticOption):
567 cmd_args.append('-lSystem')
568
569 if (not arglist.getLastArg(arglist.parser.AOption) and
570 not arglist.getLastArg(arglist.parser.nostdlibOption) and
571 not arglist.getLastArg(arglist.parser.nostartfilesOption)):
572 # endfile_spec is empty.
573 pass
574
575 arglist.addAllArgs(cmd_args, arglist.parser.TOption)
576 arglist.addAllArgs(cmd_args, arglist.parser.FOption)
577
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000578 jobs.addJob(Jobs.Command(self.getCollect2Path(), cmd_args))
Daniel Dunbara5677512009-01-05 19:53:30 +0000579
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000580 # FIXME: We need to add a dsymutil job here in some particular
581 # cases (basically whenever we have a c-family input we are
582 # compiling, I think). Find out why this is the condition, and
583 # implement. See link_command spec for more details.
584
Daniel Dunbara5677512009-01-05 19:53:30 +0000585class LipoTool(Tool):
586 def __init__(self):
587 super(LipoTool, self).__init__('lipo')
588
589 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000590 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000591 assert outputType is Types.ImageType
592
Daniel Dunbardb439902009-01-07 18:40:45 +0000593 cmd_args = ['-create']
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000594 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000595 for input in inputs:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000596 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000597 jobs.addJob(Jobs.Command('lipo', cmd_args))