/// The original path to the clang executable.
std::string ClangExecutable;
+ /// The path to the installed clang directory, if any.
+ std::string InstalledDir;
+
/// The path to the compiler resource directory.
std::string ResourceDir;
return ClangExecutable.c_str();
}
+ /// \brief Get the path to where the clang executable was installed.
+ const char *getInstalledDir() const {
+ if (!InstalledDir.empty())
+ return InstalledDir.c_str();
+ return Dir.c_str();
+ }
+ void setInstalledDir(llvm::StringRef Value) {
+ InstalledDir = Value;
+ }
+
/// @}
/// @name Primary Functionality
/// @{
Path += ToolChainDir;
getProgramPaths().push_back(Path);
- getProgramPaths().push_back(getDriver().Dir);
+ getProgramPaths().push_back(getDriver().getInstalledDir());
+ if (getDriver().getInstalledDir() != getDriver().Dir)
+ getProgramPaths().push_back(getDriver().Dir);
}
Darwin::~Darwin() {
: Darwin(Host, Triple, DarwinVersion)
{
// We expect 'as', 'ld', etc. to be adjacent to our install dir.
- getProgramPaths().push_back(getDriver().Dir);
+ getProgramPaths().push_back(getDriver().getInstalledDir());
+ if (getDriver().getInstalledDir() != getDriver().Dir)
+ getProgramPaths().push_back(getDriver().Dir);
}
void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args,
Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple)
: ToolChain(Host, Triple) {
- getProgramPaths().push_back(getDriver().Dir);
+ getProgramPaths().push_back(getDriver().getInstalledDir());
+ if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
+ getProgramPaths().push_back(getDriver().Dir);
}
Generic_GCC::~Generic_GCC() {
AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
: Generic_GCC(Host, Triple) {
- getProgramPaths().push_back(getDriver().Dir);
+ getProgramPaths().push_back(getDriver().getInstalledDir());
+ if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
+ getProgramPaths().push_back(getDriver().Dir);
getFilePaths().push_back(getDriver().Dir + "/../lib");
getFilePaths().push_back("/usr/lib");
: Generic_GCC(Host, Triple) {
// Path mangling to find libexec
- getProgramPaths().push_back(getDriver().Dir);
+ getProgramPaths().push_back(getDriver().getInstalledDir());
+ if (getDriver().getInstalledDir() != getDriver().Dir.c_str())
+ getProgramPaths().push_back(getDriver().Dir);
getFilePaths().push_back(getDriver().Dir + "/../lib");
getFilePaths().push_back("/usr/lib");
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Host.h"
#include "llvm/System/Path.h"
+#include "llvm/System/Program.h"
#include "llvm/System/Signals.h"
using namespace clang;
using namespace clang::driver;
"a.out", IsProduction, CXXIsProduction,
Diags);
+ // Attempt to find the original path used to invoke the driver, to determine
+ // the installed path. We do this manually, because we want to support that
+ // path being a symlink.
+ llvm::sys::Path InstalledPath(argv[0]);
+
+ // Do a PATH lookup, if there are no directory components.
+ if (InstalledPath.getLast() == InstalledPath.str()) {
+ llvm::sys::Path Tmp =
+ llvm::sys::Program::FindProgramByName(InstalledPath.getLast());
+ if (!Tmp.empty())
+ InstalledPath = Tmp;
+ }
+ InstalledPath.makeAbsolute();
+ InstalledPath.eraseComponent();
+ if (InstalledPath.exists())
+ TheDriver.setInstalledDir(InstalledPath.str());
+
// Check for ".*++" or ".*++-[^-]*" to determine if we are a C++
// compiler. This matches things like "c++", "clang++", and "clang++-1.1".
//