]> git.tdb.fi Git - builder.git/blob - source/buildinfo.cpp
Rewrite BuildInfo to be compiler-agnostic
[builder.git] / source / buildinfo.cpp
1 #include <algorithm>
2 #include "buildinfo.h"
3
4 using namespace std;
5 using namespace Msp;
6
7 namespace {
8
9 /** Removes any duplicate entries from a list, leaving only the first one.  The
10 order of other elements is preserved.  O(n²) efficiency. */
11 void unique(StringList &l)
12 {
13         for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
14                 for(StringList::iterator j=i; j!=l.end();)
15                 {
16                         if(j!=i && *j==*i)
17                                 j = l.erase(j);
18                         else
19                                 ++j;
20                 }
21 }
22
23 }
24
25
26 BuildInfo::BuildInfo():
27         threads(false),
28         debug(false),
29         optimize(0),
30         strip(false)
31 { }
32
33 void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
34 {
35         for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i)
36                 defines[i->first] = i->second;
37         incpath.insert(incpath.end(), bi.incpath.begin(), bi.incpath.end());
38         if(level!=CHAINED)
39         {
40                 libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end());
41                 libs.insert(libs.end(), bi.libs.begin(), bi.libs.end());
42         }
43         warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end());
44         threads = bi.threads;
45         if(level==LOCAL)
46         {
47                 debug = bi.debug;
48                 optimize = bi.optimize;
49                 strip = bi.strip;
50         }
51 }
52
53 void BuildInfo::unique()
54 {
55         ::unique(incpath);
56         ::unique(libpath);
57         ::unique(libs);
58
59         for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i)
60         {
61                 bool flag = i->compare(0, 3, "no-");
62
63                 string warn = (flag ? *i : i->substr(3));
64                 string no_warn = "no-"+warn;
65
66                 for(StringList::iterator j=i; j!=warnings.end();)
67                 {
68                         if(j!=i && (*j==warn || *j==no_warn))
69                         {
70                                 flag = (*j==warn);
71                                 j = warnings.erase(j);
72                         }
73                         else
74                                 ++j;
75                 }
76
77                 *i = (flag ? warn : no_warn);
78         }
79 }
80
81
82 BuildInfo::Loader::Loader(BuildInfo &bi):
83         DataFile::ObjectLoader<BuildInfo>(bi)
84 {
85         add("debug",    &BuildInfo::debug);
86         add("define",   &Loader::define);
87         add("incpath",  &Loader::incpath);
88         add("libpath",  &Loader::libpath);
89         add("library",  &Loader::library);
90         add("optimize", &BuildInfo::optimize);
91         add("strip",    &BuildInfo::strip);
92         add("threads",  &BuildInfo::threads);
93         add("warning",  &Loader::warning);
94 }
95
96 void BuildInfo::Loader::incpath(const std::string &s)
97 {
98         obj.incpath.push_back(s);
99 }
100
101 void BuildInfo::Loader::define(const std::string &d, const std::string &v)
102 {
103         obj.defines[d] = v;
104 }
105
106 void BuildInfo::Loader::libpath(const std::string &s)
107 {
108         obj.libpath.push_back(s);
109 }
110
111 void BuildInfo::Loader::library(const std::string &s)
112 {
113         obj.libs.push_back(s);
114 }
115
116 void BuildInfo::Loader::warning(const std::string &s)
117 {
118         obj.warnings.push_back(s);
119 }