From 2606b03da59dc10e3826b833a2fceb0831d79972 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 6 May 2012 14:48:46 +0300 Subject: [PATCH] Split Binary filename generation to Executable and SharedLibrary Use architecture patterns to generate executable and library names --- source/binary.cpp | 29 ++--------------------------- source/binary.h | 7 ++----- source/executable.cpp | 12 +++++++++++- source/executable.h | 3 +++ source/sharedlibrary.cpp | 14 +++++++++++++- source/sharedlibrary.h | 1 + source/staticlibrary.cpp | 5 ++++- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/source/binary.cpp b/source/binary.cpp index a809e64..17ec735 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -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 &objs): - FileTarget(b, &c.get_package(), generate_target_path(c)) +Binary::Binary(Builder &b, const Component &c, const std::string &p, const list &objs): + FileTarget(b, &c.get_package(), c.get_package().get_out_dir()/p) { component = &c; for(list::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); -} diff --git a/source/binary.h b/source/binary.h index ef71a06..303bd51 100644 --- a/source/binary.h +++ b/source/binary.h @@ -14,13 +14,10 @@ class Binary: public FileTarget { protected: Binary(Builder &, const Msp::FS::Path &); - Binary(Builder &, const Component &, const std::list &); + Binary(Builder &, const Component &, const std::string &, const std::list &); + 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 diff --git a/source/executable.cpp b/source/executable.cpp index 923ff88..2460f02 100644 --- a/source/executable.cpp +++ b/source/executable.cpp @@ -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 &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()); +} diff --git a/source/executable.h b/source/executable.h index d07f89b..6bba919 100644 --- a/source/executable.h +++ b/source/executable.h @@ -7,7 +7,10 @@ class Executable: public Binary { public: Executable(Builder &, const Component &, const std::list &); + virtual const char *get_type() const { return "Executable"; } +private: + static std::string generate_filename(const Component &); }; #endif diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp index d3a8ceb..9f983ef 100644 --- a/source/sharedlibrary.cpp +++ b/source/sharedlibrary.cpp @@ -1,5 +1,6 @@ #include #include +#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 &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