1 #include <msp/core/maputils.h>
2 #include <msp/fs/utils.h>
3 #include <msp/io/print.h>
4 #include <msp/strings/regex.h>
7 #include "sourcefile.h"
8 #include "sourcepackage.h"
13 SourceFile::SourceFile(Builder &b, const FS::Path &p):
18 SourceFile::SourceFile(Builder &b, const Component &c, const FS::Path &p):
19 FileTarget(b, &c.get_package(), p),
23 void SourceFile::find_depends()
31 const SourcePackage &spkg = comp->get_package();
32 string relname = FS::relative(path, spkg.get_source()).str();
33 DependencyCache &deps_cache = spkg.get_deps_cache();
34 bool deps_found = false;
35 if(mtime<deps_cache.get_mtime())
39 includes = deps_cache.get_deps(relname);
42 catch(const key_error &)
50 IO::BufferedFile in(path.str());
52 if(builder.get_verbose()>=4)
53 IO::print("Reading includes from %s\n", path.str());
55 Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
58 while(in.getline(line))
59 if(RegMatch match = r_include.match(line))
60 includes.push_back(match[1].str);
62 deps_cache.set_deps(relname, includes);
64 catch(const IO::file_not_found &)
66 if(builder.get_verbose()>=4)
67 IO::print("Failed to read includes from %s\n", path.str());
73 const StringList &incpath = comp->get_build_info().incpath;
75 FS::Path dir = FS::dirname(path);
76 for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
78 Target *hdr = builder.get_vfs().find_header(*i, dir, incpath);