]> git.tdb.fi Git - builder.git/blob - source/objectfile.cpp
f3d6183afa6b01161b1039af0bb6f838d571e5d8
[builder.git] / source / objectfile.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2010  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 &s):
22         FileTarget(b, &c.get_package(), generate_target_path(c, FS::basename(s.get_path()))),
23         comp(c),
24         source(s)       
25 {
26         buildable = true;
27         add_depend(&source);
28 }
29
30 void ObjectFile::find_depends()
31 {
32         for(TargetList::iterator i=new_deps.begin(); i!=new_deps.end();)
33         {
34                 Target *tgt = *i;
35                 if(tgt->get_depends_ready())
36                 {
37                         i = new_deps.erase(i);
38                         find_depends(tgt);
39                 }
40                 else
41                         ++i;
42         }
43
44         deps_ready = new_deps.empty();
45 }
46
47
48 void ObjectFile::find_depends(Target *tgt)
49 {
50         SourceFile *src = dynamic_cast<SourceFile *>(tgt->get_real_target());
51         FileTarget *file = dynamic_cast<FileTarget *>(tgt);
52         if(!src || !file)
53                 return;
54
55         FS::Path spath = FS::dirname(file->get_path());
56         const StringList &incpath = comp.get_build_info().incpath;
57
58         const list<string> &includes = src->get_includes();
59         for(list<string>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
60         {
61                 Target *hdr = builder.get_header(*i, spath, incpath);
62                 if(hdr && find(depends.begin(), depends.end(), hdr)==depends.end())
63                         add_depend(hdr);
64         }
65 }
66
67 void ObjectFile::add_depend(Target *tgt)
68 {
69         Target::add_depend(tgt);
70         new_deps.push_back(tgt);
71 }
72
73 Action *ObjectFile::create_action()
74 {
75         return new Compile(builder, *this);
76 }
77
78 FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src)
79 {
80         const SourcePackage &pkg = comp.get_package();
81         return pkg.get_temp_dir()/comp.get_name()/(FS::basepart(src)+".o");
82 }