]> git.tdb.fi Git - builder.git/blob - source/objectfile.cpp
Add command line options (not all of them work yet)
[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 void ObjectFile::find_depends()
22 {
23         find_depends(depends.front());
24 }
25
26 Action *ObjectFile::build()
27 {
28         return Target::build(new Compile(builder, depends.front()->get_name(), name, comp));
29 }
30
31 void ObjectFile::find_depends(Target *tgt)
32 {
33         SourceFile *src=dynamic_cast<SourceFile *>(tgt);
34         if(!src)
35         {
36                 Install *inst=dynamic_cast<Install *>(tgt);
37                 if(inst)
38                         src=dynamic_cast<SourceFile *>(inst->get_depends().front());
39         }
40         if(!src)
41                 return;
42
43         const string &sname=src->get_name();
44         string path=sname.substr(0, sname.rfind('/'));
45
46         const list<string> &includes=src->get_includes();
47         for(list<string>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
48         {
49                 Target *hdr2=builder.get_header(*i, path, package->get_build_info().incpath);
50                 if(hdr2)
51                         add_depend(hdr2);
52         }
53 }
54
55 string ObjectFile::generate_target_name(const Component &comp, const string &src)
56 {
57         return (comp.get_package().get_source()/"temp"/comp.get_name()/(Path::splitext(src.substr(src.rfind('/')+1)).base+".o")).str();
58 }