]> git.tdb.fi Git - builder.git/commitdiff
Support building static libraries (but not using them yet)
authorMikko Rasa <tdb@tdb.fi>
Tue, 31 Oct 2006 01:53:40 +0000 (01:53 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 31 Oct 2006 01:53:40 +0000 (01:53 +0000)
Separate class SharedLibrary (almost no-op)
Eliminate redundant Component parameter from Link

source/archive.cpp [new file with mode: 0644]
source/archive.h [new file with mode: 0644]
source/builder.cpp
source/executable.cpp
source/executable.h
source/link.cpp
source/link.h
source/sharedlibrary.cpp [new file with mode: 0644]
source/sharedlibrary.h [new file with mode: 0644]
source/staticlibrary.cpp [new file with mode: 0644]
source/staticlibrary.h [new file with mode: 0644]

diff --git a/source/archive.cpp b/source/archive.cpp
new file mode 100644 (file)
index 0000000..daff233
--- /dev/null
@@ -0,0 +1,33 @@
+#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();
+}
diff --git a/source/archive.h b/source/archive.h
new file mode 100644 (file)
index 0000000..49b5fe0
--- /dev/null
@@ -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
index 0b1d1bf55163b3a8c44d2a767bcb4e790a0b7b7a..28d57d44012ce1465720185b1ea5d04c7558b910 100644 (file)
@@ -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);
+                                               }
                                        }
                                }
                        }
index 630ac71f717e639173cc47ea3b74a7df28b84ffb..fb1edfb2f2193b34b9f46ff35d0b95817a66b8a4 100644 (file)
@@ -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();
 }
index f118b8762b0ab568cc2ad8ae5e88a1299a754c5d..81637a7ae461f334a5866e02e0517eee6a37c5d5 100644 (file)
@@ -11,6 +11,7 @@ class Executable: public Target
 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:
index 96089da8b58116ee24d95b9d57171bca04d0cd8c..8b4c56421089e34d8bee43ffbd378c28cfb1566d 100644 (file)
@@ -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)
index eecbcbdc1bb4182c9ad897005a93d159ef16bf53..63ebf356548c8f80fdb06c10f1b7d1fbf77587d2 100644 (file)
@@ -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 (file)
index 0000000..557f7fe
--- /dev/null
@@ -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<ObjectFile *> &objs):
+       Executable(b, c, objs)
+{ }
+
diff --git a/source/sharedlibrary.h b/source/sharedlibrary.h
new file mode 100644 (file)
index 0000000..96a38fa
--- /dev/null
@@ -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<ObjectFile *> &);
+       const char *get_type() const { return "SharedLibrary"; }
+};
+
+#endif
diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp
new file mode 100644 (file)
index 0000000..df0cc7c
--- /dev/null
@@ -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<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();
+}
diff --git a/source/staticlibrary.h b/source/staticlibrary.h
new file mode 100644 (file)
index 0000000..f7f178a
--- /dev/null
@@ -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<ObjectFile *> &);
+       const char *get_type() const { return "StaticLibrary"; }
+       const Component &get_component() const { return comp; }
+       Action *build();
+private:
+       const Component &comp;
+
+       std::string generate_target_name(const Component &);
+};
+
+#endif