Makefile.cpp

Go to the documentation of this file.
00001 /*
00002 This file is part of hugin.
00003 
00004 hugin is free software: you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation, either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 hugin is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with hugin.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00025 #include "Makefile.h"
00026 #include "MakefileItem.h"
00027 
00028 namespace makefile
00029 {
00030 
00031 // intialize static singelton instance pointer
00032 Makefile* Makefile::instance = NULL;
00033 
00034 // static
00036 const std::locale Makefile::locale(std::locale("C"));
00037 
00038 const std::locale GetMakefileLocale()
00039 {
00040     return Makefile::locale;
00041 };
00042 
00043 Makefile& Makefile::getSingleton()
00044 {
00045         if(!instance)
00046                 instance = new Makefile();
00047         return *instance;
00048 }
00049 
00050 void Makefile::clean()
00051 {
00052         if(instance)
00053                 delete instance;
00054         instance = NULL;
00055 }
00056 
00057 void Makefile::remove(MakefileItem* item)
00058 {
00059         if(instance && !instance->written)
00060         {
00061                 std::cerr <<
00062                 "WARNING: A MakefileItem was removed before the Makefile::writeMakefile() was called.\n"
00063                 "This is likely to be a programming error (out of scope?)" << std::endl;
00064         }
00065         clean();
00066 }
00067 
00068 //#define WIN32
00093 string Makefile::quote(const string& in, Makefile::QuoteMode mode)
00094 {
00095         regex toescape;
00096         string output;
00097         switch(mode)
00098         {
00099         case Makefile::SHELL:
00100 #ifdef WIN32
00101                 toescape.assign(cstr("(\\$[^\\(])|(\\\\)|(\\#)"));
00102                 // uses a nice regex feature "recursive expressions" for doing it all in one (subexpression) cascade.
00103                 output.assign(cstr("(?1\\$$&)(?2/)(?3\\\\$&)"));
00104                 return string(cstr("\"") + boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all) + cstr("\""));
00105 #else
00106                 // because parenthesis are replaced too, the first pattern detects variable references and passes them unchanged.
00107                 toescape.assign(cstr("(\\$\\([^\\)]+\\))|(\\$)|([\\\\ \\~\"\\|\\'\\`\\{\\}\\[\\]\\(\\)\\*\\#\\:\\=\\&])"));
00108                 output.assign(cstr("(?1$&)(?2\\\\\\$$&)(?3\\\\$&)"));
00109                 return boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all);
00110 #endif
00111                 break;
00112         case Makefile::MAKE:
00113 #ifdef WIN32
00114                 toescape.assign(cstr("(\\$[^\\(])|(\\\\)|([ \\#\\=])"));
00115                 output.assign(cstr("(?1\\$$&)(?2/)(?3\\\\$&)"));
00116                 return boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all);
00117 #else
00118                 // do not replace $ if followed by a (. To allow variable references.
00119                 toescape.assign(cstr("(\\$[^\\(])|([ \\#\\:\\=])"));
00120                 output.assign(cstr("(?1\\$$&)(?2\\\\$&)"));
00121                 return boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all);
00122 #endif
00123                 break;
00124         default:
00125                 return string(in);
00126         }
00127 }
00128 
00129 #ifdef WIN32
00130 
00133 string Makefile::quoteEnvironment(const string& in)
00134 {
00135     regex toescape;
00136     string output;
00137     toescape.assign(cstr("(\\$)|(\\#)"));
00138     output.assign(cstr("(?1\\$$&)(?2\\\\$&)"));
00139     return boost::regex_replace(in, toescape, output, boost::match_default | boost::format_all);
00140 };
00141 #endif
00142 
00143 int Makefile::writeMakefile(ostream& out)
00144 {
00145         for(std::vector<MakefileItem*>::iterator i = items.begin(); i != items.end(); i++)
00146         {
00147                 out << **i;
00148         }
00149         written = true;
00150         return items.size();
00151 }
00152 
00153 }

Generated on Sun Apr 20 01:25:40 2014 for Hugintrunk by  doxygen 1.3.9.1