]> git.tdb.fi Git - builder.git/blob - source/sourcefile.cpp
c4eea79eee84fa2b4c76d18c5f8e3619746513d9
[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 #include <iostream>
11
12 SourceFile::SourceFile(Builder &b, const Component *c, const string &n):
13         Target(b, c?&c->get_package():0, n),
14         comp(c)
15 { }
16
17 /**
18 Parses include directives from the file and looks up the appropriate targets
19 from Builder.
20 */
21 void SourceFile::find_depends()
22 {
23         ifstream in(name.c_str());
24         if(!in) return;
25
26         Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
27
28         string line;
29         while(getline(in, line))
30                 if(RegMatch match=r_include.match(line))
31                         includes.push_back(match[1].str());
32
33         string path=name.substr(0, name.rfind('/'));
34         for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
35         {
36                 Target *hdr=builder.get_header(*i, path, comp->get_build_info().incpath);
37                 if(hdr)
38                         add_depend(hdr);
39         }
40
41         deps_ready=true;
42 }