2929#include " llvm/Support/raw_ostream.h"
3030#include < cstdlib>
3131#include < set>
32- #include < unordered_set>
3332#include < vector>
33+ #include < unordered_set>
3434
3535using namespace llvm ;
3636
@@ -46,22 +46,6 @@ using namespace llvm;
4646// create entries for pseudo groups like x86 or all-targets.
4747#include " LibraryDependencies.inc"
4848
49- // LinkMode determines what libraries and flags are returned by llvm-config.
50- enum LinkMode {
51- // LinkModeAuto will link with the default link mode for the installation,
52- // which is dependent on the value of LLVM_LINK_LLVM_DYLIB, and fall back
53- // to the alternative if the required libraries are not available.
54- LinkModeAuto = 0 ,
55-
56- // LinkModeDyLib will link with the single dynamic library if it exists,
57- // and return an error if it does not exist.
58- LinkModeDyLib = 1 ,
59-
60- // LinkModeStatic will link with the individual component static libraries
61- // if they exist, and fail if any one does not exist.
62- LinkModeStatic = 2 ,
63- };
64-
6549// / \brief Traverse a single component adding to the topological ordering in
6650// / \arg RequiredLibs.
6751// /
@@ -72,13 +56,12 @@ enum LinkMode {
7256// / libraries.
7357// / \param GetComponentNames - Get the component names instead of the
7458// / library name.
75- static void VisitComponent (const std::string & Name,
76- const StringMap<AvailableComponent *> &ComponentMap,
77- std::set<AvailableComponent *> &VisitedComponents,
59+ static void VisitComponent (const std::string& Name,
60+ const StringMap<AvailableComponent*> &ComponentMap,
61+ std::set<AvailableComponent*> &VisitedComponents,
7862 std::vector<std::string> &RequiredLibs,
7963 bool IncludeNonInstalled, bool GetComponentNames,
80- const std::string *ActiveLibDir,
81- std::vector<std::string> *Missing) {
64+ const std::string *ActiveLibDir, bool *HasMissing) {
8265 // Lookup the component.
8366 AvailableComponent *AC = ComponentMap.lookup (Name);
8467 assert (AC && " Invalid component name!" );
@@ -97,7 +80,7 @@ static void VisitComponent(const std::string &Name,
9780 for (unsigned i = 0 ; AC->RequiredLibraries [i]; ++i) {
9881 VisitComponent (AC->RequiredLibraries [i], ComponentMap, VisitedComponents,
9982 RequiredLibs, IncludeNonInstalled, GetComponentNames,
100- ActiveLibDir, Missing );
83+ ActiveLibDir, HasMissing );
10184 }
10285
10386 if (GetComponentNames) {
@@ -107,10 +90,8 @@ static void VisitComponent(const std::string &Name,
10790
10891 // Add to the required library list.
10992 if (AC->Library ) {
110- if (Missing && ActiveLibDir) {
111- std::string path = *ActiveLibDir + " /" + AC->Library ;
112- if (!sys::fs::exists (path))
113- Missing->push_back (path);
93+ if (!IncludeNonInstalled && HasMissing && !*HasMissing && ActiveLibDir) {
94+ *HasMissing = !sys::fs::exists (*ActiveLibDir + " /" + AC->Library );
11495 }
11596 RequiredLibs.push_back (AC->Library );
11697 }
@@ -127,13 +108,12 @@ static void VisitComponent(const std::string &Name,
127108static std::vector<std::string>
128109ComputeLibsForComponents (const std::vector<StringRef> &Components,
129110 bool IncludeNonInstalled, bool GetComponentNames,
130- const std::string *ActiveLibDir,
131- std::vector<std::string> *Missing) {
111+ const std::string *ActiveLibDir, bool *HasMissing) {
132112 std::vector<std::string> RequiredLibs;
133113 std::set<AvailableComponent *> VisitedComponents;
134114
135115 // Build a map of component names to information.
136- StringMap<AvailableComponent *> ComponentMap;
116+ StringMap<AvailableComponent*> ComponentMap;
137117 for (unsigned i = 0 ; i != array_lengthof (AvailableComponents); ++i) {
138118 AvailableComponent *AC = &AvailableComponents[i];
139119 ComponentMap[AC->Name ] = AC;
@@ -153,7 +133,7 @@ ComputeLibsForComponents(const std::vector<StringRef> &Components,
153133
154134 VisitComponent (ComponentLower, ComponentMap, VisitedComponents,
155135 RequiredLibs, IncludeNonInstalled, GetComponentNames,
156- ActiveLibDir, Missing );
136+ ActiveLibDir, HasMissing );
157137 }
158138
159139 // The list is now ordered with leafs first, we want the libraries to printed
@@ -199,8 +179,6 @@ Options:\n\
199179 --build-system Print the build system used to build LLVM (autoconf or cmake).\n \
200180 --has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n \
201181 --shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n \
202- --link-shared Link the components as a shared library.\n \
203- --link-static Link the components as a static libraries.\n \
204182Typical components:\n \
205183 all All LLVM libraries (default).\n \
206184 engine Either a native JIT or a bitcode interpreter.\n " ;
@@ -211,7 +189,7 @@ Typical components:\n\
211189std::string GetExecutablePath (const char *Argv0) {
212190 // This just needs to be some symbol in the binary; C++ doesn't
213191 // allow taking the address of ::main however.
214- void *P = (void *) (intptr_t )GetExecutablePath;
192+ void *P = (void *) (intptr_t ) GetExecutablePath;
215193 return llvm::sys::fs::getMainExecutable (Argv0, P);
216194}
217195
@@ -265,8 +243,8 @@ int main(int argc, char **argv) {
265243 // Create an absolute path, and pop up one directory (we expect to be inside a
266244 // bin dir).
267245 sys::fs::make_absolute (CurrentPath);
268- CurrentExecPrefix =
269- sys::path::parent_path ( sys::path::parent_path (CurrentPath)).str ();
246+ CurrentExecPrefix = sys::path::parent_path (
247+ sys::path::parent_path (CurrentPath)).str ();
270248
271249 // Check to see if we are inside a development tree by comparing to possible
272250 // locations (prefix style or CMake style).
@@ -327,8 +305,8 @@ int main(int argc, char **argv) {
327305 }
328306
329307 // We need to include files from both the source and object trees.
330- ActiveIncludeOption =
331- ( " -I " + ActiveIncludeDir + " " + " -I" + ActiveObjRoot + " /include" );
308+ ActiveIncludeOption = ( " -I " + ActiveIncludeDir + " " +
309+ " -I" + ActiveObjRoot + " /include" );
332310 } else {
333311 ActivePrefix = CurrentExecPrefix;
334312 ActiveIncludeDir = ActivePrefix + " /include" ;
@@ -345,25 +323,25 @@ int main(int argc, char **argv) {
345323 // / in the first place. This can't be done at configure/build time.
346324
347325 StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,
348- StaticPrefix, StaticDir = " lib" ;
326+ StaticPrefix, StaticDir = " lib" ;
349327 const Triple HostTriple (Triple::normalize (LLVM_DEFAULT_TARGET_TRIPLE));
350328 if (HostTriple.isOSWindows ()) {
351329 SharedExt = " dll" ;
352- SharedVersionedExt = LLVM_DYLIB_VERSION " .dll" ;
330+ SharedVersionedExt = PACKAGE_VERSION " .dll" ;
353331 StaticExt = " a" ;
354332 SharedDir = ActiveBinDir;
355333 StaticDir = ActiveLibDir;
356334 StaticPrefix = SharedPrefix = " lib" ;
357335 } else if (HostTriple.isOSDarwin ()) {
358336 SharedExt = " dylib" ;
359- SharedVersionedExt = LLVM_DYLIB_VERSION " .dylib" ;
337+ SharedVersionedExt = PACKAGE_VERSION " .dylib" ;
360338 StaticExt = " a" ;
361339 StaticDir = SharedDir = ActiveLibDir;
362340 StaticPrefix = SharedPrefix = " lib" ;
363341 } else {
364342 // default to the unix values:
365343 SharedExt = " so" ;
366- SharedVersionedExt = LLVM_DYLIB_VERSION " .so" ;
344+ SharedVersionedExt = PACKAGE_VERSION " .so" ;
367345 StaticExt = " a" ;
368346 StaticDir = SharedDir = ActiveLibDir;
369347 StaticPrefix = SharedPrefix = " lib" ;
@@ -384,22 +362,11 @@ int main(int argc, char **argv) {
384362
385363 bool DyLibExists = false ;
386364 const std::string DyLibName =
387- (SharedPrefix + " LLVM-" + SharedVersionedExt).str ();
388-
389- // If LLVM_LINK_DYLIB is ON, the single shared library will be returned
390- // for "--libs", etc, if they exist. This behaviour can be overridden with
391- // --link-static or --link-shared.
392- bool LinkDyLib = (std::strcmp (LLVM_LINK_DYLIB, " ON" ) == 0 );
365+ (SharedPrefix + " LLVM-" + SharedVersionedExt).str ();
393366
394367 if (BuiltDyLib) {
395368 DyLibExists = sys::fs::exists (SharedDir + " /" + DyLibName);
396- if (!DyLibExists) {
397- // The shared library does not exist: don't error unless the user
398- // explicitly passes --link-shared.
399- LinkDyLib = false ;
400- }
401369 }
402- LinkMode LinkMode = LinkDyLib ? LinkModeDyLib : LinkModeAuto;
403370
404371 // / Get the component's library name without the lib prefix and the
405372 // / extension. Returns true if Lib is in a recognized format.
@@ -534,10 +501,6 @@ int main(int argc, char **argv) {
534501 OS << ActivePrefix << ' \n ' ;
535502 } else if (Arg == " --src-root" ) {
536503 OS << LLVM_SRC_ROOT << ' \n ' ;
537- } else if (Arg == " --link-shared" ) {
538- LinkMode = LinkModeDyLib;
539- } else if (Arg == " --link-static" ) {
540- LinkMode = LinkModeStatic;
541504 } else {
542505 usage ();
543506 }
@@ -549,11 +512,6 @@ int main(int argc, char **argv) {
549512 if (!HasAnyOption)
550513 usage ();
551514
552- if (LinkMode == LinkModeDyLib && !DyLibExists) {
553- errs () << " llvm-config: error: " << DyLibName << " is missing\n\n " ;
554- usage ();
555- }
556-
557515 if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs ||
558516 PrintSharedMode) {
559517
@@ -567,31 +525,11 @@ int main(int argc, char **argv) {
567525 Components.push_back (" all" );
568526
569527 // Construct the list of all the required libraries.
570- std::vector<std::string> MissingLibs ;
528+ bool HasMissing = false ;
571529 std::vector<std::string> RequiredLibs =
572530 ComputeLibsForComponents (Components,
573531 /* IncludeNonInstalled=*/ IsInDevelopmentTree,
574- false , &ActiveLibDir, &MissingLibs);
575- if (!MissingLibs.empty ()) {
576- switch (LinkMode) {
577- case LinkModeDyLib:
578- break ;
579- case LinkModeAuto:
580- if (DyLibExists) {
581- LinkMode = LinkModeDyLib;
582- break ;
583- }
584- errs ()
585- << " llvm-config: error: component libraries and shared library\n\n " ;
586- // fall through
587- case LinkModeStatic:
588- for (auto &Lib : MissingLibs)
589- errs () << " llvm-config: error: missing: " << Lib << " \n " ;
590- return 1 ;
591- }
592- } else if (LinkMode == LinkModeAuto) {
593- LinkMode = LinkModeStatic;
594- }
532+ false , &ActiveLibDir, &HasMissing);
595533
596534 if (PrintSharedMode) {
597535 std::unordered_set<std::string> FullDyLibComponents;
@@ -611,7 +549,7 @@ int main(int argc, char **argv) {
611549 }
612550 FullDyLibComponents.clear ();
613551
614- if (LinkMode == LinkModeDyLib ) {
552+ if (HasMissing && DyLibExists ) {
615553 OS << " shared\n " ;
616554 return 0 ;
617555 } else {
@@ -643,7 +581,7 @@ int main(int argc, char **argv) {
643581 }
644582 };
645583
646- if (LinkMode == LinkModeDyLib ) {
584+ if (HasMissing && DyLibExists ) {
647585 PrintForLib (DyLibName, true );
648586 } else {
649587 for (unsigned i = 0 , e = RequiredLibs.size (); i != e; ++i) {
0 commit comments