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);
41 void Binary::find_dependencies()
46 list<const Component *> queue;
47 list<Target *> dep_libs;
48 set<string> missing_libs;
49 queue.push_back(component);
52 queue.erase(queue.begin());
55 collect_build_info(binfo);
57 for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
59 if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework"))
62 BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i);
63 Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
66 Target *real = lib->get_real_target();
67 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(real))
69 dep_libs.push_back(stlib);
70 if(stlib->get_component())
71 queue.push_back(stlib->get_component());
74 dep_libs.push_back(lib);
76 else if(missing_libs.insert(*i).second)
77 problems.push_back(format("Required library %s not found", *i));
81 /* Add only the last occurrence of each library to the actual dependencies.
82 This ensures that static library ordering is correct. */
83 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
86 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
87 last = (j==i || *j!=*i);