--- /dev/null
+#include <msp/path/utils.h>
+#include "archive.h"
+#include "builder.h"
+#include "component.h"
+#include "objectfile.h"
+#include "package.h"
+#include "staticlibrary.h"
+
+using namespace std;
+using namespace Msp;
+
+Archive::Archive(Builder &b, const StaticLibrary &lib):
+ ExternalAction(b)
+{
+ const Component &comp=lib.get_component();
+
+ argv.push_back("ar");
+ argv.push_back("rc");
+
+ argv.push_back(lib.get_name());
+ const list<Target *> &deps=lib.get_depends();
+ for(list<Target *>::const_iterator i=deps.begin(); i!=deps.end(); ++i)
+ if(dynamic_cast<ObjectFile *>(*i))
+ argv.push_back((*i)->get_name());
+
+ Path::Path lpath=lib.get_name();
+ if(!builder.get_dry_run())
+ Path::mkpath(lpath.subpath(0, lpath.size()-1), 0755);
+
+ announce(comp.get_package().get_name(), "AR ", relative(lpath, comp.get_package().get_source()).str());
+
+ launch();
+}
--- /dev/null
+#ifndef ARCHIVE_H_
+#define ARCHIVE_H_
+
+#include "externalaction.h"
+
+class StaticLibrary;
+
+class Archive: public ExternalAction
+{
+public:
+ Archive(Builder &, const StaticLibrary &);
+};
+
+#endif
#include "misc.h"
#include "objectfile.h"
#include "package.h"
+#include "sharedlibrary.h"
+#include "staticlibrary.h"
#include "systemlibrary.h"
#include "virtualtarget.h"
if(build_exe)
{
- Executable *exe=new Executable(*this, *j, objs);
+ Executable *exe=0;
+ StaticLibrary *slib=0;
+ if(j->get_type()==Component::LIBRARY)
+ {
+ exe=new SharedLibrary(*this, *j, objs);
+ slib=new StaticLibrary(*this, *j, objs);
+ add_target(slib);
+ }
+ else
+ exe=new Executable(*this, *j, objs);
+
add_target(exe);
if(i->second==default_pkg)
+ {
def_tgt->add_depend(exe);
+ if(slib) def_tgt->add_depend(slib);
+ }
else
+ {
world->add_depend(exe);
+ if(slib) world->add_depend(slib);
+ }
if(j->get_install())
{
Install *inst=new Install(*this, *i->second, *exe, (inst_base/inst_dir/Path::basename(exe->get_name())).str());
add_target(inst);
install->add_depend(inst);
+
+ if(slib)
+ {
+ inst=new Install(*this, *i->second, *slib, (inst_base/inst_dir/Path::basename(slib->get_name())).str());
+ add_target(inst);
+ install->add_depend(inst);
+ }
}
}
}
Action *Executable::build()
{
- return Target::build(new Link(builder, *this, comp));;
+ return Target::build(new Link(builder, *this));;
}
-string Executable::generate_target_name(const Component &comp)
+string Executable::generate_target_name(const Component &c)
{
- string prefix;
- string suffix;
+ string prefix,suffix;
- if(comp.get_type()==Component::LIBRARY)
+ if(c.get_type()==Component::LIBRARY)
{
prefix="lib";
suffix=".so";
}
- return (comp.get_package().get_source()/(prefix+comp.get_name()+suffix)).str();
+ return (c.get_package().get_source()/(prefix+c.get_name()+suffix)).str();
}
public:
Executable(Builder &, const Component &, const std::list<ObjectFile *> &);
const char *get_type() const { return "Executable"; }
+ const Component &get_component() const { return comp; }
void find_depends();
Action *build();
private:
using namespace std;
using namespace Msp;
-Link::Link(Builder &b, const Executable &exe, const Component &comp):
+Link::Link(Builder &b, const Executable &exe):
ExternalAction(b)
{
+ const Component &comp=exe.get_component();
+
argv.push_back("g++");
if(comp.get_type()==Component::LIBRARY)
#include "externalaction.h"
-class Component;
class Executable;
class Link: public ExternalAction
{
public:
- Link(Builder &, const Executable &, const Component &);
+ Link(Builder &, const Executable &);
};
#endif
--- /dev/null
+#include "component.h"
+#include "package.h"
+#include "sharedlibrary.h"
+
+using namespace std;
+
+SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
+ Executable(b, c, objs)
+{ }
+
--- /dev/null
+#ifndef SHAREDLIB_H_
+#define SHAREDLIB_H_
+
+#include "executable.h"
+
+class SharedLibrary: public Executable
+{
+public:
+ SharedLibrary(Builder &, const Component &, const std::list<ObjectFile *> &);
+ const char *get_type() const { return "SharedLibrary"; }
+};
+
+#endif
--- /dev/null
+#include "archive.h"
+#include "component.h"
+#include "objectfile.h"
+#include "package.h"
+#include "staticlibrary.h"
+
+using namespace std;
+
+StaticLibrary::StaticLibrary(Builder &b, const Component &c, const std::list<ObjectFile *> &objs):
+ Target(b, &c.get_package(), generate_target_name(c)),
+ comp(c)
+{
+ buildable=true;
+ for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
+ add_depend(*i);
+}
+
+Action *StaticLibrary::build()
+{
+ return Target::build(new Archive(builder, *this));;
+}
+
+string StaticLibrary::generate_target_name(const Component &c)
+{
+ return (c.get_package().get_source()/("lib"+c.get_name()+".a")).str();
+}
--- /dev/null
+#ifndef STATICLIB_H_
+#define STATICLIB_H_
+
+#include "target.h"
+
+class Component;
+class ObjectFile;
+
+class StaticLibrary: public Target
+{
+public:
+ StaticLibrary(Builder &, const Component &, const std::list<ObjectFile *> &);
+ const char *get_type() const { return "StaticLibrary"; }
+ const Component &get_component() const { return comp; }
+ Action *build();
+private:
+ const Component ∁
+
+ std::string generate_target_name(const Component &);
+};
+
+#endif