]> git.tdb.fi Git - builder.git/blob - source/objectfile.cpp
Reorder class members
[builder.git] / source / objectfile.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <algorithm>
9 #include <msp/fs/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 void ObjectFile::find_depends()
30 {
31         for(TargetList::iterator i=new_deps.begin(); i!=new_deps.end();)
32         {
33                 Target *tgt=*i;
34                 if(tgt->get_depends_ready())
35                 {
36                         i=new_deps.erase(i);
37                         find_depends(tgt);
38                 }
39                 else
40                         ++i;
41         }
42
43         deps_ready=new_deps.empty();
44 }
45
46
47 void ObjectFile::find_depends(Target *tgt)
48 {
49         const string &tname=tgt->get_name();
50         string path=tname.substr(0, tname.rfind('/'));
51
52         SourceFile *src=dynamic_cast<SourceFile *>(tgt);
53         if(!src)
54         {
55                 Install *inst=dynamic_cast<Install *>(tgt);
56                 if(inst)
57                         src=dynamic_cast<SourceFile *>(inst->get_depends().front());
58         }
59         if(!src)
60                 return;
61
62         const StringList &incpath=comp.get_build_info().incpath;
63
64         const list<string> &includes=src->get_includes();
65         for(list<string>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
66         {
67                 Target *hdr2=builder.get_header(*i, path, incpath);
68                 if(hdr2 && find(depends.begin(), depends.end(), hdr2)==depends.end())
69                         add_depend(hdr2);
70         }
71 }
72
73 void ObjectFile::add_depend(Target *tgt)
74 {
75         Target::add_depend(tgt);
76         new_deps.push_back(tgt);
77 }
78
79 Action *ObjectFile::create_action()
80 {
81         return new Compile(builder, *this);
82 }
83
84 string ObjectFile::generate_target_name(const Component &comp, const string &src)
85 {
86         const SourcePackage &pkg=comp.get_package();
87         return (pkg.get_temp_dir()/comp.get_name()/(FS::basepart(FS::basename(src))+".o")).str();
88 }