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