blob: 7b14a20f187e83b345d3a9aa5dab693ee92d4dfe [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 }
Mike Stump1eb44332009-09-09 15:08:12 +000071
Daniel Dunbarc50b00d2009-03-23 16:15:50 +000072 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 Dunbar0dcb9a32009-09-09 18:36:12 +0000136DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
137 const char *BoundArch) const {
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000138 DerivedArgList *DAL = new DerivedArgList(Args, false);
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000139 const OptTable &Opts = getHost().getDriver().getOpts();
140
141 // FIXME: We really want to get out of the tool chain level argument
142 // translation business, as it makes the driver functionality much
143 // more opaque. For now, we follow gcc closely solely for the
144 // purpose of easily achieving feature parity & testability. Once we
145 // have something that works, we should reevaluate each translation
Mike Stump1eb44332009-09-09 15:08:12 +0000146 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000147
Mike Stump1eb44332009-09-09 15:08:12 +0000148 Arg *OSXVersion =
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000149 Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
150 Arg *iPhoneVersion =
Mike Stump1eb44332009-09-09 15:08:12 +0000151 Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000152 if (OSXVersion && iPhoneVersion) {
153 getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
154 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000155 << iPhoneVersion->getAsString(Args);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000156 } else if (!OSXVersion && !iPhoneVersion) {
157 // Chose the default version based on the arch.
158 //
Daniel Dunbar30392de2009-09-04 18:35:21 +0000159 // FIXME: Are there iPhone overrides for this?
Daniel Dunbarf36a06a2009-04-10 21:00:07 +0000160
Daniel Dunbar30392de2009-09-04 18:35:21 +0000161 if (!isIPhone()) {
162 // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
163 // from the host.
164 const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
165 if (!Version)
166 Version = MacosxVersionMin.c_str();
167 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
168 DAL->append(DAL->MakeJoinedArg(0, O, Version));
169 } else {
170 const char *Version = IPhoneOSVersionMin.c_str();
171 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
172 DAL->append(DAL->MakeJoinedArg(0, O, Version));
173 }
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000174 }
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000176 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
177 Arg *A = *it;
178
179 if (A->getOption().matches(options::OPT_Xarch__)) {
180 // FIXME: Canonicalize name.
181 if (getArchName() != A->getValue(Args, 0))
182 continue;
183
184 // FIXME: The arg is leaked here, and we should have a nicer
185 // interface for this.
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000186 unsigned Prev, Index = Prev = A->getIndex() + 1;
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000187 Arg *XarchArg = Opts.ParseOneArg(Args, Index);
Mike Stump1eb44332009-09-09 15:08:12 +0000188
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000189 // If the argument parsing failed or more than one argument was
190 // consumed, the -Xarch_ argument's parameter tried to consume
191 // extra arguments. Emit an error and ignore.
192 //
193 // We also want to disallow any options which would alter the
194 // driver behavior; that isn't going to work in our model. We
195 // use isDriverOption() as an approximation, although things
196 // like -O4 are going to slip through.
Mike Stump1eb44332009-09-09 15:08:12 +0000197 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000198 XarchArg->getOption().isDriverOption()) {
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000199 getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument)
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000200 << A->getAsString(Args);
201 continue;
202 }
203
Daniel Dunbar478edc22009-03-29 22:29:05 +0000204 XarchArg->setBaseArg(A);
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000205 A = XarchArg;
Mike Stump1eb44332009-09-09 15:08:12 +0000206 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000207
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000208 // Sob. These is strictly gcc compatible for the time being. Apple
209 // gcc translates options twice, which means that self-expanding
210 // options add duplicates.
211 options::ID id = A->getOption().getId();
212 switch (id) {
213 default:
214 DAL->append(A);
215 break;
216
217 case options::OPT_mkernel:
218 case options::OPT_fapple_kext:
219 DAL->append(A);
Daniel Dunbar478edc22009-03-29 22:29:05 +0000220 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
221 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000222 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000223
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000224 case options::OPT_dependency_file:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000225 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000226 A->getValue(Args)));
227 break;
228
229 case options::OPT_gfull:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000230 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
231 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000232 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)));
233 break;
234
235 case options::OPT_gused:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000236 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag)));
237 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000238 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)));
239 break;
240
241 case options::OPT_fterminated_vtables:
242 case options::OPT_findirect_virtual_calls:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000243 DAL->append(DAL->MakeFlagArg(A,
244 Opts.getOption(options::OPT_fapple_kext)));
245 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000246 break;
247
248 case options::OPT_shared:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000249 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000250 break;
251
252 case options::OPT_fconstant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000253 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000254 Opts.getOption(options::OPT_mconstant_cfstrings)));
255 break;
256
257 case options::OPT_fno_constant_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000258 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000259 Opts.getOption(options::OPT_mno_constant_cfstrings)));
260 break;
261
262 case options::OPT_Wnonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000263 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000264 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)));
265 break;
266
267 case options::OPT_Wno_nonportable_cfstrings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000268 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000269 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)));
270 break;
271
272 case options::OPT_fpascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000273 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000274 Opts.getOption(options::OPT_mpascal_strings)));
275 break;
276
277 case options::OPT_fno_pascal_strings:
Daniel Dunbar478edc22009-03-29 22:29:05 +0000278 DAL->append(DAL->MakeFlagArg(A,
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000279 Opts.getOption(options::OPT_mno_pascal_strings)));
280 break;
281 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000282 }
283
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000284 // FIXME: Actually, gcc always adds this, but it is filtered for
285 // duplicates somewhere. This also changes the order of things, so
286 // look it up.
287 if (getArchName() == "x86_64")
288 if (!Args.hasArg(options::OPT_m64, false))
Daniel Dunbar478edc22009-03-29 22:29:05 +0000289 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64)));
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000290
291 if (!Args.hasArg(options::OPT_mtune_EQ, false))
Daniel Dunbar478edc22009-03-29 22:29:05 +0000292 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ),
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000293 "core2"));
294
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000295 return DAL;
Mike Stump1eb44332009-09-09 15:08:12 +0000296}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000297
Daniel Dunbarf3955282009-09-04 18:34:51 +0000298bool Darwin::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000299 return false;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000300}
301
Daniel Dunbarf3955282009-09-04 18:34:51 +0000302bool Darwin::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000303 // FIXME: Gross; we should probably have some separate target
304 // definition, possibly even reusing the one in clang.
305 return getArchName() == "x86_64";
306}
307
Daniel Dunbarf3955282009-09-04 18:34:51 +0000308const char *Darwin::GetDefaultRelocationModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000309 return "pic";
310}
311
Daniel Dunbarf3955282009-09-04 18:34:51 +0000312const char *Darwin::GetForcedPicModel() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000313 if (getArchName() == "x86_64")
314 return "pic";
315 return 0;
316}
317
Daniel Dunbar39176082009-03-20 00:20:03 +0000318/// Generic_GCC - A tool chain using the 'gcc' command to perform
319/// all subcommands; this relies on gcc translating the majority of
320/// command line options.
321
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000322Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
Mike Stump1eb44332009-09-09 15:08:12 +0000323 : ToolChain(Host, Triple) {
Daniel Dunbar82fa7c52009-03-24 04:07:10 +0000324 std::string Path(getHost().getDriver().Dir);
325 Path += "/../libexec";
326 getProgramPaths().push_back(Path);
327
Mike Stump1eb44332009-09-09 15:08:12 +0000328 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000329}
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
Mike Stump1eb44332009-09-09 15:08:12 +0000338Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000339 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;
Mike Stump1eb44332009-09-09 15:08:12 +0000364
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000365 // 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 {
Mike Stump1eb44332009-09-09 15:08:12 +0000376 return true;
Daniel Dunbar39176082009-03-20 00:20:03 +0000377}
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
Daniel Dunbar0dcb9a32009-09-09 18:36:12 +0000393DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args,
394 const char *BoundArch) const {
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000395 return new DerivedArgList(Args, true);
396}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000397
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000398/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
399
400OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
401 : Generic_GCC(Host, Triple) {
402 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
403 getFilePaths().push_back("/usr/lib");
404}
405
406Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
407 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000408 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000409 Key = Action::AnalyzeJobClass;
410 else
411 Key = JA.getKind();
412
413 Tool *&T = Tools[Key];
414 if (!T) {
415 switch (Key) {
416 case Action::AssembleJobClass:
417 T = new tools::openbsd::Assemble(*this); break;
418 case Action::LinkJobClass:
419 T = new tools::openbsd::Link(*this); break;
420 default:
421 T = &Generic_GCC::SelectTool(C, JA);
422 }
423 }
424
425 return *T;
426}
427
Daniel Dunbar75358d22009-03-30 21:06:03 +0000428/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
429
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000430FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
431 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000432 if (Lib32) {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000433 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000434 getFilePaths().push_back("/usr/lib32");
435 } else {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000436 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000437 getFilePaths().push_back("/usr/lib");
438 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000439}
440
441Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
442 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000443 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000444 Key = Action::AnalyzeJobClass;
445 else
446 Key = JA.getKind();
447
448 Tool *&T = Tools[Key];
449 if (!T) {
450 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000451 case Action::AssembleJobClass:
452 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000453 case Action::LinkJobClass:
454 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000455 default:
456 T = &Generic_GCC::SelectTool(C, JA);
457 }
458 }
459
460 return *T;
461}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000462
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000463/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
464
465AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
466 : Generic_GCC(Host, Triple) {
467
468 // Path mangling to find libexec
469 std::string Path(getHost().getDriver().Dir);
470
471 Path += "/../libexec";
472 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000473 getProgramPaths().push_back(getHost().getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000474
475 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
476 getFilePaths().push_back("/usr/lib");
477 getFilePaths().push_back("/usr/sfw/lib");
478 getFilePaths().push_back("/opt/gcc4/lib");
479
480}
481
482Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
483 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000484 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000485 Key = Action::AnalyzeJobClass;
486 else
487 Key = JA.getKind();
488
489 Tool *&T = Tools[Key];
490 if (!T) {
491 switch (Key) {
492 case Action::AssembleJobClass:
493 T = new tools::auroraux::Assemble(*this); break;
494 case Action::LinkJobClass:
495 T = new tools::auroraux::Link(*this); break;
496 default:
497 T = &Generic_GCC::SelectTool(C, JA);
498 }
499 }
500
501 return *T;
502}
503
504
Eli Friedman6b3454a2009-05-26 07:52:18 +0000505/// Linux toolchain (very bare-bones at the moment).
506
507Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
508 : Generic_GCC(Host, Triple) {
509 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/");
510 getFilePaths().push_back("/lib/");
511 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000512
513 // Depending on the Linux distribution, any combination of lib{,32,64} is
514 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
515 // openSUSE uses lib and lib64 for the same purpose.
516 getFilePaths().push_back("/lib32/");
517 getFilePaths().push_back("/usr/lib32/");
518 getFilePaths().push_back("/lib64/");
519 getFilePaths().push_back("/usr/lib64/");
520
Eli Friedman6b3454a2009-05-26 07:52:18 +0000521 // FIXME: Figure out some way to get gcc's libdir
522 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
523 // crtbegin.o/crtend.o/etc., and want static versions of various
524 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
525 // get away with using shared versions in /usr/lib, though.
526 // We could fall back to the approach we used for includes (a massive
527 // list), but that's messy at best.
528}
529
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000530/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
531
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000532DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
533 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000534
535 // Path mangling to find libexec
536 std::string Path(getHost().getDriver().Dir);
537
538 Path += "/../libexec";
539 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000540 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000541
542 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
543 getFilePaths().push_back("/usr/lib");
544 getFilePaths().push_back("/usr/lib/gcc41");
545}
546
547Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
548 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000549 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000550 Key = Action::AnalyzeJobClass;
551 else
552 Key = JA.getKind();
553
554 Tool *&T = Tools[Key];
555 if (!T) {
556 switch (Key) {
557 case Action::AssembleJobClass:
558 T = new tools::dragonfly::Assemble(*this); break;
559 case Action::LinkJobClass:
560 T = new tools::dragonfly::Link(*this); break;
561 default:
562 T = &Generic_GCC::SelectTool(C, JA);
563 }
564 }
565
566 return *T;
567}