3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/fs/utils.h>
9 #include <msp/io/except.h>
10 #include <msp/io/print.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 FS::Path &p):
25 SourceFile::SourceFile(Builder &b, const Component &c, const FS::Path &p):
26 FileTarget(b, &c.get_package(), p),
30 void SourceFile::find_depends()
38 const SourcePackage &spkg = comp->get_package();
39 string relname = FS::relative(name, spkg.get_source()).str();
40 DependencyCache &deps_cache = spkg.get_deps_cache();
41 bool deps_found = false;
42 if(mtime<deps_cache.get_mtime())
46 includes = deps_cache.get_deps(relname);
49 catch(const KeyError &)
57 IO::BufferedFile in(name);
59 if(builder.get_verbose()>=4)
60 IO::print("Reading includes from %s\n", name);
62 Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
65 while(in.getline(line))
66 if(RegMatch match = r_include.match(line))
67 includes.push_back(match[1].str);
69 deps_cache.set_deps(relname, includes);
71 catch(const IO::FileNotFound &)
78 const StringList &incpath = comp->get_build_info().incpath;
80 FS::Path dir = FS::dirname(path);
81 for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
83 Target *hdr = builder.get_header(*i, dir, incpath);