X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbuildinfo.cpp;h=ec8156798d70628d0597e6936ecd39622d9fff58;hb=50be4619cca4bb44e5abf8759720c255ef6d3b45;hp=5164ab08841c1ceed879f6fc5e4939770cd85cca;hpb=bdc8b6638b486aa668b4a9c6c5cce5f6b5f18222;p=builder.git diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index 5164ab0..ec81567 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -1,63 +1,121 @@ -/* $Id$ - -This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include "buildinfo.h" +using namespace std; using namespace Msp; -/** -Adds another BuildInfo to the end of this one. -*/ -void BuildInfo::add(const BuildInfo &bi) +namespace { + +/** Removes any duplicate entries from a list, leaving only the first one. The +order of other elements is preserved. O(n²) efficiency. */ +void unique(StringList &l) { - cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end()); - defines.insert(defines.end(), bi.defines.begin(), bi.defines.end()); + for(StringList::iterator i=l.begin(); i!=l.end(); ++i) + for(StringList::iterator j=i; j!=l.end();) + { + if(j!=i && *j==*i) + j = l.erase(j); + else + ++j; + } +} + +} + + +BuildInfo::BuildInfo(): + threads(false), + debug(false), + optimize(0), + strip(false) +{ } + +void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level) +{ + for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i) + defines[i->first] = i->second; incpath.insert(incpath.end(), bi.incpath.begin(), bi.incpath.end()); - ldflags.insert(ldflags.end(), bi.ldflags.begin(), bi.ldflags.end()); - libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end()); - libs.insert(libs.end(), bi.libs.begin(), bi.libs.end()); + if(level!=CHAINED) + { + libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end()); + libs.insert(libs.end(), bi.libs.begin(), bi.libs.end()); + } + warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end()); + threads = bi.threads; + if(level==LOCAL) + { + debug = bi.debug; + optimize = bi.optimize; + strip = bi.strip; + } + + unique(); } -/** -Makes sure there are no duplicate entries in the lists. -*/ void BuildInfo::unique() { - unique(cflags); - unique(defines); - unique(incpath); - unique(ldflags); - unique(libpath); - unique(libs); + ::unique(incpath); + ::unique(libpath); + ::unique(libs); + + for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i) + { + bool flag = i->compare(0, 3, "no-"); + + string warn = (flag ? *i : i->substr(3)); + string no_warn = "no-"+warn; + + for(StringList::iterator j=i; j!=warnings.end();) + { + if(j!=i && (*j==warn || *j==no_warn)) + { + flag = (*j==warn); + j = warnings.erase(j); + } + else + ++j; + } + + *i = (flag ? warn : no_warn); + } +} + + +BuildInfo::Loader::Loader(BuildInfo &bi): + DataFile::ObjectLoader(bi) +{ + add("debug", &BuildInfo::debug); + add("define", &Loader::define); + add("incpath", &Loader::incpath); + add("libpath", &Loader::libpath); + add("library", &Loader::library); + add("optimize", &BuildInfo::optimize); + add("strip", &BuildInfo::strip); + add("threads", &BuildInfo::threads); + add("warning", &Loader::warning); } -/** -Removes any duplicate entries from a list, leaving only the first one. The -order of other elements is preserved. O(n²) efficiency. -*/ -void BuildInfo::unique(StringList &l) +void BuildInfo::Loader::incpath(const std::string &s) { - StringList l2; - for(StringList::iterator i=l.begin(); i!=l.end(); ++i) - if(find(l2.begin(), l2.end(), *i)==l2.end()) - l2.push_back(*i); - swap(l, l2); + obj.incpath.push_back(s); } -BuildInfo::Loader::Loader(BuildInfo &bi): - binfo(bi) +void BuildInfo::Loader::define(const std::string &d, const std::string &v) { - add("cflag", &Loader::cflag); - add("incpath", &Loader::incpath); - add("define", &Loader::define); - add("ldflag", &Loader::ldflag); - add("libpath", &Loader::libpath); - add("library", &Loader::library); + obj.defines[d] = v; } +void BuildInfo::Loader::libpath(const std::string &s) +{ + obj.libpath.push_back(s); +} +void BuildInfo::Loader::library(const std::string &s) +{ + obj.libs.push_back(s); +} + +void BuildInfo::Loader::warning(const std::string &s) +{ + obj.warnings.push_back(s); +}