blob: 7f3b0cf6300512fef5da056b534888bc363204a5 [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
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000166 def getMacosxVersionTuple(self, arglist):
167 arg = arglist.getLastArg(arglist.parser.m_macosxVersionMinOption)
168 if arg:
169 version = arglist.getValue(arg)
170 components = version.split('.')
171 try:
172 return tuple(map(int, components))
173 except:
174 raise ArgumentError,"invalid version number %r" % version
175 else:
176 major,minor,minorminor = self.darwinVersion
177 return (10, major-4, minor)
178
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000179 def addDarwinArch(self, cmd_args, arch, arglist):
180 # Derived from darwin_arch spec.
181 cmd_args.append('-arch')
182 # FIXME: The actual spec uses -m64 for this, but we want to
183 # respect arch. Figure out what exactly gcc is doing.
184 #if arglist.getLastArg(arglist.parser.m_64Option):
185 if arglist.getValue(arch) == 'x86_64':
186 cmd_args.append('x86_64')
187 else:
188 cmd_args.append('i386')
189
190 def addDarwinSubArch(self, cmd_args, arch, arglist):
191 # Derived from darwin_subarch spec, not sure what the
192 # distinction exists for but at least for this chain it is the same.
193 return self.addDarwinArch(cmd_args, arch, arglist)
194
195 def addLinkArgs(self, cmd_args, arch, arglist):
196 # Derived from link spec.
197 if arglist.getLastArg(arglist.parser.staticOption):
198 cmd_args.append('-static')
199 else:
200 cmd_args.append('-dynamic')
201 if arglist.getLastArg(arglist.parser.f_gnuRuntimeOption):
202 # FIXME: Replace -lobjc in forward args with
203 # -lobjc-gnu. How do we wish to handle such things?
204 pass
205
206 if not arglist.getLastArg(arglist.parser.ZdynamiclibOption):
207 if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption):
208 self.addDarwinArch(cmd_args, arch, arglist)
209 cmd_args.append('-force_cpusubtype_all')
210 else:
211 self.addDarwinSubArch(cmd_args, arch, arglist)
212
213 if arglist.getLastArg(arglist.parser.ZbundleOption):
214 cmd_args.append('-bundle')
215 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zbundle_loaderOption,
216 '-bundle_loader')
217 arglist.addAllArgs(cmd_args, arglist.parser.client_nameOption)
218 if arglist.getLastArg(arglist.parser.compatibility_versionOption):
219 # FIXME: Where should diagnostics go?
220 print >>sys.stderr, "-compatibility_version only allowed with -dynamiclib"
221 sys.exit(1)
222 if arglist.getLastArg(arglist.parser.current_versionOption):
223 print >>sys.stderr, "-current_version only allowed with -dynamiclib"
224 sys.exit(1)
225 if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption):
226 cmd_args.append('-force_flat_namespace')
227 if arglist.getLastArg(arglist.parser.Zinstall_nameOption):
228 print >>sys.stderr, "-install_name only allowed with -dynamiclib"
229 sys.exit(1)
230 arglist.addLastArg(cmd_args, arglist.parser.keep_private_externsOption)
231 arglist.addLastArg(cmd_args, arglist.parser.private_bundleOption)
232 else:
233 cmd_args.append('-dylib')
234 if arglist.getLastArg(arglist.parser.ZbundleOption):
235 print >>sys.stderr, "-bundle not allowed with -dynamiclib"
236 sys.exit(1)
237 if arglist.getLastArg(arglist.parser.Zbundle_loaderOption):
238 print >>sys.stderr, "-bundle_loader not allowed with -dynamiclib"
239 sys.exit(1)
240 if arglist.getLastArg(arglist.parser.client_nameOption):
241 print >>sys.stderr, "-client_name not allowed with -dynamiclib"
242 sys.exit(1)
243 arglist.addAllArgsTranslated(cmd_args, arglist.parser.compatibility_versionOption,
244 '-dylib_compatibility_version')
245 arglist.addAllArgsTranslated(cmd_args, arglist.parser.current_versionOption,
246 '-dylib_current_version')
247
248 if arglist.getLastArg(arglist.parser.Zforce_cpusubtype_ALLOption):
249 self.addDarwinArch(cmd_args, arch, arglist)
250 # NOTE: We don't add -force_cpusubtype_ALL on this path. Ok.
251 else:
252 self.addDarwinSubArch(cmd_args, arch, arglist)
253
254 if arglist.getLastArg(arglist.parser.Zforce_flat_namespaceOption):
255 print >>sys.stderr, "-force_flat_namespace not allowed with -dynamiclib"
256 sys.exit(1)
257
258 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zinstall_nameOption,
259 '-dylib_install_name')
260
261 if arglist.getLastArg(arglist.parser.keep_private_externsOption):
262 print >>sys.stderr, "-keep_private_externs not allowed with -dynamiclib"
263 sys.exit(1)
264 if arglist.getLastArg(arglist.parser.private_bundleOption):
265 print >>sys.stderr, "-private_bundle not allowed with -dynamiclib"
266 sys.exit(1)
267
268 if arglist.getLastArg(arglist.parser.Zall_loadOption):
269 cmd_args.append('-all_load')
270
271 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zallowable_clientOption,
272 '-allowable_client')
273
274 if arglist.getLastArg(arglist.parser.Zbind_at_loadOption):
275 cmd_args.append('-bind_at_load')
276
277 if arglist.getLastArg(arglist.parser.Zdead_stripOption):
278 cmd_args.append('-dead_strip')
279
280 if arglist.getLastArg(arglist.parser.Zno_dead_strip_inits_and_termsOption):
281 cmd_args.append('-no_dead_strip_inits_and_terms')
282
283 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zdylib_fileOption,
284 '-dylib_file')
285
286 if arglist.getLastArg(arglist.parser.ZdynamicOption):
287 cmd_args.append('-dynamic')
288
289 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zexported_symbols_listOption,
290 '-exported_symbols_list')
291
292 if arglist.getLastArg(arglist.parser.Zflat_namespaceOption):
293 cmd_args.append('-flat_namespace')
294
295 arglist.addAllArgs(cmd_args, arglist.parser.headerpad_max_install_namesOption)
296 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zimage_baseOption,
297 '-image_base')
298 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZinitOption,
299 '-init')
300
301 if not arglist.getLastArg(arglist.parser.m_macosxVersionMinOption):
302 if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
303 # FIXME: I don't understand what is going on
304 # here. This is supposed to come from
305 # darwin_ld_minversion, but gcc doesn't seem to be
306 # following that; it must be getting over-ridden
307 # somewhere.
308 cmd_args.append('-macosx_version_min')
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000309 cmd_args.append(self.getMacosxVersionMin())
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000310 else:
311 # addAll doesn't make sense here but this is what gcc
312 # does.
313 arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_macosxVersionMinOption,
314 '-macosx_version_min')
315
316 arglist.addAllArgsTranslated(cmd_args, arglist.parser.m_iphoneosVersionMinOption,
317 '-iphoneos_version_min')
318 arglist.addLastArg(cmd_args, arglist.parser.nomultidefsOption)
319
320 if arglist.getLastArg(arglist.parser.Zmulti_moduleOption):
321 cmd_args.append('-multi_module')
322
323 if arglist.getLastArg(arglist.parser.Zsingle_moduleOption):
324 cmd_args.append('-single_module')
325
326 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zmultiply_definedOption,
327 '-multiply_defined')
328
329 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZmultiplydefinedunusedOption,
330 '-multiply_defined_unused')
331
332 if arglist.getLastArg(arglist.parser.f_pieOption):
333 cmd_args.append('-pie')
334
335 arglist.addLastArg(cmd_args, arglist.parser.prebindOption)
336 arglist.addLastArg(cmd_args, arglist.parser.noprebindOption)
337 arglist.addLastArg(cmd_args, arglist.parser.nofixprebindingOption)
338 arglist.addLastArg(cmd_args, arglist.parser.prebind_all_twolevel_modulesOption)
339 arglist.addLastArg(cmd_args, arglist.parser.read_only_relocsOption)
340 arglist.addAllArgs(cmd_args, arglist.parser.sectcreateOption)
341 arglist.addAllArgs(cmd_args, arglist.parser.sectorderOption)
342 arglist.addAllArgs(cmd_args, arglist.parser.seg1addrOption)
343 arglist.addAllArgs(cmd_args, arglist.parser.segprotOption)
344 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZsegaddrOption,
345 '-segaddr')
346 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_only_addrOption,
347 '-segs_read_only_addr')
348 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zsegs_read_write_addrOption,
349 '-segs_read_write_addr')
350 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zseg_addr_tableOption,
351 '-seg_addr_table')
352 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zfn_seg_addr_table_filenameOption,
353 '-fn_seg_addr_table_filename')
354 arglist.addAllArgs(cmd_args, arglist.parser.sub_libraryOption)
355 arglist.addAllArgs(cmd_args, arglist.parser.sub_umbrellaOption)
356 arglist.addAllArgsTranslated(cmd_args, arglist.parser.isysrootOption,
357 '-syslibroot')
358 arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespaceOption)
359 arglist.addLastArg(cmd_args, arglist.parser.twolevel_namespace_hintsOption)
360 arglist.addAllArgsTranslated(cmd_args, arglist.parser.ZumbrellaOption,
361 '-umbrella')
362 arglist.addAllArgs(cmd_args, arglist.parser.undefinedOption)
363 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zunexported_symbols_listOption,
364 '-unexported_symbols_list')
365 arglist.addAllArgsTranslated(cmd_args, arglist.parser.Zweak_reference_mismatchesOption,
366 '-weak_reference_mismatches')
367
368 if not arglist.getLastArg(arglist.parser.Zweak_reference_mismatchesOption):
369 cmd_args.append('-weak_reference_mismatches')
370 cmd_args.append('non-weak')
371
372 arglist.addLastArg(cmd_args, arglist.parser.XOption)
373 arglist.addAllArgs(cmd_args, arglist.parser.yOption)
374 arglist.addLastArg(cmd_args, arglist.parser.wOption)
375 arglist.addAllArgs(cmd_args, arglist.parser.pagezero_sizeOption)
376 arglist.addAllArgs(cmd_args, arglist.parser.segs_read_Option)
377 arglist.addLastArg(cmd_args, arglist.parser.seglinkeditOption)
378 arglist.addLastArg(cmd_args, arglist.parser.noseglinkeditOption)
379 arglist.addAllArgs(cmd_args, arglist.parser.sectalignOption)
380 arglist.addAllArgs(cmd_args, arglist.parser.sectobjectsymbolsOption)
381 arglist.addAllArgs(cmd_args, arglist.parser.segcreateOption)
382 arglist.addLastArg(cmd_args, arglist.parser.whyloadOption)
383 arglist.addLastArg(cmd_args, arglist.parser.whatsloadedOption)
384 arglist.addAllArgs(cmd_args, arglist.parser.dylinker_install_nameOption)
385 arglist.addLastArg(cmd_args, arglist.parser.dylinkerOption)
386 arglist.addLastArg(cmd_args, arglist.parser.MachOption)
Daniel Dunbara5677512009-01-05 19:53:30 +0000387
388 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000389 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000390 assert outputType is Types.ImageType
391
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000392 # The logic here is derived from gcc's behavior; most of which
Daniel Dunbaree8cc262009-01-12 02:24:21 +0000393 # comes from specs (starting with link_command). Consult gcc
394 # for more information.
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000395
396 # FIXME: gcc's spec controls when this is done; certain things
397 # like -filelist or -Wl, still trigger a link stage. I don't
398 # quite understand how gcc decides to execute the linker,
399 # investigate. Also, the spec references -fdump= which seems
400 # to have disappeared?
Daniel Dunbara5677512009-01-05 19:53:30 +0000401 cmd_args = []
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000402
403 # Not sure why this particular decomposition exists in gcc.
404 self.addLinkArgs(cmd_args, arch, arglist)
405
Daniel Dunbaree8cc262009-01-12 02:24:21 +0000406 # This toolchain never accumlates options in specs, the only
407 # place this gets used is to add -ObjC.
408 if (arglist.getLastArg(arglist.parser.ObjCOption) or
409 arglist.getLastArg(arglist.parser.f_objcOption)):
410 cmd_args.append('-ObjC')
411 if arglist.getLastArg(arglist.parser.ObjCXXOption):
412 cmd_args.append('-ObjC')
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000413
414 # FIXME: gcc has %{x} in here. How could this ever happen?
415 # Cruft?
416 arglist.addLastArg(cmd_args, arglist.parser.dOption)
417 arglist.addLastArg(cmd_args, arglist.parser.tOption)
418 arglist.addLastArg(cmd_args, arglist.parser.ZOption)
419 arglist.addLastArg(cmd_args, arglist.parser.uOption)
420 arglist.addLastArg(cmd_args, arglist.parser.AOption)
421 arglist.addLastArg(cmd_args, arglist.parser.eOption)
422 arglist.addLastArg(cmd_args, arglist.parser.mOption)
423 arglist.addLastArg(cmd_args, arglist.parser.rOption)
424
425 cmd_args.extend(arglist.render(output))
426
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000427 macosxVersion = self.getMacosxVersionTuple(arglist)
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000428 if (not arglist.getLastArg(arglist.parser.AOption) and
429 not arglist.getLastArg(arglist.parser.nostdlibOption) and
430 not arglist.getLastArg(arglist.parser.nostartfilesOption)):
431 # Derived from startfile spec.
432 if arglist.getLastArg(arglist.parser.ZdynamiclibOption):
433 # Derived from darwin_dylib1 spec.
434 if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
435 cmd_args.append('-ldylib1.o')
436 else:
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000437 if macosxVersion < (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000438 cmd_args.append('-ldylib1.o')
439 else:
440 cmd_args.append('-ldylib1.10.5.o')
441 else:
442 if arglist.getLastArg(arglist.parser.ZbundleOption):
443 if not arglist.getLastArg(arglist.parser.staticOption):
444 cmd_args.append('-lbundle1.o')
445 else:
446 if arglist.getLastArg(arglist.parser.pgOption):
447 if arglist.getLastArg(arglist.parser.staticOption):
448 cmd_args.append('-lgcrt0.o')
449 else:
450 if arglist.getLastArg(arglist.parser.objectOption):
451 cmd_args.append('-lgcrt0.o')
452 else:
453 if arglist.getLastArg(arglist.parser.preloadOption):
454 cmd_args.append('-lgcrt0.o')
455 else:
456 cmd_args.append('-lgcrt1.o')
457
458 # darwin_crt2 spec is empty.
459 pass
460 else:
461 if arglist.getLastArg(arglist.parser.staticOption):
462 cmd_args.append('-lcrt0.o')
463 else:
464 if arglist.getLastArg(arglist.parser.objectOption):
465 cmd_args.append('-lcrt0.o')
466 else:
467 if arglist.getLastArg(arglist.parser.preloadOption):
468 cmd_args.append('-lcrt0.o')
469 else:
470 # Derived from darwin_crt1 spec.
471 if arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
472 cmd_args.append('-lcrt1.o')
473 else:
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000474 if macosxVersion < (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000475 cmd_args.append('-lcrt1.o')
476 else:
477 cmd_args.append('-lcrt1.10.5.o')
478
479 # darwin_crt2 spec is empty.
480 pass
481
482 if arglist.getLastArg(arglist.parser.sharedLibgccOption):
483 if not arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000484 if macosxVersion < (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000485 # FIXME: gcc does a library search for this
486 # file, this will be be broken currently.
487 cmd_args.append('crt3.o')
488
489 arglist.addAllArgs(cmd_args, arglist.parser.LOption)
490
491 if arglist.getLastArg(arglist.parser.f_openmpOption):
492 # This is more complicated in gcc...
493 cmd_args.append('-lgomp')
494
495 # FIXME: Derive these correctly.
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000496 tcDir = self.getToolChainDir()
497 if arglist.getValue(arch) == 'x86_64':
498 cmd_args.extend(["-L/usr/lib/gcc/%s/x86_64" % tcDir,
499 "-L/usr/lib/gcc/%s/x86_64" % tcDir])
500 cmd_args.extend(["-L/usr/lib/%s" % tcDir,
501 "-L/usr/lib/gcc/%s" % tcDir,
502 "-L/usr/lib/gcc/%s" % tcDir,
503 "-L/usr/lib/gcc/%s/../../../%s" % (tcDir,tcDir),
504 "-L/usr/lib/gcc/%s/../../.." % tcDir])
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000505
Daniel Dunbara5677512009-01-05 19:53:30 +0000506 for input in inputs:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000507 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000508
509 if (arglist.getLastArg(arglist.parser.f_profileArcsOption) or
510 arglist.getLastArg(arglist.parser.f_profileGenerateOption) or
511 arglist.getLastArg(arglist.parser.f_createProfileOption) or
512 arglist.getLastArg(arglist.parser.coverageOption)):
513 cmd_args.append('-lgcov')
514
515 if arglist.getLastArg(arglist.parser.f_nestedFunctionsOption):
516 cmd_args.append('-allow_stack_execute')
517
518 if (not arglist.getLastArg(arglist.parser.nostdlibOption) and
519 not arglist.getLastArg(arglist.parser.nodefaultlibsOption)):
520 # link_ssp spec is empty.
521
522 # Derived from libgcc spec.
523 if arglist.getLastArg(arglist.parser.staticOption):
524 cmd_args.append('-lgcc_static')
525 elif arglist.getLastArg(arglist.parser.staticLibgccOption):
526 cmd_args.append('-lgcc_eh')
527 cmd_args.append('-lgcc')
528 elif arglist.getLastArg(arglist.parser.m_iphoneosVersionMinOption):
529 # Derived from darwin_iphoneos_libgcc spec.
530 cmd_args.append('-lgcc_s.10.5')
531 cmd_args.append('-lgcc')
532 elif (arglist.getLastArg(arglist.parser.sharedLibgccOption) or
533 arglist.getLastArg(arglist.parser.f_exceptionsOption) or
534 arglist.getLastArg(arglist.parser.f_gnuRuntimeOption)):
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000535 if macosxVersion < (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000536 cmd_args.append('-lgcc_s.10.4')
537 else:
538 cmd_args.append('-lgcc_s.10.5')
539 cmd_args.append('-lgcc')
540 else:
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000541 if macosxVersion < (10,5) and macosxVersion >= (10,3,9):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000542 cmd_args.append('-lgcc_s.10.4')
Daniel Dunbar4a0ba1a2009-01-12 05:02:38 +0000543 if macosxVersion >= (10,5):
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000544 cmd_args.append('-lgcc_s.10.5')
545 cmd_args.append('-lgcc')
546
547 # Derived from lib spec.
548 if not arglist.getLastArg(arglist.parser.staticOption):
549 cmd_args.append('-lSystem')
550
551 if (not arglist.getLastArg(arglist.parser.AOption) and
552 not arglist.getLastArg(arglist.parser.nostdlibOption) and
553 not arglist.getLastArg(arglist.parser.nostartfilesOption)):
554 # endfile_spec is empty.
555 pass
556
557 arglist.addAllArgs(cmd_args, arglist.parser.TOption)
558 arglist.addAllArgs(cmd_args, arglist.parser.FOption)
559
Daniel Dunbar9c257c32009-01-12 04:21:12 +0000560 jobs.addJob(Jobs.Command(self.getCollect2Path(), cmd_args))
Daniel Dunbara5677512009-01-05 19:53:30 +0000561
Daniel Dunbar9c199a02009-01-11 23:13:15 +0000562 # FIXME: We need to add a dsymutil job here in some particular
563 # cases (basically whenever we have a c-family input we are
564 # compiling, I think). Find out why this is the condition, and
565 # implement. See link_command spec for more details.
566
Daniel Dunbara5677512009-01-05 19:53:30 +0000567class LipoTool(Tool):
568 def __init__(self):
569 super(LipoTool, self).__init__('lipo')
570
571 def constructJob(self, phase, arch, jobs, inputs,
Daniel Dunbardb439902009-01-07 18:40:45 +0000572 output, outputType, args, arglist):
Daniel Dunbara5677512009-01-05 19:53:30 +0000573 assert outputType is Types.ImageType
574
Daniel Dunbardb439902009-01-07 18:40:45 +0000575 cmd_args = ['-create']
Daniel Dunbar39cbfaa2009-01-07 18:54:26 +0000576 cmd_args.extend(arglist.render(output))
Daniel Dunbara5677512009-01-05 19:53:30 +0000577 for input in inputs:
Daniel Dunbar2ec55bc2009-01-12 03:33:58 +0000578 cmd_args.extend(arglist.renderAsInput(input.source))
Daniel Dunbara5677512009-01-05 19:53:30 +0000579 jobs.addJob(Jobs.Command('lipo', cmd_args))