]> git.tdb.fi Git - builder.git/blobdiff - source/component.cpp
Support building modular programs
[builder.git] / source / component.cpp
index 22392f0d91212cd0a01586e4bd1b941d46f8b47b..27a4c53c08805db4e23e2bdbbb186ba9c6ca018d 100644 (file)
@@ -1,13 +1,18 @@
+#include <msp/error.h>
 #include "component.h"
 #include "package.h"
 
 using namespace std;
 
+#include <iostream>
+
 Component::Component(Package &p, Type t, const string &n):
        pkg(p),
        type(t),
        name(n),
-       install(false)
+       install(false),
+       module_host(0),
+       modular(false)
 { }
 
 /**
@@ -34,6 +39,18 @@ void Component::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();
 }
 
@@ -45,6 +62,8 @@ Component::Loader::Loader(Component &c):
        add("install_headers", &Component::install_headers);
        add("build_info",      &Loader::build_info);
        add("require",         &Loader::require);
+       add("modular",         &Loader::modular);
+       add("host",            &Loader::host);
 }
 
 void Component::Loader::source(const string &s)
@@ -57,6 +76,28 @@ 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()
 {
        load_sub(comp.build_info);