blob: 9a3930c5beeca315dde26b94b8e8e778cdce3238 [file] [log] [blame]
Daniel Dunbar47ac7d22009-03-18 06:00:36 +00001//===--- Tools.cpp - Tools Implementations ------------------------------*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "Tools.h"
11
Daniel Dunbar1d460332009-03-18 10:01:51 +000012#include "clang/Driver/Action.h"
Daniel Dunbar871adcf2009-03-18 07:06:02 +000013#include "clang/Driver/Arg.h"
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000014#include "clang/Driver/ArgList.h"
Daniel Dunbar1d460332009-03-18 10:01:51 +000015#include "clang/Driver/Driver.h" // FIXME: Remove?
16#include "clang/Driver/DriverDiagnostic.h" // FIXME: Remove?
Daniel Dunbar871adcf2009-03-18 07:06:02 +000017#include "clang/Driver/Compilation.h"
18#include "clang/Driver/Job.h"
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000019#include "clang/Driver/HostInfo.h"
20#include "clang/Driver/Option.h"
21#include "clang/Driver/ToolChain.h"
Daniel Dunbar871adcf2009-03-18 07:06:02 +000022#include "clang/Driver/Util.h"
23
24#include "llvm/ADT/SmallVector.h"
25
26#include "InputInfo.h"
27
Daniel Dunbar47ac7d22009-03-18 06:00:36 +000028using namespace clang::driver;
29using namespace clang::driver::tools;
30
31void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Daniel Dunbar871adcf2009-03-18 07:06:02 +000032 Job &Dest,
33 const InputInfo &Output,
Daniel Dunbar62cf6012009-03-18 06:07:59 +000034 const InputInfoList &Inputs,
Daniel Dunbar1d460332009-03-18 10:01:51 +000035 const ArgList &Args,
Daniel Dunbar47ac7d22009-03-18 06:00:36 +000036 const char *LinkingOutput) const {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000037 ArgStringList CmdArgs;
38
Daniel Dunbar1d460332009-03-18 10:01:51 +000039 if (isa<AnalyzeJobAction>(JA)) {
40 assert(JA.getType() == types::TY_Plist && "Invalid output type.");
41 CmdArgs.push_back("-analyze");
42 } else if (isa<PreprocessJobAction>(JA)) {
43 CmdArgs.push_back("-E");
44 } else if (isa<PrecompileJobAction>(JA)) {
45 // No special option needed, driven by -x.
46 //
47 // FIXME: Don't drive this by -x, that is gross.
48
49 // FIXME: This is a total hack. Copy the input header file
50 // to the output, so that it can be -include'd by clang.
51 assert(Inputs.size() == 1 && "Cannot make PCH with multiple inputs.");
Daniel Dunbar115a7922009-03-19 07:29:38 +000052 assert(Output.isFilename() && "Unexpected output");
Daniel Dunbar1d460332009-03-18 10:01:51 +000053 assert(!Inputs[0].isPipe() && "Unexpected pipe");
Daniel Dunbar115a7922009-03-19 07:29:38 +000054 assert(Inputs[0].isFilename() && "Unexpected input");
55 const char *InputPath = Inputs[0].getFilename();
56 llvm::sys::Path OutputPath(Output.getFilename());
Daniel Dunbar1d460332009-03-18 10:01:51 +000057 OutputPath.eraseComponent();
58 if (OutputPath.empty())
59 OutputPath = llvm::sys::Path(InputPath).getLast();
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000060 else
Daniel Dunbar1d460332009-03-18 10:01:51 +000061 OutputPath.appendComponent(llvm::sys::Path(InputPath).getLast());
62 if (!OutputPath.exists()) {
63 ArgStringList CpArgs;
64 CpArgs.push_back(InputPath);
65 CpArgs.push_back(Args.MakeArgString(OutputPath.c_str()));
Daniel Dunbarecc63622009-03-18 23:34:15 +000066 const char *Exec =
67 Args.MakeArgString(getToolChain().GetProgramPath(C, "cp").c_str());
68 C.getJobs().addJob(new Command(Exec, CpArgs));
Daniel Dunbar1d460332009-03-18 10:01:51 +000069 }
70 } else {
71 assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool.");
72
73 if (JA.getType() == types::TY_Nothing) {
74 CmdArgs.push_back("-fsyntax-only");
75 } else if (JA.getType() == types::TY_LLVMAsm) {
76 CmdArgs.push_back("-emit-llvm");
77 } else if (JA.getType() == types::TY_LLVMBC) {
78 CmdArgs.push_back("-emit-llvm-bc");
79 } else if (JA.getType() == types::TY_PP_Asm) {
80 CmdArgs.push_back("-S");
81 }
Daniel Dunbarb488c1d2009-03-18 08:07:30 +000082 }
83
Daniel Dunbar1d460332009-03-18 10:01:51 +000084 // The make clang go fast button.
85 CmdArgs.push_back("-disable-free");
86
87 if (isa<AnalyzeJobAction>(JA)) {
88 // Add default argument set.
89 //
90 // FIXME: Move into clang?
91 CmdArgs.push_back("-warn-dead-stores");
92 CmdArgs.push_back("-checker-cfref");
93 CmdArgs.push_back("-warn-objc-methodsigs");
94 // Do not enable the missing -dealloc check.
95 // '-warn-objc-missing-dealloc',
96 CmdArgs.push_back("-warn-objc-unused-ivars");
97
98 CmdArgs.push_back("-analyzer-output=plist");
99
100 // Add -Xanalyzer arguments when running as analyzer.
101 Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
102 } else {
103 // Perform argument translation for LLVM backend. This
104 // takes some care in reconciling with llvm-gcc. The
105 // issue is that llvm-gcc translates these options based on
106 // the values in cc1, whereas we are processing based on
107 // the driver arguments.
108 //
109 // FIXME: This is currently broken for -f flags when -fno
110 // variants are present.
111
112 // This comes from the default translation the driver + cc1
113 // would do to enable flag_pic.
114 //
115 // FIXME: Centralize this code.
116 bool PICEnabled = (Args.hasArg(options::OPT_fPIC) ||
117 Args.hasArg(options::OPT_fpic) ||
118 Args.hasArg(options::OPT_fPIE) ||
119 Args.hasArg(options::OPT_fpie));
120 bool PICDisabled = (Args.hasArg(options::OPT_mkernel) ||
121 Args.hasArg(options::OPT_static));
122 const char *Model = getToolChain().GetForcedPicModel();
123 if (!Model) {
124 if (Args.hasArg(options::OPT_mdynamic_no_pic))
125 Model = "dynamic-no-pic";
126 else if (PICDisabled)
127 Model = "static";
128 else if (PICEnabled)
129 Model = "pic";
130 else
131 Model = getToolChain().GetDefaultRelocationModel();
132 }
133 CmdArgs.push_back("--relocation-model");
134 CmdArgs.push_back(Model);
135
136 if (Args.hasArg(options::OPT_ftime_report))
137 CmdArgs.push_back("--time-passes");
138 // FIXME: Set --enable-unsafe-fp-math.
139 if (!Args.hasArg(options::OPT_fomit_frame_pointer))
140 CmdArgs.push_back("--disable-fp-elim");
141 if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,
142 options::OPT_fno_zero_initialized_in_bss,
143 true))
144 CmdArgs.push_back("--nozero-initialized-in-bss");
145 if (Args.hasArg(options::OPT_dA))
146 CmdArgs.push_back("--asm-verbose");
147 if (Args.hasArg(options::OPT_fdebug_pass_structure))
148 CmdArgs.push_back("--debug-pass=Structure");
149 if (Args.hasArg(options::OPT_fdebug_pass_arguments))
150 CmdArgs.push_back("--debug-pass=Arguments");
151 // FIXME: set --inline-threshhold=50 if (optimize_size || optimize
152 // < 3)
153 if (Args.hasFlag(options::OPT_funwind_tables,
154 options::OPT_fno_unwind_tables,
155 getToolChain().IsUnwindTablesDefault()))
156 CmdArgs.push_back("--unwind-tables=1");
157 else
158 CmdArgs.push_back("--unwind-tables=0");
159 if (!Args.hasFlag(options::OPT_mred_zone,
160 options::OPT_mno_red_zone,
161 true))
162 CmdArgs.push_back("--disable-red-zone");
163 if (Args.hasFlag(options::OPT_msoft_float,
164 options::OPT_mno_soft_float,
165 false))
166 CmdArgs.push_back("--soft-float");
167
168 // FIXME: Need target hooks.
169 if (memcmp(getToolChain().getPlatform().c_str(), "darwin", 6) == 0) {
170 if (getToolChain().getArchName() == "x86_64")
171 CmdArgs.push_back("--mcpu=core2");
172 else if (getToolChain().getArchName() == "i386")
173 CmdArgs.push_back("--mcpu=yonah");
174 }
175
176 // FIXME: Ignores ordering. Also, we need to find a realistic
177 // solution for this.
178 static const struct {
179 options::ID Pos, Neg;
180 const char *Name;
181 } FeatureOptions[] = {
182 { options::OPT_mmmx, options::OPT_mno_mmx, "mmx" },
183 { options::OPT_msse, options::OPT_mno_sse, "sse" },
184 { options::OPT_msse2, options::OPT_mno_sse2, "sse2" },
185 { options::OPT_msse3, options::OPT_mno_sse3, "sse3" },
186 { options::OPT_mssse3, options::OPT_mno_ssse3, "ssse3" },
187 { options::OPT_msse41, options::OPT_mno_sse41, "sse41" },
188 { options::OPT_msse42, options::OPT_mno_sse42, "sse42" },
189 { options::OPT_msse4a, options::OPT_mno_sse4a, "sse4a" },
190 { options::OPT_m3dnow, options::OPT_mno_3dnow, "3dnow" },
191 { options::OPT_m3dnowa, options::OPT_mno_3dnowa, "3dnowa" }
192 };
193 const unsigned NumFeatureOptions =
194 sizeof(FeatureOptions)/sizeof(FeatureOptions[0]);
195
196 // FIXME: Avoid std::string
197 std::string Attrs;
198 for (unsigned i=0; i < NumFeatureOptions; ++i) {
199 if (Args.hasArg(FeatureOptions[i].Pos)) {
Daniel Dunbar55b3b5f2009-03-19 17:36:04 +0000200 if (!Attrs.empty())
201 Attrs += ',';
Daniel Dunbar1d460332009-03-18 10:01:51 +0000202 Attrs += '+';
203 Attrs += FeatureOptions[i].Name;
204 } else if (Args.hasArg(FeatureOptions[i].Neg)) {
Daniel Dunbar55b3b5f2009-03-19 17:36:04 +0000205 if (!Attrs.empty())
206 Attrs += ',';
Daniel Dunbar1d460332009-03-18 10:01:51 +0000207 Attrs += '-';
208 Attrs += FeatureOptions[i].Name;
209 }
210 }
211 if (!Attrs.empty()) {
212 CmdArgs.push_back("--mattr");
213 CmdArgs.push_back(Args.MakeArgString(Attrs.c_str()));
214 }
215
216 if (Args.hasFlag(options::OPT_fmath_errno,
217 options::OPT_fno_math_errno,
218 getToolChain().IsMathErrnoDefault()))
219 CmdArgs.push_back("--fmath-errno=1");
220 else
221 CmdArgs.push_back("--fmath-errno=0");
222
223 if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
224 CmdArgs.push_back("--limit-float-precision");
225 CmdArgs.push_back(A->getValue(Args));
226 }
227
228 // FIXME: Add --stack-protector-buffer-size=<xxx> on
229 // -fstack-protect.
230
231 Args.AddLastArg(CmdArgs, options::OPT_MD);
232 Args.AddLastArg(CmdArgs, options::OPT_MM);
233 Args.AddAllArgs(CmdArgs, options::OPT_MF);
234 Args.AddLastArg(CmdArgs, options::OPT_MP);
235 Args.AddAllArgs(CmdArgs, options::OPT_MT);
236
237 Arg *Unsupported = Args.getLastArg(options::OPT_M);
238 if (!Unsupported)
239 Unsupported = Args.getLastArg(options::OPT_MM);
240 if (!Unsupported)
241 Unsupported = Args.getLastArg(options::OPT_MG);
242 if (!Unsupported)
243 Unsupported = Args.getLastArg(options::OPT_MQ);
244 if (Unsupported) {
245 const Driver &D = getToolChain().getHost().getDriver();
246 D.Diag(clang::diag::err_drv_unsupported_opt)
247 << Unsupported->getOption().getName();
248 }
249 }
250
251 Args.AddAllArgs(CmdArgs, options::OPT_v);
252 Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U);
253 Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
254 Args.AddLastArg(CmdArgs, options::OPT_P);
255 Args.AddAllArgs(CmdArgs, options::OPT_mmacosx_version_min_EQ);
256
257 // Special case debug options to only pass -g to clang. This is
258 // wrong.
259 if (Args.hasArg(options::OPT_g_Group))
260 CmdArgs.push_back("-g");
261
262 Args.AddLastArg(CmdArgs, options::OPT_nostdinc);
263
264 // FIXME: Clang isn't going to accept just anything here.
265 Args.AddAllArgs(CmdArgs, options::OPT_i_Group);
266
267 // Automatically load .pth or .gch files which match -include
268 // options. It's wonky, but we include looking for .gch so we can
269 // support seamless replacement into a build system already set up
270 // to be generating .gch files.
271
272 // FIXME: Need to use an iterator for this to be efficient.
273 for (ArgList::const_iterator
274 it = Args.begin(), ie = Args.end(); it != ie; ++it) {
275 const Arg *A = *it;
276 if (A->getOption().matches(options::OPT_include)) {
277 llvm::sys::Path P(A->getValue(Args));
278 P.appendSuffix("pth");
279 if (P.exists()) {
280 CmdArgs.push_back("-token-cache");
281 CmdArgs.push_back(Args.MakeArgString(P.c_str()));
282 } else {
283 P.eraseSuffix();
284 P.appendSuffix("gch");
285 if (P.exists()) {
286 CmdArgs.push_back("-token-cache");
287 CmdArgs.push_back(Args.MakeArgString(P.c_str()));
288 }
289 }
290 }
291 }
292
293 // Manually translate -O to -O1; let clang reject others.
294 if (Arg *A = Args.getLastArg(options::OPT_O)) {
295 if (A->getValue(Args)[0] == '\0')
296 CmdArgs.push_back("-O1");
297 else
Daniel Dunbar5697aa02009-03-18 23:39:35 +0000298 A->render(Args, CmdArgs);
Daniel Dunbar1d460332009-03-18 10:01:51 +0000299 }
300
Daniel Dunbarff7488d2009-03-20 00:52:38 +0000301 Args.AddAllArgs(CmdArgs, options::OPT_clang_W_Group,
302 options::OPT_pedantic_Group);
Daniel Dunbar1d460332009-03-18 10:01:51 +0000303 Args.AddLastArg(CmdArgs, options::OPT_w);
304 Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi,
305 options::OPT_trigraphs);
306
307 if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) {
308 CmdArgs.push_back("-ftemplate-depth");
309 CmdArgs.push_back(A->getValue(Args));
310 }
311
312 Args.AddAllArgs(CmdArgs, options::OPT_clang_f_Group);
313
314 Args.AddLastArg(CmdArgs, options::OPT_dM);
315
316 Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
317
318 // FIXME: Always pass the full triple once we aren't concerned with
319 // ccc compat.
320 CmdArgs.push_back("-arch");
321 CmdArgs.push_back(getToolChain().getArchName().c_str());
322
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000323 if (Output.isPipe()) {
324 CmdArgs.push_back("-o");
325 CmdArgs.push_back("-");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000326 } else if (Output.isFilename()) {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000327 CmdArgs.push_back("-o");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000328 CmdArgs.push_back(Output.getFilename());
329 } else {
330 assert(Output.isNothing() && "Invalid output.");
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000331 }
332
Daniel Dunbar1d460332009-03-18 10:01:51 +0000333 for (InputInfoList::const_iterator
334 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
335 const InputInfo &II = *it;
336 CmdArgs.push_back("-x");
337 CmdArgs.push_back(types::getTypeName(II.getType()));
338 if (II.isPipe())
339 CmdArgs.push_back("-");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000340 else if (II.isFilename())
341 CmdArgs.push_back(II.getFilename());
Daniel Dunbar1d460332009-03-18 10:01:51 +0000342 else
Daniel Dunbar115a7922009-03-19 07:29:38 +0000343 II.getInputArg().renderAsInput(Args, CmdArgs);
Daniel Dunbar1d460332009-03-18 10:01:51 +0000344 }
345
346 const char *Exec =
347 Args.MakeArgString(getToolChain().GetProgramPath(C, "clang").c_str());
348 Dest.addCommand(new Command(Exec, CmdArgs));
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000349}
350
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000351void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,
352 Job &Dest,
353 const InputInfo &Output,
354 const InputInfoList &Inputs,
Daniel Dunbar1d460332009-03-18 10:01:51 +0000355 const ArgList &Args,
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000356 const char *LinkingOutput) const {
357 ArgStringList CmdArgs;
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000358
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000359 for (ArgList::const_iterator
Daniel Dunbar1d460332009-03-18 10:01:51 +0000360 it = Args.begin(), ie = Args.end(); it != ie; ++it) {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000361 Arg *A = *it;
Daniel Dunbar75877192009-03-19 07:55:12 +0000362 if (A->getOption().hasForwardToGCC()) {
363 // It is unfortunate that we have to claim here, as this means
364 // we will basically never report anything interesting for
365 // platforms using a generic gcc.
366 A->claim();
Daniel Dunbar1d460332009-03-18 10:01:51 +0000367 A->render(Args, CmdArgs);
Daniel Dunbar75877192009-03-19 07:55:12 +0000368 }
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000369 }
370
371 RenderExtraToolArgs(CmdArgs);
372
373 // If using a driver driver, force the arch.
374 if (getToolChain().getHost().useDriverDriver()) {
375 CmdArgs.push_back("-arch");
376 CmdArgs.push_back(getToolChain().getArchName().c_str());
377 }
378
379 if (Output.isPipe()) {
380 CmdArgs.push_back("-o");
381 CmdArgs.push_back("-");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000382 } else if (Output.isFilename()) {
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000383 CmdArgs.push_back("-o");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000384 CmdArgs.push_back(Output.getFilename());
385 } else {
386 assert(Output.isNothing() && "Unexpected output");
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000387 CmdArgs.push_back("-fsyntax-only");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000388 }
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000389
390
391 // Only pass -x if gcc will understand it; otherwise hope gcc
392 // understands the suffix correctly. The main use case this would go
393 // wrong in is for linker inputs if they happened to have an odd
394 // suffix; really the only way to get this to happen is a command
395 // like '-x foobar a.c' which will treat a.c like a linker input.
396 //
397 // FIXME: For the linker case specifically, can we safely convert
398 // inputs into '-Wl,' options?
399 for (InputInfoList::const_iterator
400 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
401 const InputInfo &II = *it;
402 if (types::canTypeBeUserSpecified(II.getType())) {
403 CmdArgs.push_back("-x");
404 CmdArgs.push_back(types::getTypeName(II.getType()));
405 }
406
407 if (II.isPipe())
408 CmdArgs.push_back("-");
Daniel Dunbar115a7922009-03-19 07:29:38 +0000409 else if (II.isFilename())
410 CmdArgs.push_back(II.getFilename());
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000411 else
Daniel Dunbar115a7922009-03-19 07:29:38 +0000412 // Don't render as input, we need gcc to do the translations.
413 II.getInputArg().render(Args, CmdArgs);
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000414 }
415
Daniel Dunbar632f50e2009-03-18 21:34:08 +0000416 const char *Exec =
417 Args.MakeArgString(getToolChain().GetProgramPath(C, "gcc").c_str());
418 Dest.addCommand(new Command(Exec, CmdArgs));
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000419}
420
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000421void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
422 CmdArgs.push_back("-E");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000423}
424
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000425void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
426 // The type is good enough.
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000427}
428
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000429void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
430 CmdArgs.push_back("-S");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000431}
432
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000433void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
434 CmdArgs.push_back("-c");
Daniel Dunbar47ac7d22009-03-18 06:00:36 +0000435}
Daniel Dunbarb488c1d2009-03-18 08:07:30 +0000436
437void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const {
438 // The types are (hopefully) good enough.
439}
440
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000441void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
442 Job &Dest, const InputInfo &Output,
443 const InputInfoList &Inputs,
444 const ArgList &Args,
445 const char *LinkingOutput) const {
446 ArgStringList CmdArgs;
447
448 assert(Inputs.size() == 1 && "Unexpected number of inputs.");
449 const InputInfo &Input = Inputs[0];
450
451 // Bit of a hack, this is only used for original inputs.
452 if (Input.isFilename() &&
453 strcmp(Input.getFilename(), Input.getBaseInput()) == 0 &&
454 Args.hasArg(options::OPT_g_Group))
455 CmdArgs.push_back("--gstabs");
456
457 // Derived from asm spec.
458 CmdArgs.push_back("-arch");
459 CmdArgs.push_back(getToolChain().getArchName().c_str());
460
461 CmdArgs.push_back("-force_cpusubtype_ALL");
462 if ((Args.hasArg(options::OPT_mkernel) ||
463 Args.hasArg(options::OPT_static) ||
464 Args.hasArg(options::OPT_fapple_kext)) &&
465 !Args.hasArg(options::OPT_dynamic))
466 CmdArgs.push_back("-static");
467
468 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
469 options::OPT_Xassembler);
470
471 assert(Output.isFilename() && "Unexpected lipo output.");
472 CmdArgs.push_back("-o");
473 CmdArgs.push_back(Output.getFilename());
474
475 if (Input.isPipe()) {
476 CmdArgs.push_back("-");
477 } else {
478 assert(Input.isFilename() && "Invalid input.");
479 CmdArgs.push_back(Input.getFilename());
480 }
481
482 // asm_final spec is empty.
483
484 const char *Exec =
485 Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str());
486 Dest.addCommand(new Command(Exec, CmdArgs));
487}
Daniel Dunbarff7488d2009-03-20 00:52:38 +0000488
489void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA,
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000490 Job &Dest, const InputInfo &Output,
Daniel Dunbarff7488d2009-03-20 00:52:38 +0000491 const InputInfoList &Inputs,
492 const ArgList &Args,
493 const char *LinkingOutput) const {
494 ArgStringList CmdArgs;
495
496 CmdArgs.push_back("-create");
497 assert(Output.isFilename() && "Unexpected lipo output.");
498 CmdArgs.push_back(Output.getFilename());
499 for (InputInfoList::const_iterator
500 it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
501 const InputInfo &II = *it;
502 assert(II.isFilename() && "Unexpected lipo input.");
503 CmdArgs.push_back(II.getFilename());
504 }
505 const char *Exec =
506 Args.MakeArgString(getToolChain().GetProgramPath(C, "lipo").c_str());
507 Dest.addCommand(new Command(Exec, CmdArgs));
508}