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):
23 FileTarget(b, &p, generate_target_path(s)),
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)
47 const SourcePackage *spkg=dynamic_cast<const SourcePackage *>(tgt.get_package());
49 FS::Path base=spkg->get_builder().get_prefix();
50 string tgtname=FS::basename(tgt.get_path());
53 if(const Header *hdr=dynamic_cast<const Header *>(&tgt))
54 mid="include/"+hdr->get_component()->get_install_headers();
55 else if(dynamic_cast<const Executable *>(&tgt))
57 else if(const SharedLibrary *shlib=dynamic_cast<const SharedLibrary *>(&tgt))
59 const Component &comp=shlib->get_component();
60 if(comp.get_type()==Component::LIBRARY)
62 else if(comp.get_type()==Component::MODULE)
63 mid="lib/"+tgt.get_package()->get_name();
65 else if(dynamic_cast<const StaticLibrary *>(&tgt))
67 else if(dynamic_cast<const PkgConfig *>(&tgt))
71 throw InvalidParameterValue("Don't know where to install "+tgtname);
73 return (base/mid/tgtname).str();