X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fobjectfile.cpp;h=a2f80729878630a2e081caca19a818b8e88e8d4b;hb=9f885c3eec8f065b7dc400acfb9dd67158284fcf;hp=683c724306d1f56db62a9585b69aeaf78cadbff7;hpb=242c55b17e6608b29a77ca17a5b677e202a3ca90;p=builder.git diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 683c724..a2f8072 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -1,16 +1,7 @@ -/* $Id$ - -This file is part of builder -Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include +#include #include #include "builder.h" -#include "compile.h" #include "component.h" -#include "install.h" #include "objectfile.h" #include "sourcefile.h" #include "sourcepackage.h" @@ -18,71 +9,103 @@ Distributed under the LGPL using namespace std; using namespace Msp; -ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &src): - Target(b, &c.get_package(), generate_target_name(c, src.get_name())), - comp(c) +ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s): + FileTarget(b, c.get_package(), generate_target_path(c, s.get_path())), + source(s), + used_in_shlib(false) { - buildable=true; - add_depend(&src); + component = &c; + add_dependency(source); } -void ObjectFile::find_depends() +FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path &src) { - for(TargetList::iterator i=new_deps.begin(); i!=new_deps.end();) + const SourcePackage &pkg = comp.get_package(); + FS::Path temp_dir = pkg.get_temp_directory(); + FS::Path rel_src; + if(FS::descendant_depth(src, temp_dir)>=0) + rel_src = FS::relative(src, temp_dir); + else + rel_src = FS::relative(src, pkg.get_source_directory()); + string fn; + for(const string &c: rel_src) { - Target *tgt=*i; - if(tgt->get_depends_ready()) - { - i=new_deps.erase(i); - find_depends(tgt); - } - else - ++i; + if(!fn.empty()) + fn += '_'; + if(c!=".") + fn += c; } - - deps_ready=new_deps.empty(); + const Architecture &arch = comp.get_package().get_builder().get_current_arch(); + return temp_dir/comp.get_name()/arch.create_filename(FS::basepart(fn)); } - -void ObjectFile::find_depends(Target *tgt) +void ObjectFile::set_used_in_shared_library(bool u) { - const string &tname=tgt->get_name(); - string path=tname.substr(0, tname.rfind('/')); - - SourceFile *src=dynamic_cast(tgt); - if(!src) - { - Install *inst=dynamic_cast(tgt); - if(inst) - src=dynamic_cast(inst->get_depends().front()); - } - if(!src) - return; - - const StringList &incpath=comp.get_build_info().incpath; - - const list &includes=src->get_includes(); - for(list::const_iterator i=includes.begin(); i!=includes.end(); ++i) - { - Target *hdr2=builder.get_header(*i, path, incpath); - if(hdr2 && find(depends.begin(), depends.end(), hdr2)==depends.end()) - add_depend(hdr2); - } + used_in_shlib = u; } -void ObjectFile::add_depend(Target *tgt) +void ObjectFile::collect_build_info(BuildInfo &binfo) const { - Target::add_depend(tgt); - new_deps.push_back(tgt); + Target::collect_build_info(binfo); + binfo.update_from(component->get_build_info_for_path(source.get_path())); } -Action *ObjectFile::create_action() +void ObjectFile::find_dependencies() { - return new Compile(builder, *this); + vector headers; + find_dependencies(source, headers); + for(FileTarget *h: headers) + { + add_dependency(*h); + if(h->get_real_target()->is_buildable()) + h->signal_modified.connect(sigc::mem_fun(this, static_cast(&ObjectFile::find_dependencies))); + } } -string ObjectFile::generate_target_name(const Component &comp, const string &src) +void ObjectFile::find_dependencies(FileTarget &tgt, vector &headers) { - const SourcePackage &pkg=comp.get_package(); - return (pkg.get_temp_dir()/comp.get_name()/(FS::basepart(FS::basename(src))+".o")).str(); + tgt.prepare(); + + FileTarget *rtgt = dynamic_cast(tgt.get_real_target()); + Dependencies deps_to_add = rtgt->get_transitive_dependencies(); + if(rtgt!=&tgt) + { + FS::Path inst_dir = rtgt->get_component()->get_install_map().get_install_location(*rtgt); + /* The target has been displaced by installing it. Displace any + dependencies that come from the same package as well. */ + const SourcePackage *tpkg = rtgt->get_package(); + for(Target *&d: deps_to_add) + { + FileTarget *file = dynamic_cast(d); + if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source_directory())>=0) + { + const Component *tcomp = file->get_component(); + FS::Path dep_inst = tcomp->get_install_map().get_install_location(*file); + FS::Path displaced = FS::dirname(tgt.get_path())/FS::relative(dep_inst, inst_dir)/FS::basename(file->get_path()); + d = builder.get_vfs().get_target(displaced); + if(!d) + { + /* If the target was in an overlay directory and the displaced + dependency is not found, try removing the overlay from the path. */ + string last_dir = FS::basename(FS::dirname(displaced)); + if(any_equals(tcomp->get_overlays(), last_dir)) + { + displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path()); + d = builder.get_vfs().get_target(displaced); + } + } + } + } + } + + for(Target *d: deps_to_add) + if(FileTarget *file = dynamic_cast(d)) + { + auto i = lower_bound(headers, file); + if(i==headers.end() || *i!=file) + { + headers.insert(i, file); + find_dependencies(*file, headers); + } + } }