From: Mikko Rasa Date: Fri, 4 May 2012 18:10:47 +0000 (+0300) Subject: Have Architecture provide pattern lists for library and executable filenames X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=40177b0cfc0d4e67f971941f632e4f1f7e7c3f88;p=builder.git Have Architecture provide pattern lists for library and executable filenames --- diff --git a/source/architecture.cpp b/source/architecture.cpp index e0b6966..8e618de 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -105,6 +105,21 @@ Architecture::Architecture(Builder &b, const string &spec): if(!cpu.empty()) name += format("-%s", cpu); name += format("-%d-%s", bits, system); + + if(system=="windows") + { + sharedlib_patterns.push_back(Pattern("%.dll")); + sharedlib_patterns.push_back(Pattern("lib%.dll")); + staticlib_patterns.push_back(Pattern("lib%.a")); + staticlib_patterns.push_back(Pattern("lib%.dll.a")); + executable_patterns.push_back(Pattern("%.exe")); + } + else + { + sharedlib_patterns.push_back(Pattern("lib%.so")); + staticlib_patterns.push_back(Pattern("lib%.a")); + executable_patterns.push_back(Pattern("%")); + } } void Architecture::set_tool(const string &t, const string &p) diff --git a/source/architecture.h b/source/architecture.h index 1f643dc..3ea13a0 100644 --- a/source/architecture.h +++ b/source/architecture.h @@ -4,6 +4,7 @@ #include #include "buildinfo.h" #include "misc.h" +#include "pattern.h" class Builder; @@ -23,6 +24,8 @@ public: void tool(const std::string &t, const std::string &p); }; + typedef std::list PatternList; + private: Builder &builder; std::string type; @@ -33,6 +36,9 @@ private: bool native; std::string cross_prefix; StringMap tools; + PatternList sharedlib_patterns; + PatternList staticlib_patterns; + PatternList executable_patterns; public: Architecture(Builder &b, const std::string &spec); @@ -49,6 +55,10 @@ public: std::string get_tool(const std::string &t) const; const std::string &get_cross_prefix() const { return cross_prefix; } + const PatternList &get_shared_library_patterns() const { return sharedlib_patterns; } + const PatternList &get_static_library_patterns() const { return staticlib_patterns; } + const PatternList &get_executable_patterns() const { return executable_patterns; } + private: std::string resolve_alias(const std::string &) const; void parse_specification(const std::string &); diff --git a/source/pattern.cpp b/source/pattern.cpp new file mode 100644 index 0000000..e87981f --- /dev/null +++ b/source/pattern.cpp @@ -0,0 +1,18 @@ +#include +#include "pattern.h" + +using namespace std; + +Pattern::Pattern(const string &pat) +{ + string::size_type percent = pat.find('%'); + if(percent==string::npos) + throw invalid_argument("No percent sign in pattern"); + prefix = pat.substr(0, percent); + suffix = pat.substr(percent+1); +} + +string Pattern::apply(const string &body) const +{ + return prefix+body+suffix; +} diff --git a/source/pattern.h b/source/pattern.h new file mode 100644 index 0000000..de8e7b2 --- /dev/null +++ b/source/pattern.h @@ -0,0 +1,18 @@ +#ifndef PATTERN_H_ +#define PATTERN_H_ + +#include + +class Pattern +{ +private: + std::string prefix; + std::string suffix; + +public: + Pattern(const std::string &); + + std::string apply(const std::string &) const; +}; + +#endif diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index be646cd..ef7605b 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -163,22 +163,11 @@ FileTarget *VirtualFileSystem::get_library(const string &lib, const FS::Path &pa const Architecture &arch = builder.get_current_arch(); if(mode!=ALL_STATIC) - { - // XXX Should probably let the Architecture populate the list - if(arch.get_system()=="windows") - { - candidates.push_back("lib"+lib+".dll"); - candidates.push_back(lib+".dll"); - } - else - candidates.push_back("lib"+lib+".so"); - } + fill_candidates(candidates, arch.get_shared_library_patterns(), lib); /* Static libraries are always considered, since sometimes shared versions may not be available */ - candidates.push_back("lib"+lib+".a"); - if(arch.get_system()=="windows") - candidates.push_back("lib"+lib+".dll.a"); + fill_candidates(candidates, arch.get_static_library_patterns(), lib); for(StringList::iterator i=candidates.begin(); i!=candidates.end(); ++i) { @@ -205,3 +194,9 @@ FileTarget *VirtualFileSystem::get_library(const string &lib, const FS::Path &pa return 0; } + +void VirtualFileSystem::fill_candidates(StringList &candidates, const list &patterns, const string &base) +{ + for(list::const_iterator i=patterns.begin(); i!=patterns.end(); ++i) + candidates.push_back(i->apply(base)); +} diff --git a/source/virtualfilesystem.h b/source/virtualfilesystem.h index 16f8c6d..5ecc04b 100644 --- a/source/virtualfilesystem.h +++ b/source/virtualfilesystem.h @@ -7,6 +7,7 @@ class Builder; class FileTarget; +class Pattern; class VirtualFileSystem { @@ -50,6 +51,8 @@ private: FileTarget *get_header(const Msp::FS::Path &); FileTarget *get_library(const std::string &, const Msp::FS::Path &, LibMode); + + void fill_candidates(std::list &, const std::list &, const std::string &); }; #endif