#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"
+#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)
{ }
/**
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();
}
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)
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);
void source(const std::string &);
void require(const std::string &);
+ void modular();
+ void host(const std::string &);
void build_info();
};
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();
PathList sources;
bool install;
std::string install_headers;
+ const Component *module_host;
+ bool modular;
BuildInfo build_info;
PkgRefList requires;
};
{
LibMode libmode=package->get_library_mode();
- //XXX Duplicate libraries?
list<const Component *> queue;
+ list<Target *> dep_libs;
queue.push_back(&comp);
while(!queue.empty())
{
{
if(contains(depends, lib))
continue;
- add_depend(lib);
+
+ dep_libs.push_front(lib);
if(dynamic_cast<Install *>(lib))
lib=lib->get_depends().front();
}
}
+ for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
+ add_depend(*i);
+
deps_ready=true;
}
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();
}
//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");
-#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"
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;
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");
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);
}
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);
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();
};