]> git.tdb.fi Git - builder.git/blobdiff - source/gnuarchiver.cpp
Support source generators that combine multiple files into one
[builder.git] / source / gnuarchiver.cpp
index 8eab751e7ad405faf49951bff4f763fd003303d6..170007028a5201f26bf64160402a2bab3f8bebd7 100644 (file)
 using namespace std;
 using namespace Msp;
 
-GnuArchiver::GnuArchiver(Builder &b):
-       Tool(b, "AR")
+GnuArchiver::GnuArchiver(Builder &b, const Architecture &a):
+       Tool(b, a, "AR")
 {
+       set_command("ar", true);
        input_suffixes.push_back(".o");
+       processing_unit = COMPONENT;
 }
 
-Target *GnuArchiver::create_target(const list<Target *> &sources, const string &) const
+Target *GnuArchiver::create_target(const list<Target *> &sources, const string &)
 {
        if(sources.empty())
                throw invalid_argument("GnuArchiver::create_target");
@@ -30,39 +32,37 @@ Target *GnuArchiver::create_target(const list<Target *> &sources, const string &
                if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
                        objs.push_back(obj);
                else
-                       throw invalid_argument("GnuLinker::create_target");
+                       throw invalid_argument("GnuArchiver::create_target");
        }
 
-       const Component &comp = objs.front()->get_component();
+       const Component &comp = *objs.front()->get_component();
        StaticLibrary *lib = new StaticLibrary(builder, comp, objs);
        lib->set_tool(*this);
        return lib;
 }
 
+string GnuArchiver::create_build_signature(const BuildInfo &) const
+{
+       return FS::basename(executable->get_path());
+}
+
 Task *GnuArchiver::run(const Target &target) const
 {
        const StaticLibrary &lib = dynamic_cast<const StaticLibrary &>(target);
-       const Component &comp = lib.get_component();
+       const Component &comp = *lib.get_component();
 
        vector<string> argv;
-       argv.push_back("ar");
+       argv.push_back(executable->get_path().str());
        argv.push_back("rc");
 
-       FS::Path work_dir = comp.get_package().get_source();
+       FS::Path work_dir = comp.get_package().get_source_directory();
 
        argv.push_back(relative(lib.get_path(), work_dir).str());
 
-       const TargetList &deps = lib.get_depends();
-       for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
+       const Target::Dependencies &deps = lib.get_dependencies();
+       for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
                if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
                        argv.push_back(relative(obj->get_path(), work_dir).str());
 
-       if(!builder.get_dry_run())
-       {
-               FS::mkpath(FS::dirname(lib.get_path()), 0755);
-               if(FS::exists(lib.get_path()))
-                       FS::unlink(lib.get_path());
-       }
-
        return new ExternalTask(argv, work_dir);
 }