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