using namespace Msp;
ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s):
- FileTarget(b, c.get_package(), generate_target_path(c, FS::relative(s.get_path(), c.get_package().get_source_directory()).str())),
+ FileTarget(b, c.get_package(), generate_target_path(c, s.get_path())),
source(s)
{
component = &c;
add_dependency(source);
}
-FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src)
+FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path &src)
{
const SourcePackage &pkg = comp.get_package();
- string fn = FS::basepart(src)+".o";
- if(!fn.compare(0, 2, "./"))
- fn.erase(0, 2);
- for(string::iterator i=fn.begin(); i!=fn.end(); ++i)
- if(*i=='/')
- *i = '_';
- return pkg.get_temp_dir()/comp.get_name()/fn;
+ FS::Path rel_src = FS::relative(src, pkg.get_source_directory()).str();
+ string fn;
+ for(FS::Path::Iterator i=rel_src.begin(); i!=rel_src.end(); ++i)
+ {
+ if(!fn.empty())
+ fn += '_';
+ if(*i!=".")
+ fn += *i;
+ }
+ return pkg.get_temp_dir()/comp.get_name()/(FS::basepart(fn)+".o");
}
void ObjectFile::find_dependencies()
public:
ObjectFile(Builder &, const Component &, SourceFile &);
private:
- static Msp::FS::Path generate_target_path(const Component &, const std::string &);
+ static Msp::FS::Path generate_target_path(const Component &, const Msp::FS::Path &);
public:
virtual const char *get_type() const { return "ObjectFile"; }