[cfe-commits] r127994 - in /cfe/trunk: include/clang/Driver/Driver.h lib/Driver/Driver.cpp lib/Driver/Tools.cpp

Joerg Sonnenberger joerg at bec.de
Mon Mar 21 06:51:30 PDT 2011


Author: joerg
Date: Mon Mar 21 08:51:29 2011
New Revision: 127994

URL: http://llvm.org/viewvc/llvm-project?rev=127994&view=rev
Log:
Remember sysroot in Driver. Pass it down to ld for NetBSD, FreeBSD
and DragonFly. Use the --sysroot= form for Linux. Fix handling of =
prefix for -B.

Modified:
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=127994&r1=127993&r2=127994&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Mon Mar 21 08:51:29 2011
@@ -77,6 +77,9 @@
   typedef llvm::SmallVector<std::string, 4> prefix_list;
   prefix_list PrefixDirs;
 
+  /// sysroot, if present
+  std::string SysRoot;
+
   /// Default host triple.
   std::string DefaultHostTriple;
 

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=127994&r1=127993&r2=127994&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Mar 21 08:51:29 2011
@@ -287,6 +287,8 @@
     A->claim();
     PrefixDirs.push_back(A->getValue(*Args, 0));
   }
+  if (const Arg *A = Args->getLastArg(options::OPT__sysroot_EQ))
+    SysRoot = A->getValue(*Args);
 
   Host = GetHostInfo(DefaultHostTriple.c_str());
 
@@ -1261,7 +1263,12 @@
   // attempting to use this prefix when lokup up program paths.
   for (Driver::prefix_list::const_iterator it = PrefixDirs.begin(),
        ie = PrefixDirs.end(); it != ie; ++it) {
-    llvm::sys::Path P(*it);
+    std::string Dir(*it);
+    if (Dir.empty())
+      continue;
+    if (Dir[0] == '=')
+      Dir = SysRoot + Dir.substr(1);
+    llvm::sys::Path P(Dir);
     P.appendComponent(Name);
     bool Exists;
     if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)
@@ -1271,7 +1278,12 @@
   const ToolChain::path_list &List = TC.getFilePaths();
   for (ToolChain::path_list::const_iterator
          it = List.begin(), ie = List.end(); it != ie; ++it) {
-    llvm::sys::Path P(*it);
+    std::string Dir(*it);
+    if (Dir.empty())
+      continue;
+    if (Dir[0] == '=')
+      Dir = SysRoot + Dir.substr(1);
+    llvm::sys::Path P(Dir);
     P.appendComponent(Name);
     bool Exists;
     if (!llvm::sys::fs::exists(P.str(), Exists) && Exists)

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=127994&r1=127993&r2=127994&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Mar 21 08:51:29 2011
@@ -3259,6 +3259,9 @@
   const Driver &D = getToolChain().getDriver();
   ArgStringList CmdArgs;
 
+  if (!D.SysRoot.empty())
+    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
   if (Args.hasArg(options::OPT_static)) {
     CmdArgs.push_back("-Bstatic");
   } else {
@@ -3437,6 +3440,9 @@
   const Driver &D = getToolChain().getDriver();
   ArgStringList CmdArgs;
 
+  if (!D.SysRoot.empty())
+    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
   if (Args.hasArg(options::OPT_static)) {
     CmdArgs.push_back("-Bstatic");
   } else {
@@ -3594,10 +3600,8 @@
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
-    CmdArgs.push_back("--sysroot");
-    CmdArgs.push_back(A->getValue(Args));
-  }
+  if (!D.SysRoot.empty())
+    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
   if (Args.hasArg(options::OPT_pie))
     CmdArgs.push_back("-pie");
@@ -3878,6 +3882,9 @@
   const Driver &D = getToolChain().getDriver();
   ArgStringList CmdArgs;
 
+  if (!D.SysRoot.empty())
+    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
   if (Args.hasArg(options::OPT_static)) {
     CmdArgs.push_back("-Bstatic");
   } else {





More information about the cfe-commits mailing list