Split Darwin toolchain into Clang and GCC Darwin toolchains with a common base.

llvm-svn: 82213
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp
index 5db58c1..3d692b0 100644
--- a/clang/lib/Driver/ToolChains.cpp
+++ b/clang/lib/Driver/ToolChains.cpp
@@ -29,23 +29,31 @@
 /// Darwin - Darwin tool chain for i386 and x86_64.
 
 Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
-               const unsigned (&_DarwinVersion)[3],
-               const unsigned (&_GCCVersion)[3],
-               bool _IsIPhone)
-  : ToolChain(Host, Triple) {
+               const unsigned (&_DarwinVersion)[3], bool _IsIPhoneOS)
+  : ToolChain(Host, Triple),
+    IsIPhoneOS(_IsIPhoneOS)
+{
   DarwinVersion[0] = _DarwinVersion[0];
   DarwinVersion[1] = _DarwinVersion[1];
   DarwinVersion[2] = _DarwinVersion[2];
-  GCCVersion[0] = _GCCVersion[0];
-  GCCVersion[1] = _GCCVersion[1];
-  GCCVersion[2] = _GCCVersion[2];
-  IsIPhone = _IsIPhone;
 
   llvm::raw_string_ostream(MacosxVersionMin)
     << "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1];
 
   // FIXME: Lift default up.
   IPhoneOSVersionMin = "3.0";
+}
+
+DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple,
+                     const unsigned (&DarwinVersion)[3],
+                     const unsigned (&_GCCVersion)[3], bool IsIPhoneOS)
+  : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
+{
+  GCCVersion[0] = _GCCVersion[0];
+  GCCVersion[1] = _GCCVersion[1];
+  GCCVersion[2] = _GCCVersion[2];
+
+  // Set up the tool chain paths to match gcc.
 
   ToolChainDir = "i686-apple-darwin";
   ToolChainDir += llvm::utostr(DarwinVersion[0]);
@@ -134,8 +142,8 @@
   return *T;
 }
 
-void Darwin::AddLinkSearchPathArgs(const ArgList &Args,
-                                   ArgStringList &CmdArgs) const {
+void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args,
+                                      ArgStringList &CmdArgs) const {
   // FIXME: Derive these correctly.
   if (getArchName() == "x86_64") {
     CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir +
@@ -154,8 +162,8 @@
                                        "/../../.."));
 }
 
-void Darwin::AddLinkRuntimeLibArgs(const ArgList &Args,
-                                   ArgStringList &CmdArgs) const {
+void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
+                                      ArgStringList &CmdArgs) const {
   unsigned MacosxVersionMin[3];
   getMacosxVersionMin(Args, MacosxVersionMin);
 
@@ -167,7 +175,7 @@
       CmdArgs.push_back("-lgcc_eh");
     } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
       // Derived from darwin_iphoneos_libgcc spec.
-      if (isIPhone()) {
+      if (isIPhoneOS()) {
         CmdArgs.push_back("-lgcc_s.1");
       } else {
         CmdArgs.push_back("-lgcc_s.10.5");
@@ -190,7 +198,7 @@
         CmdArgs.push_back("-lgcc_s.10.5");
     }
 
-    if (isIPhone() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
+    if (isIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
       CmdArgs.push_back("-lgcc");
       CmdArgs.push_back("-lSystem");
     } else {
@@ -200,6 +208,46 @@
   }
 }
 
+DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple,
+                         const unsigned (&DarwinVersion)[3],
+                         bool IsIPhoneOS)
+  : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS)
+{
+  // We expect 'as', 'ld', etc. to be adjacent to our install dir.
+  getProgramPaths().push_back(getHost().getDriver().Dir);
+}
+
+void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
+                                       ArgStringList &CmdArgs) const {
+  // The Clang toolchain uses explicit paths for internal libraries.
+}
+
+void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
+                                        ArgStringList &CmdArgs) const {
+  // Check for static linking.
+  if (Args.hasArg(options::OPT_static)) {
+    // FIXME: We need to have compiler-rt available (perhaps as
+    // libclang_static.a) to link against.
+    return;
+  }
+
+  // Reject -static-libgcc for now, we can deal with this when and if someone
+  // cares. This is useful in situations where someone wants to statically link
+  // something like libstdc++, and needs its runtime support routines.
+  if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) {
+    getHost().getDriver().Diag(clang::diag::err_drv_unsupported_opt)
+      << A->getAsString(Args);
+    return;
+  }
+
+  // Otherwise link libSystem, which should have the support routines.
+  //
+  // FIXME: This is only true for 10.6 and beyond. Legacy support isn't
+  // critical, but it should work... we should just link in the static
+  // compiler-rt library.
+  CmdArgs.push_back("-lSystem");
+}
+
 void Darwin::getMacosxVersionMin(const ArgList &Args,
                                  unsigned (&Res)[3]) const {
   if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
@@ -240,7 +288,7 @@
     //
     // FIXME: Are there iPhone overrides for this?
 
-    if (!isIPhone()) {
+    if (!isIPhoneOS()) {
       // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
       // from the host.
       const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");