On Thu, Mar 17, 2011 at 11:11:01PM +0100, Joerg Sonnenberger wrote:
> I would expect a sane cross-compiling setup for other platforms to be
> quite similar. With some additional changes to make the look up for
> crt0.o and libgcc honour --sysroot, all that is needed for
> cross-compiliation is using "clang -ccc-host-triple i486--netbsdelf
> --sysroot $DESTDIR" or adding a symlink and using "i486--netbsdelf-clang
> --sysroot $DESTDIR".

Attached patch implements the missing parts of --sysroot. I'm not
completely happy of moving it to driver, but I wouldn't find an easier
way to get to the command line arguments early enough.

Again, other platforms likely want to have the same changes.

Joerg
Index: include/clang/Driver/Driver.h
===================================================================
--- include/clang/Driver/Driver.h	(revision 127752)
+++ include/clang/Driver/Driver.h	(working copy)
@@ -77,6 +77,12 @@
   typedef llvm::SmallVector<std::string, 4> prefix_list;
   prefix_list PrefixDirs;
 
+  /// sysroot, if present
+  std::string SysRoot;
+
+  /// If the standard library is used
+  bool UseStdLib;
+
   /// Default host triple.
   std::string DefaultHostTriple;
 
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 127752)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -3417,6 +3428,11 @@
   const Driver &D = getToolChain().getDriver();
   ArgStringList CmdArgs;
 
+  if (!D.SysRoot.empty()) {
+    CmdArgs.push_back("--sysroot");
+    CmdArgs.push_back(D.SysRoot.c_str());
+  }
+
   if (Args.hasArg(options::OPT_static)) {
     CmdArgs.push_back("-Bstatic");
   } else {
Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp	(revision 127752)
+++ lib/Driver/ToolChains.cpp	(working copy)
@@ -1159,12 +1159,15 @@
         llvm::Triple::x86_64)
     Lib32 = true;
 
-  getProgramPaths().push_back(getDriver().Dir + "/../libexec");
-  getProgramPaths().push_back("/usr/libexec");
-  if (Lib32) {
-    getFilePaths().push_back("/usr/lib/i386");
-  } else {
-    getFilePaths().push_back("/usr/lib");
+  if (getDriver().UseStdLib) {
+    const char *LibDir;
+    if (Lib32) {
+      LibDir = "/usr/lib/i386";
+    } else {
+      LibDir = "/usr/lib";
+    }
+
+    getFilePaths().push_back(getDriver().SysRoot + LibDir);
   }
 }
 
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp	(revision 127769)
+++ lib/Driver/Driver.cpp	(working copy)
@@ -58,8 +58,8 @@
                bool IsProduction, bool CXXIsProduction,
                Diagnostic &_Diags)
   : Opts(createDriverOptTable()), Diags(_Diags),
-    ClangExecutable(_ClangExecutable), DefaultHostTriple(_DefaultHostTriple),
-    DefaultImageName(_DefaultImageName),
+    ClangExecutable(_ClangExecutable), UseStdLib(true),
+    DefaultHostTriple(_DefaultHostTriple), DefaultImageName(_DefaultImageName),
     DriverTitle("clang \"gcc-compatible\" driver"),
     Host(0),
     CCPrintOptionsFilename(0), CCPrintHeadersFilename(0), CCCIsCXX(false),
@@ -287,6 +287,10 @@
     A->claim();
     PrefixDirs.push_back(A->getValue(*Args, 0));
   }
+  if (const Arg *A = Args->getLastArg(options::OPT__sysroot_EQ))
+    SysRoot = A->getValue(*Args);
+  if (Args->hasArg(options::OPT_nostdlib))
+    UseStdLib = false;
 
   Host = GetHostInfo(DefaultHostTriple.c_str());
 
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to