#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 <cstdlib>
#include <set>
static void VisitComponent(StringRef Name,
const StringMap<AvailableComponent*> &ComponentMap,
std::set<AvailableComponent*> &VisitedComponents,
- std::vector<StringRef> &RequiredLibs) {
+ std::vector<StringRef> &RequiredLibs,
+ bool IncludeNonInstalled) {
// Lookup the component.
AvailableComponent *AC = ComponentMap.lookup(Name);
assert(AC && "Invalid component 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.
/// \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<StringRef> &Components,
- std::vector<StringRef> &RequiredLibs) {
+ std::vector<StringRef> &RequiredLibs,
+ bool IncludeNonInstalled) {
std::set<AvailableComponent*> VisitedComponents;
// Build a map of component names to information.
}
VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
- RequiredLibs);
+ RequiredLibs, IncludeNonInstalled);
}
// The list is now ordered with leafs first, we want the libraries to printed
--build-mode Print build mode of LLVM tree (e.g. Debug or Release).\n\
Typical components:\n\
all All LLVM libraries (default).\n\
- backend Either a native backend or the C backend.\n\
engine Either a native JIT or a bitcode interpreter.\n";
exit(1);
}
/// \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) {
// 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;
// Create an absolute path, and pop up one directory (we expect to be inside a
// bin dir).
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;
+ 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
+ // always want to provide information for the host triple.
+ if (sys::path::filename(LLVM_OBJ_ROOT) == "BuildTools") {
+ ActiveObjRoot = sys::path::parent_path(LLVM_OBJ_ROOT);
+ } else {
+ ActiveObjRoot = LLVM_OBJ_ROOT;
+ }
+ } else if (sys::fs::equivalent(CurrentExecPrefix, LLVM_OBJ_ROOT)) {
IsInDevelopmentTree = true;
- DevelopmentTreeLayoutIsCMakeStyle = false;
- } else if (CurrentExecPrefix == std::string(LLVM_OBJ_ROOT) + "/bin") {
+ 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
std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir;
std::string ActiveIncludeOption;
if (IsInDevelopmentTree) {
+ ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
ActivePrefix = CurrentExecPrefix;
// CMake organizes the products differently than a normal prefix style
// layout.
- if (DevelopmentTreeLayoutIsCMakeStyle) {
- ActiveIncludeDir = std::string(LLVM_OBJ_ROOT) + "/include";
- ActiveBinDir = std::string(LLVM_OBJ_ROOT) + "/bin/" + LLVM_BUILDMODE;
- ActiveLibDir = std::string(LLVM_OBJ_ROOT) + "/lib/" + LLVM_BUILDMODE;
- } else {
- ActiveIncludeDir = std::string(LLVM_OBJ_ROOT) + "/include";
- ActiveBinDir = std::string(LLVM_OBJ_ROOT) + "/" + LLVM_BUILDMODE + "/bin";
- ActiveLibDir = std::string(LLVM_OBJ_ROOT) + "/" + LLVM_BUILDMODE + "/lib";
+ 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.
ActiveIncludeOption = ("-I" + ActiveIncludeDir + " " +
- "-I" + LLVM_OBJ_ROOT + "/include");
+ "-I" + ActiveObjRoot + "/include");
} else {
ActivePrefix = CurrentExecPrefix;
ActiveIncludeDir = ActivePrefix + "/include";
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") {
usage();
if (PrintLibs || PrintLibNames || PrintLibFiles) {
+ // If no components were specified, default to "all".
+ if (Components.empty())
+ Components.push_back("all");
+
// Construct the list of all the required libraries.
std::vector<StringRef> RequiredLibs;
- ComputeLibsForComponents(Components, RequiredLibs);
+ ComputeLibsForComponents(Components, RequiredLibs,
+ /*IncludeNonInstalled=*/IsInDevelopmentTree);
for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
StringRef Lib = RequiredLibs[i];