2
This file is part of hugin.
4
hugin is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 2 of the License, or
7
(at your option) any later version.
9
hugin is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with hugin. If not, see <http://www.gnu.org/licenses/>.
21
* Created on: May 25, 2010
22
* @author Florian Achleitner <florian.achleitner.2.6.31@gmail.com>
26
#include "MakefileItem.h"
31
// intialize static singelton instance pointer
32
Makefile* Makefile::instance = NULL;
35
/// Used for numeric output to get a decimal dot anyways.
36
const std::locale Makefile::locale(std::locale("C"));
38
const std::locale GetMakefileLocale()
40
return Makefile::locale;
43
Makefile& Makefile::getSingleton()
46
instance = new Makefile();
50
void Makefile::clean()
57
void Makefile::remove(MakefileItem* item)
59
if(instance && !instance->written)
62
"WARNING: A MakefileItem was removed before the Makefile::writeMakefile() was called.\n"
63
"This is likely to be a programming error (out of scope?)" << std::endl;
70
* Quotes and escapes characters using regular expressions. Two modes are currently distinguished,
71
* depending on the usage of the string.
72
* The regular expressions need a lot of backslash escaping, eg. \\\\ means backslash. We need to get
73
* through the compiler and the boost::regex library with the special characters
75
* The replacements in detail:
77
* - WIN32: $ --> $$, \ --> /, # --> \#, and surround with quotes
78
* - others: $ --> \$$, [\ ~"|'`{}[]()*#:=] --> escape with backslash
80
* - WIN32: $ --> $$, [ #=] --> escape with backslash
81
* - others: $ --> $$, [ #:=] --> escape with backslash
83
* All replacements take care of variable references and do not replace $(varname) patterns.
85
* @note src/hugin_base/hugin_utils/platform.h is where the information is from.
86
* Unfortunately there are lots of comments in that code, which say that the correctness
87
* of the escaping rules is rather unsure.
89
* @param in Input string.
91
* @return A new string containing the processed content.
93
string Makefile::quote(const string& in, Makefile::QuoteMode mode)
101
toescape.assign(cstr("(\\$[^\\(])|(\\\\)|(\\#)"));
102
// uses a nice regex feature "recursive expressions" for doing it all in one (subexpression) cascade.
103
output.assign(cstr("(?1\\$$&)(?2/)(?3\\\\$&)"));
104
return string(cstr("\"") + boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all) + cstr("\""));
106
// because parenthesis are replaced too, the first pattern detects variable references and passes them unchanged.
107
toescape.assign(cstr("(\\$\\([^\\)]+\\))|(\\$)|([\\\\ \\~\"\\|\\'\\`\\{\\}\\[\\]\\(\\)\\*\\#\\:\\=])"));
108
output.assign(cstr("(?1$&)(?2\\\\\\$$&)(?3\\\\$&)"));
109
return boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all);
114
toescape.assign(cstr("(\\$[^\\(])|(\\\\)|([ \\#\\=])"));
115
output.assign(cstr("(?1\\$$&)(?2/)(?3\\\\$&)"));
116
return boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all);
118
// do not replace $ if followed by a (. To allow variable references.
119
toescape.assign(cstr("(\\$[^\\(])|([ \\#\\:\\=])"));
120
output.assign(cstr("(?1\\$$&)(?2\\\\$&)"));
121
return boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all);
129
int Makefile::writeMakefile(ostream& out)
131
for(std::vector<MakefileItem*>::iterator i = items.begin(); i != items.end(); i++)