3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
9 #include <msp/fs/utils.h>
10 #include <msp/io/except.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 FS::Path &p):
21 FileTarget(b, (c ? &c->get_package() : 0), p),
25 void SourceFile::find_depends()
30 const SourcePackage &spkg=comp->get_package();
31 string relname=FS::relative(name, spkg.get_source()).str();
32 DependencyCache &deps_cache=spkg.get_deps_cache();
33 bool deps_found=false;
34 if(mtime<deps_cache.get_mtime())
38 includes=deps_cache.get_deps(relname);
41 catch(const KeyError &)
49 IO::BufferedFile in(name);
51 if(builder.get_verbose()>=4)
52 cout<<"Reading includes from "<<name<<'\n';
54 Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
57 while(in.getline(line))
58 if(RegMatch match=r_include.match(line))
59 includes.push_back(match[1].str);
61 deps_cache.set_deps(relname, includes);
63 catch(const IO::FileNotFound &)
69 const StringList &incpath=comp->get_build_info().incpath;
71 FS::Path dir=FS::dirname(path);
72 for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
74 Target *hdr=builder.get_header(*i, dir, incpath);