-
-/// LinkLibraries - takes the specified library files and links them into the
-/// main bytecode object file.
-///
-/// Inputs:
-/// progname - The name of the program (infamous argv[0]).
-/// HeadModule - The module into which all necessary libraries will be linked.
-/// Libraries - The list of libraries to link into the module.
-/// LibPaths - The list of library paths in which to find libraries.
-/// Verbose - Flags whether verbose messages should be printed.
-/// Native - Flags whether native code is being generated.
-///
-/// Outputs:
-/// HeadModule - The module will have all necessary libraries linked in.
-///
-/// Return value:
-/// FALSE - No error.
-/// TRUE - Error.
-///
-void llvm::LinkLibraries(const char *progname, Module *HeadModule,
- const std::vector<std::string> &Libraries,
- const std::vector<std::string> &LibPaths,
- bool Verbose, bool Native) {
- // String in which to receive error messages.
- std::string ErrorMessage;
-
- for (unsigned i = 0; i < Libraries.size(); ++i) {
- // Determine where this library lives.
- std::string Pathname = FindLib(Libraries[i], LibPaths);
- if (Pathname.empty()) {
- // If the pathname does not exist, then continue to the next one if
- // we're doing a native link and give an error if we're doing a bytecode
- // link.
- if (!Native) {
- std::cerr << progname << ": WARNING: Cannot find library -l"
- << Libraries[i] << "\n";
- continue;
- }
- }
-
- // A user may specify an ar archive without -l, perhaps because it
- // is not installed as a library. Detect that and link the library.
- if (IsArchive(Pathname)) {
- if (Verbose)
- std::cerr << "Trying to link archive '" << Pathname << "' (-l"
- << Libraries[i] << ")\n";
-
- if (LinkInArchive(HeadModule, Pathname, &ErrorMessage, Verbose)) {
- std::cerr << progname << ": " << ErrorMessage
- << ": Error linking in archive '" << Pathname << "' (-l"
- << Libraries[i] << ")\n";
- exit(1);
- }
- } else if (IsBytecode(Pathname)) {
- if (Verbose)
- std::cerr << "Trying to link bytecode file '" << Pathname
- << "' (-l" << Libraries[i] << ")\n";
-
- if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) {
- std::cerr << progname << ": " << ErrorMessage
- << ": error linking in bytecode file '" << Pathname << "' (-l"
- << Libraries[i] << ")\n";
- exit(1);
- }
- }
- }
-}