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"
15 #include "pkgconfig.h"
16 #include "sharedlibrary.h"
17 #include "staticlibrary.h"
22 Install::Install(Builder &b, const SourcePackage &p, FileTarget &s, const std::string &loc):
23 FileTarget(b, &p, generate_target_path(s, loc)),
30 void Install::check_rebuild()
33 mark_rebuild("Does not exist");
34 else if(source.get_mtime()>mtime)
35 mark_rebuild(FS::basename(source.get_name())+" has changed");
36 else if(source.get_rebuild())
37 mark_rebuild(FS::basename(source.get_name())+" needs rebuilding");
40 Action *Install::create_action()
42 return new Copy(builder, *package, source.get_path(), path);
45 FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string &loc)
47 if(!tgt.get_package())
48 throw InvalidParameterValue("Can't install package-less targets");
50 FS::Path base=tgt.get_package()->get_builder().get_prefix();
51 string tgtname=FS::basename(tgt.get_path());
56 else if(const Header *hdr=dynamic_cast<const Header *>(&tgt))
58 if(hdr->get_component()->get_type()!=Component::HEADERS)
59 throw Exception("Header install from non-header component?");
60 mid="include/"+hdr->get_component()->get_name();
62 else if(dynamic_cast<const Executable *>(&tgt))
64 else if(const SharedLibrary *shlib=dynamic_cast<const SharedLibrary *>(&tgt))
66 const Component &comp=shlib->get_component();
67 if(comp.get_type()==Component::LIBRARY)
69 else if(comp.get_type()==Component::MODULE)
70 mid="lib/"+tgt.get_package()->get_name();
72 else if(dynamic_cast<const StaticLibrary *>(&tgt))
74 else if(dynamic_cast<const PkgConfig *>(&tgt))
78 throw InvalidParameterValue("Don't know where to install "+tgtname);
80 return (base/mid/tgtname).str();