1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include <msp/fs/utils.h>
7 #include "externaltask.h"
8 #include "gnuarchiver.h"
9 #include "objectfile.h"
10 #include "sourcepackage.h"
11 #include "staticlibrary.h"
16 GnuArchiver::GnuArchiver(Builder &b, const Architecture &a):
19 set_command("ar", true);
20 input_suffixes.push_back(".o");
21 processing_unit = COMPONENT;
25 Target *GnuArchiver::create_target(const vector<Target *> &sources, const string &)
28 throw invalid_argument("GnuArchiver::create_target");
30 vector<ObjectFile *> objs;
31 objs.reserve(sources.size());
32 for(Target *s: sources)
33 objs.push_back(&dynamic_cast<ObjectFile &>(*s));
35 const Component &comp = *objs.front()->get_component();
36 StaticLibrary *lib = new StaticLibrary(builder, comp, objs);
41 Task *GnuArchiver::_run(const StaticLibrary &lib)
43 const Tool &tool = *lib.get_tool();
44 const Component &comp = *lib.get_component();
47 argv.push_back(tool.get_executable()->get_path().str());
50 FS::Path work_dir = comp.get_package().get_source_directory();
52 argv.push_back(relative(lib.get_path(), work_dir).str());
54 for(Target *d: lib.get_dependencies())
55 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
56 argv.push_back(relative(obj->get_path(), work_dir).str());
58 return new ExternalTask(argv, work_dir);