3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/fs/utils.h>
11 #include "executable.h"
16 #include "pkgconfig.h"
17 #include "sharedlibrary.h"
18 #include "staticlibrary.h"
23 Install::Install(Builder &b, const SourcePackage &p, FileTarget &s, const std::string &loc):
24 FileTarget(b, &p, generate_target_path(s, loc)),
31 void Install::check_rebuild()
34 mark_rebuild("Does not exist");
35 else if(source.get_mtime()>mtime || source.get_size()!=size)
36 mark_rebuild(FS::basename(source.get_name())+" has changed");
37 else if(source.get_rebuild())
38 mark_rebuild(FS::basename(source.get_name())+" needs rebuilding");
41 Action *Install::create_action()
43 return new Copy(builder, *package, source.get_path(), path);
46 FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string &loc)
48 if(!tgt.get_package())
49 throw InvalidParameterValue("Can't install package-less targets");
51 FS::Path base = tgt.get_package()->get_builder().get_prefix();
52 string tgtname = FS::basename(tgt.get_path());
57 else if(const Header *hdr = dynamic_cast<const Header *>(&tgt))
59 if(hdr->get_component()->get_type()!=Component::HEADERS)
60 throw Exception("Header install from non-header component?");
61 mid = "include/"+hdr->get_component()->get_name();
63 else if(dynamic_cast<const Executable *>(&tgt))
65 else if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&tgt))
67 const Component &comp = shlib->get_component();
68 if(comp.get_type()==Component::LIBRARY)
70 else if(comp.get_type()==Component::MODULE)
71 mid = "lib/"+tgt.get_package()->get_name();
73 else if(dynamic_cast<const StaticLibrary *>(&tgt))
75 else if(dynamic_cast<const PkgConfig *>(&tgt))
76 mid = "lib/pkgconfig";
77 else if(dynamic_cast<const ::DataFile *>(&tgt))
78 mid = "share/"+tgt.get_package()->get_name();
81 throw InvalidParameterValue("Don't know where to install "+tgtname);
83 return (base/mid/tgtname).str();