1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include <msp/strings/utils.h>
7 #include "objectfile.h"
8 #include "sharedlibrary.h"
9 #include "sourcepackage.h"
10 #include "staticlibrary.h"
16 Binary::Binary(Builder &b, const FS::Path &p):
20 Binary::Binary(Builder &b, const Component &c, const string &p, const list<ObjectFile *> &objs):
21 FileTarget(b, c.get_package(), c.get_package().get_output_directory()/p),
25 for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
28 nested_build_sig = true;
29 arch_in_build_sig = true;
32 void Binary::collect_build_info(BuildInfo &binfo) const
34 for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
35 if(const Tool *obj_tool = (*i)->get_tool())
36 binfo.update_from(obj_tool->get_build_info());
38 Target::collect_build_info(binfo);
40 binfo.update_from(static_binfo);
43 void Binary::find_dependencies()
49 list<Target *> dep_libs;
50 set<string> missing_libs;
51 queue.push_back(this);
52 for(list<Target *>::iterator j=queue.begin(); j!=queue.end(); ++j)
57 tgt->collect_build_info(binfo);
60 static_binfo.libpath.insert(static_binfo.libpath.end(), binfo.libpath.begin(), binfo.libpath.end());
61 static_binfo.keep_symbols.insert(static_binfo.keep_symbols.end(), binfo.keep_symbols.begin(), binfo.keep_symbols.end());
63 static_binfo.threads = true;
66 list<Target *> libs_to_process;
67 for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
69 if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework"))
72 BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i);
73 Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
75 libs_to_process.push_back(lib);
76 else if(missing_libs.insert(*i).second)
77 problems.push_back(format("Required library %s not found", *i));
82 const Target::Dependencies &tdeps = tgt->get_transitive_dependencies();
83 libs_to_process.insert(libs_to_process.end(), tdeps.begin(), tdeps.end());
86 list<Target *>::iterator insert_pos = j;
88 for(list<Target *>::const_iterator i=libs_to_process.begin(); i!=libs_to_process.end(); ++i)
90 Target *real = (*i)->get_real_target();
91 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(real))
92 queue.insert(insert_pos, stlib);
94 dep_libs.push_back(*i);
99 dep_libs.splice(dep_libs.begin(), queue);
101 /* Add only the last occurrence of each library to the actual dependencies.
102 This ensures that static library ordering is correct. */
103 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
106 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
107 last = (j==i || *j!=*i);