1cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//===-- llvm-config.cpp - LLVM project configuration utility --------------===//
2cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//
3cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//                     The LLVM Compiler Infrastructure
4cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//
5cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// This file is distributed under the University of Illinois Open Source
6cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// License. See LICENSE.TXT for details.
7cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//
8cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//===----------------------------------------------------------------------===//
9cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//
10cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// This tool encapsulates information about an LLVM project configuration for
11cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// use by other project's build environments (to determine installed path,
12cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// available features, required libraries, etc.).
13cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//
14cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// Note that although this tool *may* be used by some parts of LLVM's build
15cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// itself (i.e., the Makefiles use it to compute required libraries when linking
16cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// tools), this tool is primarily designed to support external projects.
17cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//
18cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//===----------------------------------------------------------------------===//
19cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
20cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/ADT/STLExtras.h"
21cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/ADT/StringMap.h"
22cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/ADT/StringRef.h"
2336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/ADT/Triple.h"
24cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/ADT/Twine.h"
25cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/Config/config.h"
26cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/Config/llvm-config.h"
27cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/Support/FileSystem.h"
28cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/Support/Path.h"
29cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "llvm/Support/raw_ostream.h"
30cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include <cstdlib>
31cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include <set>
32cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include <vector>
33cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
34cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbarusing namespace llvm;
35cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
36cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// Include the build time variables we can report to the user. This is generated
37cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// at build time from the BuildVariables.inc.in file by the build system.
38cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "BuildVariables.inc"
39cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
40cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// Include the component table. This creates an array of struct
41cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// AvailableComponent entries, which record the component name, library name,
42cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// and required components for all of the available libraries.
43cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar//
44cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// Not all components define a library, we also use "library groups" as a way to
45cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar// create entries for pseudo groups like x86 or all-targets.
46cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar#include "LibraryDependencies.inc"
47cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
48cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \brief Traverse a single component adding to the topological ordering in
49cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \arg RequiredLibs.
50cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar///
51cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \param Name - The component to traverse.
52cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \param ComponentMap - A prebuilt map of component names to descriptors.
53cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \param VisitedComponents [in] [out] - The set of already visited components.
54cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \param RequiredLibs [out] - The ordered list of required libraries.
55cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbarstatic void VisitComponent(StringRef Name,
56cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar                           const StringMap<AvailableComponent*> &ComponentMap,
57cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar                           std::set<AvailableComponent*> &VisitedComponents,
58b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar                           std::vector<StringRef> &RequiredLibs,
59b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar                           bool IncludeNonInstalled) {
60cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Lookup the component.
61cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  AvailableComponent *AC = ComponentMap.lookup(Name);
62cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  assert(AC && "Invalid component name!");
63cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
64cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Add to the visited table.
65cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  if (!VisitedComponents.insert(AC).second) {
66cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // We are done if the component has already been visited.
67cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    return;
68cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  }
69cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
70b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar  // Only include non-installed components if requested.
71b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar  if (!AC->IsInstalled && !IncludeNonInstalled)
72b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar    return;
73b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar
74cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Otherwise, visit all the dependencies.
75cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
76cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
77b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar                   RequiredLibs, IncludeNonInstalled);
78cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  }
79cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
80cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Add to the required library list.
81cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  if (AC->Library)
82cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    RequiredLibs.push_back(AC->Library);
83cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar}
84cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
85cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \brief Compute the list of required libraries for a given list of
86cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// components, in an order suitable for passing to a linker (that is, libraries
87cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// appear prior to their dependencies).
88cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar///
89cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \param Components - The names of the components to find libraries for.
90cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \param RequiredLibs [out] - On return, the ordered list of libraries that
91cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// are required to link the given components.
92b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar/// \param IncludeNonInstalled - Whether non-installed components should be
93b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar/// reported.
94cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbarvoid ComputeLibsForComponents(const std::vector<StringRef> &Components,
95b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar                              std::vector<StringRef> &RequiredLibs,
96b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar                              bool IncludeNonInstalled) {
97cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  std::set<AvailableComponent*> VisitedComponents;
98cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
99cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Build a map of component names to information.
100cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  StringMap<AvailableComponent*> ComponentMap;
101cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  for (unsigned i = 0; i != array_lengthof(AvailableComponents); ++i) {
102cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    AvailableComponent *AC = &AvailableComponents[i];
103cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ComponentMap[AC->Name] = AC;
104cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  }
105cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
106cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Visit the components.
107cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  for (unsigned i = 0, e = Components.size(); i != e; ++i) {
108cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // Users are allowed to provide mixed case component names.
109cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    std::string ComponentLower = Components[i].lower();
110cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
111cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // Validate that the user supplied a valid component name.
112cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    if (!ComponentMap.count(ComponentLower)) {
113cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      llvm::errs() << "llvm-config: unknown component name: " << Components[i]
114cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar                   << "\n";
115cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      exit(1);
116cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    }
117cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
118cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
119b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar                   RequiredLibs, IncludeNonInstalled);
120cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  }
121cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
122cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // The list is now ordered with leafs first, we want the libraries to printed
123cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // in the reverse order of dependency.
124cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  std::reverse(RequiredLibs.begin(), RequiredLibs.end());
125cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar}
126cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
127cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/* *** */
128cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
129cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbarvoid usage() {
130cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  errs() << "\
131cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbarusage: llvm-config <OPTION>... [<COMPONENT>...]\n\
132cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar\n\
133cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel DunbarGet various configuration information needed to compile programs which use\n\
134cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel DunbarLLVM.  Typically called from 'configure' scripts.  Examples:\n\
135cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  llvm-config --cxxflags\n\
136cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  llvm-config --ldflags\n\
137cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  llvm-config --libs engine bcreader scalaropts\n\
138cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar\n\
139cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel DunbarOptions:\n\
140cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --version         Print LLVM version.\n\
141cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --prefix          Print the installation prefix.\n\
142cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --src-root        Print the source root LLVM was built from.\n\
143cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --obj-root        Print the object root used to build LLVM.\n\
144cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --bindir          Directory containing LLVM executables.\n\
145cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --includedir      Directory containing LLVM headers.\n\
146cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --libdir          Directory containing LLVM libraries.\n\
147cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --cppflags        C preprocessor flags for files that include LLVM headers.\n\
148cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --cflags          C compiler flags for files that include LLVM headers.\n\
149cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --cxxflags        C++ compiler flags for files that include LLVM headers.\n\
150cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --ldflags         Print Linker flags.\n\
15136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  --system-libs     System Libraries needed to link against LLVM components.\n\
152cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --libs            Libraries needed to link against LLVM components.\n\
153cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --libnames        Bare library names for in-tree builds.\n\
154cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --libfiles        Fully qualified library filenames for makefile depends.\n\
155cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --components      List of all possible components.\n\
156cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --targets-built   List of all targets currently built.\n\
157cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --host-target     Target triple used to configure LLVM.\n\
158cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  --build-mode      Print build mode of LLVM tree (e.g. Debug or Release).\n\
15936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  --assertion-mode  Print assertion mode of LLVM tree (ON or OFF).\n\
160cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel DunbarTypical components:\n\
161cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  all               All LLVM libraries (default).\n\
162cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  engine            Either a native JIT or a bitcode interpreter.\n";
163cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  exit(1);
164cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar}
165cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
166cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar/// \brief Compute the path to the main executable.
16750188c1f42c122640ab9ccac2134acf371c26b2cRafael Espindolastd::string GetExecutablePath(const char *Argv0) {
168cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // This just needs to be some symbol in the binary; C++ doesn't
169cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // allow taking the address of ::main however.
170cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  void *P = (void*) (intptr_t) GetExecutablePath;
17150188c1f42c122640ab9ccac2134acf371c26b2cRafael Espindola  return llvm::sys::fs::getMainExecutable(Argv0, P);
172cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar}
173cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
174cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbarint main(int argc, char **argv) {
175cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  std::vector<StringRef> Components;
176cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  bool PrintLibs = false, PrintLibNames = false, PrintLibFiles = false;
17736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool PrintSystemLibs = false;
178cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  bool HasAnyOption = false;
179cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
180cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // llvm-config is designed to support being run both from a development tree
181cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // and from an installed path. We try and auto-detect which case we are in so
182cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // that we can report the correct information when run from a development
183cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // tree.
184b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne  bool IsInDevelopmentTree;
185b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne  enum { MakefileStyle, CMakeStyle, CMakeBuildModeStyle } DevelopmentTreeLayout;
18650188c1f42c122640ab9ccac2134acf371c26b2cRafael Espindola  llvm::SmallString<256> CurrentPath(GetExecutablePath(argv[0]));
187cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  std::string CurrentExecPrefix;
188cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  std::string ActiveObjRoot;
189cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
19036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // If CMAKE_CFG_INTDIR is given, honor it as build mode.
19136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  char const *build_mode = LLVM_BUILDMODE;
19236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#if defined(CMAKE_CFG_INTDIR)
19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (!(CMAKE_CFG_INTDIR[0] == '.' && CMAKE_CFG_INTDIR[1] == '\0'))
19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    build_mode = CMAKE_CFG_INTDIR;
19536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#endif
19636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
197cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Create an absolute path, and pop up one directory (we expect to be inside a
198cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // bin dir).
199cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  sys::fs::make_absolute(CurrentPath);
200cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  CurrentExecPrefix = sys::path::parent_path(
201cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    sys::path::parent_path(CurrentPath)).str();
202cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
203cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Check to see if we are inside a development tree by comparing to possible
20440d65dc3058e8d58426953d44e2ea0eccf996371Daniel Dunbar  // locations (prefix style or CMake style).
20540d65dc3058e8d58426953d44e2ea0eccf996371Daniel Dunbar  if (sys::fs::equivalent(CurrentExecPrefix,
20636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                          Twine(LLVM_OBJ_ROOT) + "/" + build_mode)) {
207cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    IsInDevelopmentTree = true;
208b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    DevelopmentTreeLayout = MakefileStyle;
209cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
210cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // If we are in a development tree, then check if we are in a BuildTools
211cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // directory. This indicates we are built for the build triple, but we
212cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // always want to provide information for the host triple.
213cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    if (sys::path::filename(LLVM_OBJ_ROOT) == "BuildTools") {
214cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      ActiveObjRoot = sys::path::parent_path(LLVM_OBJ_ROOT);
215cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    } else {
216cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      ActiveObjRoot = LLVM_OBJ_ROOT;
217cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    }
21840d65dc3058e8d58426953d44e2ea0eccf996371Daniel Dunbar  } else if (sys::fs::equivalent(CurrentExecPrefix, LLVM_OBJ_ROOT)) {
219b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    IsInDevelopmentTree = true;
220b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    DevelopmentTreeLayout = CMakeStyle;
221b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    ActiveObjRoot = LLVM_OBJ_ROOT;
22240d65dc3058e8d58426953d44e2ea0eccf996371Daniel Dunbar  } else if (sys::fs::equivalent(CurrentExecPrefix,
22340d65dc3058e8d58426953d44e2ea0eccf996371Daniel Dunbar                                 Twine(LLVM_OBJ_ROOT) + "/bin")) {
224cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    IsInDevelopmentTree = true;
225b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    DevelopmentTreeLayout = CMakeBuildModeStyle;
226cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActiveObjRoot = LLVM_OBJ_ROOT;
227cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  } else {
228cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    IsInDevelopmentTree = false;
2299778ad51ee1d2a604b6cc4bece336d2bc4bfbe20Duncan Sands    DevelopmentTreeLayout = MakefileStyle; // Initialized to avoid warnings.
230cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  }
231cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
232cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // Compute various directory locations based on the derived location
233cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  // information.
234cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir;
235cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  std::string ActiveIncludeOption;
236cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  if (IsInDevelopmentTree) {
237cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
238cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActivePrefix = CurrentExecPrefix;
239cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
240cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // CMake organizes the products differently than a normal prefix style
241cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // layout.
242b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    switch (DevelopmentTreeLayout) {
243b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    case MakefileStyle:
24436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      ActivePrefix = ActiveObjRoot;
24536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      ActiveBinDir = ActiveObjRoot + "/" + build_mode + "/bin";
24636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      ActiveLibDir = ActiveObjRoot + "/" + build_mode + "/lib";
247b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne      break;
248b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    case CMakeStyle:
249b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne      ActiveBinDir = ActiveObjRoot + "/bin";
250b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne      ActiveLibDir = ActiveObjRoot + "/lib";
251b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne      break;
252b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne    case CMakeBuildModeStyle:
25336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      ActivePrefix = ActiveObjRoot;
25436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      ActiveBinDir = ActiveObjRoot + "/bin/" + build_mode;
25536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      ActiveLibDir = ActiveObjRoot + "/lib/" + build_mode;
256b56900aa86aa535fb1f060f5935d1e209e45d907Peter Collingbourne      break;
257cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    }
258cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
259cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // We need to include files from both the source and object trees.
260cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActiveIncludeOption = ("-I" + ActiveIncludeDir + " " +
261cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar                           "-I" + ActiveObjRoot + "/include");
262cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  } else {
263cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActivePrefix = CurrentExecPrefix;
264cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActiveIncludeDir = ActivePrefix + "/include";
265cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActiveBinDir = ActivePrefix + "/bin";
266cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActiveLibDir = ActivePrefix + "/lib";
267cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    ActiveIncludeOption = "-I" + ActiveIncludeDir;
268cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  }
269cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
270cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  raw_ostream &OS = outs();
271cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  for (int i = 1; i != argc; ++i) {
272cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    StringRef Arg = argv[i];
273cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
274cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    if (Arg.startswith("-")) {
275cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      HasAnyOption = true;
276cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      if (Arg == "--version") {
277cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << PACKAGE_VERSION << '\n';
278cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--prefix") {
279cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << ActivePrefix << '\n';
280cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--bindir") {
281cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << ActiveBinDir << '\n';
282cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--includedir") {
283cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << ActiveIncludeDir << '\n';
284cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--libdir") {
285cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << ActiveLibDir << '\n';
286cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--cppflags") {
287cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << ActiveIncludeOption << ' ' << LLVM_CPPFLAGS << '\n';
288cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--cflags") {
289cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << ActiveIncludeOption << ' ' << LLVM_CFLAGS << '\n';
290cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--cxxflags") {
291cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n';
292cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--ldflags") {
29336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        OS << "-L" << ActiveLibDir << ' ' << LLVM_LDFLAGS << '\n';
29436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      } else if (Arg == "--system-libs") {
29536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        PrintSystemLibs = true;
296cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--libs") {
297cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        PrintLibs = true;
298cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--libnames") {
299cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        PrintLibNames = true;
300cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--libfiles") {
301cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        PrintLibFiles = true;
302cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--components") {
303cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) {
304b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar          // Only include non-installed components when in a development tree.
305b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar          if (!AvailableComponents[j].IsInstalled && !IsInDevelopmentTree)
306b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar            continue;
307b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar
308cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar          OS << ' ';
309cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar          OS << AvailableComponents[j].Name;
310cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        }
311cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << '\n';
312cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--targets-built") {
313275dd94afedd3b7331e5e93c9bbadac9a0415798Daniel Dunbar        OS << LLVM_TARGETS_BUILT << '\n';
314cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--host-target") {
31536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        OS << Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE) << '\n';
316cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--build-mode") {
31736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        OS << build_mode << '\n';
31836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      } else if (Arg == "--assertion-mode") {
31936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#if defined(NDEBUG)
32036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        OS << "OFF\n";
32136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#else
32236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        OS << "ON\n";
32336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#endif
324cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--obj-root") {
32536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        OS << ActivePrefix << '\n';
326cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else if (Arg == "--src-root") {
327cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        OS << LLVM_SRC_ROOT << '\n';
328cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      } else {
329cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar        usage();
330cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      }
331cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    } else {
332cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      Components.push_back(Arg);
333cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    }
334cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  }
335cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
336cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  if (!HasAnyOption)
337cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    usage();
338cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
33936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs) {
3408033f6197c2cd7a71c9a725e49efaa402a17e707Daniel Dunbar    // If no components were specified, default to "all".
3418033f6197c2cd7a71c9a725e49efaa402a17e707Daniel Dunbar    if (Components.empty())
3428033f6197c2cd7a71c9a725e49efaa402a17e707Daniel Dunbar      Components.push_back("all");
3438033f6197c2cd7a71c9a725e49efaa402a17e707Daniel Dunbar
344cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    // Construct the list of all the required libraries.
345cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    std::vector<StringRef> RequiredLibs;
346b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar    ComputeLibsForComponents(Components, RequiredLibs,
347b5cd41e26f89aad2f2dc4f5dc37577f7abf8528aDaniel Dunbar                             /*IncludeNonInstalled=*/IsInDevelopmentTree);
348cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
34936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (PrintLibs || PrintLibNames || PrintLibFiles) {
35036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
35136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        StringRef Lib = RequiredLibs[i];
35236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        if (i)
35336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          OS << ' ';
354cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
35536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        if (PrintLibNames) {
35636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          OS << Lib;
35736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        } else if (PrintLibFiles) {
35836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          OS << ActiveLibDir << '/' << Lib;
35936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        } else if (PrintLibs) {
36036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          // If this is a typical library name, include it using -l.
36136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          if (Lib.startswith("lib") && Lib.endswith(".a")) {
36236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines            OS << "-l" << Lib.slice(3, Lib.size()-2);
36336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines            continue;
36436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          }
36536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
36636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          // Otherwise, print the full path.
36736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines          OS << ActiveLibDir << '/' << Lib;
36836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines        }
369cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar      }
37036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      OS << '\n';
371cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    }
37236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
37336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // Print SYSTEM_LIBS after --libs.
37436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // FIXME: Each LLVM component may have its dependent system libs.
37536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (PrintSystemLibs)
37636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      OS << LLVM_SYSTEM_LIBS << '\n';
377cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  } else if (!Components.empty()) {
378cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    errs() << "llvm-config: error: components given, but unused\n\n";
379cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar    usage();
380cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  }
381cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar
382cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar  return 0;
383cb497b888aabebe13de431c8a6e7c7d31f4dea0cDaniel Dunbar}
384