X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-config%2Fllvm-config.cpp;h=3924e2e55da03f596234fbcdd5ae00d21c4b5308;hb=11eb51e23935e22e1cb7b346c45713e8c9169c84;hp=4b6179904afee46b0ce8db6a2e64fd6786e549c9;hpb=bcf14bbd57b8457ea09afbfc7acddf2d21a5adac;p=oota-llvm.git diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp index 4b6179904af..3924e2e55da 100644 --- a/tools/llvm-config/llvm-config.cpp +++ b/tools/llvm-config/llvm-config.cpp @@ -25,7 +25,6 @@ #include "llvm/Config/llvm-config.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -55,7 +54,8 @@ using namespace llvm; static void VisitComponent(StringRef Name, const StringMap &ComponentMap, std::set &VisitedComponents, - std::vector &RequiredLibs) { + std::vector &RequiredLibs, + bool IncludeNonInstalled) { // Lookup the component. AvailableComponent *AC = ComponentMap.lookup(Name); assert(AC && "Invalid component name!"); @@ -66,10 +66,14 @@ static void VisitComponent(StringRef Name, return; } + // Only include non-installed components if requested. + if (!AC->IsInstalled && !IncludeNonInstalled) + return; + // Otherwise, visit all the dependencies. for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) { VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents, - RequiredLibs); + RequiredLibs, IncludeNonInstalled); } // Add to the required library list. @@ -84,8 +88,11 @@ static void VisitComponent(StringRef Name, /// \param Components - The names of the components to find libraries for. /// \param RequiredLibs [out] - On return, the ordered list of libraries that /// are required to link the given components. +/// \param IncludeNonInstalled - Whether non-installed components should be +/// reported. void ComputeLibsForComponents(const std::vector &Components, - std::vector &RequiredLibs) { + std::vector &RequiredLibs, + bool IncludeNonInstalled) { std::set VisitedComponents; // Build a map of component names to information. @@ -108,7 +115,7 @@ void ComputeLibsForComponents(const std::vector &Components, } VisitComponent(ComponentLower, ComponentMap, VisitedComponents, - RequiredLibs); + RequiredLibs, IncludeNonInstalled); } // The list is now ordered with leafs first, we want the libraries to printed @@ -154,11 +161,11 @@ Typical components:\n\ } /// \brief Compute the path to the main executable. -llvm::sys::Path GetExecutablePath(const char *Argv0) { +std::string GetExecutablePath(const char *Argv0) { // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. void *P = (void*) (intptr_t) GetExecutablePath; - return llvm::sys::Path::GetMainExecutable(Argv0, P); + return llvm::sys::fs::getMainExecutable(Argv0, P); } int main(int argc, char **argv) { @@ -170,8 +177,9 @@ int main(int argc, char **argv) { // and from an installed path. We try and auto-detect which case we are in so // that we can report the correct information when run from a development // tree. - bool IsInDevelopmentTree, DevelopmentTreeLayoutIsCMakeStyle; - llvm::SmallString<256> CurrentPath(GetExecutablePath(argv[0]).str()); + bool IsInDevelopmentTree; + enum { MakefileStyle, CMakeStyle, CMakeBuildModeStyle } DevelopmentTreeLayout; + llvm::SmallString<256> CurrentPath(GetExecutablePath(argv[0])); std::string CurrentExecPrefix; std::string ActiveObjRoot; @@ -182,11 +190,11 @@ int main(int argc, char **argv) { sys::path::parent_path(CurrentPath)).str(); // Check to see if we are inside a development tree by comparing to possible - // locations (prefix style or CMake style). This could be wrong in the face of - // symbolic links, but is good enough. - if (CurrentExecPrefix == std::string(LLVM_OBJ_ROOT) + "/" + LLVM_BUILDMODE) { + // locations (prefix style or CMake style). + if (sys::fs::equivalent(CurrentExecPrefix, + Twine(LLVM_OBJ_ROOT) + "/" + LLVM_BUILDMODE)) { IsInDevelopmentTree = true; - DevelopmentTreeLayoutIsCMakeStyle = false; + DevelopmentTreeLayout = MakefileStyle; // If we are in a development tree, then check if we are in a BuildTools // directory. This indicates we are built for the build triple, but we @@ -196,12 +204,18 @@ int main(int argc, char **argv) { } else { ActiveObjRoot = LLVM_OBJ_ROOT; } - } else if (CurrentExecPrefix == std::string(LLVM_OBJ_ROOT) + "/bin") { + } else if (sys::fs::equivalent(CurrentExecPrefix, LLVM_OBJ_ROOT)) { + IsInDevelopmentTree = true; + DevelopmentTreeLayout = CMakeStyle; + ActiveObjRoot = LLVM_OBJ_ROOT; + } else if (sys::fs::equivalent(CurrentExecPrefix, + Twine(LLVM_OBJ_ROOT) + "/bin")) { IsInDevelopmentTree = true; - DevelopmentTreeLayoutIsCMakeStyle = true; + DevelopmentTreeLayout = CMakeBuildModeStyle; ActiveObjRoot = LLVM_OBJ_ROOT; } else { IsInDevelopmentTree = false; + DevelopmentTreeLayout = MakefileStyle; // Initialized to avoid warnings. } // Compute various directory locations based on the derived location @@ -214,12 +228,19 @@ int main(int argc, char **argv) { // CMake organizes the products differently than a normal prefix style // layout. - if (DevelopmentTreeLayoutIsCMakeStyle) { - ActiveBinDir = ActiveObjRoot + "/bin/" + LLVM_BUILDMODE; - ActiveLibDir = ActiveObjRoot + "/lib/" + LLVM_BUILDMODE; - } else { + switch (DevelopmentTreeLayout) { + case MakefileStyle: ActiveBinDir = ActiveObjRoot + "/" + LLVM_BUILDMODE + "/bin"; ActiveLibDir = ActiveObjRoot + "/" + LLVM_BUILDMODE + "/lib"; + break; + case CMakeStyle: + ActiveBinDir = ActiveObjRoot + "/bin"; + ActiveLibDir = ActiveObjRoot + "/lib"; + break; + case CMakeBuildModeStyle: + ActiveBinDir = ActiveObjRoot + "/bin/" + LLVM_BUILDMODE; + ActiveLibDir = ActiveObjRoot + "/lib/" + LLVM_BUILDMODE; + break; } // We need to include files from both the source and object trees. @@ -266,19 +287,16 @@ int main(int argc, char **argv) { PrintLibFiles = true; } else if (Arg == "--components") { for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) { + // Only include non-installed components when in a development tree. + if (!AvailableComponents[j].IsInstalled && !IsInDevelopmentTree) + continue; + OS << ' '; OS << AvailableComponents[j].Name; } OS << '\n'; } else if (Arg == "--targets-built") { - bool First = true; - for (TargetRegistry::iterator I = TargetRegistry::begin(), - E = TargetRegistry::end(); I != E; First = false, ++I) { - if (!First) - OS << ' '; - OS << I->getName(); - } - OS << '\n'; + OS << LLVM_TARGETS_BUILT << '\n'; } else if (Arg == "--host-target") { OS << LLVM_DEFAULT_TARGET_TRIPLE << '\n'; } else if (Arg == "--build-mode") { @@ -305,7 +323,8 @@ int main(int argc, char **argv) { // Construct the list of all the required libraries. std::vector RequiredLibs; - ComputeLibsForComponents(Components, RequiredLibs); + ComputeLibsForComponents(Components, RequiredLibs, + /*IncludeNonInstalled=*/IsInDevelopmentTree); for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) { StringRef Lib = RequiredLibs[i];