]> git.tdb.fi Git - builder.git/blob - source/installedfile.cpp
Get rid of separate header targets which serve no useful purpose
[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 "installedfile.h"
7 #include "package.h"
8 #include "pkgconfig.h"
9 #include "sharedlibrary.h"
10 #include "staticlibrary.h"
11
12 using namespace std;
13 using namespace Msp;
14
15 InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s, const std::string &loc):
16         FileTarget(b, &p, generate_target_path(b.get_prefix(), s, loc)),
17         source(s)
18 {
19         buildable = true;
20         add_depend(&source);
21
22         if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&source))
23                 if(!shlib->get_soname().empty())
24                         link = FS::dirname(path)/FS::basename(shlib->get_path());
25
26         if(!link.empty())
27                 builder.get_vfs().register_path(link, this);
28 }
29
30 Target *InstalledFile::get_real_target()
31 {
32         return source.get_real_target();
33 }
34
35 void InstalledFile::check_rebuild()
36 {
37         if(!mtime)
38                 mark_rebuild("Does not exist");
39         else if(source.get_mtime()>mtime || source.get_size()!=size)
40                 mark_rebuild(source.get_name()+" has changed");
41         else if(source.get_rebuild())
42                 mark_rebuild(source.get_name()+" needs rebuilding");
43 }
44
45 FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const std::string &loc)
46 {
47         if(!tgt.is_installable() && loc.empty())
48                 throw invalid_argument(tgt.get_name()+" is not installable");
49
50         string mid;
51         if(!loc.empty())
52                 mid = loc;
53         else
54                 mid = tgt.get_install_location();
55
56         return prefix/mid/FS::basename(tgt.get_path());
57 }