1//===--- CrossWindowsToolChain.cpp - Cross Windows Tool Chain -------------===//
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#include "clang/Driver/Driver.h"
12#include "clang/Driver/Options.h"
13#include "llvm/Option/ArgList.h"
14
15using namespace clang::driver;
16using namespace clang::driver::toolchains;
17
18CrossWindowsToolChain::CrossWindowsToolChain(const Driver &D,
19                                             const llvm::Triple &T,
20                                             const llvm::opt::ArgList &Args)
21    : Generic_GCC(D, T, Args) {
22  if (GetCXXStdlibType(Args) == ToolChain::CST_Libstdcxx) {
23    const std::string &SysRoot = D.SysRoot;
24
25    // libstdc++ resides in /usr/lib, but depends on libgcc which is placed in
26    // /usr/lib/gcc.
27    getFilePaths().push_back(SysRoot + "/usr/lib");
28    getFilePaths().push_back(SysRoot + "/usr/lib/gcc");
29  }
30}
31
32bool CrossWindowsToolChain::IsUnwindTablesDefault() const {
33  // FIXME: all non-x86 targets need unwind tables, however, LLVM currently does
34  // not know how to emit them.
35  return getArch() == llvm::Triple::x86_64;
36}
37
38bool CrossWindowsToolChain::isPICDefault() const {
39  return getArch() == llvm::Triple::x86_64;
40}
41
42bool CrossWindowsToolChain::isPIEDefault() const {
43  return getArch() == llvm::Triple::x86_64;
44}
45
46bool CrossWindowsToolChain::isPICDefaultForced() const {
47  return getArch() == llvm::Triple::x86_64;
48}
49
50void CrossWindowsToolChain::
51AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
52                          llvm::opt::ArgStringList &CC1Args) const {
53  const Driver &D = getDriver();
54  const std::string &SysRoot = D.SysRoot;
55
56  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
57    return;
58
59  addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
60  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
61    SmallString<128> ResourceDir(D.ResourceDir);
62    llvm::sys::path::append(ResourceDir, "include");
63    addSystemInclude(DriverArgs, CC1Args, ResourceDir);
64  }
65  addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
66}
67
68void CrossWindowsToolChain::
69AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
70                             llvm::opt::ArgStringList &CC1Args) const {
71  const llvm::Triple &Triple = getTriple();
72  const std::string &SysRoot = getDriver().SysRoot;
73
74  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
75      DriverArgs.hasArg(options::OPT_nostdincxx))
76    return;
77
78  switch (GetCXXStdlibType(DriverArgs)) {
79  case ToolChain::CST_Libcxx:
80    addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/v1");
81    break;
82
83  case ToolChain::CST_Libstdcxx:
84    addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++");
85    addSystemInclude(DriverArgs, CC1Args,
86                     SysRoot + "/usr/include/c++/" + Triple.str());
87    addSystemInclude(DriverArgs, CC1Args,
88                     SysRoot + "/usr/include/c++/backwards");
89  }
90}
91
92void CrossWindowsToolChain::
93AddCXXStdlibLibArgs(const llvm::opt::ArgList &DriverArgs,
94                    llvm::opt::ArgStringList &CC1Args) const {
95  switch (GetCXXStdlibType(DriverArgs)) {
96  case ToolChain::CST_Libcxx:
97    CC1Args.push_back("-lc++");
98    break;
99  case ToolChain::CST_Libstdcxx:
100    CC1Args.push_back("-lstdc++");
101    CC1Args.push_back("-lmingw32");
102    CC1Args.push_back("-lmingwex");
103    CC1Args.push_back("-lgcc");
104    CC1Args.push_back("-lmoldname");
105    CC1Args.push_back("-lmingw32");
106    break;
107  }
108}
109
110clang::SanitizerMask CrossWindowsToolChain::getSupportedSanitizers() const {
111  SanitizerMask Res = ToolChain::getSupportedSanitizers();
112  Res |= SanitizerKind::Address;
113  return Res;
114}
115
116Tool *CrossWindowsToolChain::buildLinker() const {
117  return new tools::CrossWindows::Linker(*this);
118}
119
120Tool *CrossWindowsToolChain::buildAssembler() const {
121  return new tools::CrossWindows::Assembler(*this);
122}
123