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