]> git.tdb.fi Git - builder.git/blob - source/install.cpp
Fix a bug in condition evaluation
[builder.git] / source / install.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2010  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 "datafile.h"
13 #include "header.h"
14 #include "install.h"
15 #include "package.h"
16 #include "pkgconfig.h"
17 #include "sharedlibrary.h"
18 #include "staticlibrary.h"
19
20 using namespace std;
21 using namespace Msp;
22
23 Install::Install(Builder &b, const SourcePackage &p, FileTarget &s, const std::string &loc):
24         FileTarget(b, &p, generate_target_path(s, loc)),
25         source(s)
26 {
27         buildable = true;
28         add_depend(&source);
29 }
30
31 Target *Install::get_real_target()
32 {
33         return source.get_real_target();
34 }
35
36 void Install::check_rebuild()
37 {
38         if(!mtime)
39                 mark_rebuild("Does not exist");
40         else if(source.get_mtime()>mtime || source.get_size()!=size)
41                 mark_rebuild(source.get_name()+" has changed");
42         else if(source.get_rebuild())
43                 mark_rebuild(source.get_name()+" needs rebuilding");
44 }
45
46 Action *Install::create_action()
47 {
48         return new Copy(builder, *package, source.get_path(), path);
49 }
50
51 FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string &loc)
52 {
53         if(!tgt.get_package())
54                 throw InvalidParameterValue("Can't install package-less targets");
55
56         FS::Path base = tgt.get_package()->get_builder().get_prefix();
57         string tgtname = FS::basename(tgt.get_path());
58
59         string mid;
60         if(!loc.empty())
61                 mid = loc;
62         else if(const Header *hdr = dynamic_cast<const Header *>(&tgt))
63         {
64                 if(hdr->get_component()->get_type()!=Component::HEADERS)
65                         throw Exception("Header install from non-header component?");
66                 mid = "include/"+hdr->get_component()->get_name();
67         }
68         else if(dynamic_cast<const Executable *>(&tgt))
69                 mid = "bin";
70         else if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&tgt))
71         {
72                 const Component &comp = shlib->get_component();
73                 if(comp.get_type()==Component::LIBRARY)
74                 {
75                         mid = "lib";
76                         if(!shlib->get_soname().empty())
77                                 tgtname = shlib->get_soname();
78                 }
79                 else if(comp.get_type()==Component::MODULE)
80                         mid = "lib/"+tgt.get_package()->get_name();
81         }
82         else if(dynamic_cast<const StaticLibrary *>(&tgt))
83                 mid = "lib";
84         else if(dynamic_cast<const PkgConfig *>(&tgt))
85                 mid = "lib/pkgconfig";
86         else if(dynamic_cast<const ::DataFile *>(&tgt))
87                 mid = "share/"+tgt.get_package()->get_name();
88
89         if(mid.empty())
90                 throw InvalidParameterValue("Don't know where to install "+tgtname);
91
92         return (base/mid/tgtname).str();
93 }