2015-07-07 23:10:47 +08:00
|
|
|
//===--- MinGWToolChain.cpp - MinGWToolChain Implementation ---------------===//
|
2015-07-02 12:45:27 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ToolChains.h"
|
|
|
|
#include "clang/Driver/Driver.h"
|
|
|
|
#include "clang/Driver/Options.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
|
|
|
|
using namespace clang::diag;
|
|
|
|
using namespace clang::driver;
|
|
|
|
using namespace clang::driver::toolchains;
|
|
|
|
using namespace clang;
|
|
|
|
using namespace llvm::opt;
|
|
|
|
|
2015-07-24 19:01:45 +08:00
|
|
|
namespace {
|
|
|
|
bool findGccVersion(StringRef LibDir, std::string &GccLibDir,
|
|
|
|
std::string &Ver) {
|
|
|
|
std::error_code EC;
|
|
|
|
llvm::sys::fs::directory_iterator Entry(LibDir, EC);
|
|
|
|
while (!EC) {
|
|
|
|
GccLibDir = Entry->path();
|
|
|
|
Ver = llvm::sys::path::filename(GccLibDir);
|
|
|
|
if (Ver.size() && isdigit(Ver[0]))
|
|
|
|
return true;
|
|
|
|
Entry.increment(EC);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 19:01:00 +08:00
|
|
|
void MinGW::findGccLibDir() {
|
2015-07-24 19:01:45 +08:00
|
|
|
llvm::SmallVector<llvm::SmallString<32>, 2> Archs;
|
|
|
|
Archs.emplace_back(getTriple().getArchName());
|
|
|
|
Archs[0] += "-w64-mingw32";
|
|
|
|
Archs.emplace_back("mingw32");
|
|
|
|
Arch = "unknown";
|
2015-07-20 14:38:39 +08:00
|
|
|
// lib: Arch Linux, Ubuntu, Windows
|
|
|
|
// lib64: openSUSE Linux
|
2015-07-20 20:40:25 +08:00
|
|
|
for (StringRef Lib : {"lib", "lib64"}) {
|
2015-07-24 19:01:45 +08:00
|
|
|
for (StringRef MaybeArch : Archs) {
|
|
|
|
llvm::SmallString<1024> LibDir(Base);
|
|
|
|
llvm::sys::path::append(LibDir, Lib, "gcc", MaybeArch);
|
|
|
|
if (findGccVersion(LibDir, GccLibDir, Ver)) {
|
|
|
|
Arch = MaybeArch;
|
|
|
|
return;
|
|
|
|
}
|
2015-07-20 14:38:39 +08:00
|
|
|
}
|
2015-07-02 12:45:27 +08:00
|
|
|
}
|
2015-07-21 19:01:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MinGW::MinGW(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
|
|
|
|
: ToolChain(D, Triple, Args) {
|
|
|
|
getProgramPaths().push_back(getDriver().getInstalledDir());
|
|
|
|
|
|
|
|
// In Windows there aren't any standard install locations, we search
|
|
|
|
// for gcc on the PATH. In Linux the base is always /usr.
|
|
|
|
#ifdef LLVM_ON_WIN32
|
|
|
|
if (getDriver().SysRoot.size())
|
|
|
|
Base = getDriver().SysRoot;
|
|
|
|
else if (llvm::ErrorOr<std::string> GPPName =
|
|
|
|
llvm::sys::findProgramByName("gcc"))
|
|
|
|
Base = llvm::sys::path::parent_path(
|
|
|
|
llvm::sys::path::parent_path(GPPName.get()));
|
|
|
|
else
|
|
|
|
Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
|
|
|
|
#else
|
2015-07-24 16:50:15 +08:00
|
|
|
if (getDriver().SysRoot.size())
|
|
|
|
Base = getDriver().SysRoot;
|
|
|
|
else
|
|
|
|
Base = "/usr";
|
2015-07-21 19:01:00 +08:00
|
|
|
#endif
|
2015-07-20 14:38:39 +08:00
|
|
|
|
2015-07-21 19:01:00 +08:00
|
|
|
Base += llvm::sys::path::get_separator();
|
2015-07-24 16:50:15 +08:00
|
|
|
findGccLibDir();
|
2015-07-02 12:45:27 +08:00
|
|
|
// GccLibDir must precede Base/lib so that the
|
|
|
|
// correct crtbegin.o ,cetend.o would be found.
|
|
|
|
getFilePaths().push_back(GccLibDir);
|
2015-07-24 16:50:15 +08:00
|
|
|
getFilePaths().push_back(
|
|
|
|
(Base + Arch + llvm::sys::path::get_separator() + "lib").str());
|
2015-07-20 14:38:39 +08:00
|
|
|
getFilePaths().push_back(Base + "lib");
|
|
|
|
// openSUSE
|
2015-07-24 16:50:15 +08:00
|
|
|
getFilePaths().push_back(Base + Arch + "/sys-root/mingw/lib");
|
2015-07-02 12:45:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MinGW::IsIntegratedAssemblerDefault() const { return true; }
|
|
|
|
|
|
|
|
Tool *MinGW::getTool(Action::ActionClass AC) const {
|
|
|
|
switch (AC) {
|
|
|
|
case Action::PreprocessJobClass:
|
|
|
|
if (!Preprocessor)
|
|
|
|
Preprocessor.reset(new tools::gcc::Preprocessor(*this));
|
|
|
|
return Preprocessor.get();
|
|
|
|
case Action::CompileJobClass:
|
|
|
|
if (!Compiler)
|
|
|
|
Compiler.reset(new tools::gcc::Compiler(*this));
|
|
|
|
return Compiler.get();
|
|
|
|
default:
|
|
|
|
return ToolChain::getTool(AC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *MinGW::buildAssembler() const {
|
|
|
|
return new tools::MinGW::Assembler(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *MinGW::buildLinker() const { return new tools::MinGW::Linker(*this); }
|
|
|
|
|
|
|
|
bool MinGW::IsUnwindTablesDefault() const {
|
|
|
|
return getArch() == llvm::Triple::x86_64;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MinGW::isPICDefault() const { return getArch() == llvm::Triple::x86_64; }
|
|
|
|
|
|
|
|
bool MinGW::isPIEDefault() const { return false; }
|
|
|
|
|
|
|
|
bool MinGW::isPICDefaultForced() const {
|
|
|
|
return getArch() == llvm::Triple::x86_64;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MinGW::UseSEHExceptions() const {
|
|
|
|
return getArch() == llvm::Triple::x86_64;
|
|
|
|
}
|
|
|
|
|
2015-07-21 19:01:00 +08:00
|
|
|
// Include directories for various hosts:
|
|
|
|
|
|
|
|
// Windows, mingw.org
|
2015-07-24 16:50:15 +08:00
|
|
|
// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++
|
|
|
|
// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32
|
|
|
|
// c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\backward
|
|
|
|
// c:\mingw\lib\gcc\mingw32\4.8.1\include
|
|
|
|
// c:\mingw\include
|
|
|
|
// c:\mingw\lib\gcc\mingw32\4.8.1\include-fixed
|
2015-07-21 19:01:00 +08:00
|
|
|
// c:\mingw\mingw32\include
|
|
|
|
|
|
|
|
// Windows, mingw-w64 mingw-builds
|
2015-07-24 16:50:15 +08:00
|
|
|
// c:\mingw32\lib\gcc\i686-w64-mingw32\4.9.1\include
|
|
|
|
// c:\mingw32\lib\gcc\i686-w64-mingw32\4.9.1\include-fixed
|
|
|
|
// c:\mingw32\i686-w64-mingw32\include
|
|
|
|
// c:\mingw32\i686-w64-mingw32\include\c++
|
|
|
|
// c:\mingw32\i686-w64-mingw32\include\c++\i686-w64-mingw32
|
|
|
|
// c:\mingw32\i686-w64-mingw32\include\c++\backward
|
2015-07-21 19:01:00 +08:00
|
|
|
|
|
|
|
// Windows, mingw-w64 msys2
|
2015-07-24 16:50:15 +08:00
|
|
|
// c:\msys64\mingw32\lib\gcc\i686-w64-mingw32\4.9.2\include
|
|
|
|
// c:\msys64\mingw32\include
|
|
|
|
// c:\msys64\mingw32\lib\gcc\i686-w64-mingw32\4.9.2\include-fixed
|
|
|
|
// c:\msys64\mingw32\i686-w64-mingw32\include
|
|
|
|
// c:\msys64\mingw32\include\c++\4.9.2
|
|
|
|
// c:\msys64\mingw32\include\c++\4.9.2\i686-w64-mingw32
|
2015-07-21 19:01:00 +08:00
|
|
|
// c:\msys64\mingw32\include\c++\4.9.2\backward
|
|
|
|
|
|
|
|
// openSUSE
|
|
|
|
// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++
|
|
|
|
// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32
|
|
|
|
// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward
|
|
|
|
// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include
|
|
|
|
// /usr/lib64/gcc/x86_64-w64-mingw32/5.1.0/include-fixed
|
|
|
|
// /usr/x86_64-w64-mingw32/sys-root/mingw/include
|
|
|
|
|
|
|
|
// Arch Linux
|
2015-07-24 16:50:15 +08:00
|
|
|
// /usr/i686-w64-mingw32/include/c++/5.1.0
|
|
|
|
// /usr/i686-w64-mingw32/include/c++/5.1.0/i686-w64-mingw32
|
|
|
|
// /usr/i686-w64-mingw32/include/c++/5.1.0/backward
|
|
|
|
// /usr/lib/gcc/i686-w64-mingw32/5.1.0/include
|
|
|
|
// /usr/lib/gcc/i686-w64-mingw32/5.1.0/include-fixed
|
2015-07-21 19:01:00 +08:00
|
|
|
// /usr/i686-w64-mingw32/include
|
|
|
|
|
|
|
|
// Ubuntu
|
2015-07-24 16:50:15 +08:00
|
|
|
// /usr/include/c++/4.8
|
|
|
|
// /usr/include/c++/4.8/x86_64-w64-mingw32
|
|
|
|
// /usr/include/c++/4.8/backward
|
|
|
|
// /usr/lib/gcc/x86_64-w64-mingw32/4.8/include
|
|
|
|
// /usr/lib/gcc/x86_64-w64-mingw32/4.8/include-fixed
|
|
|
|
// /usr/x86_64-w64-mingw32/include
|
2015-07-21 19:01:00 +08:00
|
|
|
|
2015-07-02 12:45:27 +08:00
|
|
|
void MinGW::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
|
|
|
if (DriverArgs.hasArg(options::OPT_nostdinc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
|
|
|
|
SmallString<1024> P(getDriver().ResourceDir);
|
|
|
|
llvm::sys::path::append(P, "include");
|
|
|
|
addSystemInclude(DriverArgs, CC1Args, P.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DriverArgs.hasArg(options::OPT_nostdlibinc))
|
|
|
|
return;
|
|
|
|
|
2015-07-23 00:01:38 +08:00
|
|
|
if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) {
|
|
|
|
llvm::SmallString<1024> IncludeDir(GccLibDir);
|
|
|
|
llvm::sys::path::append(IncludeDir, "include");
|
|
|
|
addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str());
|
|
|
|
IncludeDir += "-fixed";
|
|
|
|
// openSUSE
|
|
|
|
addSystemInclude(DriverArgs, CC1Args,
|
|
|
|
"/usr/x86_64-w64-mingw32/sys-root/mingw/include");
|
|
|
|
addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str());
|
|
|
|
}
|
2015-07-24 16:50:15 +08:00
|
|
|
addSystemInclude(DriverArgs, CC1Args,
|
|
|
|
Base + Arch + llvm::sys::path::get_separator() + "include");
|
2015-07-02 12:45:27 +08:00
|
|
|
addSystemInclude(DriverArgs, CC1Args, Base + "include");
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinGW::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
|
|
|
if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
|
|
|
|
DriverArgs.hasArg(options::OPT_nostdincxx))
|
|
|
|
return;
|
|
|
|
|
2015-07-23 00:01:38 +08:00
|
|
|
switch (GetCXXStdlibType(DriverArgs)) {
|
|
|
|
case ToolChain::CST_Libcxx:
|
2015-07-24 16:50:15 +08:00
|
|
|
addSystemInclude(DriverArgs, CC1Args,
|
|
|
|
Base + "include" + llvm::sys::path::get_separator() +
|
|
|
|
"c++" + llvm::sys::path::get_separator() + "v1");
|
2015-07-23 00:01:38 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ToolChain::CST_Libstdcxx:
|
|
|
|
llvm::SmallVector<llvm::SmallString<1024>, 4> CppIncludeBases;
|
|
|
|
CppIncludeBases.emplace_back(Base);
|
|
|
|
llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++");
|
|
|
|
CppIncludeBases.emplace_back(Base);
|
|
|
|
llvm::sys::path::append(CppIncludeBases[1], Arch, "include", "c++", Ver);
|
|
|
|
CppIncludeBases.emplace_back(Base);
|
|
|
|
llvm::sys::path::append(CppIncludeBases[2], "include", "c++", Ver);
|
|
|
|
CppIncludeBases.emplace_back(GccLibDir);
|
|
|
|
llvm::sys::path::append(CppIncludeBases[3], "include", "c++");
|
|
|
|
for (auto &CppIncludeBase : CppIncludeBases) {
|
|
|
|
addSystemInclude(DriverArgs, CC1Args, CppIncludeBase);
|
2015-07-24 16:50:15 +08:00
|
|
|
CppIncludeBase += llvm::sys::path::get_separator();
|
2015-07-23 00:01:38 +08:00
|
|
|
addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch);
|
|
|
|
addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward");
|
|
|
|
}
|
|
|
|
break;
|
2015-07-02 12:45:27 +08:00
|
|
|
}
|
|
|
|
}
|