xref: /minix3/external/bsd/llvm/dist/clang/lib/Driver/CrossWindowsToolChain.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc //===--- CrossWindowsToolChain.cpp - Cross Windows Tool Chain -------------===//
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*0a6a1f1dSLionel Sambuc // License. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc //
8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
9*0a6a1f1dSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc #include "ToolChains.h"
11*0a6a1f1dSLionel Sambuc #include "clang/Driver/Driver.h"
12*0a6a1f1dSLionel Sambuc #include "clang/Driver/Options.h"
13*0a6a1f1dSLionel Sambuc #include "llvm/Option/ArgList.h"
14*0a6a1f1dSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc using namespace clang::driver;
16*0a6a1f1dSLionel Sambuc using namespace clang::driver::toolchains;
17*0a6a1f1dSLionel Sambuc 
CrossWindowsToolChain(const Driver & D,const llvm::Triple & T,const llvm::opt::ArgList & Args)18*0a6a1f1dSLionel Sambuc CrossWindowsToolChain::CrossWindowsToolChain(const Driver &D,
19*0a6a1f1dSLionel Sambuc                                              const llvm::Triple &T,
20*0a6a1f1dSLionel Sambuc                                              const llvm::opt::ArgList &Args)
21*0a6a1f1dSLionel Sambuc     : Generic_GCC(D, T, Args) {
22*0a6a1f1dSLionel Sambuc   if (GetCXXStdlibType(Args) == ToolChain::CST_Libstdcxx) {
23*0a6a1f1dSLionel Sambuc     const std::string &SysRoot = D.SysRoot;
24*0a6a1f1dSLionel Sambuc 
25*0a6a1f1dSLionel Sambuc     // libstdc++ resides in /usr/lib, but depends on libgcc which is placed in
26*0a6a1f1dSLionel Sambuc     // /usr/lib/gcc.
27*0a6a1f1dSLionel Sambuc     getFilePaths().push_back(SysRoot + "/usr/lib");
28*0a6a1f1dSLionel Sambuc     getFilePaths().push_back(SysRoot + "/usr/lib/gcc");
29*0a6a1f1dSLionel Sambuc   }
30*0a6a1f1dSLionel Sambuc }
31*0a6a1f1dSLionel Sambuc 
IsUnwindTablesDefault() const32*0a6a1f1dSLionel Sambuc bool CrossWindowsToolChain::IsUnwindTablesDefault() const {
33*0a6a1f1dSLionel Sambuc   // FIXME: all non-x86 targets need unwind tables, however, LLVM currently does
34*0a6a1f1dSLionel Sambuc   // not know how to emit them.
35*0a6a1f1dSLionel Sambuc   return getArch() == llvm::Triple::x86_64;
36*0a6a1f1dSLionel Sambuc }
37*0a6a1f1dSLionel Sambuc 
isPICDefault() const38*0a6a1f1dSLionel Sambuc bool CrossWindowsToolChain::isPICDefault() const {
39*0a6a1f1dSLionel Sambuc   return getArch() == llvm::Triple::x86_64;
40*0a6a1f1dSLionel Sambuc }
41*0a6a1f1dSLionel Sambuc 
isPIEDefault() const42*0a6a1f1dSLionel Sambuc bool CrossWindowsToolChain::isPIEDefault() const {
43*0a6a1f1dSLionel Sambuc   return getArch() == llvm::Triple::x86_64;
44*0a6a1f1dSLionel Sambuc }
45*0a6a1f1dSLionel Sambuc 
isPICDefaultForced() const46*0a6a1f1dSLionel Sambuc bool CrossWindowsToolChain::isPICDefaultForced() const {
47*0a6a1f1dSLionel Sambuc   return getArch() == llvm::Triple::x86_64;
48*0a6a1f1dSLionel Sambuc }
49*0a6a1f1dSLionel Sambuc 
50*0a6a1f1dSLionel Sambuc void CrossWindowsToolChain::
AddClangSystemIncludeArgs(const llvm::opt::ArgList & DriverArgs,llvm::opt::ArgStringList & CC1Args) const51*0a6a1f1dSLionel Sambuc AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
52*0a6a1f1dSLionel Sambuc                           llvm::opt::ArgStringList &CC1Args) const {
53*0a6a1f1dSLionel Sambuc   const Driver &D = getDriver();
54*0a6a1f1dSLionel Sambuc   const std::string &SysRoot = D.SysRoot;
55*0a6a1f1dSLionel Sambuc 
56*0a6a1f1dSLionel Sambuc   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
57*0a6a1f1dSLionel Sambuc     return;
58*0a6a1f1dSLionel Sambuc 
59*0a6a1f1dSLionel Sambuc   addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
60*0a6a1f1dSLionel Sambuc   if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
61*0a6a1f1dSLionel Sambuc     SmallString<128> ResourceDir(D.ResourceDir);
62*0a6a1f1dSLionel Sambuc     llvm::sys::path::append(ResourceDir, "include");
63*0a6a1f1dSLionel Sambuc     addSystemInclude(DriverArgs, CC1Args, ResourceDir.str());
64*0a6a1f1dSLionel Sambuc   }
65*0a6a1f1dSLionel Sambuc   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
66*0a6a1f1dSLionel Sambuc }
67*0a6a1f1dSLionel Sambuc 
68*0a6a1f1dSLionel Sambuc void CrossWindowsToolChain::
AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList & DriverArgs,llvm::opt::ArgStringList & CC1Args) const69*0a6a1f1dSLionel Sambuc AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
70*0a6a1f1dSLionel Sambuc                              llvm::opt::ArgStringList &CC1Args) const {
71*0a6a1f1dSLionel Sambuc   const llvm::Triple &Triple = getTriple();
72*0a6a1f1dSLionel Sambuc   const std::string &SysRoot = getDriver().SysRoot;
73*0a6a1f1dSLionel Sambuc 
74*0a6a1f1dSLionel Sambuc   if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
75*0a6a1f1dSLionel Sambuc       DriverArgs.hasArg(options::OPT_nostdincxx))
76*0a6a1f1dSLionel Sambuc     return;
77*0a6a1f1dSLionel Sambuc 
78*0a6a1f1dSLionel Sambuc   switch (GetCXXStdlibType(DriverArgs)) {
79*0a6a1f1dSLionel Sambuc   case ToolChain::CST_Libcxx:
80*0a6a1f1dSLionel Sambuc     addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/v1");
81*0a6a1f1dSLionel Sambuc     break;
82*0a6a1f1dSLionel Sambuc 
83*0a6a1f1dSLionel Sambuc   case ToolChain::CST_Libstdcxx:
84*0a6a1f1dSLionel Sambuc     addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++");
85*0a6a1f1dSLionel Sambuc     addSystemInclude(DriverArgs, CC1Args,
86*0a6a1f1dSLionel Sambuc                      SysRoot + "/usr/include/c++/" + Triple.str());
87*0a6a1f1dSLionel Sambuc     addSystemInclude(DriverArgs, CC1Args,
88*0a6a1f1dSLionel Sambuc                      SysRoot + "/usr/include/c++/backwards");
89*0a6a1f1dSLionel Sambuc   }
90*0a6a1f1dSLionel Sambuc }
91*0a6a1f1dSLionel Sambuc 
92*0a6a1f1dSLionel Sambuc void CrossWindowsToolChain::
AddCXXStdlibLibArgs(const llvm::opt::ArgList & DriverArgs,llvm::opt::ArgStringList & CC1Args) const93*0a6a1f1dSLionel Sambuc AddCXXStdlibLibArgs(const llvm::opt::ArgList &DriverArgs,
94*0a6a1f1dSLionel Sambuc                     llvm::opt::ArgStringList &CC1Args) const {
95*0a6a1f1dSLionel Sambuc   switch (GetCXXStdlibType(DriverArgs)) {
96*0a6a1f1dSLionel Sambuc   case ToolChain::CST_Libcxx:
97*0a6a1f1dSLionel Sambuc     CC1Args.push_back("-lc++");
98*0a6a1f1dSLionel Sambuc     break;
99*0a6a1f1dSLionel Sambuc   case ToolChain::CST_Libstdcxx:
100*0a6a1f1dSLionel Sambuc     CC1Args.push_back("-lstdc++");
101*0a6a1f1dSLionel Sambuc     CC1Args.push_back("-lmingw32");
102*0a6a1f1dSLionel Sambuc     CC1Args.push_back("-lmingwex");
103*0a6a1f1dSLionel Sambuc     CC1Args.push_back("-lgcc");
104*0a6a1f1dSLionel Sambuc     CC1Args.push_back("-lmoldname");
105*0a6a1f1dSLionel Sambuc     CC1Args.push_back("-lmingw32");
106*0a6a1f1dSLionel Sambuc     break;
107*0a6a1f1dSLionel Sambuc   }
108*0a6a1f1dSLionel Sambuc }
109*0a6a1f1dSLionel Sambuc 
buildLinker() const110*0a6a1f1dSLionel Sambuc Tool *CrossWindowsToolChain::buildLinker() const {
111*0a6a1f1dSLionel Sambuc   return new tools::CrossWindows::Link(*this);
112*0a6a1f1dSLionel Sambuc }
113*0a6a1f1dSLionel Sambuc 
buildAssembler() const114*0a6a1f1dSLionel Sambuc Tool *CrossWindowsToolChain::buildAssembler() const {
115*0a6a1f1dSLionel Sambuc   return new tools::CrossWindows::Assemble(*this);
116*0a6a1f1dSLionel Sambuc }
117*0a6a1f1dSLionel Sambuc 
118