]> git.tdb.fi Git - builder.git/blobdiff - source/gnuarchiver.cpp
Don't store component locally in object and source files
[builder.git] / source / gnuarchiver.cpp
index 3f56a2ea4e246e701bd4b18ade03104c4d797f3b..71edc42d57d26d09560c9ddc1b389e0febcedae9 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
+#include <msp/strings/format.h>
 #include <stdexcept>
 #include "builder.h"
 #include "component.h"
 using namespace std;
 using namespace Msp;
 
-GnuArchiver::GnuArchiver(Builder &b):
-       Tool(b, "AR")
+GnuArchiver::GnuArchiver(Builder &b, const Architecture &a):
+       Tool(b, a, "AR")
 {
+       string command = "ar";
+       if(architecture->is_cross())
+               command = format("%s-%s", architecture->get_cross_prefix(), command);
+       executable = builder.get_vfs().find_binary(command);
+
        input_suffixes.push_back(".o");
 }
 
@@ -30,10 +36,10 @@ 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;
@@ -42,10 +48,10 @@ Target *GnuArchiver::create_target(const list<Target *> &sources, const string &
 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();