]> git.tdb.fi Git - builder.git/blobdiff - source/install.cpp
Also use file size to determine whether to reinstall a file
[builder.git] / source / install.cpp
index d80f9a74d80e15f9c2110f4c9745e6ba0dd7a8d9..27bb9a334a970a5936efcad487ce720917bd7588 100644 (file)
@@ -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,8 +20,8 @@ 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;
@@ -31,7 +32,7 @@ void Install::check_rebuild()
 {
        if(!mtime)
                mark_rebuild("Does not exist");
-       else if(source.get_mtime()>mtime)
+       else if(source.get_mtime()>mtime || source.get_size()!=size)
                mark_rebuild(FS::basename(source.get_name())+" has changed");
        else if(source.get_rebuild())
                mark_rebuild(FS::basename(source.get_name())+" needs rebuilding");
@@ -42,15 +43,18 @@ 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<const SourcePackage *>(tgt.get_package());
+       if(!tgt.get_package())
+               throw InvalidParameterValue("Can't install package-less targets");
 
-       FS::Path base=spkg->get_builder().get_prefix();
+       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<const Header *>(&tgt))
+       if(!loc.empty())
+               mid=loc;
+       else if(const Header *hdr=dynamic_cast<const Header *>(&tgt))
        {
                if(hdr->get_component()->get_type()!=Component::HEADERS)
                        throw Exception("Header install from non-header component?");
@@ -70,6 +74,8 @@ FS::Path Install::generate_target_path(const FileTarget &tgt)
                mid="lib";
        else if(dynamic_cast<const PkgConfig *>(&tgt))
                mid="lib/pkgconfig";
+       else if(dynamic_cast<const ::DataFile *>(&tgt))
+               mid="share/"+tgt.get_package()->get_name();
 
        if(mid.empty())
                throw InvalidParameterValue("Don't know where to install "+tgtname);