]> git.tdb.fi Git - builder.git/blob - source/buildinfo.cpp
Make warnings configurable through build_info and command line
[builder.git] / source / buildinfo.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <algorithm>
9 #include "buildinfo.h"
10
11 using namespace std;
12 using namespace Msp;
13
14 /**
15 Adds another BuildInfo to the end of this one.
16 */
17 void BuildInfo::add(const BuildInfo &bi)
18 {
19         cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end());
20         defines.insert(defines.end(), bi.defines.begin(), bi.defines.end());
21         incpath.insert(incpath.end(), bi.incpath.begin(), bi.incpath.end());
22         ldflags.insert(ldflags.end(), bi.ldflags.begin(), bi.ldflags.end());
23         libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end());
24         libs.insert(libs.end(), bi.libs.begin(), bi.libs.end());
25         warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end());
26 }
27
28 /**
29 Makes sure there are no duplicate entries in the lists.
30 */
31 void BuildInfo::unique()
32 {
33         unique(cflags);
34         unique(defines);
35         unique(incpath);
36         unique(ldflags);
37         unique(libpath);
38         unique(libs);
39
40         for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i)
41         {
42                 bool flag=i->compare(0, 3, "no-");
43
44                 string warn=(flag ? *i : i->substr(3));
45                 string no_warn="no-"+warn;
46
47                 for(StringList::iterator j=i; j!=warnings.end();)
48                 {
49                         if(j!=i && (*j==warn || *j==no_warn))
50                         {
51                                 flag=(*j==warn);
52                                 j=warnings.erase(j);
53                         }
54                         else
55                                 ++j;
56                 }
57
58                 *i=(flag ? warn : no_warn);
59         }
60 }
61
62 /**
63 Removes any duplicate entries from a list, leaving only the first one.  The
64 order of other elements is preserved.  O(n²) efficiency.
65 */
66 void BuildInfo::unique(StringList &l)
67 {
68         for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
69                 for(StringList::iterator j=i; j!=l.end();)
70                 {
71                         if(j!=i && *j==*i)
72                                 j=l.erase(j);
73                         else
74                                 ++j;
75                 }
76 }
77
78 BuildInfo::Loader::Loader(BuildInfo &bi):
79         binfo(bi)
80 {
81         add("cflag",   &Loader::cflag);
82         add("incpath", &Loader::incpath);
83         add("define",  &Loader::define);
84         add("ldflag",  &Loader::ldflag);
85         add("libpath", &Loader::libpath);
86         add("library", &Loader::library);
87         add("warning", &Loader::warning);
88 }
89
90