if(!i->compare(0, 2, "-I"))
binfo.incpath.push_back(i->substr(2));
else if(!i->compare(0, 2, "-D"))
- binfo.defines.push_back(i->substr(2));
+ {
+ string::size_type equals = i->find('=');
+ if(equals!=string::npos)
+ binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1);
+ else
+ binfo.defines[i->substr(2)] = string();
+ }
else if(!i->compare(0, 2, "-L"))
binfo.libpath.push_back(i->substr(2));
else if(!i->compare(0, 2, "-l"))
binfo.libs.push_back(i->substr(2));
+ else if(*i=="-pthread")
+ binfo.threads = true;
}
return pkg;
}
+BuildInfo::BuildInfo():
+ threads(false),
+ debug(false),
+ optimize(0),
+ strip(false)
+{ }
+
void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
{
- cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end());
- defines.insert(defines.end(), bi.defines.begin(), bi.defines.end());
+ for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i)
+ defines[i->first] = i->second;
incpath.insert(incpath.end(), bi.incpath.begin(), bi.incpath.end());
if(level!=CHAINED)
{
- ldflags.insert(ldflags.end(), bi.ldflags.begin(), bi.ldflags.end());
libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end());
libs.insert(libs.end(), bi.libs.begin(), bi.libs.end());
}
warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end());
+ threads = bi.threads;
+ if(level==LOCAL)
+ {
+ debug = bi.debug;
+ optimize = bi.optimize;
+ strip = bi.strip;
+ }
}
void BuildInfo::unique()
{
- ::unique(cflags);
- ::unique(defines);
::unique(incpath);
- ::unique(ldflags);
::unique(libpath);
::unique(libs);
BuildInfo::Loader::Loader(BuildInfo &bi):
DataFile::ObjectLoader<BuildInfo>(bi)
{
- add("cflag", &Loader::cflag);
- add("incpath", &Loader::incpath);
- add("define", &Loader::define);
- add("ldflag", &Loader::ldflag);
- add("libpath", &Loader::libpath);
- add("library", &Loader::library);
- add("warning", &Loader::warning);
-}
-
-void BuildInfo::Loader::cflag(const std::string &s)
-{
- obj.cflags.push_back(s);
+ add("debug", &BuildInfo::debug);
+ add("define", &Loader::define);
+ add("incpath", &Loader::incpath);
+ add("libpath", &Loader::libpath);
+ add("library", &Loader::library);
+ add("optimize", &BuildInfo::optimize);
+ add("strip", &BuildInfo::strip);
+ add("threads", &BuildInfo::threads);
+ add("warning", &Loader::warning);
}
void BuildInfo::Loader::incpath(const std::string &s)
obj.incpath.push_back(s);
}
-void BuildInfo::Loader::define(const std::string &s)
-{
- obj.defines.push_back(s);
-}
-
-void BuildInfo::Loader::ldflag(const std::string &s)
+void BuildInfo::Loader::define(const std::string &d, const std::string &v)
{
- obj.ldflags.push_back(s);
+ obj.defines[d] = v;
}
void BuildInfo::Loader::libpath(const std::string &s)
public:
Loader(BuildInfo &);
private:
- void cflag(const std::string &);
void incpath(const std::string &);
- void define(const std::string &);
- void ldflag(const std::string &);
+ void define(const std::string &, const std::string &);
void libpath(const std::string &);
void library(const std::string &);
void warning(const std::string &);
CHAINED
};
- StringList cflags;
- StringList defines;
+ typedef std::map<std::string, std::string> DefineMap;
+
+ DefineMap defines;
StringList incpath;
- StringList ldflags;
StringList libpath;
StringList libs;
StringList warnings;
+ bool threads;
+ bool debug;
+ int optimize;
+ bool strip;
+
+ BuildInfo();
/** Adds another BuildInfo to the end of this one. */
void update_from(const BuildInfo &, UpdateLevel = LOCAL);
}
if(type==PROGRAM)
- {
- string strip = pkg.get_config().get_option("strip").value;
- if(lexical_cast<bool>(strip))
- build_info.ldflags.push_back("-s");
- }
- else if(type==LIBRARY)
- {
- build_info.cflags.push_back("-fPIC");
- }
+ build_info.strip = lexical_cast<bool>(pkg.get_config().get_option("strip").value);
build_info.unique();
}
const BuildInfo &binfo = comp.get_build_info();
for(list<string>::const_iterator i=binfo.warnings.begin(); i!=binfo.warnings.end(); ++i)
argv.push_back("-W"+*i);
- for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
- argv.push_back(*i);
for(list<string>::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
argv.push_back("-I"+*i);
- for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
- argv.push_back("-D"+*i);
+ for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
+ {
+ if(i->second.empty())
+ argv.push_back(format("-D%s", i->first));
+ else
+ argv.push_back(format("-D%s=%s", i->first, i->second));
+ }
+ if(binfo.debug)
+ argv.push_back("-ggdb");
+ if(binfo.optimize)
+ {
+ if(binfo.optimize<0)
+ argv.push_back("-Os");
+ else
+ argv.push_back(format("-O%d", binfo.optimize));
+ }
+ if(binfo.threads)
+ argv.push_back("-pthread");
+ if(comp.get_type()==Component::LIBRARY)
+ argv.push_back("-fPIC");
const Architecture &arch = builder.get_current_arch();
const Architecture &native_arch = builder.get_native_arch();
if(shlib)
{
argv.push_back("-shared");
+ argv.push_back("-fPIC");
if(!shlib->get_soname().empty())
argv.push_back("-Wl,-soname,"+shlib->get_soname());
}
argv.push_back("-static");
const BuildInfo &binfo = comp.get_build_info();
- for(list<string>::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
- argv.push_back(*i);
for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
argv.push_back("-L"+*i);
+ if(binfo.strip)
+ argv.push_back("-s");
+ if(binfo.threads)
+ argv.push_back("-pthread");
const Architecture &arch = builder.get_current_arch();
const Architecture &native_arch = builder.get_native_arch();
IO::print(out, " -L%s", FS::relative(*i, builder.get_prefix()).str());
for(StringList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
IO::print(out, " -l%s", *i);
- for(StringList::const_iterator i=binfo.ldflags.begin(); i!=binfo.ldflags.end(); ++i)
- IO::print(out, " %s", *i);
+ if(binfo.threads)
+ out.write("-pthread");
out.put('\n');
IO::print(out, "Cflags:");
for(StringList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
IO::print(out, " -I%s", FS::relative(*i, builder.get_prefix()).str());
- for(StringList::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
- IO::print(out, " -D%s", *i);
- for(StringList::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
- IO::print(out, " %s", *i);
+ for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
+ if(i->second.empty())
+ IO::print(out, " -D%s", i->first);
+ else
+ IO::print(out, " -D%s=%s", i->first, i->second);
out.put('\n');
}
string optimize = config.get_option("optimize").value;
if(!optimize.empty() && optimize!="0")
{
- build_info.cflags.push_back("-O"+optimize);
- build_info.ldflags.push_back("-O"+optimize);
+ if(optimize=="s" || optimize=="size")
+ build_info.optimize = -1;
+ else
+ build_info.optimize = lexical_cast<unsigned>(optimize);
}
if(lexical_cast<bool>(config.get_option("debug").value))
{
- build_info.cflags.push_back("-ggdb");
- build_info.defines.push_back("DEBUG");
+ build_info.debug = true;
+ build_info.defines["DEBUG"] = "1";
}
for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
if(lexical_cast<bool>(config.get_option("with_"+i->name).value))
- build_info.cflags.push_back("-DWITH_"+toupper(i->name));
+ build_info.defines["WITH_"+toupper(i->name)] = "1";
for(ConditionList::iterator i=conditions.begin(); i!=conditions.end(); ++i)
if(i->eval())