1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
7 #include "objectfile.h"
8 #include "sharedlibrary.h"
9 #include "sourcepackage.h"
10 #include "staticlibrary.h"
15 Binary::Binary(Builder &b, const FS::Path &p):
19 Binary::Binary(Builder &b, const Component &c, const std::string &p, const list<ObjectFile *> &objs):
20 FileTarget(b, &c.get_package(), c.get_package().get_out_dir()/p)
23 for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
27 void Binary::find_depends()
32 const SourcePackage &spkg = component->get_package();
33 LibMode libmode = spkg.get_library_mode();
34 if(dynamic_cast<SharedLibrary *>(this))
37 list<const Component *> queue;
38 list<Target *> dep_libs;
39 queue.push_back(component);
42 const Component *c = queue.front();
43 queue.erase(queue.begin());
45 const StringList &libpath = c->get_build_info().libpath;
47 const list<string> &libs = c->get_build_info().libs;
48 for(StringList::const_iterator i=libs.begin(); i!=libs.end(); ++i)
50 Target *lib = builder.get_vfs().find_library(*i, libpath, libmode);
53 dep_libs.push_back(lib);
55 lib = lib->get_real_target();
56 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
57 queue.push_back(stlib->get_component());
60 builder.problem(spkg.get_name(), format("Couldn't find library %s for %s", *i, name));
64 /* Add only the last occurrence of each library to the actual dependencies.
65 This ensures that static library ordering is correct. */
66 for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
69 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
70 last = (j==i || *j!=*i);