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 "csourcefile.h"
8 #include "sourcepackage.h"
13 CSourceFile::CSourceFile(Builder &b, const FS::Path &p):
17 CSourceFile::CSourceFile(Builder &b, const Component &c, const FS::Path &p):
20 string ext = FS::extpart(FS::basename(path));
21 if(ext==".h" || ext==".H" || ext==".hpp")
22 install_location = "include/"+comp->get_name();
25 void CSourceFile::find_depends()
33 const SourcePackage &spkg = comp->get_package();
34 string relname = FS::relative(path, spkg.get_source()).str();
35 DependencyCache &deps_cache = spkg.get_deps_cache();
36 bool deps_found = false;
37 if(mtime<deps_cache.get_mtime())
41 includes = deps_cache.get_deps(relname);
44 catch(const key_error &)
52 IO::BufferedFile in(path.str());
54 if(builder.get_verbose()>=4)
55 IO::print("Reading includes from %s\n", path.str());
57 Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
60 while(in.getline(line))
61 if(RegMatch match = r_include.match(line))
62 includes.push_back(match[1].str);
64 deps_cache.set_deps(relname, includes);
66 catch(const IO::file_not_found &)
68 if(builder.get_verbose()>=4)
69 IO::print("Failed to read includes from %s\n", path.str());
75 const StringList &incpath = comp->get_build_info().incpath;
77 FS::Path dir = FS::dirname(path);
78 for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
80 Target *hdr = builder.get_vfs().find_header(*i, dir, incpath);