]> git.tdb.fi Git - builder.git/blob - source/objectfile.cpp
Adjust requires to library changes
[builder.git] / source / objectfile.cpp
1 #include <msp/path/utils.h>
2 #include "builder.h"
3 #include "compile.h"
4 #include "component.h"
5 #include "install.h"
6 #include "objectfile.h"
7 #include "package.h"
8 #include "sourcefile.h"
9
10 using namespace std;
11 using namespace Msp;
12
13 ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &src):
14         Target(b, &c.get_package(), generate_target_name(c, src.get_name())),
15         comp(c)
16 {
17         buildable=true;
18         add_depend(&src);
19 }
20
21 /**
22 Processes as many new dependences as possible.  Some may be left unprocessed
23 if their own dependencies are not ready, requiring another call to this
24 function.  Use the get_deps_ready() function to determine whether this is the
25 case.
26 */
27 void ObjectFile::find_depends()
28 {
29         for(TargetList::iterator i=new_deps.begin(); i!=new_deps.end();)
30         {
31                 Target *tgt=*i;
32                 if(tgt->get_depends_ready())
33                 {
34                         i=new_deps.erase(i);
35                         find_depends(tgt);
36                 }
37                 else
38                         ++i;
39         }
40
41         deps_ready=new_deps.empty();
42 }
43
44 Action *ObjectFile::build()
45 {
46         return Target::build(new Compile(builder, *this));
47 }
48
49 /**
50 Recursively looks for header targets and adds them as dependencies.
51 */
52 void ObjectFile::find_depends(Target *tgt)
53 {
54         const string &tname=tgt->get_name();
55         string path=tname.substr(0, tname.rfind('/'));
56
57         SourceFile *src=dynamic_cast<SourceFile *>(tgt);
58         if(!src)
59         {
60                 Install *inst=dynamic_cast<Install *>(tgt);
61                 if(inst)
62                         src=dynamic_cast<SourceFile *>(inst->get_depends().front());
63         }
64         if(!src)
65                 return;
66
67         const string &arch=comp.get_package().get_arch();
68         const StringList &incpath=comp.get_build_info().incpath;
69
70         const list<string> &includes=src->get_includes();
71         for(list<string>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
72         {
73                 Target *hdr2=builder.get_header(*i, arch, path, incpath);
74                 if(hdr2 && find(depends.begin(), depends.end(), hdr2)==depends.end())
75                         add_depend(hdr2);
76         }
77 }
78
79 /**
80 Adds a target to the dependency list as well as the new dependencies list.
81 */
82 void ObjectFile::add_depend(Target *tgt)
83 {
84         Target::add_depend(tgt);
85         new_deps.push_back(tgt);
86 }
87
88 string ObjectFile::generate_target_name(const Component &comp, const string &src)
89 {
90         return (comp.get_package().get_temp_dir()/comp.get_name()/(Path::splitext(src.substr(src.rfind('/')+1)).base+".o")).str();
91 }