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;
24 Target *GnuArchiver::create_target(const list<Target *> &sources, const string &)
27 throw invalid_argument("GnuArchiver::create_target");
29 list<ObjectFile *> objs;
30 for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
32 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
35 throw invalid_argument("GnuArchiver::create_target");
38 const Component &comp = *objs.front()->get_component();
39 StaticLibrary *lib = new StaticLibrary(builder, comp, objs);
44 string GnuArchiver::create_build_signature(const BuildInfo &) const
46 return FS::basename(executable->get_path());
49 Task *GnuArchiver::run(const Target &target) const
51 const StaticLibrary &lib = dynamic_cast<const StaticLibrary &>(target);
52 const Component &comp = *lib.get_component();
55 argv.push_back(executable->get_path().str());
58 FS::Path work_dir = comp.get_package().get_source_directory();
60 argv.push_back(relative(lib.get_path(), work_dir).str());
62 const Target::Dependencies &deps = lib.get_dependencies();
63 for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
64 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
65 argv.push_back(relative(obj->get_path(), work_dir).str());
67 return new ExternalTask(argv, work_dir);