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