blob: 355dbe4052d31b912bceee760f79ef4609e96d15 [file] [log] [blame]
Daniel Dunbar39176082009-03-20 00:20:03 +00001//===--- ToolChains.cpp - ToolChain 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 "ToolChains.h"
11
Daniel Dunbarf3cad362009-03-25 04:13:45 +000012#include "clang/Driver/Arg.h"
13#include "clang/Driver/ArgList.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000014#include "clang/Driver/Driver.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000015#include "clang/Driver/DriverDiagnostic.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000016#include "clang/Driver/HostInfo.h"
Daniel Dunbar27e738d2009-11-19 00:15:11 +000017#include "clang/Driver/OptTable.h"
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +000018#include "clang/Driver/Option.h"
Daniel Dunbar265e9ef2009-11-19 04:25:22 +000019#include "clang/Driver/Options.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000020
21#include "llvm/ADT/StringExtras.h"
Daniel Dunbar84ec96c2009-09-09 22:33:15 +000022#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000023#include "llvm/Support/raw_ostream.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000024#include "llvm/System/Path.h"
25
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000026#include <cstdlib> // ::getenv
27
Daniel Dunbar39176082009-03-20 00:20:03 +000028using namespace clang::driver;
29using namespace clang::driver::toolchains;
30
Daniel Dunbarf3955282009-09-04 18:34:51 +000031/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000032
Daniel Dunbarf3955282009-09-04 18:34:51 +000033Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000034 const unsigned (&_DarwinVersion)[3], bool _IsIPhoneOS)
35 : ToolChain(Host, Triple),
36 IsIPhoneOS(_IsIPhoneOS)
37{
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000038 DarwinVersion[0] = _DarwinVersion[0];
39 DarwinVersion[1] = _DarwinVersion[1];
40 DarwinVersion[2] = _DarwinVersion[2];
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000041
Daniel Dunbar02633b52009-03-26 16:23:12 +000042 llvm::raw_string_ostream(MacosxVersionMin)
Benjamin Kramer87f9fd92009-10-21 21:05:07 +000043 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.'
44 << DarwinVersion[1];
Daniel Dunbar02633b52009-03-26 16:23:12 +000045
Daniel Dunbar30392de2009-09-04 18:35:21 +000046 // FIXME: Lift default up.
47 IPhoneOSVersionMin = "3.0";
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000048}
49
Daniel Dunbareeff4062010-01-22 02:04:58 +000050// FIXME: Can we tablegen this?
51static const char *GetArmArchForMArch(llvm::StringRef Value) {
52 if (Value == "armv6k")
53 return "armv6";
54
55 if (Value == "armv5tej")
56 return "armv5";
57
58 if (Value == "xscale")
59 return "xscale";
60
61 if (Value == "armv4t")
62 return "armv4t";
63
64 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
65 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
66 Value == "armv7m")
67 return "armv7";
68
69 return 0;
70}
71
72// FIXME: Can we tablegen this?
73static const char *GetArmArchForMCpu(llvm::StringRef Value) {
74 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
75 Value == "arm946e-s" || Value == "arm966e-s" ||
76 Value == "arm968e-s" || Value == "arm10e" ||
77 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
78 Value == "arm1026ej-s")
79 return "armv5";
80
81 if (Value == "xscale")
82 return "xscale";
83
84 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
85 Value == "arm1176jz-s" || Value == "arm1176jzf-s")
86 return "armv6";
87
88 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
89 return "armv7";
90
91 return 0;
92}
93
94llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
95 switch (getTriple().getArch()) {
96 default:
97 return getArchName();
98
99 case llvm::Triple::arm: {
100 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
101 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
102 return Arch;
103
104 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
105 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
106 return Arch;
107
108 return "arm";
109 }
110 }
111}
112
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000113DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
114 const unsigned (&DarwinVersion)[3],
Ted Kremenek55bac532009-10-07 03:21:11 +0000115 const unsigned (&_GCCVersion)[3], bool IsIPhoneOS)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000116 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
117{
118 GCCVersion[0] = _GCCVersion[0];
119 GCCVersion[1] = _GCCVersion[1];
120 GCCVersion[2] = _GCCVersion[2];
121
122 // Set up the tool chain paths to match gcc.
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000123 ToolChainDir = "i686-apple-darwin";
Ted Kremenek55bac532009-10-07 03:21:11 +0000124 ToolChainDir += llvm::utostr(DarwinVersion[0]);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000125 ToolChainDir += "/";
126 ToolChainDir += llvm::utostr(GCCVersion[0]);
127 ToolChainDir += '.';
128 ToolChainDir += llvm::utostr(GCCVersion[1]);
129 ToolChainDir += '.';
130 ToolChainDir += llvm::utostr(GCCVersion[2]);
131
Daniel Dunbar74782b02009-10-20 19:25:43 +0000132 // Try the next major version if that tool chain dir is invalid.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000133 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir;
134 if (!llvm::sys::Path(Tmp).exists()) {
Daniel Dunbar74782b02009-10-20 19:25:43 +0000135 std::string Next = "i686-apple-darwin";
136 Next += llvm::utostr(DarwinVersion[0] + 1);
137 Next += "/";
138 Next += llvm::utostr(GCCVersion[0]);
139 Next += '.';
140 Next += llvm::utostr(GCCVersion[1]);
141 Next += '.';
142 Next += llvm::utostr(GCCVersion[2]);
143
144 // Use that if it exists, otherwise hope the user isn't linking.
145 //
146 // FIXME: Drop dependency on gcc's tool chain.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000147 Tmp = "/usr/lib/gcc/" + Next;
148 if (llvm::sys::Path(Tmp).exists())
Daniel Dunbar74782b02009-10-20 19:25:43 +0000149 ToolChainDir = Next;
150 }
151
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000152 std::string Path;
153 if (getArchName() == "x86_64") {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000154 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000155 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000156 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000157 Path += "/x86_64";
158 getFilePaths().push_back(Path);
159
160 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000161 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000162 Path += "/x86_64";
163 getFilePaths().push_back(Path);
164 }
Mike Stump1eb44332009-09-09 15:08:12 +0000165
Daniel Dunbaree788e72009-12-21 18:54:17 +0000166 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000167 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000168 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000169 getFilePaths().push_back(Path);
170
171 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000172 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000173 getFilePaths().push_back(Path);
174
Daniel Dunbaree788e72009-12-21 18:54:17 +0000175 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000176 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000177 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000178 getProgramPaths().push_back(Path);
179
180 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000181 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000182 getProgramPaths().push_back(Path);
183
Daniel Dunbaree788e72009-12-21 18:54:17 +0000184 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000185}
186
Daniel Dunbarf3955282009-09-04 18:34:51 +0000187Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000188 // Free tool implementations.
189 for (llvm::DenseMap<unsigned, Tool*>::iterator
190 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
191 delete it->second;
192}
193
Daniel Dunbarf3955282009-09-04 18:34:51 +0000194Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000195 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000196 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000197 Key = Action::AnalyzeJobClass;
198 else
199 Key = JA.getKind();
200
201 Tool *&T = Tools[Key];
202 if (!T) {
203 switch (Key) {
204 case Action::InputClass:
205 case Action::BindArchClass:
206 assert(0 && "Invalid tool kind.");
207 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000208 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000209 case Action::AnalyzeJobClass:
210 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000211 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000212 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000213 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000214 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000215 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000216 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000217 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000218 case Action::LipoJobClass:
219 T = new tools::darwin::Lipo(*this); break;
220 }
221 }
222
223 return *T;
224}
225
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000226void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
227 ArgStringList &CmdArgs) const {
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000228 // FIXME: Derive these correctly.
229 if (getArchName() == "x86_64") {
230 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
231 "/x86_64"));
232 // Intentionally duplicated for (temporary) gcc bug compatibility.
233 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
234 "/x86_64"));
235 }
236 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
237 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
238 // Intentionally duplicated for (temporary) gcc bug compatibility.
239 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
240 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
241 "/../../../" + ToolChainDir));
242 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
243 "/../../.."));
244}
245
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000246void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
247 ArgStringList &CmdArgs) const {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000248 unsigned MacosxVersionMin[3];
249 getMacosxVersionMin(Args, MacosxVersionMin);
250
251 // Derived from libgcc and lib specs but refactored.
252 if (Args.hasArg(options::OPT_static)) {
253 CmdArgs.push_back("-lgcc_static");
254 } else {
255 if (Args.hasArg(options::OPT_static_libgcc)) {
256 CmdArgs.push_back("-lgcc_eh");
257 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
258 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000259 if (isIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000260 CmdArgs.push_back("-lgcc_s.1");
261 } else {
262 CmdArgs.push_back("-lgcc_s.10.5");
263 }
264 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
Daniel Dunbar8a0d94d2010-01-10 00:46:10 +0000265 Args.hasFlag(options::OPT_fexceptions,
266 options::OPT_fno_exceptions) ||
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000267 Args.hasArg(options::OPT_fgnu_runtime)) {
268 // FIXME: This is probably broken on 10.3?
269 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
270 CmdArgs.push_back("-lgcc_s.10.4");
271 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
272 CmdArgs.push_back("-lgcc_s.10.5");
273 } else {
274 if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9))
275 ; // Do nothing.
276 else if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
277 CmdArgs.push_back("-lgcc_s.10.4");
278 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
279 CmdArgs.push_back("-lgcc_s.10.5");
280 }
281
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000282 if (isIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000283 CmdArgs.push_back("-lgcc");
284 CmdArgs.push_back("-lSystem");
285 } else {
286 CmdArgs.push_back("-lSystem");
287 CmdArgs.push_back("-lgcc");
288 }
289 }
290}
291
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000292DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
293 const unsigned (&DarwinVersion)[3],
294 bool IsIPhoneOS)
295 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
296{
297 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaree788e72009-12-21 18:54:17 +0000298 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000299}
300
301void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
302 ArgStringList &CmdArgs) const {
303 // The Clang toolchain uses explicit paths for internal libraries.
304}
305
306void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
307 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000308 // Darwin doesn't support real static executables, don't link any runtime
309 // libraries with -static.
310 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000311 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000312
313 // Reject -static-libgcc for now, we can deal with this when and if someone
314 // cares. This is useful in situations where someone wants to statically link
315 // something like libstdc++, and needs its runtime support routines.
316 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000317 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000318 << A->getAsString(Args);
319 return;
320 }
321
Daniel Dunbareec99102010-01-22 03:38:14 +0000322 // Otherwise link libSystem, then the dynamic runtime library, and finally any
323 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000324 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000325
326 // Select the dynamic runtime library and the target specific static library.
327 const char *DarwinStaticLib = 0;
328 if (isIPhoneOS()) {
329 CmdArgs.push_back("-lgcc_s.1");
330
331 // We may need some static functions for armv6/thumb which are required to
332 // be in the same linkage unit as their caller.
333 if (getDarwinArchName(Args) == "armv6")
334 DarwinStaticLib = "libclang_rt.armv6.a";
335 } else {
336 unsigned MacosxVersionMin[3];
337 getMacosxVersionMin(Args, MacosxVersionMin);
338
339 // The dynamic runtime library was merged with libSystem for 10.6 and
340 // beyond; only 10.4 and 10.5 need an additional runtime library.
341 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
342 CmdArgs.push_back("-lgcc_s.10.4");
343 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
344 CmdArgs.push_back("-lgcc_s.10.5");
345
346 // For OS X, we only need a static runtime library when targetting 10.4, to
347 // provide versions of the static functions which were omitted from
348 // 10.4.dylib.
349 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
350 DarwinStaticLib = "libclang_rt.10.4.a";
351 }
352
353 /// Add the target specific static library, if needed.
354 if (DarwinStaticLib) {
355 llvm::sys::Path P(getDriver().ResourceDir);
356 P.appendComponent("lib");
357 P.appendComponent("darwin");
358 P.appendComponent(DarwinStaticLib);
359
360 // For now, allow missing resource libraries to support developers who may
361 // not have compiler-rt checked out or integrated into their build.
362 if (!P.exists())
363 getDriver().Diag(clang::diag::warn_drv_missing_resource_library)
364 << P.str();
365 else
366 CmdArgs.push_back(Args.MakeArgString(P.str()));
367 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000368}
369
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000370void Darwin::getMacosxVersionMin(const ArgList &Args,
371 unsigned (&Res)[3]) const {
372 if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
373 bool HadExtra;
374 if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2],
375 HadExtra) ||
376 HadExtra) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000377 const Driver &D = getDriver();
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000378 D.Diag(clang::diag::err_drv_invalid_version_number)
379 << A->getAsString(Args);
380 }
381 } else
382 return getMacosxVersion(Res);
383}
384
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000385DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
386 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000387 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbaree788e72009-12-21 18:54:17 +0000388 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000389
390 // FIXME: We really want to get out of the tool chain level argument
391 // translation business, as it makes the driver functionality much
392 // more opaque. For now, we follow gcc closely solely for the
393 // purpose of easily achieving feature parity & testability. Once we
394 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000395 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000396
Mike Stump1eb44332009-09-09 15:08:12 +0000397 Arg *OSXVersion =
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000398 Args.getLastArgNoClaim(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000399 Arg *iPhoneVersion =
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000400 Args.getLastArgNoClaim(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000401 if (OSXVersion && iPhoneVersion) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000402 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000403 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000404 << iPhoneVersion->getAsString(Args);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000405 } else if (!OSXVersion && !iPhoneVersion) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000406 // If neither OS X nor iPhoneOS targets were specified, check for
407 // environment defines.
408 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
409 const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000410
Daniel Dunbar816bc312010-01-26 01:45:19 +0000411 // Ignore empty strings.
412 if (OSXTarget && OSXTarget[0] == '\0')
413 OSXTarget = 0;
414 if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0')
415 iPhoneOSTarget = 0;
416
417 if (OSXTarget && iPhoneOSTarget) {
418 getDriver().Diag(clang::diag::err_drv_conflicting_deployment_targets)
419 << OSXTarget << iPhoneOSTarget;
420 } else if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000421 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000422 DAL->append(DAL->MakeJoinedArg(0, O, OSXTarget));
423 } else if (iPhoneOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000424 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000425 DAL->append(DAL->MakeJoinedArg(0, O, iPhoneOSTarget));
426 } else {
427 // Otherwise, choose the default version based on the toolchain.
428
429 // FIXME: This is confusing it should be more explicit what the default
430 // target is.
431 if (isIPhoneOS()) {
432 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
433 DAL->append(DAL->MakeJoinedArg(0, O, IPhoneOSVersionMin));
434 } else {
435 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
436 DAL->append(DAL->MakeJoinedArg(0, O, MacosxVersionMin));
437 }
Daniel Dunbar30392de2009-09-04 18:35:21 +0000438 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000439 }
Mike Stump1eb44332009-09-09 15:08:12 +0000440
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000441 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
442 Arg *A = *it;
443
444 if (A->getOption().matches(options::OPT_Xarch__)) {
445 // FIXME: Canonicalize name.
446 if (getArchName() != A->getValue(Args, 0))
447 continue;
448
449 // FIXME: The arg is leaked here, and we should have a nicer
450 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000451 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000452 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000453
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000454 // If the argument parsing failed or more than one argument was
455 // consumed, the -Xarch_ argument's parameter tried to consume
456 // extra arguments. Emit an error and ignore.
457 //
458 // We also want to disallow any options which would alter the
459 // driver behavior; that isn't going to work in our model. We
460 // use isDriverOption() as an approximation, although things
461 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000462 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000463 XarchArg->getOption().isDriverOption()) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000464 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000465 << A->getAsString(Args);
466 continue;
467 }
468
Daniel Dunbar478edc22009-03-29 22:29:05 +0000469 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000470 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000471 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000472
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000473 // Sob. These is strictly gcc compatible for the time being. Apple
474 // gcc translates options twice, which means that self-expanding
475 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000476 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000477 default:
478 DAL->append(A);
479 break;
480
481 case options::OPT_mkernel:
482 case options::OPT_fapple_kext:
483 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000484 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
485 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000486 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000487
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000488 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000489 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000490 A->getValue(Args)));
491 break;
492
493 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000494 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
495 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000496 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
497 break;
498
499 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000500 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
501 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000502 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
503 break;
504
505 case options::OPT_fterminated_vtables:
506 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000507 DAL->append(DAL->MakeFlagArg(A,
508 Opts.getOption(options::OPT_fapple_kext)));
509 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000510 break;
511
512 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000513 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000514 break;
515
516 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000517 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000518 Opts.getOption(options::OPT_mconstant_cfstrings)));
519 break;
520
521 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000522 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000523 Opts.getOption(options::OPT_mno_constant_cfstrings)));
524 break;
525
526 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000527 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000528 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
529 break;
530
531 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000532 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000533 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
534 break;
535
536 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000537 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000538 Opts.getOption(options::OPT_mpascal_strings)));
539 break;
540
541 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000542 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000543 Opts.getOption(options::OPT_mno_pascal_strings)));
544 break;
545 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000546 }
547
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000548 if (getTriple().getArch() == llvm::Triple::x86 ||
549 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000550 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000551 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
552 "core2"));
553
554 // Add the arch options based on the particular spelling of -arch, to match
555 // how the driver driver works.
556 if (BoundArch) {
557 llvm::StringRef Name = BoundArch;
558 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
559 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
560
561 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
562 // which defines the list of which architectures we accept.
563 if (Name == "ppc")
564 ;
565 else if (Name == "ppc601")
566 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
567 else if (Name == "ppc603")
568 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
569 else if (Name == "ppc604")
570 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
571 else if (Name == "ppc604e")
572 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
573 else if (Name == "ppc750")
574 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
575 else if (Name == "ppc7400")
576 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
577 else if (Name == "ppc7450")
578 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
579 else if (Name == "ppc970")
580 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
581
582 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000583 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000584
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000585 else if (Name == "i386")
586 ;
587 else if (Name == "i486")
588 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
589 else if (Name == "i586")
590 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
591 else if (Name == "i686")
592 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
593 else if (Name == "pentium")
594 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
595 else if (Name == "pentium2")
596 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
597 else if (Name == "pentpro")
598 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
599 else if (Name == "pentIIm3")
600 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
601
602 else if (Name == "x86_64")
603 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
604
605 else if (Name == "arm")
606 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
607 else if (Name == "armv4t")
608 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
609 else if (Name == "armv5")
610 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
611 else if (Name == "xscale")
612 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
613 else if (Name == "armv6")
614 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
615 else if (Name == "armv7")
616 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
617
618 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000619 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000620 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000621
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000622 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000623}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000624
Daniel Dunbarf3955282009-09-04 18:34:51 +0000625bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000626 // FIXME: Gross; we should probably have some separate target
627 // definition, possibly even reusing the one in clang.
628 return getArchName() == "x86_64";
629}
630
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000631bool Darwin::UseDwarfDebugFlags() const {
632 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
633 return S[0] != '\0';
634 return false;
635}
636
Daniel Dunbarf3955282009-09-04 18:34:51 +0000637const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000638 return "pic";
639}
640
Daniel Dunbarf3955282009-09-04 18:34:51 +0000641const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000642 if (getArchName() == "x86_64")
643 return "pic";
644 return 0;
645}
646
Daniel Dunbar39176082009-03-20 00:20:03 +0000647/// Generic_GCC - A tool chain using the 'gcc' command to perform
648/// all subcommands; this relies on gcc translating the majority of
649/// command line options.
650
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000651Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000652 : ToolChain(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000653 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000654}
655
Daniel Dunbar39176082009-03-20 00:20:03 +0000656Generic_GCC::~Generic_GCC() {
657 // Free tool implementations.
658 for (llvm::DenseMap<unsigned, Tool*>::iterator
659 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
660 delete it->second;
661}
662
Mike Stump1eb44332009-09-09 15:08:12 +0000663Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000664 const JobAction &JA) const {
665 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000666 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000667 Key = Action::AnalyzeJobClass;
668 else
669 Key = JA.getKind();
670
671 Tool *&T = Tools[Key];
672 if (!T) {
673 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000674 case Action::InputClass:
675 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000676 assert(0 && "Invalid tool kind.");
677 case Action::PreprocessJobClass:
678 T = new tools::gcc::Preprocess(*this); break;
679 case Action::PrecompileJobClass:
680 T = new tools::gcc::Precompile(*this); break;
681 case Action::AnalyzeJobClass:
682 T = new tools::Clang(*this); break;
683 case Action::CompileJobClass:
684 T = new tools::gcc::Compile(*this); break;
685 case Action::AssembleJobClass:
686 T = new tools::gcc::Assemble(*this); break;
687 case Action::LinkJobClass:
688 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000689
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000690 // This is a bit ungeneric, but the only platform using a driver
691 // driver is Darwin.
692 case Action::LipoJobClass:
693 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000694 }
695 }
696
697 return *T;
698}
699
Daniel Dunbar39176082009-03-20 00:20:03 +0000700bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000701 // FIXME: Gross; we should probably have some separate target
702 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000703 return getArchName() == "x86_64";
704}
705
706const char *Generic_GCC::GetDefaultRelocationModel() const {
707 return "static";
708}
709
710const char *Generic_GCC::GetForcedPicModel() const {
711 return 0;
712}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000713
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000714DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
715 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000716 return new DerivedArgList(Args, true);
717}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000718
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000719/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
720
721OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
722 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000723 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000724 getFilePaths().push_back("/usr/lib");
725}
726
727Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
728 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000729 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000730 Key = Action::AnalyzeJobClass;
731 else
732 Key = JA.getKind();
733
734 Tool *&T = Tools[Key];
735 if (!T) {
736 switch (Key) {
737 case Action::AssembleJobClass:
738 T = new tools::openbsd::Assemble(*this); break;
739 case Action::LinkJobClass:
740 T = new tools::openbsd::Link(*this); break;
741 default:
742 T = &Generic_GCC::SelectTool(C, JA);
743 }
744 }
745
746 return *T;
747}
748
Daniel Dunbar75358d22009-03-30 21:06:03 +0000749/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
750
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000751FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
752 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000753 if (Lib32) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000754 getFilePaths().push_back(getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000755 getFilePaths().push_back("/usr/lib32");
756 } else {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000757 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000758 getFilePaths().push_back("/usr/lib");
759 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000760}
761
762Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
763 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000764 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000765 Key = Action::AnalyzeJobClass;
766 else
767 Key = JA.getKind();
768
769 Tool *&T = Tools[Key];
770 if (!T) {
771 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000772 case Action::AssembleJobClass:
773 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000774 case Action::LinkJobClass:
775 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000776 default:
777 T = &Generic_GCC::SelectTool(C, JA);
778 }
779 }
780
781 return *T;
782}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000783
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000784/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
785
786AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
787 : Generic_GCC(Host, Triple) {
788
Daniel Dunbaree788e72009-12-21 18:54:17 +0000789 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000790
Daniel Dunbaree788e72009-12-21 18:54:17 +0000791 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000792 getFilePaths().push_back("/usr/lib");
793 getFilePaths().push_back("/usr/sfw/lib");
794 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +0000795 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000796
797}
798
799Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
800 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000801 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000802 Key = Action::AnalyzeJobClass;
803 else
804 Key = JA.getKind();
805
806 Tool *&T = Tools[Key];
807 if (!T) {
808 switch (Key) {
809 case Action::AssembleJobClass:
810 T = new tools::auroraux::Assemble(*this); break;
811 case Action::LinkJobClass:
812 T = new tools::auroraux::Link(*this); break;
813 default:
814 T = &Generic_GCC::SelectTool(C, JA);
815 }
816 }
817
818 return *T;
819}
820
821
Eli Friedman6b3454a2009-05-26 07:52:18 +0000822/// Linux toolchain (very bare-bones at the moment).
823
824Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
825 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000826 getFilePaths().push_back(getDriver().Dir + "/../lib/clang/1.0/");
Eli Friedman6b3454a2009-05-26 07:52:18 +0000827 getFilePaths().push_back("/lib/");
828 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000829
830 // Depending on the Linux distribution, any combination of lib{,32,64} is
831 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
832 // openSUSE uses lib and lib64 for the same purpose.
833 getFilePaths().push_back("/lib32/");
834 getFilePaths().push_back("/usr/lib32/");
835 getFilePaths().push_back("/lib64/");
836 getFilePaths().push_back("/usr/lib64/");
837
Eli Friedman6b3454a2009-05-26 07:52:18 +0000838 // FIXME: Figure out some way to get gcc's libdir
839 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
840 // crtbegin.o/crtend.o/etc., and want static versions of various
841 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
842 // get away with using shared versions in /usr/lib, though.
843 // We could fall back to the approach we used for includes (a massive
844 // list), but that's messy at best.
845}
846
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000847/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
848
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000849DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
850 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000851
852 // Path mangling to find libexec
Daniel Dunbaree788e72009-12-21 18:54:17 +0000853 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000854
Daniel Dunbaree788e72009-12-21 18:54:17 +0000855 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000856 getFilePaths().push_back("/usr/lib");
857 getFilePaths().push_back("/usr/lib/gcc41");
858}
859
860Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
861 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000862 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000863 Key = Action::AnalyzeJobClass;
864 else
865 Key = JA.getKind();
866
867 Tool *&T = Tools[Key];
868 if (!T) {
869 switch (Key) {
870 case Action::AssembleJobClass:
871 T = new tools::dragonfly::Assemble(*this); break;
872 case Action::LinkJobClass:
873 T = new tools::dragonfly::Link(*this); break;
874 default:
875 T = &Generic_GCC::SelectTool(C, JA);
876 }
877 }
878
879 return *T;
880}