]> git.tdb.fi Git - builder.git/commitdiff
Support building modular programs
authorMikko Rasa <tdb@tdb.fi>
Wed, 7 Mar 2007 20:21:58 +0000 (20:21 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 7 Mar 2007 20:21:58 +0000 (20:21 +0000)
source/builder.cpp
source/component.cpp
source/component.h
source/executable.cpp
source/link.cpp
source/package.cpp
source/package.h

index 1afc741ef59ee3c9b6c060c55800dea0238f97f0..f23e85af8c06d17c1056734a0bb2ce3995d82425 100644 (file)
@@ -1,12 +1,11 @@
 #include <fstream>
 #include <iostream>
 #include <msp/progress.h>
-#include <msp/strconv.h>
-#include <msp/strutils.h>
 #include <msp/core/error.h>
 #include <msp/getopt++/getopt++.h>
 #include <msp/parser/parser.h>
 #include <msp/path/utils.h>
+#include <msp/strings/utils.h>
 #include <msp/time/units.h>
 #include <msp/time/utils.h>
 #include "action.h"
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);
index 82b32e4ad7b7717fb78b96dd92ad57fe06a8eabd..e1df73a5b232aefd9c554010b2767f9f7697c297 100644 (file)
@@ -30,6 +30,8 @@ public:
 
                void source(const std::string &);
                void require(const std::string &);
+               void modular();
+               void host(const std::string &);
                void build_info();
        };
        
@@ -49,6 +51,7 @@ public:
        const BuildInfo   &get_build_info() const      { return build_info; }
        bool              get_install() const          { return install; }
        const std::string &get_install_headers() const { return install_headers; }
+       bool              get_modular() const          { return modular; }
        const PkgRefList  &get_requires() const        { return requires; }
        void              resolve_refs();
        void              create_build_info();
@@ -59,6 +62,8 @@ protected:
        PathList    sources;
        bool        install;
        std::string install_headers;
+       const Component *module_host;
+       bool        modular;
        BuildInfo   build_info;
        PkgRefList  requires;
 };
index 1f23990da93ca569af5476a7032a468d597549d4..a5a944ed18e7131e856b7af5fbc3d13238fd4c67 100644 (file)
@@ -28,8 +28,8 @@ void Executable::find_depends()
 {
        LibMode libmode=package->get_library_mode();
        
-       //XXX Duplicate libraries?
        list<const Component *> queue;
+       list<Target *> dep_libs;
        queue.push_back(&comp);
        while(!queue.empty())
        {
@@ -44,7 +44,8 @@ void Executable::find_depends()
                        {
                                if(contains(depends, lib))
                                        continue;
-                               add_depend(lib);
+
+                               dep_libs.push_front(lib);
 
                                if(dynamic_cast<Install *>(lib))
                                        lib=lib->get_depends().front();
@@ -57,6 +58,9 @@ void Executable::find_depends()
                }
        }
 
+       for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
+               add_depend(*i);
+
        deps_ready=true;
 }
 
@@ -78,6 +82,8 @@ string Executable::generate_target_name(const Component &c)
                prefix="lib";
                suffix=".so";
        }
+       else if(c.get_type()==Component::MODULE)
+               suffix=".m";
 
        return (c.get_package().get_out_dir()/(prefix+c.get_name()+suffix)).str();
 }
index 2ff5a97e85060545194ab58b4832e219617bb542..4a96ff2e4da59b2bde1f1173584d863890f5b09a 100644 (file)
@@ -23,7 +23,7 @@ Link::Link(Builder &b, const Executable &exe):
        //XXX Determine whether to use g++ or gcc
        argv.push_back(prefix+"g++");
        
-       if(comp.get_type()==Component::LIBRARY)
+       if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
                argv.push_back("-shared");
        else if(comp.get_package().get_library_mode()==ALL_STATIC)
                argv.push_back("-static");
index 0bea2a96b03048c4d476815b56a799d7270526f2..031ceb5f95c3a0bac333ed5c50df60137c71e834 100644 (file)
@@ -1,5 +1,5 @@
-#include <msp/strconv.h>
-#include <msp/strutils.h>
+#include <msp/strings/lexicalcast.h>
+#include <msp/strings/utils.h>
 #include "builder.h"
 #include "misc.h"
 #include "package.h"
@@ -270,7 +270,7 @@ void Package::create_build_info()
                        export_binfo.libpath.push_back((Path::Path(config.get_option("prefix").value)/"lib").str());
 
                string optimize=config.get_option("optimize").value;
-               if(strtol(optimize))
+               if(lexical_cast<unsigned>(optimize))
                {
                        build_info.cflags.push_back("-O"+optimize);
                        string cpu=config.get_option("cpu").value;
@@ -278,7 +278,7 @@ void Package::create_build_info()
                                build_info.cflags.push_back("-march="+cpu);
                }
 
-               if(strtobool(config.get_option("debug").value))
+               if(lexical_cast<bool>(config.get_option("debug").value))
                {
                        build_info.cflags.push_back("-ggdb");
                        build_info.defines.push_back("DEBUG");
@@ -313,6 +313,7 @@ Package::Loader::Loader(Package &p):
        add("require",     &Loader::require);
        add("program",     &Loader::program);
        add("library",     &Loader::library);
+       add("module",      &Loader::module);
        add("headers",     &Loader::headers);
        add("build_info",  &Loader::build_info);
 }
@@ -336,6 +337,13 @@ void Package::Loader::library(const string &n)
        pkg.components.push_back(prog);
 }
 
+void Package::Loader::module(const string &n)
+{
+       Component prog(pkg, Component::MODULE, n);
+       load_sub(prog);
+       pkg.components.push_back(prog);
+}
+
 void Package::Loader::headers(const string &n)
 {
        Component prog(pkg, Component::HEADERS, n);
index 96fb6760beefe1cec0dabca79c5d2ac5c5ce378a..68e0c224c2116126d29ec620e44fe71a4bab5242 100644 (file)
@@ -43,6 +43,7 @@ public:
                void require(const std::string &);
                void program(const std::string &);
                void library(const std::string &);
+               void module(const std::string &);
                void headers(const std::string &);
                void build_info();
        };