blob: fb6217d3ed00cc7ca19509b42b5e42de5b9844b8 [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 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
Mike Stump1eb44332009-09-09 15:08:12 +0000145 // and try to push it down into tool specific logic.
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000146
Mike Stump1eb44332009-09-09 15:08:12 +0000147 Arg *OSXVersion =
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000148 Args.getLastArg(options::OPT_mmacosx_version_min_EQ, false);
149 Arg *iPhoneVersion =
Mike Stump1eb44332009-09-09 15:08:12 +0000150 Args.getLastArg(options::OPT_miphoneos_version_min_EQ, false);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000151 if (OSXVersion && iPhoneVersion) {
152 getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with)
153 << OSXVersion->getAsString(Args)
Mike Stump1eb44332009-09-09 15:08:12 +0000154 << iPhoneVersion->getAsString(Args);
Daniel Dunbarff8857a2009-04-10 20:11:50 +0000155 } 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 }
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000175 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);
Mike Stump1eb44332009-09-09 15:08:12 +0000187
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000188 // 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.
Mike Stump1eb44332009-09-09 15:08:12 +0000196 if (!XarchArg || Index > Prev + 1 ||
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000197 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;
Mike Stump1eb44332009-09-09 15:08:12 +0000205 }
Daniel Dunbar4e7e9cf2009-03-25 06:12:34 +0000206
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;
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Daniel Dunbarec069ed2009-03-25 06:58:31 +0000223 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;
Mike Stump1eb44332009-09-09 15:08:12 +0000295}
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000296
Daniel Dunbarf3955282009-09-04 18:34:51 +0000297bool Darwin::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000298 return false;
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000299}
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)
Mike Stump1eb44332009-09-09 15:08:12 +0000322 : ToolChain(Host, Triple) {
Daniel Dunbar82fa7c52009-03-24 04:07:10 +0000323 std::string Path(getHost().getDriver().Dir);
324 Path += "/../libexec";
325 getProgramPaths().push_back(Path);
326
Mike Stump1eb44332009-09-09 15:08:12 +0000327 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbarc50b00d2009-03-23 16:15:50 +0000328}
329
Daniel Dunbar39176082009-03-20 00:20:03 +0000330Generic_GCC::~Generic_GCC() {
331 // Free tool implementations.
332 for (llvm::DenseMap<unsigned, Tool*>::iterator
333 it = Tools.begin(), ie = Tools.end(); it != ie; ++it)
334 delete it->second;
335}
336
Mike Stump1eb44332009-09-09 15:08:12 +0000337Tool &Generic_GCC::SelectTool(const Compilation &C,
Daniel Dunbar39176082009-03-20 00:20:03 +0000338 const JobAction &JA) const {
339 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000340 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar39176082009-03-20 00:20:03 +0000341 Key = Action::AnalyzeJobClass;
342 else
343 Key = JA.getKind();
344
345 Tool *&T = Tools[Key];
346 if (!T) {
347 switch (Key) {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000348 case Action::InputClass:
349 case Action::BindArchClass:
Daniel Dunbar39176082009-03-20 00:20:03 +0000350 assert(0 && "Invalid tool kind.");
351 case Action::PreprocessJobClass:
352 T = new tools::gcc::Preprocess(*this); break;
353 case Action::PrecompileJobClass:
354 T = new tools::gcc::Precompile(*this); break;
355 case Action::AnalyzeJobClass:
356 T = new tools::Clang(*this); break;
357 case Action::CompileJobClass:
358 T = new tools::gcc::Compile(*this); break;
359 case Action::AssembleJobClass:
360 T = new tools::gcc::Assemble(*this); break;
361 case Action::LinkJobClass:
362 T = new tools::gcc::Link(*this); break;
Mike Stump1eb44332009-09-09 15:08:12 +0000363
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000364 // This is a bit ungeneric, but the only platform using a driver
365 // driver is Darwin.
366 case Action::LipoJobClass:
367 T = new tools::darwin::Lipo(*this); break;
Daniel Dunbar39176082009-03-20 00:20:03 +0000368 }
369 }
370
371 return *T;
372}
373
Daniel Dunbarf3955282009-09-04 18:34:51 +0000374bool Generic_GCC::IsMathErrnoDefault() const {
Mike Stump1eb44332009-09-09 15:08:12 +0000375 return true;
Daniel Dunbar39176082009-03-20 00:20:03 +0000376}
377
378bool Generic_GCC::IsUnwindTablesDefault() const {
Daniel Dunbar8eddb3f2009-03-20 00:57:52 +0000379 // FIXME: Gross; we should probably have some separate target
380 // definition, possibly even reusing the one in clang.
Daniel Dunbar39176082009-03-20 00:20:03 +0000381 return getArchName() == "x86_64";
382}
383
384const char *Generic_GCC::GetDefaultRelocationModel() const {
385 return "static";
386}
387
388const char *Generic_GCC::GetForcedPicModel() const {
389 return 0;
390}
Daniel Dunbarf3cad362009-03-25 04:13:45 +0000391
392DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args) const {
393 return new DerivedArgList(Args, true);
394}
Daniel Dunbar75358d22009-03-30 21:06:03 +0000395
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000396/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.
397
398OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
399 : Generic_GCC(Host, Triple) {
400 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
401 getFilePaths().push_back("/usr/lib");
402}
403
404Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
405 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000406 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbarf7b8eec2009-06-29 20:52:51 +0000407 Key = Action::AnalyzeJobClass;
408 else
409 Key = JA.getKind();
410
411 Tool *&T = Tools[Key];
412 if (!T) {
413 switch (Key) {
414 case Action::AssembleJobClass:
415 T = new tools::openbsd::Assemble(*this); break;
416 case Action::LinkJobClass:
417 T = new tools::openbsd::Link(*this); break;
418 default:
419 T = &Generic_GCC::SelectTool(C, JA);
420 }
421 }
422
423 return *T;
424}
425
Daniel Dunbar75358d22009-03-30 21:06:03 +0000426/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly.
427
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000428FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
429 : Generic_GCC(Host, Triple) {
Daniel Dunbarbc534662009-04-02 18:30:04 +0000430 if (Lib32) {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000431 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000432 getFilePaths().push_back("/usr/lib32");
433 } else {
Daniel Dunbar75358d22009-03-30 21:06:03 +0000434 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
Daniel Dunbarbc534662009-04-02 18:30:04 +0000435 getFilePaths().push_back("/usr/lib");
436 }
Daniel Dunbar75358d22009-03-30 21:06:03 +0000437}
438
439Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
440 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000441 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar75358d22009-03-30 21:06:03 +0000442 Key = Action::AnalyzeJobClass;
443 else
444 Key = JA.getKind();
445
446 Tool *&T = Tools[Key];
447 if (!T) {
448 switch (Key) {
Daniel Dunbar68a31d42009-03-31 17:45:15 +0000449 case Action::AssembleJobClass:
450 T = new tools::freebsd::Assemble(*this); break;
Daniel Dunbar008f54a2009-04-01 19:36:32 +0000451 case Action::LinkJobClass:
452 T = new tools::freebsd::Link(*this); break;
Daniel Dunbar75358d22009-03-30 21:06:03 +0000453 default:
454 T = &Generic_GCC::SelectTool(C, JA);
455 }
456 }
457
458 return *T;
459}
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000460
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000461/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly.
462
463AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
464 : Generic_GCC(Host, Triple) {
465
466 // Path mangling to find libexec
467 std::string Path(getHost().getDriver().Dir);
468
469 Path += "/../libexec";
470 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000471 getProgramPaths().push_back(getHost().getDriver().Dir);
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000472
473 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
474 getFilePaths().push_back("/usr/lib");
475 getFilePaths().push_back("/usr/sfw/lib");
476 getFilePaths().push_back("/opt/gcc4/lib");
477
478}
479
480Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
481 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000482 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Edward O'Callaghane7925a02009-08-22 01:06:46 +0000483 Key = Action::AnalyzeJobClass;
484 else
485 Key = JA.getKind();
486
487 Tool *&T = Tools[Key];
488 if (!T) {
489 switch (Key) {
490 case Action::AssembleJobClass:
491 T = new tools::auroraux::Assemble(*this); break;
492 case Action::LinkJobClass:
493 T = new tools::auroraux::Link(*this); break;
494 default:
495 T = &Generic_GCC::SelectTool(C, JA);
496 }
497 }
498
499 return *T;
500}
501
502
Eli Friedman6b3454a2009-05-26 07:52:18 +0000503/// Linux toolchain (very bare-bones at the moment).
504
505Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple)
506 : Generic_GCC(Host, Triple) {
507 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/");
508 getFilePaths().push_back("/lib/");
509 getFilePaths().push_back("/usr/lib/");
Daniel Dunbara9822de2009-08-06 01:47:11 +0000510
511 // Depending on the Linux distribution, any combination of lib{,32,64} is
512 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems,
513 // openSUSE uses lib and lib64 for the same purpose.
514 getFilePaths().push_back("/lib32/");
515 getFilePaths().push_back("/usr/lib32/");
516 getFilePaths().push_back("/lib64/");
517 getFilePaths().push_back("/usr/lib64/");
518
Eli Friedman6b3454a2009-05-26 07:52:18 +0000519 // FIXME: Figure out some way to get gcc's libdir
520 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need
521 // crtbegin.o/crtend.o/etc., and want static versions of various
522 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably
523 // get away with using shared versions in /usr/lib, though.
524 // We could fall back to the approach we used for includes (a massive
525 // list), but that's messy at best.
526}
527
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000528/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
529
Daniel Dunbarcb8ab232009-05-22 02:53:45 +0000530DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
531 : Generic_GCC(Host, Triple) {
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000532
533 // Path mangling to find libexec
534 std::string Path(getHost().getDriver().Dir);
535
536 Path += "/../libexec";
537 getProgramPaths().push_back(Path);
Mike Stump1eb44332009-09-09 15:08:12 +0000538 getProgramPaths().push_back(getHost().getDriver().Dir);
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000539
540 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib");
541 getFilePaths().push_back("/usr/lib");
542 getFilePaths().push_back("/usr/lib/gcc41");
543}
544
545Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
546 Action::ActionClass Key;
Daniel Dunbara6046be2009-09-08 23:36:55 +0000547 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Daniel Dunbar11e1b402009-05-02 18:28:39 +0000548 Key = Action::AnalyzeJobClass;
549 else
550 Key = JA.getKind();
551
552 Tool *&T = Tools[Key];
553 if (!T) {
554 switch (Key) {
555 case Action::AssembleJobClass:
556 T = new tools::dragonfly::Assemble(*this); break;
557 case Action::LinkJobClass:
558 T = new tools::dragonfly::Link(*this); break;
559 default:
560 T = &Generic_GCC::SelectTool(C, JA);
561 }
562 }
563
564 return *T;
565}