]> git.tdb.fi Git - builder.git/blob - source/buildinfo.cpp
Only use source files that are actually files
[builder.git] / source / buildinfo.cpp
1 #include <algorithm>
2 #include <set>
3 #include <msp/strings/format.h>
4 #include "buildinfo.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 namespace {
10
11 /** Removes any duplicate entries from a list, leaving only the first one.  The
12 order of other elements is preserved.  O(nlogn) efficiency. */
13 template<typename T>
14 void unique(list<T> &l)
15 {
16         set<T> seen;
17         for(typename list<T>::iterator i=l.begin(); i!=l.end(); )
18         {
19                 if(seen.count(*i))
20                         l.erase(i++);
21                 else
22                         seen.insert(*i++);
23         }
24 }
25
26 }
27
28
29 BuildInfo::BuildInfo():
30         libmode(DYNAMIC),
31         threads(false),
32         debug(false),
33         optimize(0),
34         strip(false),
35         warning_level(0),
36         fatal_warnings(false)
37 { }
38
39 BuildInfo::LibraryMode BuildInfo::get_libmode_for(const string &lib) const
40 {
41         LibModeMap::const_iterator i = libmodes.find(lib);
42         if(i!=libmodes.end())
43                 return i->second;
44         return libmode;
45 }
46
47 void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
48 {
49         for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i)
50                 defines[i->first] = i->second;
51         incpath.insert(incpath.begin(), bi.incpath.begin(), bi.incpath.end());
52         threads = bi.threads;
53         for(StandardMap::const_iterator i=bi.standards.begin(); i!=bi.standards.end(); ++i)
54                 standards[i->first] = i->second;
55
56         if(level!=CHAINED)
57         {
58                 libpath.insert(libpath.begin(), bi.libpath.begin(), bi.libpath.end());
59                 libs.insert(libs.begin(), bi.libs.begin(), bi.libs.end());
60         }
61
62         if(level==LOCAL)
63         {
64                 sysroot = bi.sysroot;
65                 local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end());
66                 libmode = bi.libmode;
67                 for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i)
68                         libmodes[i->first] = i->second;
69                 keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end());
70                 debug = bi.debug;
71                 optimize = bi.optimize;
72                 strip = bi.strip;
73                 warning_level = bi.warning_level;
74                 fatal_warnings = bi.fatal_warnings;
75         }
76
77         unique(incpath);
78         unique(local_incpath);
79         unique(libpath);
80         unique(libs);
81         unique(keep_symbols);
82 }
83
84
85 BuildInfo::Loader::Loader(BuildInfo &bi):
86         DataFile::ObjectLoader<BuildInfo>(bi)
87 {
88         add("debug",    &BuildInfo::debug);
89         add("define",   &Loader::define);
90         add("incpath",  &Loader::incpath);
91         add("keep_symbol", &Loader::keep_symbol);
92         add("libpath",  &Loader::libpath);
93         add("library",  &Loader::library);
94         add("libmode",  &BuildInfo::libmode);
95         add("libmode",  &Loader::libmode_for_lib);
96         add("local_incpath", &Loader::local_incpath);
97         add("optimize", &BuildInfo::optimize);
98         add("standard", &Loader::standard);
99         add("strip",    &BuildInfo::strip);
100         add("sysroot",  &Loader::sysroot);
101         add("threads",  &BuildInfo::threads);
102         add("warning_level", &BuildInfo::warning_level);
103         add("fatal_warnings", &BuildInfo::fatal_warnings);
104 }
105
106 void BuildInfo::Loader::incpath(const string &s)
107 {
108         obj.incpath.push_back(s);
109 }
110
111 void BuildInfo::Loader::define(const string &d, const string &v)
112 {
113         obj.defines[d] = v;
114 }
115
116 void BuildInfo::Loader::keep_symbol(const string &s)
117 {
118         obj.keep_symbols.push_back(s);
119 }
120
121 void BuildInfo::Loader::libmode_for_lib(const string &l, LibraryMode m)
122 {
123         obj.libmodes[l] = m;
124 }
125
126 void BuildInfo::Loader::libpath(const string &s)
127 {
128         obj.libpath.push_back(s);
129 }
130
131 void BuildInfo::Loader::library(const string &s)
132 {
133         obj.libs.push_back(s);
134 }
135
136 void BuildInfo::Loader::local_incpath(const string &s)
137 {
138         obj.local_incpath.push_back(s);
139 }
140
141 void BuildInfo::Loader::standard(DataFile::Symbol tag, const string &std)
142 {
143         obj.standards[tag.name] = std;
144 }
145
146 void BuildInfo::Loader::sysroot(const string &s)
147 {
148         obj.sysroot = s;
149 }
150
151
152 void operator>>(const LexicalConverter &conv, BuildInfo::LibraryMode &libmode)
153 {
154         if(conv.get()=="FORCE_STATIC")
155                 libmode = BuildInfo::FORCE_STATIC;
156         else if(conv.get()=="STATIC")
157                 libmode = BuildInfo::STATIC;
158         else if(conv.get()=="DYNAMIC")
159                 libmode = BuildInfo::DYNAMIC;
160         else if(conv.get()=="FORCE_DYNAMIC")
161                 libmode = BuildInfo::FORCE_DYNAMIC;
162         else
163                 throw lexical_error(format("Conversion of '%s' to LibraryMode", conv.get()));
164 }