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)
#include <msp/datafile/loader.h>
#include "buildinfo.h"
#include "misc.h"
+#include "pattern.h"
class Builder;
void tool(const std::string &t, const std::string &p);
};
+ typedef std::list<Pattern> PatternList;
+
private:
Builder &builder;
std::string type;
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);
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 &);
--- /dev/null
+#include <stdexcept>
+#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;
+}
--- /dev/null
+#ifndef PATTERN_H_
+#define PATTERN_H_
+
+#include <string>
+
+class Pattern
+{
+private:
+ std::string prefix;
+ std::string suffix;
+
+public:
+ Pattern(const std::string &);
+
+ std::string apply(const std::string &) const;
+};
+
+#endif
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)
{
return 0;
}
+
+void VirtualFileSystem::fill_candidates(StringList &candidates, const list<Pattern> &patterns, const string &base)
+{
+ for(list<Pattern>::const_iterator i=patterns.begin(); i!=patterns.end(); ++i)
+ candidates.push_back(i->apply(base));
+}
class Builder;
class FileTarget;
+class Pattern;
class VirtualFileSystem
{
FileTarget *get_header(const Msp::FS::Path &);
FileTarget *get_library(const std::string &, const Msp::FS::Path &, LibMode);
+
+ void fill_candidates(std::list<std::string> &, const std::list<Pattern> &, const std::string &);
};
#endif