X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finstall.cpp;h=ecf50ee6cfa1e73f8c8e62d4f7d05f4a6778fc01;hb=0458300fda4f345f865a7f3ee4fc0f2020a91983;hp=d80f9a74d80e15f9c2110f4c9745e6ba0dd7a8d9;hpb=96e132661ec82c9347f9155d3f30cd99ea8eca47;p=builder.git diff --git a/source/install.cpp b/source/install.cpp index d80f9a7..ecf50ee 100644 --- a/source/install.cpp +++ b/source/install.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -9,6 +9,7 @@ Distributed under the LGPL #include "builder.h" #include "copy.h" #include "executable.h" +#include "datafile.h" #include "header.h" #include "install.h" #include "package.h" @@ -19,22 +20,27 @@ Distributed under the LGPL using namespace std; using namespace Msp; -Install::Install(Builder &b, const SourcePackage &p, FileTarget &s): - FileTarget(b, &p, generate_target_path(s)), +Install::Install(Builder &b, const SourcePackage &p, FileTarget &s, const std::string &loc): + FileTarget(b, &p, generate_target_path(s, loc)), source(s) { - buildable=true; + buildable = true; add_depend(&source); } +Target *Install::get_real_target() +{ + return source.get_real_target(); +} + void Install::check_rebuild() { if(!mtime) mark_rebuild("Does not exist"); - else if(source.get_mtime()>mtime) - mark_rebuild(FS::basename(source.get_name())+" has changed"); + else if(source.get_mtime()>mtime || source.get_size()!=size) + mark_rebuild(source.get_name()+" has changed"); else if(source.get_rebuild()) - mark_rebuild(FS::basename(source.get_name())+" needs rebuilding"); + mark_rebuild(source.get_name()+" needs rebuilding"); } Action *Install::create_action() @@ -42,37 +48,46 @@ Action *Install::create_action() return new Copy(builder, *package, source.get_path(), path); } -FS::Path Install::generate_target_path(const FileTarget &tgt) +FS::Path Install::generate_target_path(const FileTarget &tgt, const std::string &loc) { - const SourcePackage *spkg=dynamic_cast(tgt.get_package()); + if(!tgt.get_package()) + throw invalid_argument("Can't install package-less targets"); - FS::Path base=spkg->get_builder().get_prefix(); - string tgtname=FS::basename(tgt.get_path()); + FS::Path base = tgt.get_package()->get_builder().get_prefix(); + string tgtname = FS::basename(tgt.get_path()); string mid; - if(const Header *hdr=dynamic_cast(&tgt)) + if(!loc.empty()) + mid = loc; + else if(const Header *hdr = dynamic_cast(&tgt)) { if(hdr->get_component()->get_type()!=Component::HEADERS) - throw Exception("Header install from non-header component?"); - mid="include/"+hdr->get_component()->get_name(); + throw logic_error("Header install from non-header component?"); + mid = "include/"+hdr->get_component()->get_name(); } else if(dynamic_cast(&tgt)) - mid="bin"; - else if(const SharedLibrary *shlib=dynamic_cast(&tgt)) + mid = "bin"; + else if(const SharedLibrary *shlib = dynamic_cast(&tgt)) { - const Component &comp=shlib->get_component(); + const Component &comp = shlib->get_component(); if(comp.get_type()==Component::LIBRARY) - mid="lib"; + { + mid = "lib"; + if(!shlib->get_soname().empty()) + tgtname = shlib->get_soname(); + } else if(comp.get_type()==Component::MODULE) - mid="lib/"+tgt.get_package()->get_name(); + mid = "lib/"+tgt.get_package()->get_name(); } else if(dynamic_cast(&tgt)) - mid="lib"; + mid = "lib"; else if(dynamic_cast(&tgt)) - mid="lib/pkgconfig"; + mid = "lib/pkgconfig"; + else if(dynamic_cast(&tgt)) + mid = "share/"+tgt.get_package()->get_name(); if(mid.empty()) - throw InvalidParameterValue("Don't know where to install "+tgtname); + throw invalid_argument("Don't know where to install "+tgtname); return (base/mid/tgtname).str(); }