3 This file is part of builder
4 Copyright © 2006-2010 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 Target *Install::get_real_target()
33 return source.get_real_target();
36 void Install::check_rebuild()
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");
46 Action *Install::create_action()
48 return new Copy(builder, *package, source.get_path(), path);
51 FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string &loc)
53 if(!tgt.get_package())
54 throw InvalidParameterValue("Can't install package-less targets");
56 FS::Path base = tgt.get_package()->get_builder().get_prefix();
57 string tgtname = FS::basename(tgt.get_path());
62 else if(const Header *hdr = dynamic_cast<const Header *>(&tgt))
64 if(hdr->get_component()->get_type()!=Component::HEADERS)
65 throw Exception("Header install from non-header component?");
66 mid = "include/"+hdr->get_component()->get_name();
68 else if(dynamic_cast<const Executable *>(&tgt))
70 else if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&tgt))
72 const Component &comp = shlib->get_component();
73 if(comp.get_type()==Component::LIBRARY)
76 if(!shlib->get_soname().empty())
77 tgtname = shlib->get_soname();
79 else if(comp.get_type()==Component::MODULE)
80 mid = "lib/"+tgt.get_package()->get_name();
82 else if(dynamic_cast<const StaticLibrary *>(&tgt))
84 else if(dynamic_cast<const PkgConfig *>(&tgt))
85 mid = "lib/pkgconfig";
86 else if(dynamic_cast<const ::DataFile *>(&tgt))
87 mid = "share/"+tgt.get_package()->get_name();
90 throw InvalidParameterValue("Don't know where to install "+tgtname);
92 return (base/mid/tgtname).str();