]> git.tdb.fi Git - builder.git/blobdiff - source/installedfile.cpp
More generic system for installing targets under different names
[builder.git] / source / installedfile.cpp
index f2909f6127ec94d72f475ed200a9182276fd4742..b2487537369076f705b136a1023371f9a9cf7356 100644 (file)
@@ -11,14 +11,18 @@ InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s,
        FileTarget(b, p, generate_target_path(b.get_prefix(), s, loc)),
        source(s)
 {
-       add_depend(source);
+       add_dependency(source);
 
-       if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&source))
-               if(!shlib->get_soname().empty())
-                       link = FS::dirname(path)/FS::basename(shlib->get_path());
-
-       if(!link.empty())
+       /* XXX Ideally, the tool should handle this (symlinks are not necessary for
+       windows dlls).  However, the tool that created the target being installed
+       knows nothing about the InstalledFile. */
+       string base_fn = FS::basename(source.get_path());
+       const string &inst_fn = source.get_install_filename();
+       if(!inst_fn.empty() && inst_fn!=base_fn)
+       {
+               link = FS::dirname(path)/base_fn;
                builder.get_vfs().register_path(link, this);
+       }
 }
 
 FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const string &loc)
@@ -34,10 +38,9 @@ FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileT
        else
                mid = tgt.get_install_location();
 
-       string fn = FS::basename(tgt.get_path());
-       if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&tgt))
-               if(!shlib->get_soname().empty())
-                       fn = shlib->get_soname();
+       string fn = tgt.get_install_filename();
+       if(fn.empty())
+               fn = FS::basename(tgt.get_path());
 
        return prefix/mid/fn;
 }
@@ -55,6 +58,22 @@ void InstalledFile::check_rebuild()
                mark_rebuild(source.get_name()+" has changed");
        else if(source.needs_rebuild())
                mark_rebuild(source.get_name()+" needs rebuilding");
-       else if(!link.empty() && !FS::exists(link))
-               mark_rebuild("Symlink does not exist");
+       if(!needs_rebuild() && !link.empty())
+       {
+               if(!FS::exists(link))
+                       mark_rebuild("Symlink does not exist");
+               else
+               {
+                       FS::Path rel_path = FS::relative(path, FS::dirname(link));
+                       if(FS::readlink(link)!=rel_path)
+                               mark_rebuild("Symlink needs updating");
+               }
+       }
+}
+
+void InstalledFile::clean()
+{
+       if(!link.empty() && mtime)
+               FS::unlink(link);
+       FileTarget::clean();
 }