3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
10 #include <msp/fs/utils.h>
11 #include <msp/strings/regex.h>
13 #include "component.h"
14 #include "sourcefile.h"
15 #include "sourcepackage.h"
20 SourceFile::SourceFile(Builder &b, const Component *c, const string &n):
21 Target(b, c?&c->get_package():0, n),
26 Parses include directives from the file and looks up the appropriate targets
29 void SourceFile::find_depends()
34 const SourcePackage &spkg=comp->get_package();
35 string relname=FS::relative(name, spkg.get_source()).str();
36 DependencyCache &deps_cache=spkg.get_deps_cache();
37 bool deps_found=false;
38 if(mtime<deps_cache.get_mtime())
42 includes=deps_cache.get_deps(relname);
45 catch(const KeyError &)
51 ifstream in(name.c_str());
54 if(builder.get_verbose()>=4)
55 cout<<"Reading includes from "<<name<<'\n';
57 Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
60 while(getline(in, line))
61 if(RegMatch match=r_include.match(line))
62 includes.push_back(match[1].str);
64 deps_cache.set_deps(relname, includes);
67 const StringList &incpath=comp->get_build_info().incpath;
69 string path=name.substr(0, name.rfind('/'));
70 for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
72 Target *hdr=builder.get_header(*i, path, incpath);