]> git.tdb.fi Git - builder.git/blob - source/installedfile.cpp
Simplify InstalledFile::generate_target_path
[builder.git] / source / installedfile.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 "installedfile.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 InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s, const std::string &loc):
17         FileTarget(b, &p, generate_target_path(b.get_prefix(), s, loc)),
18         source(s)
19 {
20         buildable = true;
21         add_depend(&source);
22
23         if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&source))
24                 if(!shlib->get_soname().empty())
25                         link = FS::dirname(path)/FS::basename(shlib->get_path());
26
27         if(!link.empty())
28                 builder.get_vfs().register_path(link, this);
29 }
30
31 Target *InstalledFile::get_real_target()
32 {
33         return source.get_real_target();
34 }
35
36 void InstalledFile::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 FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const std::string &loc)
47 {
48         if(!tgt.is_installable() && loc.empty())
49                 throw invalid_argument(tgt.get_name()+" is not installable");
50
51         string mid;
52         if(!loc.empty())
53                 mid = loc;
54         else
55                 mid = tgt.get_install_location();
56
57         return prefix/mid/FS::basename(tgt.get_path());
58 }