Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -1965,7 +1965,8 @@ TC = new toolchains::Windows(*this, Target, Args); break; case llvm::Triple::MinGW32: - // FIXME: We need a MinGW toolchain. Fallthrough for now. + TC = new toolchains::MinGW32(*this, Target, Args); + break; default: // TCE is an OSless target if (Target.getArchName() == "tce") { Index: lib/Driver/ToolChains.h =================================================================== --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -694,6 +694,22 @@ llvm::opt::ArgStringList &CmdArgs) const; }; +class LLVM_LIBRARY_VISIBILITY MinGW32 : public Generic_GCC { +public: + MinGW32(const Driver &D, const llvm::Triple &Triple, + const llvm::opt::ArgList &Args); + + virtual bool IsUnwindTablesDefault() const { return getArch() == llvm::Triple::x86_64; } + virtual bool isPICDefault() const { return getArch() == llvm::Triple::x86_64; } + virtual bool isPICDefaultForced() const { return getArch() == llvm::Triple::x86_64; } + virtual bool isPIEDefault() const { return false; } + + virtual void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const; + virtual void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const; +}; + } // end namespace toolchains } // end namespace driver } // end namespace clang Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -1543,8 +1543,12 @@ LI->path() + MIPSABIDirSuffix, TargetArch, Args)) { GCCBiarchSuffix = BiarchSuffix; - } else if (NeedsBiarchSuffix || - !hasCrtBeginObj(LI->path() + MIPSABIDirSuffix)) { + } else if (NeedsBiarchSuffix || ( + !hasCrtBeginObj(LI->path() + MIPSABIDirSuffix) && + !CandidateTriple.endswith("-mingw32") + )) { + // FIXME: MinGW doesn't hold crtbegin.o here + // Maybe there's another file we can search for instead? continue; } else { GCCBiarchSuffix.clear(); @@ -2898,3 +2902,50 @@ ArgStringList &CmdArgs) const { // We don't output any lib args. This is handled by xcc. } + +/// MinGW32 - MinGW32 toolchain (experimental). + +MinGW32::MinGW32(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) + : Generic_GCC(D, Triple, Args) { + +#if defined(_WIN32) + getFilePaths().push_back(D.SysRoot + "/lib"); + getFilePaths().push_back(D.SysRoot + "/" + Triple.getTriple() + "/lib"); +#else + getFilePaths().push_back(D.SysRoot + "/usr/lib"); + getFilePaths().push_back(D.SysRoot + "/usr/" + Triple.getTriple() + "/lib"); +#endif +} + +void MinGW32::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + if(DriverArgs.hasArg(options::OPT_nostdinc) || + DriverArgs.hasArg(options::OPT_nostdlibinc)) + return; + +#if defined(_WIN32) + addSystemInclude(DriverArgs, CC1Args, + getDriver().SysRoot + "/" + getTriple().getTriple() + "/include"); +#else + addSystemInclude(DriverArgs, CC1Args, + getDriver().SysRoot + "/usr/" + getTriple().getTriple() + "/include"); +#endif +} + +void MinGW32::AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + if(DriverArgs.hasArg(options::OPT_nostdincxx) || + DriverArgs.hasArg(options::OPT_nostdlibinc)) + return; + + if(GCCInstallation.isValid()) { + addSystemInclude(DriverArgs, CC1Args, + GCCInstallation.getInstallPath() + "/include"); + addSystemInclude(DriverArgs, CC1Args, + GCCInstallation.getInstallPath() + "/include-fixed"); + addSystemInclude(DriverArgs, CC1Args, + GCCInstallation.getInstallPath() + "/include/c++"); + addSystemInclude(DriverArgs, CC1Args, + GCCInstallation.getInstallPath() + "/include/c++/" + getTriple().getTriple()); + } +} Index: lib/Frontend/InitHeaderSearch.cpp =================================================================== --- lib/Frontend/InitHeaderSearch.cpp +++ lib/Frontend/InitHeaderSearch.cpp @@ -231,6 +231,7 @@ case llvm::Triple::NetBSD: case llvm::Triple::OpenBSD: case llvm::Triple::Bitrig: + case llvm::Triple::MinGW32: break; default: // FIXME: temporary hack: hard-coded paths. @@ -269,6 +270,7 @@ switch (os) { case llvm::Triple::Linux: case llvm::Triple::Win32: + case llvm::Triple::MinGW32: llvm_unreachable("Include management is handled in the driver."); case llvm::Triple::Haiku: @@ -310,29 +312,6 @@ case llvm::Triple::Cygwin: AddPath("/usr/include/w32api", System, false); break; - case llvm::Triple::MinGW32: { - // mingw-w64 crt include paths - // /i686-w64-mingw32/include - SmallString<128> P = StringRef(HSOpts.ResourceDir); - llvm::sys::path::append(P, "../../../i686-w64-mingw32/include"); - AddPath(P.str(), System, false); - - // /x86_64-w64-mingw32/include - P.resize(HSOpts.ResourceDir.size()); - llvm::sys::path::append(P, "../../../x86_64-w64-mingw32/include"); - AddPath(P.str(), System, false); - - // mingw.org crt include paths - // /include - P.resize(HSOpts.ResourceDir.size()); - llvm::sys::path::append(P, "../../../include"); - AddPath(P.str(), System, false); - AddPath("/mingw/include", System, false); -#if defined(_WIN32) - AddPath("c:/mingw/include", System, false); -#endif - } - break; default: break; @@ -383,6 +362,7 @@ switch (os) { case llvm::Triple::Linux: case llvm::Triple::Win32: + case llvm::Triple::MinGW32: llvm_unreachable("Include management is handled in the driver."); case llvm::Triple::Cygwin: @@ -393,30 +373,6 @@ // g++-4 / Cygwin-1.5 AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); break; - case llvm::Triple::MinGW32: - // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32) - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3"); - AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0"); - // mingw.org C++ include paths - AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS -#if defined(_WIN32) - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.8.1"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); - AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); -#endif - break; case llvm::Triple::DragonFly: if (llvm::sys::fs::exists("/usr/lib/gcc47")) AddPath("/usr/include/c++/4.7", CXXSystem, false); @@ -467,6 +423,7 @@ case llvm::Triple::Linux: case llvm::Triple::Win32: + case llvm::Triple::MinGW32: return; }