X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcomponent.cpp;h=4bdff213abcaf45a404d62444c7fe19b2b343479;hb=921fc49488a68442fb8794e1a0284a3bf1e7b91b;hp=1fd6b24bfc89676324cd80eb7fe3469c6263b86a;hpb=b1a6e6dcdd7e0da272ab0ebbed4e295f83f1165a;p=builder.git diff --git a/source/component.cpp b/source/component.cpp index 1fd6b24..4bdff21 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -1,3 +1,4 @@ +#include #include "component.h" #include "package.h" @@ -7,12 +8,48 @@ Component::Component(Package &p, Type t, const string &n): pkg(p), type(t), name(n), - install(false) + install(false), + module_host(0), + modular(false), + deflt(true) { } +/** +Tries to resolve all references to packages. +*/ +void Component::resolve_refs() +{ + for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) + i->resolve(); +} + +/** +Prepares the build information for building. +*/ void Component::create_build_info() { build_info.add(pkg.get_build_info()); + + for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) + { + if(!i->get_package()) + continue; + //i->get_package()->create_build_info(); + build_info.add(i->get_package()->get_exported_binfo()); + } + + if(modular) + { + build_info.ldflags.push_back("-rdynamic"); + build_info.libs.push_back("dl"); + } + else if(module_host) + { + const PathList &host_src=module_host->get_sources(); + for(PathList::const_iterator i=host_src.begin(); i!=host_src.end(); ++i) + build_info.incpath.push_back(i->str()); + } + build_info.unique(); } @@ -22,7 +59,11 @@ Component::Loader::Loader(Component &c): add("source", &Loader::source); add("install", &Component::install); add("install_headers", &Component::install_headers); - add("cflag", &Loader::cflag); + add("build_info", &Loader::build_info); + add("require", &Loader::require); + add("modular", &Loader::modular); + add("host", &Loader::host); + add("default", &Component::deflt); } void Component::Loader::source(const string &s) @@ -30,7 +71,34 @@ void Component::Loader::source(const string &s) comp.sources.push_back(comp.pkg.get_source()/s); } -void Component::Loader::cflag(const string &f) +void Component::Loader::require(const string &n) +{ + comp.requires.push_back(PackageRef(comp.pkg.get_builder(), n)); +} + +void Component::Loader::modular() +{ + if(comp.type!=PROGRAM) + throw Msp::Exception("Only programs can be modular"); + comp.modular=true; +} + +void Component::Loader::host(const string &n) +{ + const ComponentList &comps=comp.pkg.get_components(); + for(ComponentList::const_iterator i=comps.begin(); i!=comps.end(); ++i) + if(i->get_name()==n) + { + if(i->get_type()!=PROGRAM || !i->get_modular()) + throw Msp::Exception("Module host must be a modular program"); + comp.module_host=&*i; + return; + } + + throw Msp::Exception("Unknown component"); +} + +void Component::Loader::build_info() { - comp.build_info.cflags.push_back(f); + load_sub(comp.build_info); }