]> git.tdb.fi Git - builder.git/blob - source/sourcefile.cpp
Adjust requires to library changes
[builder.git] / source / sourcefile.cpp
1 #include <fstream>
2 #include <msp/strings/regex.h>
3 #include "builder.h"
4 #include "component.h"
5 #include "package.h"
6 #include "sourcefile.h"
7
8 using namespace std;
9 using namespace Msp;
10
11 SourceFile::SourceFile(Builder &b, const Component *c, const string &n):
12         Target(b, c?&c->get_package():0, n),
13         comp(c)
14 { }
15
16 /**
17 Parses include directives from the file and looks up the appropriate targets
18 from Builder.
19 */
20 void SourceFile::find_depends()
21 {
22         ifstream in(name.c_str());
23         if(!in) return;
24
25         Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
26
27         string line;
28         while(getline(in, line))
29                 if(RegMatch match=r_include.match(line))
30                         includes.push_back(match[1].str);
31
32         const StringList &incpath=comp->get_build_info().incpath;
33         const string &arch=comp->get_package().get_arch();
34
35         string path=name.substr(0, name.rfind('/'));
36         for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
37         {
38                 Target *hdr=builder.get_header(*i, arch, path, incpath);
39                 if(hdr)
40                         add_depend(hdr);
41         }
42
43         deps_ready=true;
44 }