blob: f07ce34f5112d77e8e37010393aa9de279123150 [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 Dunbarcc8e1892010-01-27 00:56:44 +000034 const unsigned (&_DarwinVersion)[3])
35 : ToolChain(Host, Triple), TargetInitialized(false)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000036{
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000037 DarwinVersion[0] = _DarwinVersion[0];
38 DarwinVersion[1] = _DarwinVersion[1];
39 DarwinVersion[2] = _DarwinVersion[2];
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000040
Daniel Dunbar02633b52009-03-26 16:23:12 +000041 llvm::raw_string_ostream(MacosxVersionMin)
Benjamin Kramer87f9fd92009-10-21 21:05:07 +000042 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.'
43 << DarwinVersion[1];
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000044}
45
Daniel Dunbareeff4062010-01-22 02:04:58 +000046// FIXME: Can we tablegen this?
47static const char *GetArmArchForMArch(llvm::StringRef Value) {
48 if (Value == "armv6k")
49 return "armv6";
50
51 if (Value == "armv5tej")
52 return "armv5";
53
54 if (Value == "xscale")
55 return "xscale";
56
57 if (Value == "armv4t")
58 return "armv4t";
59
60 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
61 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
62 Value == "armv7m")
63 return "armv7";
64
65 return 0;
66}
67
68// FIXME: Can we tablegen this?
69static const char *GetArmArchForMCpu(llvm::StringRef Value) {
70 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
71 Value == "arm946e-s" || Value == "arm966e-s" ||
72 Value == "arm968e-s" || Value == "arm10e" ||
73 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
74 Value == "arm1026ej-s")
75 return "armv5";
76
77 if (Value == "xscale")
78 return "xscale";
79
80 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
81 Value == "arm1176jz-s" || Value == "arm1176jzf-s")
82 return "armv6";
83
84 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
85 return "armv7";
86
87 return 0;
88}
89
90llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
91 switch (getTriple().getArch()) {
92 default:
93 return getArchName();
94
95 case llvm::Triple::arm: {
96 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
97 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
98 return Arch;
99
100 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
101 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
102 return Arch;
103
104 return "arm";
105 }
106 }
107}
108
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000109DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
110 const unsigned (&DarwinVersion)[3],
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000111 const unsigned (&_GCCVersion)[3])
112 : Darwin(Host, Triple, DarwinVersion)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000113{
114 GCCVersion[0] = _GCCVersion[0];
115 GCCVersion[1] = _GCCVersion[1];
116 GCCVersion[2] = _GCCVersion[2];
117
118 // Set up the tool chain paths to match gcc.
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000119 ToolChainDir = "i686-apple-darwin";
Ted Kremenek55bac532009-10-07 03:21:11 +0000120 ToolChainDir += llvm::utostr(DarwinVersion[0]);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000121 ToolChainDir += "/";
122 ToolChainDir += llvm::utostr(GCCVersion[0]);
123 ToolChainDir += '.';
124 ToolChainDir += llvm::utostr(GCCVersion[1]);
125 ToolChainDir += '.';
126 ToolChainDir += llvm::utostr(GCCVersion[2]);
127
Daniel Dunbar74782b02009-10-20 19:25:43 +0000128 // Try the next major version if that tool chain dir is invalid.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000129 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir;
130 if (!llvm::sys::Path(Tmp).exists()) {
Daniel Dunbar74782b02009-10-20 19:25:43 +0000131 std::string Next = "i686-apple-darwin";
132 Next += llvm::utostr(DarwinVersion[0] + 1);
133 Next += "/";
134 Next += llvm::utostr(GCCVersion[0]);
135 Next += '.';
136 Next += llvm::utostr(GCCVersion[1]);
137 Next += '.';
138 Next += llvm::utostr(GCCVersion[2]);
139
140 // Use that if it exists, otherwise hope the user isn't linking.
141 //
142 // FIXME: Drop dependency on gcc's tool chain.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000143 Tmp = "/usr/lib/gcc/" + Next;
144 if (llvm::sys::Path(Tmp).exists())
Daniel Dunbar74782b02009-10-20 19:25:43 +0000145 ToolChainDir = Next;
146 }
147
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000148 std::string Path;
149 if (getArchName() == "x86_64") {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000150 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000151 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000152 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000153 Path += "/x86_64";
154 getFilePaths().push_back(Path);
155
156 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000157 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000158 Path += "/x86_64";
159 getFilePaths().push_back(Path);
160 }
Mike Stump1eb44332009-09-09 15:08:12 +0000161
Daniel Dunbaree788e72009-12-21 18:54:17 +0000162 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000163 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000164 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000165 getFilePaths().push_back(Path);
166
167 Path = "/usr/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
Daniel Dunbaree788e72009-12-21 18:54:17 +0000171 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000172 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000173 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000174 getProgramPaths().push_back(Path);
175
176 Path = "/usr/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
Daniel Dunbaree788e72009-12-21 18:54:17 +0000180 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000181}
182
Daniel Dunbarf3955282009-09-04 18:34:51 +0000183Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000184 // Free tool implementations.
185 for (llvm::DenseMap<unsigned, Tool*>::iterator
186 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
187 delete it->second;
188}
189
Daniel Dunbarf3955282009-09-04 18:34:51 +0000190Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000191 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000192 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000193 Key = Action::AnalyzeJobClass;
194 else
195 Key = JA.getKind();
196
197 Tool *&T = Tools[Key];
198 if (!T) {
199 switch (Key) {
200 case Action::InputClass:
201 case Action::BindArchClass:
202 assert(0 && "Invalid tool kind.");
203 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000204 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000205 case Action::AnalyzeJobClass:
206 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000207 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000208 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000209 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000210 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000211 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000212 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000213 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000214 case Action::LipoJobClass:
215 T = new tools::darwin::Lipo(*this); break;
216 }
217 }
218
219 return *T;
220}
221
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000222void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
223 ArgStringList &CmdArgs) const {
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000224 // FIXME: Derive these correctly.
225 if (getArchName() == "x86_64") {
226 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
227 "/x86_64"));
228 // Intentionally duplicated for (temporary) gcc bug compatibility.
229 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
230 "/x86_64"));
231 }
232 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
233 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
234 // Intentionally duplicated for (temporary) gcc bug compatibility.
235 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
236 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
237 "/../../../" + ToolChainDir));
238 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
239 "/../../.."));
240}
241
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000242void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
243 ArgStringList &CmdArgs) const {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000244 unsigned MacosxVersionMin[3];
245 getMacosxVersionMin(Args, MacosxVersionMin);
246
247 // Derived from libgcc and lib specs but refactored.
248 if (Args.hasArg(options::OPT_static)) {
249 CmdArgs.push_back("-lgcc_static");
250 } else {
251 if (Args.hasArg(options::OPT_static_libgcc)) {
252 CmdArgs.push_back("-lgcc_eh");
253 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
254 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000255 if (isTargetIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000256 CmdArgs.push_back("-lgcc_s.1");
257 } else {
258 CmdArgs.push_back("-lgcc_s.10.5");
259 }
260 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
Daniel Dunbar8a0d94d2010-01-10 00:46:10 +0000261 Args.hasFlag(options::OPT_fexceptions,
262 options::OPT_fno_exceptions) ||
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000263 Args.hasArg(options::OPT_fgnu_runtime)) {
264 // FIXME: This is probably broken on 10.3?
265 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
266 CmdArgs.push_back("-lgcc_s.10.4");
267 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
268 CmdArgs.push_back("-lgcc_s.10.5");
269 } else {
270 if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9))
271 ; // Do nothing.
272 else if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
273 CmdArgs.push_back("-lgcc_s.10.4");
274 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
275 CmdArgs.push_back("-lgcc_s.10.5");
276 }
277
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000278 if (isTargetIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000279 CmdArgs.push_back("-lgcc");
280 CmdArgs.push_back("-lSystem");
281 } else {
282 CmdArgs.push_back("-lSystem");
283 CmdArgs.push_back("-lgcc");
284 }
285 }
286}
287
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000288DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000289 const unsigned (&DarwinVersion)[3])
290 : Darwin(Host, Triple, DarwinVersion)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000291{
292 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaree788e72009-12-21 18:54:17 +0000293 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000294}
295
296void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
297 ArgStringList &CmdArgs) const {
298 // The Clang toolchain uses explicit paths for internal libraries.
299}
300
301void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
302 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000303 // Darwin doesn't support real static executables, don't link any runtime
304 // libraries with -static.
305 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000306 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000307
308 // Reject -static-libgcc for now, we can deal with this when and if someone
309 // cares. This is useful in situations where someone wants to statically link
310 // something like libstdc++, and needs its runtime support routines.
311 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000312 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000313 << A->getAsString(Args);
314 return;
315 }
316
Daniel Dunbareec99102010-01-22 03:38:14 +0000317 // Otherwise link libSystem, then the dynamic runtime library, and finally any
318 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000319 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000320
321 // Select the dynamic runtime library and the target specific static library.
322 const char *DarwinStaticLib = 0;
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000323 if (isTargetIPhoneOS()) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000324 CmdArgs.push_back("-lgcc_s.1");
325
326 // We may need some static functions for armv6/thumb which are required to
327 // be in the same linkage unit as their caller.
328 if (getDarwinArchName(Args) == "armv6")
329 DarwinStaticLib = "libclang_rt.armv6.a";
330 } else {
331 unsigned MacosxVersionMin[3];
332 getMacosxVersionMin(Args, MacosxVersionMin);
333
334 // The dynamic runtime library was merged with libSystem for 10.6 and
335 // beyond; only 10.4 and 10.5 need an additional runtime library.
336 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
337 CmdArgs.push_back("-lgcc_s.10.4");
338 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
339 CmdArgs.push_back("-lgcc_s.10.5");
340
341 // For OS X, we only need a static runtime library when targetting 10.4, to
342 // provide versions of the static functions which were omitted from
343 // 10.4.dylib.
344 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
345 DarwinStaticLib = "libclang_rt.10.4.a";
346 }
347
348 /// Add the target specific static library, if needed.
349 if (DarwinStaticLib) {
350 llvm::sys::Path P(getDriver().ResourceDir);
351 P.appendComponent("lib");
352 P.appendComponent("darwin");
353 P.appendComponent(DarwinStaticLib);
354
355 // For now, allow missing resource libraries to support developers who may
356 // not have compiler-rt checked out or integrated into their build.
357 if (!P.exists())
358 getDriver().Diag(clang::diag::warn_drv_missing_resource_library)
359 << P.str();
360 else
361 CmdArgs.push_back(Args.MakeArgString(P.str()));
362 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000363}
364
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000365void Darwin::getMacosxVersionMin(const ArgList &Args,
366 unsigned (&Res)[3]) const {
367 if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
368 bool HadExtra;
369 if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2],
370 HadExtra) ||
371 HadExtra) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000372 const Driver &D = getDriver();
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000373 D.Diag(clang::diag::err_drv_invalid_version_number)
374 << A->getAsString(Args);
375 }
376 } else
377 return getMacosxVersion(Res);
378}
379
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000380DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
381 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000382 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbaree788e72009-12-21 18:54:17 +0000383 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000384
385 // FIXME: We really want to get out of the tool chain level argument
386 // translation business, as it makes the driver functionality much
387 // more opaque. For now, we follow gcc closely solely for the
388 // purpose of easily achieving feature parity & testability. Once we
389 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000390 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000391
Daniel Dunbar26031372010-01-27 00:56:25 +0000392 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
393 Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000394 if (OSXVersion && iPhoneVersion) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000395 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000396 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000397 << iPhoneVersion->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000398 iPhoneVersion = 0;
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000399 } else if (!OSXVersion && !iPhoneVersion) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000400 // If neither OS X nor iPhoneOS targets were specified, check for
401 // environment defines.
402 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
403 const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000404
Daniel Dunbar816bc312010-01-26 01:45:19 +0000405 // Ignore empty strings.
406 if (OSXTarget && OSXTarget[0] == '\0')
407 OSXTarget = 0;
408 if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0')
409 iPhoneOSTarget = 0;
410
411 if (OSXTarget && iPhoneOSTarget) {
412 getDriver().Diag(clang::diag::err_drv_conflicting_deployment_targets)
413 << OSXTarget << iPhoneOSTarget;
414 } else if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000415 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000416 OSXVersion = DAL->MakeJoinedArg(0, O, OSXTarget);
417 DAL->append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000418 } else if (iPhoneOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000419 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000420 iPhoneVersion = DAL->MakeJoinedArg(0, O, iPhoneOSTarget);
421 DAL->append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000422 } else {
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000423 // Otherwise, choose a default platform based on the tool chain.
424 //
425 // FIXME: Don't hardcode default here.
426 if (getTriple().getArch() == llvm::Triple::arm ||
427 getTriple().getArch() == llvm::Triple::thumb) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000428 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarcc8e1892010-01-27 00:56:44 +0000429 iPhoneVersion = DAL->MakeJoinedArg(0, O, "3.0");
Daniel Dunbar26031372010-01-27 00:56:25 +0000430 DAL->append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000431 } else {
432 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000433 OSXVersion = DAL->MakeJoinedArg(0, O, MacosxVersionMin);
434 DAL->append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000435 }
Daniel Dunbar30392de2009-09-04 18:35:21 +0000436 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000437 }
Mike Stump1eb44332009-09-09 15:08:12 +0000438
Daniel Dunbar26031372010-01-27 00:56:25 +0000439 // Set the tool chain target information.
440 unsigned Major, Minor, Micro;
441 bool HadExtra;
442 if (OSXVersion) {
443 assert(!iPhoneVersion && "Unknown target platform!");
444 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
445 Micro, HadExtra) || HadExtra ||
446 Major != 10 || Minor >= 10 || Micro >= 10)
447 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
448 << OSXVersion->getAsString(Args);
449 } else {
450 assert(iPhoneVersion && "Unknown target platform!");
451 if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor,
452 Micro, HadExtra) || HadExtra ||
453 Major >= 10 || Minor >= 100 || Micro >= 100)
454 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
455 << iPhoneVersion->getAsString(Args);
456 }
457 setTarget(iPhoneVersion, Major, Minor, Micro);
458
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000459 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
460 Arg *A = *it;
461
462 if (A->getOption().matches(options::OPT_Xarch__)) {
463 // FIXME: Canonicalize name.
464 if (getArchName() != A->getValue(Args, 0))
465 continue;
466
467 // FIXME: The arg is leaked here, and we should have a nicer
468 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000469 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000470 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000471
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000472 // If the argument parsing failed or more than one argument was
473 // consumed, the -Xarch_ argument's parameter tried to consume
474 // extra arguments. Emit an error and ignore.
475 //
476 // We also want to disallow any options which would alter the
477 // driver behavior; that isn't going to work in our model. We
478 // use isDriverOption() as an approximation, although things
479 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000480 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000481 XarchArg->getOption().isDriverOption()) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000482 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000483 << A->getAsString(Args);
484 continue;
485 }
486
Daniel Dunbar478edc22009-03-29 22:29:05 +0000487 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000488 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000489 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000490
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000491 // Sob. These is strictly gcc compatible for the time being. Apple
492 // gcc translates options twice, which means that self-expanding
493 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000494 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000495 default:
496 DAL->append(A);
497 break;
498
499 case options::OPT_mkernel:
500 case options::OPT_fapple_kext:
501 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000502 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
503 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000504 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000505
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000506 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000507 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000508 A->getValue(Args)));
509 break;
510
511 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000512 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
513 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000514 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
515 break;
516
517 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000518 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
519 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000520 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
521 break;
522
523 case options::OPT_fterminated_vtables:
524 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000525 DAL->append(DAL->MakeFlagArg(A,
526 Opts.getOption(options::OPT_fapple_kext)));
527 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000528 break;
529
530 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000531 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000532 break;
533
534 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000535 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000536 Opts.getOption(options::OPT_mconstant_cfstrings)));
537 break;
538
539 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000540 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000541 Opts.getOption(options::OPT_mno_constant_cfstrings)));
542 break;
543
544 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000545 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000546 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
547 break;
548
549 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000550 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000551 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
552 break;
553
554 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000555 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000556 Opts.getOption(options::OPT_mpascal_strings)));
557 break;
558
559 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000560 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000561 Opts.getOption(options::OPT_mno_pascal_strings)));
562 break;
563 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000564 }
565
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000566 if (getTriple().getArch() == llvm::Triple::x86 ||
567 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000568 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000569 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
570 "core2"));
571
572 // Add the arch options based on the particular spelling of -arch, to match
573 // how the driver driver works.
574 if (BoundArch) {
575 llvm::StringRef Name = BoundArch;
576 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
577 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
578
579 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
580 // which defines the list of which architectures we accept.
581 if (Name == "ppc")
582 ;
583 else if (Name == "ppc601")
584 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
585 else if (Name == "ppc603")
586 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
587 else if (Name == "ppc604")
588 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
589 else if (Name == "ppc604e")
590 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
591 else if (Name == "ppc750")
592 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
593 else if (Name == "ppc7400")
594 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
595 else if (Name == "ppc7450")
596 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
597 else if (Name == "ppc970")
598 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
599
600 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000601 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000602
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000603 else if (Name == "i386")
604 ;
605 else if (Name == "i486")
606 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
607 else if (Name == "i586")
608 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
609 else if (Name == "i686")
610 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
611 else if (Name == "pentium")
612 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
613 else if (Name == "pentium2")
614 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
615 else if (Name == "pentpro")
616 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
617 else if (Name == "pentIIm3")
618 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
619
620 else if (Name == "x86_64")
621 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
622
623 else if (Name == "arm")
624 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
625 else if (Name == "armv4t")
626 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
627 else if (Name == "armv5")
628 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
629 else if (Name == "xscale")
630 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
631 else if (Name == "armv6")
632 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
633 else if (Name == "armv7")
634 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
635
636 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000637 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000638 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000639
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000640 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000641}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000642
Daniel Dunbarf3955282009-09-04 18:34:51 +0000643bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000644 // FIXME: Gross; we should probably have some separate target
645 // definition, possibly even reusing the one in clang.
646 return getArchName() == "x86_64";
647}
648
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000649bool Darwin::UseDwarfDebugFlags() const {
650 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
651 return S[0] != '\0';
652 return false;
653}
654
Daniel Dunbarf3955282009-09-04 18:34:51 +0000655const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000656 return "pic";
657}
658
Daniel Dunbarf3955282009-09-04 18:34:51 +0000659const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000660 if (getArchName() == "x86_64")
661 return "pic";
662 return 0;
663}
664
Daniel Dunbar39176082009-03-20 00:20:03 +0000665/// Generic_GCC - A tool chain using the 'gcc' command to perform
666/// all subcommands; this relies on gcc translating the majority of
667/// command line options.
668
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000669Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000670 : ToolChain(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000671 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000672}
673
Daniel Dunbar39176082009-03-20 00:20:03 +0000674Generic_GCC::~Generic_GCC() {
675 // Free tool implementations.
676 for (llvm::DenseMap<unsigned, Tool*>::iterator
677 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
678 delete it->second;
679}
680
Mike Stump1eb44332009-09-09 15:08:12 +0000681Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000682 const JobAction &JA) const {
683 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000684 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000685 Key = Action::AnalyzeJobClass;
686 else
687 Key = JA.getKind();
688
689 Tool *&T = Tools[Key];
690 if (!T) {
691 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000692 case Action::InputClass:
693 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000694 assert(0 && "Invalid tool kind.");
695 case Action::PreprocessJobClass:
696 T = new tools::gcc::Preprocess(*this); break;
697 case Action::PrecompileJobClass:
698 T = new tools::gcc::Precompile(*this); break;
699 case Action::AnalyzeJobClass:
700 T = new tools::Clang(*this); break;
701 case Action::CompileJobClass:
702 T = new tools::gcc::Compile(*this); break;
703 case Action::AssembleJobClass:
704 T = new tools::gcc::Assemble(*this); break;
705 case Action::LinkJobClass:
706 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000707
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000708 // This is a bit ungeneric, but the only platform using a driver
709 // driver is Darwin.
710 case Action::LipoJobClass:
711 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000712 }
713 }
714
715 return *T;
716}
717
Daniel Dunbar39176082009-03-20 00:20:03 +0000718bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000719 // FIXME: Gross; we should probably have some separate target
720 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000721 return getArchName() == "x86_64";
722}
723
724const char *Generic_GCC::GetDefaultRelocationModel() const {
725 return "static";
726}
727
728const char *Generic_GCC::GetForcedPicModel() const {
729 return 0;
730}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000731
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000732DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
733 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000734 return new DerivedArgList(Args, true);
735}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000736
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000737/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
738
739OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
740 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000741 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000742 getFilePaths().push_back("/usr/lib");
743}
744
745Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
746 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000747 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000748 Key = Action::AnalyzeJobClass;
749 else
750 Key = JA.getKind();
751
752 Tool *&T = Tools[Key];
753 if (!T) {
754 switch (Key) {
755 case Action::AssembleJobClass:
756 T = new tools::openbsd::Assemble(*this); break;
757 case Action::LinkJobClass:
758 T = new tools::openbsd::Link(*this); break;
759 default:
760 T = &Generic_GCC::SelectTool(C, JA);
761 }
762 }
763
764 return *T;
765}
766
Daniel Dunbar75358d22009-03-30 21:06:03 +0000767/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
768
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000769FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
770 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000771 if (Lib32) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000772 getFilePaths().push_back(getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000773 getFilePaths().push_back("/usr/lib32");
774 } else {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000775 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000776 getFilePaths().push_back("/usr/lib");
777 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000778}
779
780Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
781 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000782 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000783 Key = Action::AnalyzeJobClass;
784 else
785 Key = JA.getKind();
786
787 Tool *&T = Tools[Key];
788 if (!T) {
789 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000790 case Action::AssembleJobClass:
791 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000792 case Action::LinkJobClass:
793 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000794 default:
795 T = &Generic_GCC::SelectTool(C, JA);
796 }
797 }
798
799 return *T;
800}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000801
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000802/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
803
804AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
805 : Generic_GCC(Host, Triple) {
806
Daniel Dunbaree788e72009-12-21 18:54:17 +0000807 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000808
Daniel Dunbaree788e72009-12-21 18:54:17 +0000809 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000810 getFilePaths().push_back("/usr/lib");
811 getFilePaths().push_back("/usr/sfw/lib");
812 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +0000813 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000814
815}
816
817Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
818 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000819 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000820 Key = Action::AnalyzeJobClass;
821 else
822 Key = JA.getKind();
823
824 Tool *&T = Tools[Key];
825 if (!T) {
826 switch (Key) {
827 case Action::AssembleJobClass:
828 T = new tools::auroraux::Assemble(*this); break;
829 case Action::LinkJobClass:
830 T = new tools::auroraux::Link(*this); break;
831 default:
832 T = &Generic_GCC::SelectTool(C, JA);
833 }
834 }
835
836 return *T;
837}
838
839
Eli Friedman6b3454a2009-05-26 07:52:18 +0000840/// Linux toolchain (very bare-bones at the moment).
841
842Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
843 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000844 getFilePaths().push_back(getDriver().Dir + "/../lib/clang/1.0/");
Eli Friedman6b3454a2009-05-26 07:52:18 +0000845 getFilePaths().push_back("/lib/");
846 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000847
848 // Depending on the Linux distribution, any combination of lib{,32,64} is
849 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
850 // openSUSE uses lib and lib64 for the same purpose.
851 getFilePaths().push_back("/lib32/");
852 getFilePaths().push_back("/usr/lib32/");
853 getFilePaths().push_back("/lib64/");
854 getFilePaths().push_back("/usr/lib64/");
855
Eli Friedman6b3454a2009-05-26 07:52:18 +0000856 // FIXME: Figure out some way to get gcc's libdir
857 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
858 // crtbegin.o/crtend.o/etc., and want static versions of various
859 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
860 // get away with using shared versions in /usr/lib, though.
861 // We could fall back to the approach we used for includes (a massive
862 // list), but that's messy at best.
863}
864
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000865/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
866
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000867DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
868 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000869
870 // Path mangling to find libexec
Daniel Dunbaree788e72009-12-21 18:54:17 +0000871 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000872
Daniel Dunbaree788e72009-12-21 18:54:17 +0000873 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000874 getFilePaths().push_back("/usr/lib");
875 getFilePaths().push_back("/usr/lib/gcc41");
876}
877
878Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
879 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000880 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000881 Key = Action::AnalyzeJobClass;
882 else
883 Key = JA.getKind();
884
885 Tool *&T = Tools[Key];
886 if (!T) {
887 switch (Key) {
888 case Action::AssembleJobClass:
889 T = new tools::dragonfly::Assemble(*this); break;
890 case Action::LinkJobClass:
891 T = new tools::dragonfly::Link(*this); break;
892 default:
893 T = &Generic_GCC::SelectTool(C, JA);
894 }
895 }
896
897 return *T;
898}