]> git.tdb.fi Git - builder.git/blobdiff - source/sourcegenerator.cpp
Create a directory structure for generated source files
[builder.git] / source / sourcegenerator.cpp
index 5123f09d0d0aad9b3e6603fd320b4b7ed92b3bf9..584822a1074b06a1fb959714cfbb463b63c54bbc 100644 (file)
@@ -30,13 +30,21 @@ Target *SourceGenerator::create_target(const list<Target *> &sources, const stri
        TemplateFile &tmpl = dynamic_cast<TemplateFile &>(*sources.front());
        const Component *comp = tmpl.get_component();
        const SourcePackage *pkg = tmpl.get_package();
+       FS::Path subdir;
        string base;
-       if(processing_unit==ONE_FILE)
-               base = FS::basepart(FS::basename(tmpl.get_path()));
-       else if(processing_unit==DIRECTORY)
-               base = FS::basename(FS::dirname(tmpl.get_path()));
-       else
+       if(processing_unit==COMPONENT)
                base = comp->get_name();
+       else
+       {
+               subdir = FS::dirname(FS::relative(tmpl.get_path(), pkg->get_source_directory()));
+               if(processing_unit==ONE_FILE)
+                       base = FS::basepart(FS::basename(tmpl.get_path()));
+               else if(processing_unit==DIRECTORY)
+               {
+                       base = FS::basename(subdir);
+                       subdir = FS::dirname(subdir);
+               }
+       }
 
        Target *primary = 0;
        for(list<string>::const_iterator i=out_suffixes.begin(); i!=out_suffixes.end(); ++i)
@@ -44,7 +52,7 @@ Target *SourceGenerator::create_target(const list<Target *> &sources, const stri
                Tool *tool = builder.get_toolchain().get_tool_for_suffix(*i, true);
                if(tool)
                {
-                       FS::Path fn = pkg->get_temp_directory()/comp->get_name()/(base+*i);
+                       FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+*i);
                        Target *target = tool->create_source(*comp, fn);
                        target->set_tool(*this);
                        for(list<Target *>::const_iterator j=sources.begin(); j!=sources.end(); ++j)