1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
6 #include "objectfile.h"
7 #include "sharedlibrary.h"
8 #include "sourcepackage.h"
9 #include "staticlibrary.h"
14 Binary::Binary(Builder &b, const FS::Path &p):
18 Binary::Binary(Builder &b, const Component &c, const string &p, const list<ObjectFile *> &objs):
19 FileTarget(b, c.get_package(), c.get_package().get_out_dir()/p)
22 for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
26 void Binary::find_depends()
31 BuildInfo::LibraryMode libmode = component->get_build_info().libmode;
33 list<const Component *> queue;
34 list<Target *> dep_libs;
35 queue.push_back(component);
38 const Component *c = queue.front();
39 queue.erase(queue.begin());
41 const BuildInfo &binfo = c->get_build_info();
42 for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
44 Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
47 dep_libs.push_back(lib);
49 lib = lib->get_real_target();
50 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
51 if(stlib->get_component())
52 queue.push_back(stlib->get_component());
55 builder.problem(package->get_name(), format("Couldn't find library %s for %s", *i, name));
59 /* Add only the last occurrence of each library to the actual dependencies.
60 This ensures that static library ordering is correct. */
61 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
64 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
65 last = (j==i || *j!=*i);