From c50b00dbd843cd929b5f220d4a8699852249f64c Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 23 Mar 2009 16:15:50 +0000 Subject: [PATCH] Driver: Setup file and program search paths in tool chains. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67529 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Driver.cpp | 11 ++---- lib/Driver/HostInfo.cpp | 4 ++- lib/Driver/ToolChains.cpp | 70 +++++++++++++++++++++++++++++++++++++++ lib/Driver/ToolChains.h | 17 ++++++++-- 4 files changed, 90 insertions(+), 12 deletions(-) diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index db084262e9..df71c97215 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -920,15 +920,8 @@ llvm::sys::Path Driver::GetProgramPath(const char *Name, return P; } - // As a last resort, always search in our directory before pulling - // from the path. - llvm::sys::Path P(Dir); - P.appendComponent(Name); - if (P.exists()) - return P; - - // Search path to increase accuracy of logging output. - P = llvm::sys::Program::FindProgramByName(Name); + // If all else failed, search the path. + llvm::sys::Path P(llvm::sys::Program::FindProgramByName(Name)); if (!P.empty()) return P; diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp index 8c24a3c707..8f762095b6 100644 --- a/lib/Driver/HostInfo.cpp +++ b/lib/Driver/HostInfo.cpp @@ -159,7 +159,9 @@ ToolChain *DarwinHostInfo::getToolChain(const ArgList &Args, if (strcmp(ArchName, "i386") == 0 || strcmp(ArchName, "x86_64") == 0) TC = new toolchains::Darwin_X86(*this, ArchName, getPlatformName().c_str(), - getOSName().c_str()); + getOSName().c_str(), + DarwinVersion, + GCCVersion); else TC = new toolchains::Darwin_GCC(*this, ArchName, getPlatformName().c_str(), diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 3165a8f395..eac72ee65a 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -9,11 +9,74 @@ #include "ToolChains.h" +#include "clang/Driver/Driver.h" +#include "clang/Driver/HostInfo.h" + +#include "llvm/ADT/StringExtras.h" +#include "llvm/System/Path.h" + using namespace clang::driver; using namespace clang::driver::toolchains; /// Darwin_X86 - Darwin tool chain for i386 and x86_64. +Darwin_X86::Darwin_X86(const HostInfo &Host, const char *Arch, + const char *Platform, const char *OS, + const unsigned (&_DarwinVersion)[3], + const unsigned (&_GCCVersion)[3]) + : ToolChain(Host, Arch, Platform, OS) +{ + DarwinVersion[0] = _DarwinVersion[0]; + DarwinVersion[1] = _DarwinVersion[1]; + DarwinVersion[2] = _DarwinVersion[2]; + GCCVersion[0] = _GCCVersion[0]; + GCCVersion[1] = _GCCVersion[1]; + GCCVersion[2] = _GCCVersion[2]; + + ToolChainDir = "i686-apple-darwin"; + ToolChainDir += llvm::utostr(DarwinVersion[0]); + ToolChainDir += "/"; + ToolChainDir += llvm::utostr(GCCVersion[0]); + ToolChainDir += '.'; + ToolChainDir += llvm::utostr(GCCVersion[1]); + ToolChainDir += '.'; + ToolChainDir += llvm::utostr(GCCVersion[2]); + + std::string Path; + if (getArchName() == "x86_64") { + Path = getHost().getDriver().Dir; + Path += "/../lib/gcc/"; + Path += getToolChainDir(); + Path += "/x86_64"; + getFilePaths().push_back(Path); + + Path = "/usr/lib/gcc/"; + Path += getToolChainDir(); + Path += "/x86_64"; + getFilePaths().push_back(Path); + } + + Path = getHost().getDriver().Dir; + Path += "/../lib/gcc/"; + Path += getToolChainDir(); + getFilePaths().push_back(Path); + + Path = "/usr/lib/gcc/"; + Path += getToolChainDir(); + getFilePaths().push_back(Path); + + Path = getHost().getDriver().Dir; + Path += "/../libexec/gcc/"; + Path += getToolChainDir(); + getProgramPaths().push_back(Path); + + Path = "/usr/libexec/gcc/"; + Path += getToolChainDir(); + getProgramPaths().push_back(Path); + + getProgramPaths().push_back(getHost().getDriver().Dir); +} + Darwin_X86::~Darwin_X86() { // Free tool implementations. for (llvm::DenseMap::iterator @@ -84,6 +147,13 @@ const char *Darwin_X86::GetForcedPicModel() const { /// all subcommands; this relies on gcc translating the majority of /// command line options. +Generic_GCC::Generic_GCC(const HostInfo &Host, const char *Arch, + const char *Platform, const char *OS) + : ToolChain(Host, Arch, Platform, OS) +{ + getProgramPaths().push_back(getHost().getDriver().Dir); +} + Generic_GCC::~Generic_GCC() { // Free tool implementations. for (llvm::DenseMap::iterator diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 9e196e02f2..ea1661a970 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -30,7 +30,7 @@ class VISIBILITY_HIDDEN Generic_GCC : public ToolChain { public: Generic_GCC(const HostInfo &Host, const char *Arch, const char *Platform, - const char *OS) : ToolChain(Host, Arch, Platform, OS) {} + const char *OS); ~Generic_GCC(); virtual ArgList *TranslateArgs(ArgList &Args) const { return &Args; } @@ -47,9 +47,19 @@ public: class VISIBILITY_HIDDEN Darwin_X86 : public ToolChain { mutable llvm::DenseMap Tools; + /// Darwin version of tool chain. + unsigned DarwinVersion[3]; + + /// GCC version to use. + unsigned GCCVersion[3]; + + /// The directory suffix for this tool chain. + std::string ToolChainDir; + public: Darwin_X86(const HostInfo &Host, const char *Arch, const char *Platform, - const char *OS) : ToolChain(Host, Arch, Platform, OS) {} + const char *OS, const unsigned (&DarwinVersion)[3], + const unsigned (&GCCVersion)[3]); ~Darwin_X86(); virtual ArgList *TranslateArgs(ArgList &Args) const; @@ -60,6 +70,9 @@ public: virtual bool IsUnwindTablesDefault() const; virtual const char *GetDefaultRelocationModel() const; virtual const char *GetForcedPicModel() const; + +private: + const std::string &getToolChainDir() const { return ToolChainDir; } }; /// Darwin_GCC - Generic Darwin tool chain using gcc. -- 2.40.0