]> git.tdb.fi Git - builder.git/blob - source/binary.cpp
Un-abbreviate function names
[builder.git] / source / binary.cpp
1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include <msp/strings/utils.h>
4 #include "binary.h"
5 #include "builder.h"
6 #include "component.h"
7 #include "objectfile.h"
8 #include "sharedlibrary.h"
9 #include "sourcepackage.h"
10 #include "staticlibrary.h"
11 #include "tool.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 Binary::Binary(Builder &b, const FS::Path &p):
17         FileTarget(b, p)
18 { }
19
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),
22         objects(objs)
23 {
24         component = &c;
25         for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
26                 add_dependency(**i);
27 }
28
29 void Binary::find_dependencies()
30 {
31         if(!component)
32                 return;
33
34         list<const Component *> queue;
35         list<Target *> dep_libs;
36         queue.push_back(component);
37         while(!queue.empty())
38         {
39                 const Component *c = queue.front();
40                 queue.erase(queue.begin());
41
42                 const BuildInfo &binfo = c->get_build_info();
43                 for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
44                 {
45                         BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i);
46                         Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
47                         if(lib)
48                         {
49                                 Target *real = lib->get_real_target();
50                                 if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(real))
51                                 {
52                                         dep_libs.push_back(stlib);
53                                         if(stlib->get_component())
54                                                 queue.push_back(stlib->get_component());
55                                 }
56                                 else
57                                         dep_libs.push_back(lib);
58                         }
59                         else
60                                 builder.problem(package->get_name(), format("Couldn't find library %s for %s", *i, name));
61                 }
62         }
63
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)
67         {
68                 bool last = true;
69                 for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
70                         last = (j==i || *j!=*i);
71                 if(last)
72                         add_dependency(**i);
73         }
74 }
75
76 string Binary::create_build_signature() const
77 {
78         set<const Tool *> object_tools;
79         for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
80                 object_tools.insert((*i)->get_tool());
81
82         list<string> sigs;
83         sigs.push_back(tool->create_build_signature(component->get_build_info()));
84         for(set<const Tool *>::const_iterator i=object_tools.begin(); i!=object_tools.end(); ++i)
85                 sigs.push_back((*i)->create_build_signature(component->get_build_info()));
86         sigs.sort();
87
88         return join(sigs.begin(), sigs.end(), ";");
89 }