Embedded SDKs commonly ship with a sysroot to use with their compilers.
It might also come useful for compiling things for different Linux
distributions.
threads = bi.threads;
if(level==LOCAL)
{
+ sysroot = bi.sysroot;
local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end());
libmode = bi.libmode;
for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i)
add("local_incpath", &Loader::local_incpath);
add("optimize", &BuildInfo::optimize);
add("strip", &BuildInfo::strip);
+ add("sysroot", &Loader::sysroot);
add("threads", &BuildInfo::threads);
add("warning_level", &BuildInfo::warning_level);
add("fatal_warnings", &BuildInfo::fatal_warnings);
obj.local_incpath.push_back(s);
}
+void BuildInfo::Loader::sysroot(const string &s)
+{
+ obj.sysroot = s;
+}
+
void operator>>(const LexicalConverter &conv, BuildInfo::LibraryMode &libmode)
{
void libpath(const std::string &);
void library(const std::string &);
void local_incpath(const std::string &);
+ void sysroot(const std::string &);
};
enum UpdateLevel
typedef std::list<std::string> WordList;
typedef std::map<std::string, LibraryMode> LibModeMap;
+ Tracked<Msp::FS::Path> sysroot;
DefineMap defines;
PathList incpath;
PathList local_incpath;
using namespace std;
using namespace Msp;
-GnuCCompiler::GnuCCompiler(Builder &b, const Architecture &a):
- GnuCompiler(b, a, "CC")
+GnuCCompiler::GnuCCompiler(Builder &b, const Architecture &a, const FS::Path &sysroot):
+ GnuCompiler(b, a, "CC", sysroot)
{
set_command("gcc", true);
input_suffixes.push_back(".c");
class GnuCCompiler: public GnuCompiler
{
public:
- GnuCCompiler(Builder &, const Architecture &);
+ GnuCCompiler(Builder &, const Architecture &, const Msp::FS::Path & = Msp::FS::Path());
virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
virtual Target *create_source(const Msp::FS::Path &) const;
using namespace std;
using namespace Msp;
-GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t):
+GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t, const FS::Path &sysroot):
Tool(b, a, t)
{
- if(architecture->is_native())
+ if(!sysroot.empty())
+ {
+ build_info.sysroot = sysroot;
+ system_path.push_back(sysroot/"usr/include");
+ }
+ else if(architecture->is_native())
system_path.push_back("/usr/include");
else
system_path.push_back("/usr/"+architecture->get_cross_prefix()+"/include");
if(binfo.fatal_warnings)
argv.push_back("-Werror");
}
+
+ const FS::Path &sysroot = binfo.sysroot;
+ if(!sysroot.empty())
+ argv.push_back("--sysroot="+sysroot.str());
for(BuildInfo::PathList::const_iterator i=binfo.local_incpath.begin(); i!=binfo.local_incpath.end(); ++i)
{
argv.push_back("-iquote");
}
for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
argv.push_back("-I"+i->str());
+
for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
{
if(i->second.empty())
else
argv.push_back(format("-D%s=%s", i->first, i->second));
}
+
if(binfo.debug)
argv.push_back("-ggdb");
if(binfo.optimize)
protected:
std::string version;
- GnuCompiler(Builder &, const Architecture &, const std::string &);
+ GnuCompiler(Builder &, const Architecture &, const std::string &, const Msp::FS::Path & = Msp::FS::Path());
public:
virtual Target *create_target(const std::list<Target *> &, const std::string &);
using namespace std;
using namespace Msp;
-GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a):
- GnuCompiler(b, a, "CXX")
+GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a, const FS::Path &sysroot):
+ GnuCompiler(b, a, "CXX", sysroot)
{
set_command("g++", true);
input_suffixes.push_back(".cpp");
class GnuCxxCompiler: public GnuCompiler
{
public:
- GnuCxxCompiler(Builder &, const Architecture &);
+ GnuCxxCompiler(Builder &, const Architecture &, const Msp::FS::Path & = Msp::FS::Path());
virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
virtual Target *create_source(const Msp::FS::Path &) const;
using namespace std;
using namespace Msp;
-GnuLinker::GnuLinker(Builder &b, const Architecture &a):
+GnuLinker::GnuLinker(Builder &b, const Architecture &a, const FS::Path &sysroot):
Tool(b, a, "LINK")
{
input_suffixes.push_back(".o");
input_suffixes.push_back(".a");
- if(architecture->is_native())
+ if(!sysroot.empty())
+ {
+ build_info.sysroot = sysroot;
+ system_path.push_back(sysroot/"usr"/"lib");
+ }
+ else if(architecture->is_native())
{
system_path.push_back("/lib");
system_path.push_back("/usr/lib");
BuildInfo binfo;
target.collect_build_info(binfo);
+
+ const FS::Path &sysroot = binfo.sysroot;
+ if(!sysroot.empty())
+ argv.push_back("--sysroot="+sysroot.str());
+
for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
argv.push_back("-L"+i->str());
if(binfo.strip)
Linker *cxx_linker;
public:
- GnuLinker(Builder &, const Architecture &);
+ GnuLinker(Builder &, const Architecture &, const Msp::FS::Path & = Msp::FS::Path());
~GnuLinker();
virtual Target *create_target(const std::list<Target *> &, const std::string &);
using namespace Msp;
-GnuObjCCompiler::GnuObjCCompiler(Builder &b, const Architecture &a):
- GnuCompiler(b, a, "OBJC")
+GnuObjCCompiler::GnuObjCCompiler(Builder &b, const Architecture &a, const FS::Path &sysroot):
+ GnuCompiler(b, a, "OBJC", sysroot)
{
set_command("gcc", true);
input_suffixes.push_back(".m");
class GnuObjCCompiler: public GnuCompiler
{
public:
- GnuObjCCompiler(Builder &, const Architecture &);
+ GnuObjCCompiler(Builder &, const Architecture &, const Msp::FS::Path & = Msp::FS::Path());
virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
virtual Target *create_source(const Msp::FS::Path &) const;