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):
19 input_suffixes.push_back(".o");
22 Target *GnuArchiver::create_target(const list<Target *> &sources, const string &) const
25 throw invalid_argument("GnuArchiver::create_target");
27 list<ObjectFile *> objs;
28 for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
30 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
33 throw invalid_argument("GnuLinker::create_target");
36 const Component &comp = objs.front()->get_component();
37 StaticLibrary *lib = new StaticLibrary(builder, comp, objs);
42 Task *GnuArchiver::run(const Target &target) const
44 const StaticLibrary &lib = dynamic_cast<const StaticLibrary &>(target);
45 const Component &comp = *lib.get_component();
51 FS::Path work_dir = comp.get_package().get_source();
53 argv.push_back(relative(lib.get_path(), work_dir).str());
55 const Target::Dependencies &deps = lib.get_depends();
56 for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
57 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
58 argv.push_back(relative(obj->get_path(), work_dir).str());
60 if(!builder.get_dry_run())
62 FS::mkpath(FS::dirname(lib.get_path()), 0755);
63 if(FS::exists(lib.get_path()))
64 FS::unlink(lib.get_path());
67 return new ExternalTask(argv, work_dir);