]> git.tdb.fi Git - builder.git/blob - source/sourcefile.cpp
55910a64823742b12f45b259289ebae5270daa6c
[builder.git] / source / sourcefile.cpp
1 #include <fstream>
2 #include <msp/regex++/regex++.h>
3 #include "builder.h"
4 #include "component.h"
5 #include "sourcefile.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 SourceFile::SourceFile(Builder &b, const Component *c, const string &n):
11         Target(b, c?&c->get_package():0, n),
12         comp(c)
13 { }
14
15 void SourceFile::find_depends()
16 {
17         ifstream in(name.c_str());
18         if(!in) return;
19
20         Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
21
22         string line;
23         while(getline(in, line))
24                 if(RegMatch match=r_include.match(line))
25                         includes.push_back(match[1].str());
26
27         string path=name.substr(0, name.rfind('/'));
28         for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
29         {
30                 Target *hdr=builder.get_header(*i, path, comp->get_build_info().incpath);
31                 if(hdr)
32                         add_depend(hdr);
33         }
34 }