]> git.tdb.fi Git - builder.git/commitdiff
Split Binary filename generation to Executable and SharedLibrary
authorMikko Rasa <tdb@tdb.fi>
Sun, 6 May 2012 11:48:46 +0000 (14:48 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:50 +0000 (00:08 +0300)
Use architecture patterns to generate executable and library names

source/binary.cpp
source/binary.h
source/executable.cpp
source/executable.h
source/sharedlibrary.cpp
source/sharedlibrary.h
source/staticlibrary.cpp

index a809e64b0745341d21c4734cb60513cf8f0b6d2a..17ec7353998f7fc7078c70d56bbb99762dfb7fa2 100644 (file)
@@ -16,8 +16,8 @@ Binary::Binary(Builder &b, const FS::Path &p):
        FileTarget(b, 0, p)
 { }
 
-Binary::Binary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
-       FileTarget(b, &c.get_package(), generate_target_path(c))
+Binary::Binary(Builder &b, const Component &c, const std::string &p, const list<ObjectFile *> &objs):
+       FileTarget(b, &c.get_package(), c.get_package().get_out_dir()/p)
 {
        component = &c;
        for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
@@ -77,28 +77,3 @@ void Binary::find_depends()
 
        deps_ready = true;
 }
-
-FS::Path Binary::generate_target_path(const Component &c)
-{
-       const SourcePackage &pkg = c.get_package();
-       string prefix, suffix;
-       const string &sys = pkg.get_builder().get_current_arch().get_system();
-
-       if(c.get_type()==Component::LIBRARY)
-       {
-               prefix = "lib";
-               if(sys=="windows")
-                       suffix = ".dll";
-               else
-                       suffix = ".so";
-       }
-       else if(c.get_type()==Component::MODULE)
-               suffix = ".m";
-       else if(c.get_type()==Component::PROGRAM)
-       {
-               if(sys=="windows")
-                       suffix = ".exe";
-       }
-
-       return pkg.get_out_dir()/(prefix+c.get_name()+suffix);
-}
index ef71a0691b6101df2661d59bf626a42e75978691..303bd51fa60589de50f6cc6ff229f0f44ce87af1 100644 (file)
@@ -14,13 +14,10 @@ class Binary: public FileTarget
 {
 protected:
        Binary(Builder &, const Msp::FS::Path &);
-       Binary(Builder &, const Component &, const std::list<ObjectFile *> &);
+       Binary(Builder &, const Component &, const std::string &, const std::list<ObjectFile *> &);
+
 public:
        virtual void find_depends();
-protected:
-       /** Returns the path for the binary.  We can't do this in the constructor
-       since we need to pass the value to the Target c'tor. */
-       static Msp::FS::Path generate_target_path(const Component &);
 };
 
 #endif
index 923ff8891ae53f8d65f00ca918b0f3279a89baff..2460f024d0f3f04647a3ba80279409c1639d1b48 100644 (file)
@@ -1,9 +1,19 @@
+#include "builder.h"
 #include "component.h"
 #include "executable.h"
 #include "sourcepackage.h"
 
+using namespace std;
+using namespace Msp;
+
 Executable::Executable(Builder &b, const Component &c, const std::list<ObjectFile *> &objs):
-       Binary(b, c, objs)
+       Binary(b, c, generate_filename(c), objs)
 {
        install_location = "bin";
 }
+
+string Executable::generate_filename(const Component &comp)
+{
+       const Architecture &arch = comp.get_package().get_builder().get_current_arch();
+       return arch.get_executable_patterns().front().apply(comp.get_name());
+}
index d07f89b09ed6c7d097dbcf3714bee96231119de9..6bba919eb3f35b800c2c6539276069af451d57c7 100644 (file)
@@ -7,7 +7,10 @@ class Executable: public Binary
 {
 public:
        Executable(Builder &, const Component &, const std::list<ObjectFile *> &);
+
        virtual const char *get_type() const { return "Executable"; }
+private:
+       static std::string generate_filename(const Component &);
 };
 
 #endif
index d3a8ceb25568e8f4077cc077f3deeb3dea69062a..9f983ef1d666fc7a690ed17da7a7cdb135e7ccaf 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
+#include "builder.h"
 #include "component.h"
 #include "sharedlibrary.h"
 #include "sourcepackage.h"
@@ -16,7 +17,7 @@ SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p):
 }
 
 SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
-       Binary(b, c, objs),
+       Binary(b, c, generate_filename(c), objs),
        libname(c.get_name()),
        soname(create_soname(c))
 {
@@ -28,6 +29,17 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFi
        }
 }
 
+string SharedLibrary::generate_filename(const Component &comp)
+{
+       if(comp.get_type()==Component::MODULE)
+               return comp.get_name()+".m";
+       else
+       {
+               const Architecture &arch = comp.get_package().get_builder().get_current_arch();
+               return arch.get_shared_library_patterns().front().apply(comp.get_name());
+       }
+}
+
 string SharedLibrary::create_soname(const Component &c)
 {
        const string &ver = c.get_package().get_version();
index 3feb9aad19176affae9f72a993e09695dd0f3199..c2fa985c7dcfd5d6d84ea76e09180a7c226c8ebe 100644 (file)
@@ -24,6 +24,7 @@ public:
        const std::string &get_soname() const { return soname; }
 
 private:
+       static std::string generate_filename(const Component &);
        std::string create_soname(const Component &);
 };
 
index 556ee54295963e8c55b7483947f6289160207da1..f6c8e56e49fc409382e0b7c399340eb6fa60ad1e 100644 (file)
@@ -1,3 +1,4 @@
+#include "builder.h"
 #include "component.h"
 #include "objectfile.h"
 #include "sourcepackage.h"
@@ -22,5 +23,7 @@ StaticLibrary::StaticLibrary(Builder &b, const Component &c, const list<ObjectFi
 
 Msp::FS::Path StaticLibrary::generate_target_path(const Component &c)
 {
-       return c.get_package().get_out_dir()/("lib"+c.get_name()+".a");
+       const Architecture &arch = c.get_package().get_builder().get_current_arch();
+       return c.get_package().get_out_dir()/
+               arch.get_static_library_patterns().front().apply(c.get_name());
 }