]> git.tdb.fi Git - builder.git/blob - source/gnuarchiver.cpp
Only get DataTransform directory contents when needed
[builder.git] / source / gnuarchiver.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include <msp/fs/utils.h>
4 #include <stdexcept>
5 #include "builder.h"
6 #include "component.h"
7 #include "externaltask.h"
8 #include "gnuarchiver.h"
9 #include "objectfile.h"
10 #include "sourcepackage.h"
11 #include "staticlibrary.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 GnuArchiver::GnuArchiver(Builder &b, const Architecture &a):
17         Tool(b, a, "AR")
18 {
19         set_command("ar", true);
20         input_suffixes.push_back(".o");
21 }
22
23 Target *GnuArchiver::create_target(const list<Target *> &sources, const string &)
24 {
25         if(sources.empty())
26                 throw invalid_argument("GnuArchiver::create_target");
27
28         list<ObjectFile *> objs;
29         for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
30         {
31                 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
32                         objs.push_back(obj);
33                 else
34                         throw invalid_argument("GnuArchiver::create_target");
35         }
36
37         const Component &comp = *objs.front()->get_component();
38         StaticLibrary *lib = new StaticLibrary(builder, comp, objs);
39         lib->set_tool(*this);
40         return lib;
41 }
42
43 string GnuArchiver::create_build_signature(const BuildInfo &) const
44 {
45         return FS::basename(executable->get_path());
46 }
47
48 Task *GnuArchiver::run(const Target &target) const
49 {
50         const StaticLibrary &lib = dynamic_cast<const StaticLibrary &>(target);
51         const Component &comp = *lib.get_component();
52
53         vector<string> argv;
54         argv.push_back(executable->get_path().str());
55         argv.push_back("rc");
56
57         FS::Path work_dir = comp.get_package().get_source_directory();
58
59         argv.push_back(relative(lib.get_path(), work_dir).str());
60
61         const Target::Dependencies &deps = lib.get_dependencies();
62         for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
63                 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
64                         argv.push_back(relative(obj->get_path(), work_dir).str());
65
66         return new ExternalTask(argv, work_dir);
67 }