]> git.tdb.fi Git - builder.git/blob - source/install.cpp
1eb510e4505f768f49d82aebadfddcd51e126cc4
[builder.git] / source / install.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/utils.h>
9 #include "builder.h"
10 #include "copy.h"
11 #include "executable.h"
12 #include "header.h"
13 #include "install.h"
14 #include "package.h"
15 #include "pkgconfig.h"
16 #include "sharedlibrary.h"
17 #include "staticlibrary.h"
18
19 using namespace std;
20 using namespace Msp;
21
22 Install::Install(Builder &b, const SourcePackage &p, FileTarget &s):
23         FileTarget(b, &p, generate_target_path(s)),
24         source(s)
25 {
26         buildable=true;
27         add_depend(&source);
28 }
29
30 void Install::check_rebuild()
31 {
32         if(!mtime)
33                 mark_rebuild("Does not exist");
34         else if(source.get_mtime()>mtime)
35                 mark_rebuild(FS::basename(source.get_name())+" has changed");
36         else if(source.get_rebuild())
37                 mark_rebuild(FS::basename(source.get_name())+" needs rebuilding");
38 }
39
40 Action *Install::create_action()
41 {
42         return new Copy(builder, *package, source.get_path(), path);
43 }
44
45 FS::Path Install::generate_target_path(const FileTarget &tgt)
46 {
47         const SourcePackage *spkg=dynamic_cast<const SourcePackage *>(tgt.get_package());
48
49         FS::Path base=spkg->get_builder().get_prefix();
50         string tgtname=FS::basename(tgt.get_path());
51
52         string mid;
53         if(const Header *hdr=dynamic_cast<const Header *>(&tgt))
54                 mid="include/"+hdr->get_component()->get_install_headers();
55         else if(dynamic_cast<const Executable *>(&tgt))
56                 mid="bin";
57         else if(const SharedLibrary *shlib=dynamic_cast<const SharedLibrary *>(&tgt))
58         {
59                 const Component &comp=shlib->get_component();
60                 if(comp.get_type()==Component::LIBRARY)
61                         mid="lib";
62                 else if(comp.get_type()==Component::MODULE)
63                         mid="lib/"+tgt.get_package()->get_name();
64         }
65         else if(dynamic_cast<const StaticLibrary *>(&tgt))
66                 mid="lib";
67         else if(dynamic_cast<const PkgConfig *>(&tgt))
68                 mid="lib/pkgconfig";
69
70         if(mid.empty())
71                 throw InvalidParameterValue("Don't know where to install "+tgtname);
72
73         return (base/mid/tgtname).str();
74 }