blob: 6512203d0931159218332e9c96adc6b21212085f [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 Dunbar4e7e9cf2009-03-25 06:12:34 +000017#include "clang/Driver/Option.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000018
19#include "llvm/ADT/StringExtras.h"
Daniel Dunbarec069ed2009-03-25 06:58:31 +000020#include "llvm/Support/raw_ostream.h"
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000021#include "llvm/System/Path.h"
22
Daniel Dunbarf36a06a2009-04-10 21:00:07 +000023#include <cstdlib> // ::getenv
24
Daniel Dunbar39176082009-03-20 00:20:03 +000025using namespace clang::driver;
26using namespace clang::driver::toolchains;
27
Daniel Dunbarf3955282009-09-04 18:34:51 +000028/// Darwin - Darwin tool chain for i386 and x86_64.
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000029
Daniel Dunbarf3955282009-09-04 18:34:51 +000030Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
31 const unsigned (&_DarwinVersion)[3],
Daniel Dunbar30392de2009-09-04 18:35:21 +000032 const unsigned (&_GCCVersion)[3],
33 bool _IsIPhone)
Daniel Dunbarcb8ab232009-05-22 02:53:45 +000034 : ToolChain(Host, Triple) {
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000035 DarwinVersion[0] = _DarwinVersion[0];
36 DarwinVersion[1] = _DarwinVersion[1];
37 DarwinVersion[2] = _DarwinVersion[2];
38 GCCVersion[0] = _GCCVersion[0];
39 GCCVersion[1] = _GCCVersion[1];
40 GCCVersion[2] = _GCCVersion[2];
Daniel Dunbar30392de2009-09-04 18:35:21 +000041 IsIPhone = _IsIPhone;
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000042
Daniel Dunbar02633b52009-03-26 16:23:12 +000043 llvm::raw_string_ostream(MacosxVersionMin)
44 << "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1];
45
Daniel Dunbar30392de2009-09-04 18:35:21 +000046 // FIXME: Lift default up.
47 IPhoneOSVersionMin = "3.0";
48
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000049 ToolChainDir = "i686-apple-darwin";
50 ToolChainDir += llvm::utostr(DarwinVersion[0]);
51 ToolChainDir += "/";
52 ToolChainDir += llvm::utostr(GCCVersion[0]);
53 ToolChainDir += '.';
54 ToolChainDir += llvm::utostr(GCCVersion[1]);
55 ToolChainDir += '.';
56 ToolChainDir += llvm::utostr(GCCVersion[2]);
57
58 std::string Path;
59 if (getArchName() == "x86_64") {
60 Path = getHost().getDriver().Dir;
61 Path += "/../lib/gcc/";
62 Path += getToolChainDir();
63 Path += "/x86_64";
64 getFilePaths().push_back(Path);
65
66 Path = "/usr/lib/gcc/";
67 Path += getToolChainDir();
68 Path += "/x86_64";
69 getFilePaths().push_back(Path);
70 }
71
72 Path = getHost().getDriver().Dir;
73 Path += "/../lib/gcc/";
74 Path += getToolChainDir();
75 getFilePaths().push_back(Path);
76
77 Path = "/usr/lib/gcc/";
78 Path += getToolChainDir();
79 getFilePaths().push_back(Path);
80
81 Path = getHost().getDriver().Dir;
82 Path += "/../libexec/gcc/";
83 Path += getToolChainDir();
84 getProgramPaths().push_back(Path);
85
86 Path = "/usr/libexec/gcc/";
87 Path += getToolChainDir();
88 getProgramPaths().push_back(Path);
89
Daniel Dunbar82fa7c52009-03-24 04:07:10 +000090 Path = getHost().getDriver().Dir;
91 Path += "/../libexec";
92 getProgramPaths().push_back(Path);
93
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000094 getProgramPaths().push_back(getHost().getDriver().Dir);
95}
96
Daniel Dunbarf3955282009-09-04 18:34:51 +000097Darwin::~Darwin() {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +000098 // Free tool implementations.
99 for (llvm::DenseMap<unsigned, Tool*>::iterator
100 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
101 delete it->second;
102}
103
Daniel Dunbarf3955282009-09-04 18:34:51 +0000104Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000105 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000106 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000107 Key = Action::AnalyzeJobClass;
108 else
109 Key = JA.getKind();
110
111 Tool *&T = Tools[Key];
112 if (!T) {
113 switch (Key) {
114 case Action::InputClass:
115 case Action::BindArchClass:
116 assert(0 && "Invalid tool kind.");
117 case Action::PreprocessJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000118 T = new tools::darwin::Preprocess(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000119 case Action::AnalyzeJobClass:
120 T = new tools::Clang(*this); break;
Daniel Dunbar9120f172009-03-29 22:27:40 +0000121 case Action::PrecompileJobClass:
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000122 case Action::CompileJobClass:
Daniel Dunbar9120f172009-03-29 22:27:40 +0000123 T = new tools::darwin::Compile(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000124 case Action::AssembleJobClass:
Daniel Dunbar8cac5f72009-03-20 16:06:39 +0000125 T = new tools::darwin::Assemble(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000126 case Action::LinkJobClass:
Daniel Dunbar8f289622009-09-04 17:39:02 +0000127 T = new tools::darwin::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000128 case Action::LipoJobClass:
129 T = new tools::darwin::Lipo(*this); break;
130 }
131 }
132
133 return *T;
134}
135
Daniel Dunbarf3955282009-09-04 18:34:51 +0000136DerivedArgList *Darwin::TranslateArgs(InputArgList &Args) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000137 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000138 const OptTable &Opts = getHost().getDriver().getOpts();
139
140 // FIXME: We really want to get out of the tool chain level argument
141 // translation business, as it makes the driver functionality much
142 // more opaque. For now, we follow gcc closely solely for the
143 // purpose of easily achieving feature parity & testability. Once we
144 // have something that works, we should reevaluate each translation
145 // and try to push it down into tool specific logic.
146
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000147 Arg *OSXVersion =
148 Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
149 Arg *iPhoneVersion =
150 Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
151 if (OSXVersion && iPhoneVersion) {
152 getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
153 << OSXVersion->getAsString(Args)
154 << iPhoneVersion->getAsString(Args);
155 } else if (!OSXVersion && !iPhoneVersion) {
156 // Chose the default version based on the arch.
157 //
Daniel Dunbar30392de2009-09-04 18:35:21 +0000158 // FIXME: Are there iPhone overrides for this?
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000159
Daniel Dunbar30392de2009-09-04 18:35:21 +0000160 if (!isIPhone()) {
161 // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
162 // from the host.
163 const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
164 if (!Version)
165 Version = MacosxVersionMin.c_str();
166 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
167 DAL->append(DAL->MakeJoinedArg(0, O, Version));
168 } else {
169 const char *Version = IPhoneOSVersionMin.c_str();
170 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
171 DAL->append(DAL->MakeJoinedArg(0, O, Version));
172 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000173 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000174
175 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
176 Arg *A = *it;
177
178 if (A->getOption().matches(options::OPT_Xarch__)) {
179 // FIXME: Canonicalize name.
180 if (getArchName() != A->getValue(Args, 0))
181 continue;
182
183 // FIXME: The arg is leaked here, and we should have a nicer
184 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000185 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000186 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000187
188 // If the argument parsing failed or more than one argument was
189 // consumed, the -Xarch_ argument's parameter tried to consume
190 // extra arguments. Emit an error and ignore.
191 //
192 // We also want to disallow any options which would alter the
193 // driver behavior; that isn't going to work in our model. We
194 // use isDriverOption() as an approximation, although things
195 // like -O4 are going to slip through.
196 if (!XarchArg || Index > Prev + 1 ||
197 XarchArg->getOption().isDriverOption()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000198 getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000199 << A->getAsString(Args);
200 continue;
201 }
202
Daniel Dunbar478edc22009-03-29 22:29:05 +0000203 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000204 A = XarchArg;
205 }
206
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000207 // Sob. These is strictly gcc compatible for the time being. Apple
208 // gcc translates options twice, which means that self-expanding
209 // options add duplicates.
210 options::ID id = A->getOption().getId();
211 switch (id) {
212 default:
213 DAL->append(A);
214 break;
215
216 case options::OPT_mkernel:
217 case options::OPT_fapple_kext:
218 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000219 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
220 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000221 break;
222
223 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000224 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000225 A->getValue(Args)));
226 break;
227
228 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000229 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
230 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000231 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
232 break;
233
234 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000235 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
236 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000237 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
238 break;
239
240 case options::OPT_fterminated_vtables:
241 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000242 DAL->append(DAL->MakeFlagArg(A,
243 Opts.getOption(options::OPT_fapple_kext)));
244 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000245 break;
246
247 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000248 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000249 break;
250
251 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000252 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000253 Opts.getOption(options::OPT_mconstant_cfstrings)));
254 break;
255
256 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000257 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000258 Opts.getOption(options::OPT_mno_constant_cfstrings)));
259 break;
260
261 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000262 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000263 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
264 break;
265
266 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000267 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000268 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
269 break;
270
271 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000272 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000273 Opts.getOption(options::OPT_mpascal_strings)));
274 break;
275
276 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000277 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000278 Opts.getOption(options::OPT_mno_pascal_strings)));
279 break;
280 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000281 }
282
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000283 // FIXME: Actually, gcc always adds this, but it is filtered for
284 // duplicates somewhere. This also changes the order of things, so
285 // look it up.
286 if (getArchName() == "x86_64")
287 if (!Args.hasArg(options::OPT_m64, false))
Daniel Dunbar478edc22009-03-29 22:29:05 +0000288 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000289
290 if (!Args.hasArg(options::OPT_mtune_EQ, false))
Daniel Dunbar478edc22009-03-29 22:29:05 +0000291 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000292 "core2"));
293
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000294 return DAL;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000295}
296
Daniel Dunbarf3955282009-09-04 18:34:51 +0000297bool Darwin::IsMathErrnoDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000298 return false;
299}
300
Daniel Dunbarf3955282009-09-04 18:34:51 +0000301bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000302 // FIXME: Gross; we should probably have some separate target
303 // definition, possibly even reusing the one in clang.
304 return getArchName() == "x86_64";
305}
306
Daniel Dunbarf3955282009-09-04 18:34:51 +0000307const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000308 return "pic";
309}
310
Daniel Dunbarf3955282009-09-04 18:34:51 +0000311const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000312 if (getArchName() == "x86_64")
313 return "pic";
314 return 0;
315}
316
Daniel Dunbar39176082009-03-20 00:20:03 +0000317/// Generic_GCC - A tool chain using the 'gcc' command to perform
318/// all subcommands; this relies on gcc translating the majority of
319/// command line options.
320
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000321Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
322 : ToolChain(Host, Triple)
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000323{
Daniel Dunbar82fa7c52009-03-24 04:07:10 +0000324 std::string Path(getHost().getDriver().Dir);
325 Path += "/../libexec";
326 getProgramPaths().push_back(Path);
327
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000328 getProgramPaths().push_back(getHost().getDriver().Dir);
329}
330
Daniel Dunbar39176082009-03-20 00:20:03 +0000331Generic_GCC::~Generic_GCC() {
332 // Free tool implementations.
333 for (llvm::DenseMap<unsigned, Tool*>::iterator
334 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
335 delete it->second;
336}
337
338Tool &Generic_GCC::SelectTool(const Compilation &C,
339 const JobAction &JA) const {
340 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000341 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000342 Key = Action::AnalyzeJobClass;
343 else
344 Key = JA.getKind();
345
346 Tool *&T = Tools[Key];
347 if (!T) {
348 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000349 case Action::InputClass:
350 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000351 assert(0 && "Invalid tool kind.");
352 case Action::PreprocessJobClass:
353 T = new tools::gcc::Preprocess(*this); break;
354 case Action::PrecompileJobClass:
355 T = new tools::gcc::Precompile(*this); break;
356 case Action::AnalyzeJobClass:
357 T = new tools::Clang(*this); break;
358 case Action::CompileJobClass:
359 T = new tools::gcc::Compile(*this); break;
360 case Action::AssembleJobClass:
361 T = new tools::gcc::Assemble(*this); break;
362 case Action::LinkJobClass:
363 T = new tools::gcc::Link(*this); break;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000364
365 // This is a bit ungeneric, but the only platform using a driver
366 // driver is Darwin.
367 case Action::LipoJobClass:
368 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000369 }
370 }
371
372 return *T;
373}
374
Daniel Dunbarf3955282009-09-04 18:34:51 +0000375bool Generic_GCC::IsMathErrnoDefault() const {
Daniel Dunbar39176082009-03-20 00:20:03 +0000376 return true;
377}
378
379bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000380 // FIXME: Gross; we should probably have some separate target
381 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000382 return getArchName() == "x86_64";
383}
384
385const char *Generic_GCC::GetDefaultRelocationModel() const {
386 return "static";
387}
388
389const char *Generic_GCC::GetForcedPicModel() const {
390 return 0;
391}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000392
393DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args) const {
394 return new DerivedArgList(Args, true);
395}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000396
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000397/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
398
399OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
400 : Generic_GCC(Host, Triple) {
401 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
402 getFilePaths().push_back("/usr/lib");
403}
404
405Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
406 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000407 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000408 Key = Action::AnalyzeJobClass;
409 else
410 Key = JA.getKind();
411
412 Tool *&T = Tools[Key];
413 if (!T) {
414 switch (Key) {
415 case Action::AssembleJobClass:
416 T = new tools::openbsd::Assemble(*this); break;
417 case Action::LinkJobClass:
418 T = new tools::openbsd::Link(*this); break;
419 default:
420 T = &Generic_GCC::SelectTool(C, JA);
421 }
422 }
423
424 return *T;
425}
426
Daniel Dunbar75358d22009-03-30 21:06:03 +0000427/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
428
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000429FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
430 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000431 if (Lib32) {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000432 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000433 getFilePaths().push_back("/usr/lib32");
434 } else {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000435 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000436 getFilePaths().push_back("/usr/lib");
437 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000438}
439
440Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
441 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000442 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000443 Key = Action::AnalyzeJobClass;
444 else
445 Key = JA.getKind();
446
447 Tool *&T = Tools[Key];
448 if (!T) {
449 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000450 case Action::AssembleJobClass:
451 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000452 case Action::LinkJobClass:
453 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000454 default:
455 T = &Generic_GCC::SelectTool(C, JA);
456 }
457 }
458
459 return *T;
460}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000461
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000462/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
463
464AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
465 : Generic_GCC(Host, Triple) {
466
467 // Path mangling to find libexec
468 std::string Path(getHost().getDriver().Dir);
469
470 Path += "/../libexec";
471 getProgramPaths().push_back(Path);
472 getProgramPaths().push_back(getHost().getDriver().Dir);
473
474 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
475 getFilePaths().push_back("/usr/lib");
476 getFilePaths().push_back("/usr/sfw/lib");
477 getFilePaths().push_back("/opt/gcc4/lib");
478
479}
480
481Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
482 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000483 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000484 Key = Action::AnalyzeJobClass;
485 else
486 Key = JA.getKind();
487
488 Tool *&T = Tools[Key];
489 if (!T) {
490 switch (Key) {
491 case Action::AssembleJobClass:
492 T = new tools::auroraux::Assemble(*this); break;
493 case Action::LinkJobClass:
494 T = new tools::auroraux::Link(*this); break;
495 default:
496 T = &Generic_GCC::SelectTool(C, JA);
497 }
498 }
499
500 return *T;
501}
502
503
Eli Friedman6b3454a2009-05-26 07:52:18 +0000504/// Linux toolchain (very bare-bones at the moment).
505
506Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
507 : Generic_GCC(Host, Triple) {
508 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/");
509 getFilePaths().push_back("/lib/");
510 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000511
512 // Depending on the Linux distribution, any combination of lib{,32,64} is
513 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
514 // openSUSE uses lib and lib64 for the same purpose.
515 getFilePaths().push_back("/lib32/");
516 getFilePaths().push_back("/usr/lib32/");
517 getFilePaths().push_back("/lib64/");
518 getFilePaths().push_back("/usr/lib64/");
519
Eli Friedman6b3454a2009-05-26 07:52:18 +0000520 // FIXME: Figure out some way to get gcc's libdir
521 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
522 // crtbegin.o/crtend.o/etc., and want static versions of various
523 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
524 // get away with using shared versions in /usr/lib, though.
525 // We could fall back to the approach we used for includes (a massive
526 // list), but that's messy at best.
527}
528
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000529/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
530
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000531DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
532 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000533
534 // Path mangling to find libexec
535 std::string Path(getHost().getDriver().Dir);
536
537 Path += "/../libexec";
538 getProgramPaths().push_back(Path);
539 getProgramPaths().push_back(getHost().getDriver().Dir);
540
541 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
542 getFilePaths().push_back("/usr/lib");
543 getFilePaths().push_back("/usr/lib/gcc41");
544}
545
546Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
547 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000548 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000549 Key = Action::AnalyzeJobClass;
550 else
551 Key = JA.getKind();
552
553 Tool *&T = Tools[Key];
554 if (!T) {
555 switch (Key) {
556 case Action::AssembleJobClass:
557 T = new tools::dragonfly::Assemble(*this); break;
558 case Action::LinkJobClass:
559 T = new tools::dragonfly::Link(*this); break;
560 default:
561 T = &Generic_GCC::SelectTool(C, JA);
562 }
563 }
564
565 return *T;
566}