X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbinarycomponent.cpp;h=49c4897ce69d7d25492ebe1521257dca04c77062;hb=HEAD;hp=608ed3f6596b51b13522333358f2214cf6f093c1;hpb=aa053d637e8259755af7d2e4b510a242f4d29c7b;p=builder.git diff --git a/source/binarycomponent.cpp b/source/binarycomponent.cpp deleted file mode 100644 index 608ed3f..0000000 --- a/source/binarycomponent.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include "binarycomponent.h" -#include "builder.h" -#include "filetarget.h" -#include "sourcepackage.h" -#include "tool.h" - -using namespace std; -using namespace Msp; - -BinaryComponent::BinaryComponent(SourcePackage &p, const string &n, Type t): - Component(p, n), - type(t) -{ } - -void BinaryComponent::create_build_info() -{ - Component::create_build_info(); - - for(const Component *u: uses) - { - /* Select an include path that contains all the sources for this and the - used component. This should produce a sensible result in most cases. */ - FS::Path base; - for(const FS::Path &s: sources) - base = base.empty() ? s : FS::common_ancestor(base, s); - for(const FS::Path &s: u->get_sources()) - base = FS::common_ancestor(base, s); - build_info.incpath.push_back(base); - build_info.libs.push_back(u->get_name()); - if(!u->get_install()) - { - build_info.libmodes[u->get_name()] = BuildInfo::STATIC; - build_info.libpath.push_back(u->get_package().get_output_directory()); - } - } - - if(type==LIBRARY || type==MODULE) - if(build_info.libmode objs; - vector source_filenames = collect_source_files(); - objs.reserve(source_filenames.size()); - for(auto i=source_filenames.begin(); i!=source_filenames.end(); ++i) - { - string ext = FS::extpart(FS::basename(*i)); - Target *src = 0; - - Tool *gen = pkg_tools.get_tool_for_suffix(ext); - if(gen) - { - vector templates; - templates.push_back(gen->create_source(*this, *i)); - - Tool::ProcessingUnit processing_unit = gen->get_processing_unit(); - if(processing_unit!=Tool::ONE_FILE) - { - FS::Path source_dir = FS::dirname(*i); - for(auto j=next(i); j!=source_filenames.end(); ) - { - if((processing_unit!=Tool::DIRECTORY || FS::dirname(*j)==source_dir) && - pkg_tools.get_tool_for_suffix(FS::extpart(FS::basename(*j)))==gen) - { - templates.push_back(gen->create_source(*this, *j)); - // Remove additional files so they won't get processed again - j = source_filenames.erase(j); - } - else - ++j; - } - } - - src = gen->create_target(templates); - ext = FS::extpart(FS::basename(dynamic_cast(*src).get_path())); - } - - Tool *tool = toolchain.get_tool_for_suffix(ext, true); - if(tool) - { - if(!src) - src = tool->create_source(*this, *i); - if(!src) - continue; - - if(tool->accepts_suffix(ext)) - { - Target *obj = tool->create_target(*src); - objs.push_back(obj); - } - - if(type==LIBRARY && install) - { - if(dynamic_cast(src)->is_installable()) - build_graph.add_installed_target(*src); - - for(Target *s: src->get_side_effects()) - if(dynamic_cast(s)->is_installable()) - build_graph.add_installed_target(*s); - } - } - } - - Tool &linker = toolchain.get_tool("LINK"); - - vector results; - results.reserve(2); - if(type==LIBRARY) - { - Tool &archiver = toolchain.get_tool("AR"); - results.push_back(linker.create_target(objs, "shared")); - results.push_back(archiver.create_target(objs)); - } - else if(type==MODULE) - results.push_back(linker.create_target(objs, "shared")); - else - results.push_back(linker.create_target(objs)); - - for(Target *r: results) - { - build_graph.add_primary_target(*r); - if(install) - build_graph.add_installed_target(*r); - } -} - -BinaryComponent::Loader::Loader(BinaryComponent &c): - DataFile::DerivedObjectLoader(c) -{ - add("use", &Loader::use); -} - -void BinaryComponent::Loader::use(const string &n) -{ - const BinaryComponent *comp = dynamic_cast(&obj.package.get_component(n)); - if(!comp || comp->type!=LIBRARY) - throw logic_error(n+" is not a library"); - - obj.uses.push_back(comp); -}