]> git.tdb.fi Git - builder.git/blob - source/archive.cpp
55b1f4615efe053bf1cf6dc68f915163929aae9d
[builder.git] / source / archive.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <msp/fs/dir.h>
9 #include <msp/fs/stat.h>
10 #include <msp/fs/utils.h>
11 #include "archive.h"
12 #include "builder.h"
13 #include "component.h"
14 #include "objectfile.h"
15 #include "sourcepackage.h"
16 #include "staticlibrary.h"
17
18 using namespace std;
19 using namespace Msp;
20
21 Archive::Archive(Builder &b, const StaticLibrary &lib):
22         ExternalAction(b)
23 {
24         const Component &comp=lib.get_component();
25
26         work_dir=comp.get_package().get_source();
27
28         std::string tool="AR";
29         argv.push_back(builder.get_current_arch().get_tool(tool));
30         argv.push_back("rc");
31
32         argv.push_back(relative(lib.get_path(), work_dir).str());
33         const TargetList &deps=lib.get_depends();
34         for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
35                 if(ObjectFile *obj=dynamic_cast<ObjectFile *>(*i))
36                         argv.push_back(relative(obj->get_path(), work_dir).str());
37
38         FS::Path lpath=lib.get_path();
39         if(!builder.get_dry_run())
40         {
41                 FS::mkpath(FS::dirname(lpath), 0755);
42                 if(FS::exists(lib.get_path()))
43                         FS::unlink(lib.get_path());
44         }
45
46         announce(comp.get_package().get_name(), tool, relative(lpath, work_dir).str());
47
48         launch();
49 }