From: Mikko Rasa Date: Tue, 31 Oct 2006 01:53:40 +0000 (+0000) Subject: Support building static libraries (but not using them yet) X-Git-Tag: 0.9~50 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=4fcc283a4bb1f695bd124006906bcdaba053193f;p=builder.git Support building static libraries (but not using them yet) Separate class SharedLibrary (almost no-op) Eliminate redundant Component parameter from Link --- diff --git a/source/archive.cpp b/source/archive.cpp new file mode 100644 index 0000000..daff233 --- /dev/null +++ b/source/archive.cpp @@ -0,0 +1,33 @@ +#include +#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 &deps=lib.get_depends(); + for(list::const_iterator i=deps.begin(); i!=deps.end(); ++i) + if(dynamic_cast(*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(); +} diff --git a/source/archive.h b/source/archive.h new file mode 100644 index 0000000..49b5fe0 --- /dev/null +++ b/source/archive.h @@ -0,0 +1,14 @@ +#ifndef ARCHIVE_H_ +#define ARCHIVE_H_ + +#include "externalaction.h" + +class StaticLibrary; + +class Archive: public ExternalAction +{ +public: + Archive(Builder &, const StaticLibrary &); +}; + +#endif diff --git a/source/builder.cpp b/source/builder.cpp index 0b1d1bf..28d57d4 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -18,6 +18,8 @@ #include "misc.h" #include "objectfile.h" #include "package.h" +#include "sharedlibrary.h" +#include "staticlibrary.h" #include "systemlibrary.h" #include "virtualtarget.h" @@ -443,12 +445,28 @@ int Builder::create_targets() 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()) { @@ -462,6 +480,13 @@ int Builder::create_targets() 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); + } } } } diff --git a/source/executable.cpp b/source/executable.cpp index 630ac71..fb1edfb 100644 --- a/source/executable.cpp +++ b/source/executable.cpp @@ -31,19 +31,18 @@ void Executable::find_depends() 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(); } diff --git a/source/executable.h b/source/executable.h index f118b87..81637a7 100644 --- a/source/executable.h +++ b/source/executable.h @@ -11,6 +11,7 @@ class Executable: public Target public: Executable(Builder &, const Component &, const std::list &); const char *get_type() const { return "Executable"; } + const Component &get_component() const { return comp; } void find_depends(); Action *build(); private: diff --git a/source/link.cpp b/source/link.cpp index 96089da..8b4c564 100644 --- a/source/link.cpp +++ b/source/link.cpp @@ -9,9 +9,11 @@ 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) diff --git a/source/link.h b/source/link.h index eecbcbd..63ebf35 100644 --- a/source/link.h +++ b/source/link.h @@ -3,13 +3,12 @@ #include "externalaction.h" -class Component; class Executable; class Link: public ExternalAction { public: - Link(Builder &, const Executable &, const Component &); + Link(Builder &, const Executable &); }; #endif diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp new file mode 100644 index 0000000..557f7fe --- /dev/null +++ b/source/sharedlibrary.cpp @@ -0,0 +1,10 @@ +#include "component.h" +#include "package.h" +#include "sharedlibrary.h" + +using namespace std; + +SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list &objs): + Executable(b, c, objs) +{ } + diff --git a/source/sharedlibrary.h b/source/sharedlibrary.h new file mode 100644 index 0000000..96a38fa --- /dev/null +++ b/source/sharedlibrary.h @@ -0,0 +1,13 @@ +#ifndef SHAREDLIB_H_ +#define SHAREDLIB_H_ + +#include "executable.h" + +class SharedLibrary: public Executable +{ +public: + SharedLibrary(Builder &, const Component &, const std::list &); + const char *get_type() const { return "SharedLibrary"; } +}; + +#endif diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp new file mode 100644 index 0000000..df0cc7c --- /dev/null +++ b/source/staticlibrary.cpp @@ -0,0 +1,26 @@ +#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 &objs): + Target(b, &c.get_package(), generate_target_name(c)), + comp(c) +{ + buildable=true; + for(list::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(); +} diff --git a/source/staticlibrary.h b/source/staticlibrary.h new file mode 100644 index 0000000..f7f178a --- /dev/null +++ b/source/staticlibrary.h @@ -0,0 +1,22 @@ +#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 &); + 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