]> granicus.if.org Git - clang/commitdiff
Driver/Darwin: Honor --sysroot= when invoking the linker, on Darwin.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 2 May 2011 21:03:47 +0000 (21:03 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 2 May 2011 21:03:47 +0000 (21:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130723 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/sysroot.c [new file with mode: 0644]

index 60803ddf93c8ab0400f3761778267912d9f59682..89cf228d9520c3b3180936825b1076f9e3351823 100644 (file)
@@ -2893,12 +2893,17 @@ void darwin::Link::AddLinkArgs(Compilation &C,
   Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
   Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
 
-  Args.AddAllArgsTranslated(CmdArgs, options::OPT_isysroot, "-syslibroot");
-  if (getDarwinToolChain().isTargetIPhoneOS()) {
-    if (!Args.hasArg(options::OPT_isysroot)) {
-      CmdArgs.push_back("-syslibroot");
-      CmdArgs.push_back("/Developer/SDKs/Extra");
-    }
+  // Give --sysroot= preference, over the Apple specific behavior to also use
+  // --isysroot as the syslibroot.
+  if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
+    CmdArgs.push_back("-syslibroot");
+    CmdArgs.push_back(A->getValue(Args));
+  } else if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
+    CmdArgs.push_back("-syslibroot");
+    CmdArgs.push_back(A->getValue(Args));
+  } else if (getDarwinToolChain().isTargetIPhoneOS()) {
+    CmdArgs.push_back("-syslibroot");
+    CmdArgs.push_back("/Developer/SDKs/Extra");
   }
 
   Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace);
diff --git a/test/Driver/sysroot.c b/test/Driver/sysroot.c
new file mode 100644 (file)
index 0000000..0348d72
--- /dev/null
@@ -0,0 +1,18 @@
+// Check that --sysroot= also applies to header search paths.
+// RUN: %clang -ccc-host-triple unknown --sysroot=/FOO -### -E %s 2> %t1
+// RUN: FileCheck --check-prefix=CHECK-SYSROOTEQ < %t1 %s
+// CHECK-SYSROOTEQ: "-cc1"{{.*}} "-isysroot" "/FOO"
+
+// Apple Darwin uses -isysroot as the syslib root, too.
+// RUN: touch %t2.o
+// RUN: %clang -ccc-host-triple i386-apple-darwin10 \
+// RUN:   -isysroot /FOO -### %t2.o 2> %t2
+// RUN: FileCheck --check-prefix=CHECK-APPLE-ISYSROOT < %t2 %s
+// CHECK-APPLE-ISYSROOT: "-arch" "i386"{{.*}} "-syslibroot" "/FOO"
+
+// Check that honor --sysroot= over -isysroot, for Apple Darwin.
+// RUN: touch %t3.o
+// RUN: %clang -ccc-host-triple i386-apple-darwin10 \
+// RUN:   -isysroot /FOO --sysroot=/BAR -### %t3.o 2> %t3
+// RUN: FileCheck --check-prefix=CHECK-APPLE-SYSROOT < %t3 %s
+// CHECK-APPLE-SYSROOT: "-arch" "i386"{{.*}} "-syslibroot" "/BAR"