blob: a48a91c569a0a19e971e4b883d898badfd4962f0 [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)
Daniel Dunbar26031372010-01-27 00:56:25 +000035 : ToolChain(Host, Triple), TargetInitialized(false), IsIPhoneOS(_IsIPhoneOS)
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 Dunbar02633b52009-03-26 16:23:12 +000044
Daniel Dunbar30392de2009-09-04 18:35:21 +000045 // FIXME: Lift default up.
46 IPhoneOSVersionMin = "3.0";
Daniel Dunbar1d4612b2009-09-18 08:15:13 +000047}
48
Daniel Dunbareeff4062010-01-22 02:04:58 +000049// FIXME: Can we tablegen this?
50static const char *GetArmArchForMArch(llvm::StringRef Value) {
51 if (Value == "armv6k")
52 return "armv6";
53
54 if (Value == "armv5tej")
55 return "armv5";
56
57 if (Value == "xscale")
58 return "xscale";
59
60 if (Value == "armv4t")
61 return "armv4t";
62
63 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" ||
64 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" ||
65 Value == "armv7m")
66 return "armv7";
67
68 return 0;
69}
70
71// FIXME: Can we tablegen this?
72static const char *GetArmArchForMCpu(llvm::StringRef Value) {
73 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" ||
74 Value == "arm946e-s" || Value == "arm966e-s" ||
75 Value == "arm968e-s" || Value == "arm10e" ||
76 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" ||
77 Value == "arm1026ej-s")
78 return "armv5";
79
80 if (Value == "xscale")
81 return "xscale";
82
83 if (Value == "arm1136j-s" || Value == "arm1136jf-s" ||
84 Value == "arm1176jz-s" || Value == "arm1176jzf-s")
85 return "armv6";
86
87 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3")
88 return "armv7";
89
90 return 0;
91}
92
93llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const {
94 switch (getTriple().getArch()) {
95 default:
96 return getArchName();
97
98 case llvm::Triple::arm: {
99 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
100 if (const char *Arch = GetArmArchForMArch(A->getValue(Args)))
101 return Arch;
102
103 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
104 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args)))
105 return Arch;
106
107 return "arm";
108 }
109 }
110}
111
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000112DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
113 const unsigned (&DarwinVersion)[3],
Ted Kremenek55bac532009-10-07 03:21:11 +0000114 const unsigned (&_GCCVersion)[3], bool IsIPhoneOS)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000115 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
116{
117 GCCVersion[0] = _GCCVersion[0];
118 GCCVersion[1] = _GCCVersion[1];
119 GCCVersion[2] = _GCCVersion[2];
120
121 // Set up the tool chain paths to match gcc.
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000122 ToolChainDir = "i686-apple-darwin";
Ted Kremenek55bac532009-10-07 03:21:11 +0000123 ToolChainDir += llvm::utostr(DarwinVersion[0]);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000124 ToolChainDir += "/";
125 ToolChainDir += llvm::utostr(GCCVersion[0]);
126 ToolChainDir += '.';
127 ToolChainDir += llvm::utostr(GCCVersion[1]);
128 ToolChainDir += '.';
129 ToolChainDir += llvm::utostr(GCCVersion[2]);
130
Daniel Dunbar74782b02009-10-20 19:25:43 +0000131 // Try the next major version if that tool chain dir is invalid.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000132 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir;
133 if (!llvm::sys::Path(Tmp).exists()) {
Daniel Dunbar74782b02009-10-20 19:25:43 +0000134 std::string Next = "i686-apple-darwin";
135 Next += llvm::utostr(DarwinVersion[0] + 1);
136 Next += "/";
137 Next += llvm::utostr(GCCVersion[0]);
138 Next += '.';
139 Next += llvm::utostr(GCCVersion[1]);
140 Next += '.';
141 Next += llvm::utostr(GCCVersion[2]);
142
143 // Use that if it exists, otherwise hope the user isn't linking.
144 //
145 // FIXME: Drop dependency on gcc's tool chain.
Daniel Dunbar080fb192009-10-22 00:12:00 +0000146 Tmp = "/usr/lib/gcc/" + Next;
147 if (llvm::sys::Path(Tmp).exists())
Daniel Dunbar74782b02009-10-20 19:25:43 +0000148 ToolChainDir = Next;
149 }
150
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000151 std::string Path;
152 if (getArchName() == "x86_64") {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000153 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000154 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000155 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000156 Path += "/x86_64";
157 getFilePaths().push_back(Path);
158
159 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000160 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000161 Path += "/x86_64";
162 getFilePaths().push_back(Path);
163 }
Mike Stump1eb44332009-09-09 15:08:12 +0000164
Daniel Dunbaree788e72009-12-21 18:54:17 +0000165 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000166 Path += "/../lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000167 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000168 getFilePaths().push_back(Path);
169
170 Path = "/usr/lib/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000171 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000172 getFilePaths().push_back(Path);
173
Daniel Dunbaree788e72009-12-21 18:54:17 +0000174 Path = getDriver().Dir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000175 Path += "/../libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000176 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000177 getProgramPaths().push_back(Path);
178
179 Path = "/usr/libexec/gcc/";
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000180 Path += ToolChainDir;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000181 getProgramPaths().push_back(Path);
182
Daniel Dunbaree788e72009-12-21 18:54:17 +0000183 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000184}
185
Daniel Dunbarf3955282009-09-04 18:34:51 +0000186Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000187 // Free tool implementations.
188 for (llvm::DenseMap<unsigned, Tool*>::iterator
189 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
190 delete it->second;
191}
192
Daniel Dunbarf3955282009-09-04 18:34:51 +0000193Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000194 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000195 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000196 Key = Action::AnalyzeJobClass;
197 else
198 Key = JA.getKind();
199
200 Tool *&T = Tools[Key];
201 if (!T) {
202 switch (Key) {
203 case Action::InputClass:
204 case Action::BindArchClass:
205 assert(0 && "Invalid tool kind.");
206 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000207 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000208 case Action::AnalyzeJobClass:
209 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000210 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000211 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000212 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000213 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000214 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000215 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000216 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000217 case Action::LipoJobClass:
218 T = new tools::darwin::Lipo(*this); break;
219 }
220 }
221
222 return *T;
223}
224
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000225void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
226 ArgStringList &CmdArgs) const {
Daniel Dunbar6b200b22009-09-18 08:14:36 +0000227 // FIXME: Derive these correctly.
228 if (getArchName() == "x86_64") {
229 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
230 "/x86_64"));
231 // Intentionally duplicated for (temporary) gcc bug compatibility.
232 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
233 "/x86_64"));
234 }
235 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir));
236 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
237 // Intentionally duplicated for (temporary) gcc bug compatibility.
238 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir));
239 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
240 "/../../../" + ToolChainDir));
241 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
242 "/../../.."));
243}
244
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000245void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
246 ArgStringList &CmdArgs) const {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000247 unsigned MacosxVersionMin[3];
248 getMacosxVersionMin(Args, MacosxVersionMin);
249
250 // Derived from libgcc and lib specs but refactored.
251 if (Args.hasArg(options::OPT_static)) {
252 CmdArgs.push_back("-lgcc_static");
253 } else {
254 if (Args.hasArg(options::OPT_static_libgcc)) {
255 CmdArgs.push_back("-lgcc_eh");
256 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
257 // Derived from darwin_iphoneos_libgcc spec.
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000258 if (isTargetIPhoneOS()) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000259 CmdArgs.push_back("-lgcc_s.1");
260 } else {
261 CmdArgs.push_back("-lgcc_s.10.5");
262 }
263 } else if (Args.hasArg(options::OPT_shared_libgcc) ||
Daniel Dunbar8a0d94d2010-01-10 00:46:10 +0000264 Args.hasFlag(options::OPT_fexceptions,
265 options::OPT_fno_exceptions) ||
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000266 Args.hasArg(options::OPT_fgnu_runtime)) {
267 // FIXME: This is probably broken on 10.3?
268 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
269 CmdArgs.push_back("-lgcc_s.10.4");
270 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
271 CmdArgs.push_back("-lgcc_s.10.5");
272 } else {
273 if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9))
274 ; // Do nothing.
275 else if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
276 CmdArgs.push_back("-lgcc_s.10.4");
277 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
278 CmdArgs.push_back("-lgcc_s.10.5");
279 }
280
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000281 if (isTargetIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
Daniel Dunbar6cd41542009-09-18 08:15:03 +0000282 CmdArgs.push_back("-lgcc");
283 CmdArgs.push_back("-lSystem");
284 } else {
285 CmdArgs.push_back("-lSystem");
286 CmdArgs.push_back("-lgcc");
287 }
288 }
289}
290
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000291DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
292 const unsigned (&DarwinVersion)[3],
293 bool IsIPhoneOS)
294 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
295{
296 // We expect 'as', 'ld', etc. to be adjacent to our install dir.
Daniel Dunbaree788e72009-12-21 18:54:17 +0000297 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000298}
299
300void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
301 ArgStringList &CmdArgs) const {
302 // The Clang toolchain uses explicit paths for internal libraries.
303}
304
305void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
306 ArgStringList &CmdArgs) const {
Daniel Dunbareec99102010-01-22 03:38:14 +0000307 // Darwin doesn't support real static executables, don't link any runtime
308 // libraries with -static.
309 if (Args.hasArg(options::OPT_static))
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000310 return;
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000311
312 // Reject -static-libgcc for now, we can deal with this when and if someone
313 // cares. This is useful in situations where someone wants to statically link
314 // something like libstdc++, and needs its runtime support routines.
315 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000316 getDriver().Diag(clang::diag::err_drv_unsupported_opt)
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000317 << A->getAsString(Args);
318 return;
319 }
320
Daniel Dunbareec99102010-01-22 03:38:14 +0000321 // Otherwise link libSystem, then the dynamic runtime library, and finally any
322 // target specific static runtime library.
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000323 CmdArgs.push_back("-lSystem");
Daniel Dunbareec99102010-01-22 03:38:14 +0000324
325 // Select the dynamic runtime library and the target specific static library.
326 const char *DarwinStaticLib = 0;
Daniel Dunbar251ca6c2010-01-27 00:56:37 +0000327 if (isTargetIPhoneOS()) {
Daniel Dunbareec99102010-01-22 03:38:14 +0000328 CmdArgs.push_back("-lgcc_s.1");
329
330 // We may need some static functions for armv6/thumb which are required to
331 // be in the same linkage unit as their caller.
332 if (getDarwinArchName(Args) == "armv6")
333 DarwinStaticLib = "libclang_rt.armv6.a";
334 } else {
335 unsigned MacosxVersionMin[3];
336 getMacosxVersionMin(Args, MacosxVersionMin);
337
338 // The dynamic runtime library was merged with libSystem for 10.6 and
339 // beyond; only 10.4 and 10.5 need an additional runtime library.
340 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
341 CmdArgs.push_back("-lgcc_s.10.4");
342 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
343 CmdArgs.push_back("-lgcc_s.10.5");
344
345 // For OS X, we only need a static runtime library when targetting 10.4, to
346 // provide versions of the static functions which were omitted from
347 // 10.4.dylib.
348 if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
349 DarwinStaticLib = "libclang_rt.10.4.a";
350 }
351
352 /// Add the target specific static library, if needed.
353 if (DarwinStaticLib) {
354 llvm::sys::Path P(getDriver().ResourceDir);
355 P.appendComponent("lib");
356 P.appendComponent("darwin");
357 P.appendComponent(DarwinStaticLib);
358
359 // For now, allow missing resource libraries to support developers who may
360 // not have compiler-rt checked out or integrated into their build.
361 if (!P.exists())
362 getDriver().Diag(clang::diag::warn_drv_missing_resource_library)
363 << P.str();
364 else
365 CmdArgs.push_back(Args.MakeArgString(P.str()));
366 }
Daniel Dunbar1d4612b2009-09-18 08:15:13 +0000367}
368
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000369void Darwin::getMacosxVersionMin(const ArgList &Args,
370 unsigned (&Res)[3]) const {
371 if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
372 bool HadExtra;
373 if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2],
374 HadExtra) ||
375 HadExtra) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000376 const Driver &D = getDriver();
Daniel Dunbar48d5aae2009-09-18 08:14:46 +0000377 D.Diag(clang::diag::err_drv_invalid_version_number)
378 << A->getAsString(Args);
379 }
380 } else
381 return getMacosxVersion(Res);
382}
383
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000384DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
385 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000386 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbaree788e72009-12-21 18:54:17 +0000387 const OptTable &Opts = getDriver().getOpts();
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000388
389 // FIXME: We really want to get out of the tool chain level argument
390 // translation business, as it makes the driver functionality much
391 // more opaque. For now, we follow gcc closely solely for the
392 // purpose of easily achieving feature parity & testability. Once we
393 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000394 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000395
Daniel Dunbar26031372010-01-27 00:56:25 +0000396 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ);
397 Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000398 if (OSXVersion && iPhoneVersion) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000399 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000400 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000401 << iPhoneVersion->getAsString(Args);
Daniel Dunbar26031372010-01-27 00:56:25 +0000402 iPhoneVersion = 0;
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000403 } else if (!OSXVersion && !iPhoneVersion) {
Daniel Dunbar816bc312010-01-26 01:45:19 +0000404 // If neither OS X nor iPhoneOS targets were specified, check for
405 // environment defines.
406 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET");
407 const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET");
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000408
Daniel Dunbar816bc312010-01-26 01:45:19 +0000409 // Ignore empty strings.
410 if (OSXTarget && OSXTarget[0] == '\0')
411 OSXTarget = 0;
412 if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0')
413 iPhoneOSTarget = 0;
414
415 if (OSXTarget && iPhoneOSTarget) {
416 getDriver().Diag(clang::diag::err_drv_conflicting_deployment_targets)
417 << OSXTarget << iPhoneOSTarget;
418 } else if (OSXTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000419 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000420 OSXVersion = DAL->MakeJoinedArg(0, O, OSXTarget);
421 DAL->append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000422 } else if (iPhoneOSTarget) {
Daniel Dunbar30392de2009-09-04 18:35:21 +0000423 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000424 iPhoneVersion = DAL->MakeJoinedArg(0, O, iPhoneOSTarget);
425 DAL->append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000426 } 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);
Daniel Dunbar26031372010-01-27 00:56:25 +0000433 iPhoneVersion = DAL->MakeJoinedArg(0, O, IPhoneOSVersionMin) ;
434 DAL->append(iPhoneVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000435 } else {
436 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
Daniel Dunbar26031372010-01-27 00:56:25 +0000437 OSXVersion = DAL->MakeJoinedArg(0, O, MacosxVersionMin);
438 DAL->append(OSXVersion);
Daniel Dunbar816bc312010-01-26 01:45:19 +0000439 }
Daniel Dunbar30392de2009-09-04 18:35:21 +0000440 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000441 }
Mike Stump1eb44332009-09-09 15:08:12 +0000442
Daniel Dunbar26031372010-01-27 00:56:25 +0000443 // Set the tool chain target information.
444 unsigned Major, Minor, Micro;
445 bool HadExtra;
446 if (OSXVersion) {
447 assert(!iPhoneVersion && "Unknown target platform!");
448 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor,
449 Micro, HadExtra) || HadExtra ||
450 Major != 10 || Minor >= 10 || Micro >= 10)
451 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
452 << OSXVersion->getAsString(Args);
453 } else {
454 assert(iPhoneVersion && "Unknown target platform!");
455 if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor,
456 Micro, HadExtra) || HadExtra ||
457 Major >= 10 || Minor >= 100 || Micro >= 100)
458 getDriver().Diag(clang::diag::err_drv_invalid_version_number)
459 << iPhoneVersion->getAsString(Args);
460 }
461 setTarget(iPhoneVersion, Major, Minor, Micro);
462
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000463 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
464 Arg *A = *it;
465
466 if (A->getOption().matches(options::OPT_Xarch__)) {
467 // FIXME: Canonicalize name.
468 if (getArchName() != A->getValue(Args, 0))
469 continue;
470
471 // FIXME: The arg is leaked here, and we should have a nicer
472 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000473 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000474 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000475
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000476 // If the argument parsing failed or more than one argument was
477 // consumed, the -Xarch_ argument's parameter tried to consume
478 // extra arguments. Emit an error and ignore.
479 //
480 // We also want to disallow any options which would alter the
481 // driver behavior; that isn't going to work in our model. We
482 // use isDriverOption() as an approximation, although things
483 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000484 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000485 XarchArg->getOption().isDriverOption()) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000486 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000487 << A->getAsString(Args);
488 continue;
489 }
490
Daniel Dunbar478edc22009-03-29 22:29:05 +0000491 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000492 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000493 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000494
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000495 // Sob. These is strictly gcc compatible for the time being. Apple
496 // gcc translates options twice, which means that self-expanding
497 // options add duplicates.
Daniel Dunbar9e1f9822009-11-19 04:14:53 +0000498 switch ((options::ID) A->getOption().getID()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000499 default:
500 DAL->append(A);
501 break;
502
503 case options::OPT_mkernel:
504 case options::OPT_fapple_kext:
505 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000506 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
507 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000508 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000509
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000510 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000511 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000512 A->getValue(Args)));
513 break;
514
515 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000516 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
517 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000518 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
519 break;
520
521 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000522 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
523 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000524 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
525 break;
526
527 case options::OPT_fterminated_vtables:
528 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000529 DAL->append(DAL->MakeFlagArg(A,
530 Opts.getOption(options::OPT_fapple_kext)));
531 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000532 break;
533
534 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000535 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000536 break;
537
538 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000539 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000540 Opts.getOption(options::OPT_mconstant_cfstrings)));
541 break;
542
543 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000544 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000545 Opts.getOption(options::OPT_mno_constant_cfstrings)));
546 break;
547
548 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000549 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000550 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
551 break;
552
553 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000554 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000555 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
556 break;
557
558 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000559 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000560 Opts.getOption(options::OPT_mpascal_strings)));
561 break;
562
563 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000564 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000565 Opts.getOption(options::OPT_mno_pascal_strings)));
566 break;
567 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000568 }
569
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000570 if (getTriple().getArch() == llvm::Triple::x86 ||
571 getTriple().getArch() == llvm::Triple::x86_64)
Daniel Dunbare4bdae72009-11-19 04:00:53 +0000572 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000573 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
574 "core2"));
575
576 // Add the arch options based on the particular spelling of -arch, to match
577 // how the driver driver works.
578 if (BoundArch) {
579 llvm::StringRef Name = BoundArch;
580 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ);
581 const Option *MArch = Opts.getOption(options::OPT_march_EQ);
582
583 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch,
584 // which defines the list of which architectures we accept.
585 if (Name == "ppc")
586 ;
587 else if (Name == "ppc601")
588 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601"));
589 else if (Name == "ppc603")
590 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603"));
591 else if (Name == "ppc604")
592 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604"));
593 else if (Name == "ppc604e")
594 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e"));
595 else if (Name == "ppc750")
596 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750"));
597 else if (Name == "ppc7400")
598 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400"));
599 else if (Name == "ppc7450")
600 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450"));
601 else if (Name == "ppc970")
602 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970"));
603
604 else if (Name == "ppc64")
Daniel Dunbar478edc22009-03-29 22:29:05 +0000605 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000606
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000607 else if (Name == "i386")
608 ;
609 else if (Name == "i486")
610 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486"));
611 else if (Name == "i586")
612 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586"));
613 else if (Name == "i686")
614 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686"));
615 else if (Name == "pentium")
616 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium"));
617 else if (Name == "pentium2")
618 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
619 else if (Name == "pentpro")
620 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro"));
621 else if (Name == "pentIIm3")
622 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2"));
623
624 else if (Name == "x86_64")
625 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
626
627 else if (Name == "arm")
628 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
629 else if (Name == "armv4t")
630 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t"));
631 else if (Name == "armv5")
632 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej"));
633 else if (Name == "xscale")
634 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale"));
635 else if (Name == "armv6")
636 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k"));
637 else if (Name == "armv7")
638 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a"));
639
640 else
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +0000641 llvm_unreachable("invalid Darwin arch");
Daniel Dunbar84ec96c2009-09-09 22:33:15 +0000642 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000643
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000644 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000645}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000646
Daniel Dunbarf3955282009-09-04 18:34:51 +0000647bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000648 // FIXME: Gross; we should probably have some separate target
649 // definition, possibly even reusing the one in clang.
650 return getArchName() == "x86_64";
651}
652
Daniel Dunbarf2d8b9f2009-12-18 02:43:17 +0000653bool Darwin::UseDwarfDebugFlags() const {
654 if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
655 return S[0] != '\0';
656 return false;
657}
658
Daniel Dunbarf3955282009-09-04 18:34:51 +0000659const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000660 return "pic";
661}
662
Daniel Dunbarf3955282009-09-04 18:34:51 +0000663const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000664 if (getArchName() == "x86_64")
665 return "pic";
666 return 0;
667}
668
Daniel Dunbar39176082009-03-20 00:20:03 +0000669/// Generic_GCC - A tool chain using the 'gcc' command to perform
670/// all subcommands; this relies on gcc translating the majority of
671/// command line options.
672
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000673Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000674 : ToolChain(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000675 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000676}
677
Daniel Dunbar39176082009-03-20 00:20:03 +0000678Generic_GCC::~Generic_GCC() {
679 // Free tool implementations.
680 for (llvm::DenseMap<unsigned, Tool*>::iterator
681 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
682 delete it->second;
683}
684
Mike Stump1eb44332009-09-09 15:08:12 +0000685Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000686 const JobAction &JA) const {
687 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000688 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000689 Key = Action::AnalyzeJobClass;
690 else
691 Key = JA.getKind();
692
693 Tool *&T = Tools[Key];
694 if (!T) {
695 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000696 case Action::InputClass:
697 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000698 assert(0 && "Invalid tool kind.");
699 case Action::PreprocessJobClass:
700 T = new tools::gcc::Preprocess(*this); break;
701 case Action::PrecompileJobClass:
702 T = new tools::gcc::Precompile(*this); break;
703 case Action::AnalyzeJobClass:
704 T = new tools::Clang(*this); break;
705 case Action::CompileJobClass:
706 T = new tools::gcc::Compile(*this); break;
707 case Action::AssembleJobClass:
708 T = new tools::gcc::Assemble(*this); break;
709 case Action::LinkJobClass:
710 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000711
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000712 // This is a bit ungeneric, but the only platform using a driver
713 // driver is Darwin.
714 case Action::LipoJobClass:
715 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000716 }
717 }
718
719 return *T;
720}
721
Daniel Dunbar39176082009-03-20 00:20:03 +0000722bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000723 // FIXME: Gross; we should probably have some separate target
724 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000725 return getArchName() == "x86_64";
726}
727
728const char *Generic_GCC::GetDefaultRelocationModel() const {
729 return "static";
730}
731
732const char *Generic_GCC::GetForcedPicModel() const {
733 return 0;
734}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000735
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000736DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
737 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000738 return new DerivedArgList(Args, true);
739}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000740
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000741/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
742
743OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
744 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000745 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000746 getFilePaths().push_back("/usr/lib");
747}
748
749Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
750 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000751 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000752 Key = Action::AnalyzeJobClass;
753 else
754 Key = JA.getKind();
755
756 Tool *&T = Tools[Key];
757 if (!T) {
758 switch (Key) {
759 case Action::AssembleJobClass:
760 T = new tools::openbsd::Assemble(*this); break;
761 case Action::LinkJobClass:
762 T = new tools::openbsd::Link(*this); break;
763 default:
764 T = &Generic_GCC::SelectTool(C, JA);
765 }
766 }
767
768 return *T;
769}
770
Daniel Dunbar75358d22009-03-30 21:06:03 +0000771/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
772
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000773FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
774 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000775 if (Lib32) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000776 getFilePaths().push_back(getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000777 getFilePaths().push_back("/usr/lib32");
778 } else {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000779 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000780 getFilePaths().push_back("/usr/lib");
781 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000782}
783
784Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
785 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000786 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000787 Key = Action::AnalyzeJobClass;
788 else
789 Key = JA.getKind();
790
791 Tool *&T = Tools[Key];
792 if (!T) {
793 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000794 case Action::AssembleJobClass:
795 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000796 case Action::LinkJobClass:
797 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000798 default:
799 T = &Generic_GCC::SelectTool(C, JA);
800 }
801 }
802
803 return *T;
804}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000805
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000806/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
807
808AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
809 : Generic_GCC(Host, Triple) {
810
Daniel Dunbaree788e72009-12-21 18:54:17 +0000811 getProgramPaths().push_back(getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000812
Daniel Dunbaree788e72009-12-21 18:54:17 +0000813 getFilePaths().push_back(getDriver().Dir + "/../lib");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000814 getFilePaths().push_back("/usr/lib");
815 getFilePaths().push_back("/usr/sfw/lib");
816 getFilePaths().push_back("/opt/gcc4/lib");
Edward O'Callaghan7adf9492009-10-15 07:44:07 +0000817 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4");
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000818
819}
820
821Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
822 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000823 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000824 Key = Action::AnalyzeJobClass;
825 else
826 Key = JA.getKind();
827
828 Tool *&T = Tools[Key];
829 if (!T) {
830 switch (Key) {
831 case Action::AssembleJobClass:
832 T = new tools::auroraux::Assemble(*this); break;
833 case Action::LinkJobClass:
834 T = new tools::auroraux::Link(*this); break;
835 default:
836 T = &Generic_GCC::SelectTool(C, JA);
837 }
838 }
839
840 return *T;
841}
842
843
Eli Friedman6b3454a2009-05-26 07:52:18 +0000844/// Linux toolchain (very bare-bones at the moment).
845
846Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
847 : Generic_GCC(Host, Triple) {
Daniel Dunbaree788e72009-12-21 18:54:17 +0000848 getFilePaths().push_back(getDriver().Dir + "/../lib/clang/1.0/");
Eli Friedman6b3454a2009-05-26 07:52:18 +0000849 getFilePaths().push_back("/lib/");
850 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000851
852 // Depending on the Linux distribution, any combination of lib{,32,64} is
853 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
854 // openSUSE uses lib and lib64 for the same purpose.
855 getFilePaths().push_back("/lib32/");
856 getFilePaths().push_back("/usr/lib32/");
857 getFilePaths().push_back("/lib64/");
858 getFilePaths().push_back("/usr/lib64/");
859
Eli Friedman6b3454a2009-05-26 07:52:18 +0000860 // FIXME: Figure out some way to get gcc's libdir
861 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
862 // crtbegin.o/crtend.o/etc., and want static versions of various
863 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
864 // get away with using shared versions in /usr/lib, though.
865 // We could fall back to the approach we used for includes (a massive
866 // list), but that's messy at best.
867}
868
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000869/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
870
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000871DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
872 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000873
874 // Path mangling to find libexec
Daniel Dunbaree788e72009-12-21 18:54:17 +0000875 getProgramPaths().push_back(getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000876
Daniel Dunbaree788e72009-12-21 18:54:17 +0000877 getFilePaths().push_back(getDriver().Dir + "/../lib");
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000878 getFilePaths().push_back("/usr/lib");
879 getFilePaths().push_back("/usr/lib/gcc41");
880}
881
882Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
883 Action::ActionClass Key;
Daniel Dunbaree788e72009-12-21 18:54:17 +0000884 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000885 Key = Action::AnalyzeJobClass;
886 else
887 Key = JA.getKind();
888
889 Tool *&T = Tools[Key];
890 if (!T) {
891 switch (Key) {
892 case Action::AssembleJobClass:
893 T = new tools::dragonfly::Assemble(*this); break;
894 case Action::LinkJobClass:
895 T = new tools::dragonfly::Link(*this); break;
896 default:
897 T = &Generic_GCC::SelectTool(C, JA);
898 }
899 }
900
901 return *T;
902}