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),
22 string ext = FS::extpart(FS::basename(path));
23 if(ext==".h" || ext==".H" || ext==".hpp")
24 install_location = "include/"+comp->get_name();
27 void SourceFile::find_depends()
35 const SourcePackage &spkg = comp->get_package();
36 string relname = FS::relative(path, spkg.get_source()).str();
37 DependencyCache &deps_cache = spkg.get_deps_cache();
38 bool deps_found = false;
39 if(mtime<deps_cache.get_mtime())
43 includes = deps_cache.get_deps(relname);
46 catch(const key_error &)
54 IO::BufferedFile in(path.str());
56 if(builder.get_verbose()>=4)
57 IO::print("Reading includes from %s\n", path.str());
59 Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
62 while(in.getline(line))
63 if(RegMatch match = r_include.match(line))
64 includes.push_back(match[1].str);
66 deps_cache.set_deps(relname, includes);
68 catch(const IO::file_not_found &)
70 if(builder.get_verbose()>=4)
71 IO::print("Failed to read includes from %s\n", path.str());
77 const StringList &incpath = comp->get_build_info().incpath;
79 FS::Path dir = FS::dirname(path);
80 for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
82 Target *hdr = builder.get_vfs().find_header(*i, dir, incpath);