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 = FS::Path("include")/package->get_name();
25 void CSourceFile::find_dependencies()
27 if(!component || !mtime)
30 const SourcePackage &spkg = component->get_package();
32 Cache &cache = spkg.get_cache();
33 if(mtime<cache.get_mtime() && cache.has_key(this, "includes"))
34 includes = cache.get_values(this, "includes");
37 IO::BufferedFile in(path.str());
39 builder.get_logger().log("files", format("Reading includes from %s", path.str()));
41 Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
44 while(in.getline(line))
45 if(RegMatch match = r_include.match(line))
46 includes.push_back(match[1].str);
48 cache.set_values(this, "includes", includes);
51 const BuildInfo &build_info = component->get_build_info_for_path(path);
52 const BuildInfo::PathList &incpath = build_info.incpath;
53 BuildInfo::PathList local_incpath = incpath;
54 local_incpath.insert(local_incpath.begin(), build_info.local_incpath.begin(), build_info.local_incpath.end());
55 local_incpath.push_front(FS::dirname(path).str());
57 for(IncludeList::iterator i=includes.begin(); i!=includes.end(); ++i)
59 Target *hdr = builder.get_vfs().find_header(i->substr(1), ((*i)[0]=='"' ? local_incpath : incpath));
65 void CSourceFile::modified()