Distributed under the LGPL
*/
-#include <fstream>
#include <iostream>
#include <set>
-#include <msp/core/error.h>
+#include <msp/core/except.h>
#include <msp/core/getopt.h>
#include <msp/datafile/parser.h>
+#include <msp/io/buffered.h>
+#include <msp/io/except.h>
+#include <msp/io/file.h>
#include <msp/path/utils.h>
#include <msp/strings/formatter.h>
+#include <msp/strings/regex.h>
#include <msp/strings/utils.h>
#include <msp/time/units.h>
#include <msp/time/utils.h>
is not found but a file exists, a new SystemHeader target will be created and
returned.
*/
-Target *Builder::get_header(const string &include, const string &, const string &from, const list<string> &path)
+Target *Builder::get_header(const string &include, const string &arch, const string &from, const list<string> &path)
{
string hash(8, 0);
update_hash(hash, from);
if(i!=includes.end())
return i->second;
- string fn=include.substr(1);
- Target *tgt=0;
- if(include[0]=='"' && (tgt=get_header(Path(from)/fn)))
- ;
- else if((tgt=get_header(Path("/usr/include")/fn)))
- ;
- //XXX Determine the C++ header location dynamically
- else if((tgt=get_header(Path("/usr/include/c++/4.1.2")/fn)))
- ;
- else
+ static string cxx_ver;
+ if(cxx_ver.empty())
{
- for(list<string>::const_iterator j=path.begin(); (j!=path.end() && !tgt); ++j)
- tgt=get_header(cwd/ *j/fn);
+ StringList argv;
+ argv.push_back(get_architecture(arch).get_tool("CXX"));
+ argv.push_back("--version");
+ cxx_ver=Regex("[0-9]\\.[0-9.]+").match(run_command(argv))[0].str;
+ while(!cxx_ver.empty() && !exists(Path("/usr/include/c++")/cxx_ver))
+ {
+ unsigned dot=cxx_ver.rfind('.');
+ if(dot==string::npos)
+ break;
+ cxx_ver.erase(dot);
+ }
+ if(verbose>=5)
+ cout<<"C++ version is "<<cxx_ver<<'\n';
}
+ string fn=include.substr(1);
+ if(verbose>=5)
+ cout<<"Looking for include "<<fn<<" with path "<<join(path.begin(), path.end())<<'\n';
+
+ StringList syspath;
+ if(arch=="native")
+ syspath.push_back("/usr/include");
+ else
+ syspath.push_back("/usr/"+get_architecture(arch).get_prefix()+"/include");
+ syspath.push_back((Path("/usr/include/c++/")/cxx_ver/fn).str());
+
+ Target *tgt=0;
+ if(include[0]=='\"')
+ tgt=get_header(Path(from)/fn);
+ for(list<string>::const_iterator j=path.begin(); (!tgt && j!=path.end()); ++j)
+ tgt=get_header(cwd/ *j/fn);
+ for(list<string>::const_iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
+ tgt=get_header(Path(*j)/fn);
+
includes.insert(TargetMap::value_type(id, tgt));
return tgt;
else
syspath.push_back("/usr/"+get_architecture(arch).get_prefix()+"/lib");
+ if(verbose>=5)
+ cout<<"Looking for library "<<lib<<" with path "<<join(path.begin(), path.end())<<'\n';
+
Target *tgt=0;
- for(StringList::iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
- tgt=get_library(lib, arch, *j, mode);
for(StringList::const_iterator j=path.begin(); (!tgt && j!=path.end()); ++j)
tgt=get_library(lib, arch, cwd/ *j, mode);
+ for(StringList::iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
+ tgt=get_library(lib, arch, *j, mode);
libraries.insert(TargetMap::value_type(id, tgt));
problem(spkg->get_name(), format("wrong architecture (%s)", spkg->get_arch()));
}
- if(!problems.empty())
- {
- cerr<<"The following problems were detected:\n";
- for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i)
- cerr<<" "<<i->package<<": "<<i->descr<<'\n';
- cerr<<"Please fix them and try again.\n";
- return 1;
- }
-
if(conf_only)
return 0;
if(analyzer)
analyzer->analyze();
+ if(!problems.empty())
+ {
+ cerr<<"The following problems were detected:\n";
+ for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i)
+ cerr<<" "<<i->package<<": "<<i->descr<<'\n';
+ cerr<<"Please fix them and try again.\n";
+ return 1;
+ }
+
//if(create_makefile
if(clean)
*/
int Builder::load_build_file(const Path &fn)
{
- ifstream in(fn.str().c_str());
- if(!in)
- return -1;
+ try
+ {
+ IO::File inf(fn.str());
+ IO::Buffered in(inf);
- if(verbose>=3)
- cout<<"Reading "<<fn<<'\n';
+ if(verbose>=3)
+ cout<<"Reading "<<fn<<'\n';
- DataFile::Parser parser(in, fn.str());
- Loader loader(*this, fn.subpath(0, fn.size()-1));
- loader.load(parser);
+ DataFile::Parser parser(in, fn.str());
+ Loader loader(*this, fn.subpath(0, fn.size()-1));
+ loader.load(parser);
+ }
+ catch(const IO::FileNotFound &)
+ {
+ return -1;
+ }
return 0;
}
if(mode!=ALL_STATIC)
{
if(arch=="win32")
+ {
candidates.push_back("lib"+lib+".dll");
+ candidates.push_back(lib+".dll");
+ }
else
candidates.push_back("lib"+lib+".so");
}