]> git.tdb.fi Git - builder.git/blob - source/installedfile.cpp
4ee821fab1ab55bc74a5075a378f2b926e89b990
[builder.git] / source / installedfile.cpp
1 #include <msp/fs/utils.h>
2 #include "builder.h"
3 #include "installedfile.h"
4 #include "sharedlibrary.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s, const string &loc):
10         FileTarget(b, &p, generate_target_path(b.get_prefix(), s, loc)),
11         source(s)
12 {
13         add_depend(&source);
14
15         if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&source))
16                 if(!shlib->get_soname().empty())
17                         link = FS::dirname(path)/FS::basename(shlib->get_path());
18
19         if(!link.empty())
20                 builder.get_vfs().register_path(link, this);
21 }
22
23 Target *InstalledFile::get_real_target()
24 {
25         return source.get_real_target();
26 }
27
28 void InstalledFile::check_rebuild()
29 {
30         if(!mtime)
31                 mark_rebuild("Does not exist");
32         else if(source.get_mtime()>mtime || source.get_size()!=size)
33                 mark_rebuild(source.get_name()+" has changed");
34         else if(source.needs_rebuild())
35                 mark_rebuild(source.get_name()+" needs rebuilding");
36 }
37
38 FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const string &loc)
39 {
40         if(!tgt.is_installable() && loc.empty())
41                 throw invalid_argument(tgt.get_name()+" is not installable");
42
43         string mid;
44         if(!loc.empty())
45                 mid = loc;
46         else
47                 mid = tgt.get_install_location();
48
49         return prefix/mid/FS::basename(tgt.get_path());
50 }