clang API Documentation

CrossWindowsToolChain.cpp
Go to the documentation of this file.
00001 //===--- CrossWindowsToolChain.cpp - Cross Windows Tool Chain -------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "ToolChains.h"
00011 #include "clang/Driver/Driver.h"
00012 #include "clang/Driver/Options.h"
00013 #include "llvm/Option/ArgList.h"
00014 
00015 using namespace clang::driver;
00016 using namespace clang::driver::toolchains;
00017 
00018 CrossWindowsToolChain::CrossWindowsToolChain(const Driver &D,
00019                                              const llvm::Triple &T,
00020                                              const llvm::opt::ArgList &Args)
00021     : Generic_GCC(D, T, Args) {
00022   if (GetCXXStdlibType(Args) == ToolChain::CST_Libstdcxx) {
00023     const std::string &SysRoot = D.SysRoot;
00024 
00025     // libstdc++ resides in /usr/lib, but depends on libgcc which is placed in
00026     // /usr/lib/gcc.
00027     getFilePaths().push_back(SysRoot + "/usr/lib");
00028     getFilePaths().push_back(SysRoot + "/usr/lib/gcc");
00029   }
00030 }
00031 
00032 bool CrossWindowsToolChain::IsUnwindTablesDefault() const {
00033   // FIXME: all non-x86 targets need unwind tables, however, LLVM currently does
00034   // not know how to emit them.
00035   return getArch() == llvm::Triple::x86_64;
00036 }
00037 
00038 bool CrossWindowsToolChain::isPICDefault() const {
00039   return getArch() == llvm::Triple::x86_64;
00040 }
00041 
00042 bool CrossWindowsToolChain::isPIEDefault() const {
00043   return getArch() == llvm::Triple::x86_64;
00044 }
00045 
00046 bool CrossWindowsToolChain::isPICDefaultForced() const {
00047   return getArch() == llvm::Triple::x86_64;
00048 }
00049 
00050 void CrossWindowsToolChain::
00051 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00052                           llvm::opt::ArgStringList &CC1Args) const {
00053   const Driver &D = getDriver();
00054   const std::string &SysRoot = D.SysRoot;
00055 
00056   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
00057     return;
00058 
00059   addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
00060   if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
00061     SmallString<128> ResourceDir(D.ResourceDir);
00062     llvm::sys::path::append(ResourceDir, "include");
00063     addSystemInclude(DriverArgs, CC1Args, ResourceDir.str());
00064   }
00065   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
00066 }
00067 
00068 void CrossWindowsToolChain::
00069 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
00070                              llvm::opt::ArgStringList &CC1Args) const {
00071   const llvm::Triple &Triple = getTriple();
00072   const std::string &SysRoot = getDriver().SysRoot;
00073 
00074   if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
00075       DriverArgs.hasArg(options::OPT_nostdincxx))
00076     return;
00077 
00078   switch (GetCXXStdlibType(DriverArgs)) {
00079   case ToolChain::CST_Libcxx:
00080     addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/c++/v1");
00081     break;
00082 
00083   case ToolChain::CST_Libstdcxx:
00084     addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/incldue/c++");
00085     addSystemInclude(DriverArgs, CC1Args,
00086                      SysRoot + "/usr/include/c++/" + Triple.str());
00087     addSystemInclude(DriverArgs, CC1Args,
00088                      SysRoot + "/usr/include/c++/backwards");
00089   }
00090 }
00091 
00092 void CrossWindowsToolChain::
00093 AddCXXStdlibLibArgs(const llvm::opt::ArgList &DriverArgs,
00094                     llvm::opt::ArgStringList &CC1Args) const {
00095   switch (GetCXXStdlibType(DriverArgs)) {
00096   case ToolChain::CST_Libcxx:
00097     CC1Args.push_back("-lc++");
00098     break;
00099   case ToolChain::CST_Libstdcxx:
00100     CC1Args.push_back("-lstdc++");
00101     CC1Args.push_back("-lmingw32");
00102     CC1Args.push_back("-lmingwex");
00103     CC1Args.push_back("-lgcc");
00104     CC1Args.push_back("-lmoldname");
00105     CC1Args.push_back("-lmingw32");
00106     break;
00107   }
00108 }
00109 
00110 Tool *CrossWindowsToolChain::buildLinker() const {
00111   return new tools::CrossWindows::Link(*this);
00112 }
00113 
00114 Tool *CrossWindowsToolChain::buildAssembler() const {
00115   return new tools::CrossWindows::Assemble(*this);
00116 }
00117