]> git.tdb.fi Git - builder.git/blob - source/binary.cpp
Un-abbreviate some function and variable names
[builder.git] / source / binary.cpp
1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include "binary.h"
4 #include "builder.h"
5 #include "component.h"
6 #include "objectfile.h"
7 #include "sharedlibrary.h"
8 #include "sourcepackage.h"
9 #include "staticlibrary.h"
10
11 using namespace std;
12 using namespace Msp;
13
14 Binary::Binary(Builder &b, const FS::Path &p):
15         FileTarget(b, p)
16 { }
17
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)
20 {
21         component = &c;
22         for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
23                 add_dependency(**i);
24 }
25
26 void Binary::find_dependencies()
27 {
28         if(!component)
29                 return;
30
31         BuildInfo::LibraryMode libmode = component->get_build_info().libmode;
32
33         list<const Component *> queue;
34         list<Target *> dep_libs;
35         queue.push_back(component);
36         while(!queue.empty())
37         {
38                 const Component *c = queue.front();
39                 queue.erase(queue.begin());
40
41                 const BuildInfo &binfo = c->get_build_info();
42                 for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
43                 {
44                         Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
45                         if(lib)
46                         {
47                                 dep_libs.push_back(lib);
48
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());
53                         }
54                         else
55                                 builder.problem(package->get_name(), format("Couldn't find library %s for %s", *i, name));
56                 }
57         }
58
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)
62         {
63                 bool last = true;
64                 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
65                         last = (j==i || *j!=*i);
66                 if(last)
67                         add_dependency(**i);
68         }
69 }