X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbuildinfo.cpp;h=e2df34c06e3ec91cb56500f97c3bed1b53b23d02;hb=HEAD;hp=8e116709a57a934403d89d947a9cef840e6b4e64;hpb=d1f9551e05c9d341149eb490e05b1465d3d6b711;p=builder.git diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp deleted file mode 100644 index 8e11670..0000000 --- a/source/buildinfo.cpp +++ /dev/null @@ -1,196 +0,0 @@ -#include -#include -#include "buildinfo.h" - -using namespace std; -using namespace Msp; - -namespace { - -/** Removes any duplicate entries from a vector, leaving only the first one. -The order of other elements is preserved. */ -template -void unique(vector &v) -{ - vector seen; - for(auto i=v.begin(); i!=v.end(); ) - { - auto j = lower_bound(seen, *i); - if(j!=seen.end() && *j==*i) - i = v.erase(i); - else - seen.insert(j, *i++); - } -} - -} - - -BuildInfo::LibraryMode BuildInfo::get_libmode_for(const string &lib) const -{ - auto i = libmodes.find(lib); - if(i!=libmodes.end()) - return i->second; - return libmode; -} - -void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level) -{ - for(const auto &kvp: bi.defines) - defines[kvp.first] = kvp.second; - incpath.insert(incpath.begin(), bi.incpath.begin(), bi.incpath.end()); - threads = bi.threads; - - for(const auto &kvp: bi.standards) - { - auto j = standards.find(kvp.first); - if(j==standards.end()) - standards.insert(kvp); - else if(kvp.second.type!=j->second.type || kvp.second.year!=j->second.year) - { - if(!kvp.second.type.compare(0, 3, "gnu")) - j->second.type = kvp.second.type; - if(kvp.second.year>j->second.year) - j->second.year = kvp.second.year; - } - } - - if(level!=CHAINED) - { - libpath.insert(libpath.begin(), bi.libpath.begin(), bi.libpath.end()); - libs.insert(libs.begin(), bi.libs.begin(), bi.libs.end()); - } - - if(level==LOCAL) - { - sysroot = bi.sysroot; - local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end()); - libmode = bi.libmode; - rpath_mode = bi.rpath_mode; - for(const auto &kvp: bi.libmodes) - libmodes[kvp.first] = kvp.second; - keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end()); - debug = bi.debug; - optimize = bi.optimize; - strip = bi.strip; - warning_level = bi.warning_level; - fatal_warnings = bi.fatal_warnings; - } - - unique(incpath); - unique(local_incpath); - unique(libpath); - unique(libs); - unique(keep_symbols); -} - - -BuildInfo::LanguageStandard::LanguageStandard(const string &std) -{ - auto i = find_if(std, [](char c){ return isdigit(static_cast(c)); }); - string::size_type num = i-std.begin(); - type = std.substr(0, num); - year = lexical_cast(std.substr(num)); - year += (year<70 ? 2000 : 1900); -} - -string BuildInfo::LanguageStandard::str() const -{ - return format("%s%02d", type, year%100); -} - - -BuildInfo::Loader::Loader(BuildInfo &bi): - DataFile::ObjectLoader(bi) -{ - add("debug", &BuildInfo::debug); - add("define", &Loader::define); - add("incpath", &Loader::incpath); - add("keep_symbol", &Loader::keep_symbol); - add("libpath", &Loader::libpath); - add("library", &Loader::library); - add("libmode", &BuildInfo::libmode); - add("libmode", &Loader::libmode_for_lib); - add("local_incpath", &Loader::local_incpath); - add("optimize", &BuildInfo::optimize); - add("runtime_path_mode", &BuildInfo::rpath_mode); - add("standard", &Loader::standard); - add("strip", &BuildInfo::strip); - add("sysroot", &Loader::sysroot); - add("threads", &BuildInfo::threads); - add("warning_level", &BuildInfo::warning_level); - add("fatal_warnings", &BuildInfo::fatal_warnings); -} - -void BuildInfo::Loader::incpath(const string &s) -{ - obj.incpath.push_back(s); -} - -void BuildInfo::Loader::define(const string &d, const string &v) -{ - obj.defines[d] = v; -} - -void BuildInfo::Loader::keep_symbol(const string &s) -{ - obj.keep_symbols.push_back(s); -} - -void BuildInfo::Loader::libmode_for_lib(const string &l, LibraryMode m) -{ - obj.libmodes[l] = m; -} - -void BuildInfo::Loader::libpath(const string &s) -{ - obj.libpath.push_back(s); -} - -void BuildInfo::Loader::library(const string &s) -{ - obj.libs.push_back(s); -} - -void BuildInfo::Loader::local_incpath(const string &s) -{ - obj.local_incpath.push_back(s); -} - -void BuildInfo::Loader::standard(DataFile::Symbol tag, const string &std) -{ - obj.standards[tag.name] = std; -} - -void BuildInfo::Loader::sysroot(const string &s) -{ - obj.sysroot = s; -} - - -void operator>>(const LexicalConverter &conv, BuildInfo::LibraryMode &libmode) -{ - if(conv.get()=="FORCE_STATIC") - libmode = BuildInfo::FORCE_STATIC; - else if(conv.get()=="STATIC") - libmode = BuildInfo::STATIC; - else if(conv.get()=="DYNAMIC") - libmode = BuildInfo::DYNAMIC; - else if(conv.get()=="FORCE_DYNAMIC") - libmode = BuildInfo::FORCE_DYNAMIC; - else - throw lexical_error(format("Conversion of '%s' to LibraryMode", conv.get())); -} - - -void operator>>(const LexicalConverter &conv, BuildInfo::RuntimePathMode &rpath_mode) -{ - if(conv.get()=="NONE") - rpath_mode = BuildInfo::NO_RPATH; - else if(conv.get()=="RELATIVE") - rpath_mode = BuildInfo::RELATIVE; - else if(conv.get()=="ABSOLUTE") - rpath_mode = BuildInfo::ABSOLUTE; - else - throw lexical_error(format("Conversion of '%s' to RuntimePathMode", conv.get())); -}