if the action has completed successfully, 1 if an error was encountered and
-1 if it is still executing.
*/
- virtual int check()=0;
+ virtual int check() = 0;
protected:
/**
if(mode!=REBUILD && mode!=ALLDEPS)
{
// Skip trivial targets
- if(ObjectFile *obj=dynamic_cast<ObjectFile *>(&tgt))
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(&tgt))
return build_depend_table(obj->get_source(), depth);
- else if(Install *inst=dynamic_cast<Install *>(&tgt))
+ else if(Install *inst = dynamic_cast<Install *>(&tgt))
return build_depend_table(inst->get_source(), depth);
}
else if(mode==REBUILD && !tgt.get_rebuild())
string fn;
if(full_paths)
- fn=tgt.get_name();
+ fn = tgt.get_name();
else
- fn=FS::basename(tgt.get_name());
+ fn = FS::basename(tgt.get_name());
row.push_back(string(depth*2, ' ')+fn);
- const Package *pkg=tgt.get_package();
+ const Package *pkg = tgt.get_package();
if(pkg)
row.push_back(pkg->get_name());
else
if(!max_depth || depth<max_depth-1)
{
- const TargetList &depends=tgt.get_depends();
+ const TargetList &depends = tgt.get_depends();
//XXX If we want to sort the targets, we need to take the value of full_paths into account
//depends.sort(target_order);
for(TargetList::const_iterator i=depends.begin(); i!=depends.end(); ++i)
if(col_width.size()<i->size())
col_width.resize(i->size(), 0);
for(unsigned j=0; j<i->size(); ++j)
- col_width[j]=max(col_width[j], (*i)[j].size());
+ col_width[j] = max(col_width[j], (*i)[j].size());
}
for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
for(unsigned j=0; j<i->size(); ++j)
{
if(j>0)
- line+=" ";
- line+=lexical_cast((*i)[j], Fmt("%-s").width(col_width[j]));
+ line += " ";
+ line += lexical_cast((*i)[j], Fmt("%-s").width(col_width[j]));
}
IO::print("%s\n", line);
}
public:
Analyzer(Builder &);
- void set_mode(Mode m) { mode=m; }
- void set_max_depth(unsigned m) { max_depth=m; }
- void set_full_paths(bool f) { full_paths=f; }
+ void set_mode(Mode m) { mode = m; }
+ void set_max_depth(unsigned m) { max_depth = m; }
+ void set_full_paths(bool f) { full_paths = f; }
/**
Performs the analysis and prints out the resulting dependency tree.
void Architecture::set_tool(const string &t, const string &p)
{
- tools[t]=p;
+ tools[t] = p;
}
std::string Architecture::get_tool(const string &t) const
{
- StringMap::const_iterator i=tools.find(t);
+ StringMap::const_iterator i = tools.find(t);
if(i!=tools.end())
{
if(i->second[0]=='-')
if(!native)
{
- const Architecture &native_arch=builder.get_native_arch();
+ const Architecture &native_arch = builder.get_native_arch();
return prefix+"-"+native_arch.get_tool(t);
}
else
void Architecture::Loader::tool(const string &t, const string &p)
{
- arch.tools[t]=p;
+ arch.tools[t] = p;
}
StringMap tools;
public:
- Architecture(Builder &b, const std::string &n, bool a=false);
+ Architecture(Builder &b, const std::string &n, bool a = false);
void set_tool(const std::string &t, const std::string &p);
std::string get_tool(const std::string &t) const;
const std::string &get_name() const { return name; }
Archive::Archive(Builder &b, const StaticLibrary &lib):
ExternalAction(b)
{
- const Component &comp=lib.get_component();
+ const Component &comp = lib.get_component();
- work_dir=comp.get_package().get_source();
+ work_dir = comp.get_package().get_source();
- std::string tool="AR";
+ std::string tool = "AR";
argv.push_back(builder.get_current_arch().get_tool(tool));
argv.push_back("rc");
argv.push_back(relative(lib.get_path(), work_dir).str());
- const TargetList &deps=lib.get_depends();
+ const TargetList &deps = lib.get_depends();
for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
- if(ObjectFile *obj=dynamic_cast<ObjectFile *>(*i))
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
argv.push_back(relative(obj->get_path(), work_dir).str());
- FS::Path lpath=lib.get_path();
+ FS::Path lpath = lib.get_path();
if(!builder.get_dry_run())
{
FS::mkpath(FS::dirname(lpath), 0755);
FileTarget(b, &c.get_package(), generate_target_path(c)),
comp(c)
{
- buildable=true;
+ buildable = true;
for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
add_depend(*i);
}
void Binary::find_depends()
{
- LibMode libmode=comp.get_package().get_library_mode();
+ LibMode libmode = comp.get_package().get_library_mode();
if(dynamic_cast<SharedLibrary *>(this))
- libmode=DYNAMIC;
+ libmode = DYNAMIC;
list<const Component *> queue;
list<Target *> dep_libs;
queue.push_back(&comp);
while(!queue.empty())
{
- const Component *c=queue.front();
+ const Component *c = queue.front();
queue.erase(queue.begin());
- const StringList &libpath=c->get_build_info().libpath;
+ const StringList &libpath = c->get_build_info().libpath;
- const list<string> &libs=c->get_build_info().libs;
+ const list<string> &libs = c->get_build_info().libs;
for(StringList::const_iterator i=libs.begin(); i!=libs.end(); ++i)
{
- Target *lib=builder.get_library(*i, libpath, libmode);
+ Target *lib = builder.get_library(*i, libpath, libmode);
if(lib)
{
dep_libs.push_back(lib);
- if(Install *inst=dynamic_cast<Install *>(lib))
- lib=&inst->get_source();
- if(StaticLibrary *stlib=dynamic_cast<StaticLibrary *>(lib))
+ if(Install *inst = dynamic_cast<Install *>(lib))
+ lib = &inst->get_source();
+ if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
queue.push_back(&stlib->get_component());
}
else
This ensures that static library ordering is correct. */
for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
{
- bool last=true;
+ bool last = true;
for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
- last=(j==i || *j!=*i);
+ last = (j==i || *j!=*i);
if(last)
add_depend(*i);
}
- deps_ready=true;
+ deps_ready = true;
}
Action *Binary::create_action()
FS::Path Binary::generate_target_path(const Component &c)
{
- const SourcePackage &pkg=c.get_package();
+ const SourcePackage &pkg = c.get_package();
string prefix, suffix;
- const string &arch=pkg.get_builder().get_current_arch().get_name();
+ const string &arch = pkg.get_builder().get_current_arch().get_name();
if(c.get_type()==Component::LIBRARY)
{
- prefix="lib";
+ prefix = "lib";
if(arch=="win32")
- suffix=".dll";
+ suffix = ".dll";
else
- suffix=".so";
+ suffix = ".so";
}
else if(c.get_type()==Component::MODULE)
- suffix=".m";
+ suffix = ".m";
else if(c.get_type()==Component::PROGRAM)
{
if(arch=="win32")
- suffix=".exe";
+ suffix = ".exe";
}
return pkg.get_out_dir()/(prefix+c.get_name()+suffix);
Package(b, n),
need_path(false)
{
- use_pkgconfig=false;
+ use_pkgconfig = false;
}
void BinaryPackage::set_path(const FS::Path &p)
{
- path=builder.get_cwd()/p;
+ path = builder.get_cwd()/p;
}
void BinaryPackage::create_build_info()
{
for(StringList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
if((*i)[0]=='@')
- *i=(path/i->substr(1)).str();
+ *i = (path/i->substr(1)).str();
for(StringList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
if((*i)[0]=='@')
- *i=(path/i->substr(1)).str();
+ *i = (path/i->substr(1)).str();
}
BinaryPackage *BinaryPackage::from_pkgconfig(Builder &builder, const string &name)
{
- string info=builder.run_pkgconfig(name, "flags");
+ string info = builder.run_pkgconfig(name, "flags");
- BinaryPackage *pkg=new BinaryPackage(builder, name);
- pkg->use_pkgconfig=true;
- BuildInfo &binfo=pkg->export_binfo;
+ BinaryPackage *pkg = new BinaryPackage(builder, name);
+ pkg->use_pkgconfig = true;
+ BuildInfo &binfo = pkg->export_binfo;
- vector<string> flags=split(info);
+ vector<string> flags = split(info);
for(vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i)
{
if(!i->compare(0, 2, "-I"))
void update_hash(string &hash, const string &value)
{
for(unsigned i=0; i<value.size(); ++i)
- hash[i%hash.size()]^=value[i];
+ hash[i%hash.size()] ^= value[i];
}
}
{
string analyze_mode;
string work_dir;
- bool full_paths=false;
- unsigned max_depth=5;
+ bool full_paths = false;
+ unsigned max_depth = 5;
StringList cmdline_warn;
string prfx;
string arch;
getopt.add_option( "max-depth", max_depth, GetOpt::REQUIRED_ARG).set_help("Maximum depth to show in analysis.", "NUM");
getopt.add_option( "prefix", prfx, GetOpt::REQUIRED_ARG).set_help("Directory to install things to.", "DIR");
getopt.add_option( "warnings", cmdline_warn, GetOpt::REQUIRED_ARG).set_help("Compiler warnings to use.", "LIST");
- usagemsg=getopt.generate_usage(argv[0])+" [<target> ...]";
- helpmsg=getopt.generate_help();
+ usagemsg = getopt.generate_usage(argv[0])+" [<target> ...]";
+ helpmsg = getopt.generate_help();
getopt(argc, argv);
if(!analyze_mode.empty())
{
- analyzer=new Analyzer(*this);
+ analyzer = new Analyzer(*this);
if(analyze_mode=="deps")
analyzer->set_mode(Analyzer::DEPS);
analyzer->set_full_paths(full_paths);
}
else if(!clean && !create_makefile)
- build=true;
+ build = true;
- const vector<string> &args=getopt.get_args();
+ const vector<string> &args = getopt.get_args();
for(vector<string>::const_iterator i=args.begin(); i!=args.end(); ++i)
{
- string::size_type equal=i->find('=');
+ string::size_type equal = i->find('=');
if(equal!=string::npos)
cmdline_options.insert(StringMap::value_type(i->substr(0, equal), i->substr(equal+1)));
else
if(!work_dir.empty())
FS::chdir(work_dir);
- cwd=FS::getcwd();
+ cwd = FS::getcwd();
utsname un;
- string sysname="native";
+ string sysname = "native";
if(uname(&un)==0)
- sysname=tolower(un.sysname);
+ sysname = tolower(un.sysname);
- native_arch=&archs.insert(ArchMap::value_type(sysname, Architecture(*this, sysname, true))).first->second;
+ native_arch = &archs.insert(ArchMap::value_type(sysname, Architecture(*this, sysname, true))).first->second;
native_arch->set_tool("CC", "gcc");
native_arch->set_tool("CXX", "g++");
native_arch->set_tool("LD", "gcc");
load_build_file((FS::get_user_data_dir("builder")/"rc").str());
if(arch.empty())
- current_arch=native_arch;
+ current_arch = native_arch;
else
- current_arch=&get_architecture(arch);
+ current_arch = &get_architecture(arch);
if(prfx.empty())
{
if(current_arch->is_native())
- prefix=(FS::get_home_dir()/"local").str();
+ prefix = (FS::get_home_dir()/"local").str();
else
- prefix=(FS::get_home_dir()/"local"/current_arch->get_name()).str();
+ prefix = (FS::get_home_dir()/"local"/current_arch->get_name()).str();
}
else
- prefix=FS::getcwd()/prfx;
+ prefix = FS::getcwd()/prfx;
warnings.push_back("all");
warnings.push_back("extra");
warnings.push_back("error");
for(StringList::iterator i=cmdline_warn.begin(); i!=cmdline_warn.end(); ++i)
{
- vector<string> warns=split(*i, ',');
+ vector<string> warns = split(*i, ',');
warnings.insert(warnings.end(), warns.begin(), warns.end());
}
{
if(prefix.str()!="/usr")
{
- FS::Path pcdir=prefix/"lib"/"pkgconfig";
- if(const char *pcp=getenv("PKG_CONFIG_PATH"))
+ FS::Path pcdir = prefix/"lib"/"pkgconfig";
+ if(const char *pcp = getenv("PKG_CONFIG_PATH"))
{
- vector<string> path=split(pcp, ':');
- bool found=false;
+ vector<string> path = split(pcp, ':');
+ bool found = false;
for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
- found=(*i==pcdir.str());
+ found = (*i==pcdir.str());
if(!found)
{
path.push_back(pcdir.str());
if(!conf_only && create_targets())
return 1;
- PackageList all_reqs=main_pkg->collect_requires();
+ PackageList all_reqs = main_pkg->collect_requires();
if(conf_only)
return 0;
IO::print(" %s", (*i)->get_name());
if(dynamic_cast<SourcePackage *>(*i))
IO::print("*");
- unsigned count=0;
- unsigned to_be_built=0;
+ unsigned count = 0;
+ unsigned to_be_built = 0;
for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
if(j->second->get_package()==*i)
{
}
if(clean)
- exit_code=do_clean();
+ exit_code = do_clean();
else if(build)
- exit_code=do_build();
+ exit_code = do_build();
return exit_code;
}
IO::print("Running %s\n", join(argv.begin(), argv.end()));
int status;
- string res=run_command(argv, &status);
+ string res = run_command(argv, &status);
if(status)
throw Exception(format("pkg-config for package %s failed", pkg));
Package *Builder::get_package(const string &name)
{
- PackageMap::iterator i=packages.find(format("%s/%s", name, current_arch->get_name()));
+ PackageMap::iterator i = packages.find(format("%s/%s", name, current_arch->get_name()));
if(i==packages.end())
- i=packages.find(name);
+ i = packages.find(name);
if(i!=packages.end())
return i->second;
- FS::Path path=get_package_location(name);
+ FS::Path path = get_package_location(name);
if(!path.empty() && !load_build_file(path/"Build"))
{
- i=packages.find(name);
+ i = packages.find(name);
if(i!=packages.end())
return i->second;
}
- Package *pkg=0;
+ Package *pkg = 0;
try
{
// Package source not found - create a binary package
- pkg=BinaryPackage::from_pkgconfig(*this, name);
+ pkg = BinaryPackage::from_pkgconfig(*this, name);
}
catch(...)
{
Target *Builder::get_target(const string &n) const
{
// XXX Used for getting targets by path. get_target(const FS::Path &)?
- TargetMap::const_iterator i=targets.find(n);
+ TargetMap::const_iterator i = targets.find(n);
if(i!=targets.end())
return i->second;
return 0;
for(list<string>::const_iterator i=path.begin(); i!=path.end(); ++i)
update_hash(hash, *i);
- string id=hash+include;
- TargetMap::iterator i=includes.find(id);
+ string id = hash+include;
+ TargetMap::iterator i = includes.find(id);
if(i!=includes.end())
return i->second;
StringList argv;
argv.push_back(current_arch->get_tool("CXX"));
argv.push_back("--version");
- if(RegMatch m=Regex("[0-9]\\.[0-9.]+").match(run_command(argv)))
+ if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(run_command(argv)))
{
- cxx_ver=m[0].str;
+ cxx_ver = m[0].str;
while(!cxx_ver.empty() && !FS::is_dir(FS::Path("/usr/include/c++")/cxx_ver))
{
- string::size_type dot=cxx_ver.rfind('.');
+ string::size_type dot = cxx_ver.rfind('.');
if(dot==string::npos)
break;
cxx_ver.erase(dot);
IO::print("C++ version is %s\n", cxx_ver);
}
else
- cxx_ver="-";
+ cxx_ver = "-";
}
- string fn=include.substr(1);
+ string fn = include.substr(1);
if(verbose>=5)
IO::print("Looking for include %s from %s with path %s\n", fn, from, join(path.begin(), path.end()));
if(cxx_ver!="-")
syspath.push_back((FS::Path("/usr/include/c++/")/cxx_ver).str());
- Target *tgt=0;
+ Target *tgt = 0;
if(include[0]=='\"')
- tgt=get_header(FS::Path(from)/fn);
+ tgt = get_header(FS::Path(from)/fn);
for(list<string>::const_iterator j=path.begin(); (!tgt && j!=path.end()); ++j)
- tgt=get_header(cwd/ *j/fn);
+ tgt = get_header(cwd/ *j/fn);
for(list<string>::const_iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
- tgt=get_header(FS::Path(*j)/fn);
+ tgt = get_header(FS::Path(*j)/fn);
includes.insert(TargetMap::value_type(id, tgt));
for(list<string>::const_iterator i=path.begin(); i!=path.end(); ++i)
update_hash(hash, *i);
- string id=hash+string(1, mode)+lib;
- TargetMap::iterator i=libraries.find(id);
+ string id = hash+string(1, mode)+lib;
+ TargetMap::iterator i = libraries.find(id);
if(i!=libraries.end())
return i->second;
if(verbose>=5)
IO::print("Looking for library %s with path %s\n", lib, join(path.begin(), path.end()));
- Target *tgt=0;
+ Target *tgt = 0;
for(StringList::const_iterator j=path.begin(); (!tgt && j!=path.end()); ++j)
- tgt=get_library(lib, cwd/ *j, mode);
+ tgt = get_library(lib, cwd/ *j, mode);
for(StringList::iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
- tgt=get_library(lib, *j, mode);
+ tgt = get_library(lib, *j, mode);
libraries.insert(TargetMap::value_type(id, tgt));
const Architecture &Builder::get_architecture(const string &arch) const
{
- ArchMap::const_iterator i=archs.find(arch);
+ ArchMap::const_iterator i = archs.find(arch);
if(i==archs.end())
throw KeyError("Unknown architecture", arch);
void Builder::apply_profile_template(Config &config, const string &pt) const
{
- vector<string> parts=split(pt, '-');
+ vector<string> parts = split(pt, '-');
for(vector<string>::iterator i=parts.begin(); i!=parts.end(); ++i)
{
- ProfileTemplateMap::const_iterator j=profile_tmpl.find(*i);
+ ProfileTemplateMap::const_iterator j = profile_tmpl.find(*i);
if(j==profile_tmpl.end())
continue;
try
{
// Try to get source directory with pkgconfig
- string srcdir=strip(run_pkgconfig(name, "source"));
+ string srcdir = strip(run_pkgconfig(name, "source"));
if(!srcdir.empty())
return srcdir;
}
{
for(list<FS::Path>::const_iterator i=pkg_path.begin(); i!=pkg_path.end(); ++i)
{
- list<string> files=list_files(*i);
+ list<string> files = list_files(*i);
for(list<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
{
- FS::Path full=*i / *j;
+ FS::Path full = *i / *j;
if(FS::exists(full/"Build"))
pkg_dirs.push_back(full);
}
IO::print("%d packages found in path\n", pkg_dirs.size());
}
- bool msp=!name.compare(0, 3, "msp");
+ bool msp = !name.compare(0, 3, "msp");
for(list<FS::Path>::const_iterator i=pkg_dirs.begin(); i!=pkg_dirs.end(); ++i)
{
- string base=basename(*i);
- unsigned dash=base.rfind('-');
+ string base = basename(*i);
+ unsigned dash = base.rfind('-');
if(!base.compare(0, dash, name))
return *i;
int Builder::create_targets()
{
- Target *world=new VirtualTarget(*this, "world");
+ Target *world = new VirtualTarget(*this, "world");
- Target *def_tgt=new VirtualTarget(*this, "default");
+ Target *def_tgt = new VirtualTarget(*this, "default");
world->add_depend(def_tgt);
- Target *install=new VirtualTarget(*this, "install");
+ Target *install = new VirtualTarget(*this, "install");
world->add_depend(install);
- Target *tarballs=new VirtualTarget(*this, "tarballs");
+ Target *tarballs = new VirtualTarget(*this, "tarballs");
world->add_depend(tarballs);
- PackageList all_reqs=main_pkg->collect_requires();
+ PackageList all_reqs = main_pkg->collect_requires();
for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
{
- SourcePackage *spkg=dynamic_cast<SourcePackage *>(*i);
+ SourcePackage *spkg = dynamic_cast<SourcePackage *>(*i);
if(!spkg)
continue;
- const ComponentList &components=spkg->get_components();
+ const ComponentList &components = spkg->get_components();
for(ComponentList::const_iterator j=components.begin(); j!=components.end(); ++j)
j->create_targets();
if(spkg->get_install_flags()&(SourcePackage::LIB|SourcePackage::INCLUDE))
{
- PkgConfig *pc=new PkgConfig(*this, *spkg);
+ PkgConfig *pc = new PkgConfig(*this, *spkg);
install->add_depend(new Install(*this, *spkg, *pc));
}
}
// Find dependencies until no new targets are created
while(!new_tgts.empty())
{
- Target *tgt=new_tgts.front();
+ Target *tgt = new_tgts.front();
new_tgts.erase(new_tgts.begin());
tgt->find_depends();
if(!tgt->get_depends_ready())
// Apply what-ifs
for(StringList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
{
- Target *tgt=get_target((cwd/ *i).str());
+ Target *tgt = get_target((cwd/ *i).str());
if(!tgt)
{
IO::print(IO::cerr, "Unknown what-if target %s\n", *i);
}
// Make the cmdline target depend on all targets mentioned on the command line
- Target *cmdline=new VirtualTarget(*this, "cmdline");
- bool build_world=false;
+ Target *cmdline = new VirtualTarget(*this, "cmdline");
+ bool build_world = false;
for(list<string>::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i)
{
- Target *tgt=get_target(*i);
+ Target *tgt = get_target(*i);
if(!tgt)
- tgt=get_target((cwd/ *i).str());
+ tgt = get_target((cwd/ *i).str());
if(!tgt)
{
IO::print("I don't know anything about %s\n", *i);
return -1;
}
if(tgt==world)
- build_world=true;
+ build_world = true;
cmdline->add_depend(tgt);
}
cmdline->prepare();
for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
- if(SourcePackage *spkg=dynamic_cast<SourcePackage *>(i->second))
+ if(SourcePackage *spkg = dynamic_cast<SourcePackage *>(i->second))
spkg->get_deps_cache().save();
return 0;
Target *Builder::get_header(const FS::Path &fn)
{
- Target *tgt=get_target(fn.str());
+ Target *tgt = get_target(fn.str());
if(tgt) return tgt;
if(FS::is_reg(fn))
{
- tgt=new SystemHeader(*this, fn.str());
+ tgt = new SystemHeader(*this, fn.str());
return tgt;
}
return 0;
for(StringList::iterator i=candidates.begin(); i!=candidates.end(); ++i)
{
- string full=(path/ *i).str();
- Target *tgt=get_target(full);
+ string full = (path/ *i).str();
+ Target *tgt = get_target(full);
if(tgt)
{
- Target *real_tgt=tgt;
- if(Install *inst=dynamic_cast<Install *>(tgt))
- real_tgt=&inst->get_source();
+ Target *real_tgt = tgt;
+ if(Install *inst = dynamic_cast<Install *>(tgt))
+ real_tgt = &inst->get_source();
/* Ignore dynamic libraries from local packages unless library mode is
DYNAMIC */
}
else if(FS::is_reg(full))
{
- tgt=new SystemLibrary(*this, full);
+ tgt = new SystemLibrary(*this, full);
return tgt;
}
}
int Builder::do_build()
{
- Target *cmdline=get_target("cmdline");
+ Target *cmdline = get_target("cmdline");
- unsigned total=0;
+ unsigned total = 0;
for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
if(i->second->is_buildable() && i->second->get_rebuild())
++total;
vector<Action *> actions;
- unsigned count=0;
+ unsigned count = 0;
- bool fail=false;
- bool finish=false;
+ bool fail = false;
+ bool finish = false;
while(!finish)
{
if(actions.size()<jobs && !fail)
{
- Target *tgt=cmdline->get_buildable_target();
+ Target *tgt = cmdline->get_buildable_target();
if(tgt)
{
- Action *action=tgt->build();
+ Action *action = tgt->build();
if(action)
actions.push_back(action);
IO::print("%d of %d target%s built\033[1G", count, total, (total!=1 ? "s" : ""));
}
else if(actions.empty())
- finish=true;
+ finish = true;
}
else
Time::sleep(10*Time::msec);
for(unsigned i=0; i<actions.size();)
{
- int status=actions[i]->check();
+ int status = actions[i]->check();
if(status>=0)
{
++count;
delete actions[i];
actions.erase(actions.begin()+i);
if(status>0)
- fail=true;
+ fail = true;
if(actions.empty() && fail)
- finish=true;
+ finish = true;
}
else
++i;
while(!queue.empty())
{
- Target *tgt=queue.front();
+ Target *tgt = queue.front();
queue.erase(queue.begin());
if(tgt->is_buildable() && (tgt->get_package()==main_pkg || clean>=2))
clean_tgts.insert(tgt);
- const TargetList &deps=tgt->get_depends();
+ const TargetList &deps = tgt->get_depends();
for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
if(!clean_tgts.count(*i))
queue.push_back(*i);
}
for(set<Target *>::iterator i=clean_tgts.begin(); i!=clean_tgts.end(); ++i)
- if(FileTarget *ft=dynamic_cast<FileTarget *>(*i))
+ if(FileTarget *ft = dynamic_cast<FileTarget *>(*i))
{
- Action *action=new Unlink(*this, *ft);
+ Action *action = new Unlink(*this, *ft);
while(action->check()<0) ;
delete action;
}
void Builder::package_help()
{
- const Config &config=main_pkg->get_config();
- const Config::OptionMap &options=config.get_options();
+ const Config &config = main_pkg->get_config();
+ const Config::OptionMap &options = config.get_options();
IO::print("Required packages:\n ");
- const PackageList &requires=main_pkg->get_requires();
+ const PackageList &requires = main_pkg->get_requires();
for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i)
{
if(i!=requires.begin())
IO::print("\n\nPackage configuration:\n");
for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
{
- const Config::Option &opt=i->second;
+ const Config::Option &opt = i->second;
IO::print(" %s: %s (%s)", opt.name, opt.descr, opt.value);
if(opt.value!=opt.defv)
IO::print(" [%s]", opt.defv);
void Builder::Loader::binpkg(const string &n)
{
- BinaryPackage *pkg=new BinaryPackage(bld, n);
+ BinaryPackage *pkg = new BinaryPackage(bld, n);
load_sub(*pkg);
bld.packages.insert(PackageMap::value_type(n, pkg));
}
void Builder::Loader::package(const string &n)
{
- SourcePackage *pkg=new SourcePackage(bld, n, src);
+ SourcePackage *pkg = new SourcePackage(bld, n, src);
if(!bld.main_pkg)
- bld.main_pkg=pkg;
+ bld.main_pkg = pkg;
load_sub(*pkg);
bld.packages.insert(PackageMap::value_type(n, pkg));
for(StringList::iterator j=i; j!=l.end();)
{
if(j!=i && *j==*i)
- j=l.erase(j);
+ j = l.erase(j);
else
++j;
}
for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i)
{
- bool flag=i->compare(0, 3, "no-");
+ bool flag = i->compare(0, 3, "no-");
- string warn=(flag ? *i : i->substr(3));
- string no_warn="no-"+warn;
+ string warn = (flag ? *i : i->substr(3));
+ string no_warn = "no-"+warn;
for(StringList::iterator j=i; j!=warnings.end();)
{
if(j!=i && (*j==warn || *j==no_warn))
{
- flag=(*j==warn);
- j=warnings.erase(j);
+ flag = (*j==warn);
+ j = warnings.erase(j);
}
else
++j;
}
- *i=(flag ? warn : no_warn);
+ *i = (flag ? warn : no_warn);
}
}
Compile::Compile(Builder &b, const ObjectFile &obj):
ExternalAction(b)
{
- const Component &comp=obj.get_component();
+ const Component &comp = obj.get_component();
- work_dir=comp.get_package().get_source();
+ work_dir = comp.get_package().get_source();
- FS::Path spath=obj.get_source().get_path();
+ FS::Path spath = obj.get_source().get_path();
- string ext=FS::extpart(spath.str());
- const char *tool=0;
+ string ext = FS::extpart(spath.str());
+ const char *tool = 0;
if(ext==".cpp" || ext==".cc")
- tool="CXX";
+ tool = "CXX";
else
- tool="CC";
+ tool = "CC";
argv.push_back(builder.get_current_arch().get_tool(tool));
argv.push_back("-c");
- const BuildInfo &binfo=comp.get_build_info();
+ 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)
for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
argv.push_back("-D"+*i);
- FS::Path opath=obj.get_path();
+ FS::Path opath = obj.get_path();
argv.push_back("-o");
argv.push_back(relative(opath, work_dir).str());
argv.push_back(relative(spath, work_dir).str());
build_info.add((*i)->get_exported_binfo());
for(StringList::iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i)
- *i=(pkg.get_source() / *i).str();
+ *i = (pkg.get_source() / *i).str();
for(StringList::iterator i=build_info.libpath.begin(); i!=build_info.libpath.end(); ++i)
- *i=(pkg.get_source() / *i).str();
+ *i = (pkg.get_source() / *i).str();
if(pkg.get_library_mode()!=DYNAMIC)
{
// XXX This may pull in some unnecessary libpaths too. More thought required.
- PackageList reqs=pkg.collect_requires();
+ PackageList reqs = pkg.collect_requires();
for(PackageList::iterator i=reqs.begin(); i!=reqs.end(); ++i)
{
- const BuildInfo &ebi=(*i)->get_exported_binfo();
+ const BuildInfo &ebi = (*i)->get_exported_binfo();
build_info.libpath.insert(build_info.libpath.end(), ebi.libpath.begin(), ebi.libpath.end());
}
}
if(type==PROGRAM)
{
- string strip=pkg.get_config().get_option("strip").value;
+ string strip = pkg.get_config().get_option("strip").value;
if(lexical_cast<bool>(strip))
build_info.ldflags.push_back("-s");
}
}
else if(module_host)
{
- const PathList &host_src=module_host->get_sources();
+ const PathList &host_src = module_host->get_sources();
for(PathList::const_iterator i=host_src.begin(); i!=host_src.end(); ++i)
build_info.incpath.push_back(i->str());
}
void Component::create_targets() const
{
- Builder &builder=pkg.get_builder();
- Target *world=builder.get_target("world");
- Target *def_tgt=builder.get_target("default");
+ Builder &builder = pkg.get_builder();
+ Target *world = builder.get_target("world");
+ Target *def_tgt = builder.get_target("default");
- PathList files=collect_source_files();
+ PathList files = collect_source_files();
list<FileTarget *> inst_list;
string inst_loc;
if(type==TARBALL)
{
- string tarname=name;
+ string tarname = name;
if(name=="@src")
- tarname=pkg.get_name()+"-"+pkg.get_version();
- TarBall *result=new TarBall(builder, pkg, tarname);
+ tarname = pkg.get_name()+"-"+pkg.get_version();
+ TarBall *result = new TarBall(builder, pkg, tarname);
if(name=="@src")
{
- const TargetMap &targets=builder.get_targets();
+ const TargetMap &targets = builder.get_targets();
for(TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
if(i->second->get_package()==&pkg && !i->second->is_buildable())
result->add_depend(i->second);
for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
{
FileTarget *ft;
- if(Target *tgt=builder.get_target(i->str()))
- ft=dynamic_cast<FileTarget *>(tgt);
+ if(Target *tgt = builder.get_target(i->str()))
+ ft = dynamic_cast<FileTarget *>(tgt);
else
- ft=new File(builder, *i);
+ ft = new File(builder, *i);
result->add_depend(ft);
}
- Target *tarbls_tgt=builder.get_target("tarballs");
+ Target *tarbls_tgt = builder.get_target("tarballs");
tarbls_tgt->add_depend(result);
return;
}
else if(type==INSTALL)
{
- inst_loc=name;
+ inst_loc = name;
for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
{
FileTarget *ft;
- if(Target *tgt=builder.get_target(i->str()))
- ft=dynamic_cast<FileTarget *>(tgt);
+ if(Target *tgt = builder.get_target(i->str()))
+ ft = dynamic_cast<FileTarget *>(tgt);
else
- ft=new File(builder, pkg, *i);
+ ft = new File(builder, pkg, *i);
inst_list.push_back(ft);
}
}
else if(type==DATAFILE)
{
File *source;
- if(Target *tgt=builder.get_target(files.front().str()))
- source=dynamic_cast<File *>(tgt);
+ if(Target *tgt = builder.get_target(files.front().str()))
+ source = dynamic_cast<File *>(tgt);
else
- source=new File(builder, pkg, files.front());
- ::DataFile *result=new ::DataFile(builder, *this, *source);
+ source = new File(builder, pkg, files.front());
+ ::DataFile *result = new ::DataFile(builder, *this, *source);
if(&pkg==builder.get_main_package() && deflt)
def_tgt->add_depend(result);
{
for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
{
- string ext=FS::extpart(FS::basename(*i));
+ string ext = FS::extpart(FS::basename(*i));
if(ext==".h")
{
- FileTarget *hdr=dynamic_cast<FileTarget *>(builder.get_target(i->str()));
+ FileTarget *hdr = dynamic_cast<FileTarget *>(builder.get_target(i->str()));
if(!hdr)
- hdr=new Header(builder, *this, i->str());
+ hdr = new Header(builder, *this, i->str());
// Install headers if requested
if(type==HEADERS && install)
list<ObjectFile *> objs;
for(PathList::const_iterator i=files.begin(); i!=files.end(); ++i)
{
- string ext=FS::extpart(FS::basename(*i));
+ string ext = FS::extpart(FS::basename(*i));
if((ext==".cpp" || ext==".cc" || ext==".c"))
{
- SourceFile *src=new SourceFile(builder, *this, i->str());
- ObjectFile *obj=new ObjectFile(builder, *this, *src);
+ SourceFile *src = new SourceFile(builder, *this, i->str());
+ ObjectFile *obj = new ObjectFile(builder, *this, *src);
objs.push_back(obj);
}
}
}
}
- Target *inst_tgt=builder.get_target("install");
+ Target *inst_tgt = builder.get_target("install");
for(list<FileTarget *>::const_iterator i=inst_list.begin(); i!=inst_list.end(); ++i)
inst_tgt->add_depend(new Install(builder, pkg, **i, inst_loc));
}
{
if(FS::is_dir(*i))
{
- list<string> sfiles=list_files(*i);
+ list<string> sfiles = list_files(*i);
for(list<string>::iterator j=sfiles.begin(); j!=sfiles.end(); ++j)
files.push_back(*i / *j);
}
if(!inst_hdr.empty())
{
Component hdrcomp(comp.pkg, HEADERS, inst_hdr);
- hdrcomp.sources=comp.sources;
- hdrcomp.install=true;
+ hdrcomp.sources = comp.sources;
+ hdrcomp.install = true;
const_cast<ComponentList &>(comp.pkg.get_components()).push_back(hdrcomp);
}
}
void Component::Loader::require(const string &n)
{
- Package *req=comp.pkg.get_builder().get_package(n);
+ Package *req = comp.pkg.get_builder().get_package(n);
if(req)
comp.requires.push_back(req);
}
{
if(comp.type!=PROGRAM)
throw Exception("Only programs can be modular");
- comp.modular=true;
+ comp.modular = true;
}
void Component::Loader::host(const string &n)
{
- const ComponentList &comps=comp.pkg.get_components();
+ const ComponentList &comps = comp.pkg.get_components();
for(ComponentList::const_iterator i=comps.begin(); i!=comps.end(); ++i)
if(i->get_name()==n)
{
if(i->get_type()!=PROGRAM || !i->is_modular())
throw Exception("Module host must be a modular program");
- comp.module_host=&*i;
+ comp.module_host = &*i;
return;
}
IO::print("%s: Note: install_headers is deprecated\n", get_source());
if(comp.type==HEADERS)
{
- comp.name=p;
- comp.install=true;
+ comp.name = p;
+ comp.install = true;
}
else
- inst_hdr=p;
+ inst_hdr = p;
}
void Component::Loader::build_info()
Condition::Condition(SourcePackage &p, const string &expr):
pkg(p)
{
- vector<string> parts=split(expr);
+ vector<string> parts = split(expr);
for(vector<string>::iterator i=parts.begin(); i!=parts.end(); ++i)
{
if(*i=="and")
continue;
- string::size_type token=i->find_first_of("=!");
+ string::size_type token = i->find_first_of("=!");
if(token==string::npos)
expression.insert(StringMap::value_type(*i, "!0"));
else if(token==0 && (*i)[0]=='!')
bool Condition::eval()
{
- const Config &conf=pkg.get_config();
+ const Config &conf = pkg.get_config();
- bool result=true;
+ bool result = true;
for(StringMap::iterator i=expression.begin(); i!=expression.end(); ++i)
{
- bool neg=(i->second[0]=='!');
- unsigned start=1;
+ bool neg = (i->second[0]=='!');
+ unsigned start = 1;
if(i->second[1]=='=')
++start;
string value;
if(conf.is_option(i->first))
- value=conf.get_option(i->first).value;
+ value = conf.get_option(i->first).value;
else if(i->first=="arch")
- value=pkg.get_builder().get_current_arch().get_name();
+ value = pkg.get_builder().get_current_arch().get_name();
if((value==i->second.substr(start))==neg)
- result=false;
+ result = false;
}
return result;
const Config::Option &Config::get_option(const string &name) const
{
- OptionMap::const_iterator i=options.find(name);
+ OptionMap::const_iterator i = options.find(name);
if(i==options.end())
throw KeyError("Unknown option", name);
catch(const IO::FileNotFound &)
{ }
- freeze_mtime=true;
+ freeze_mtime = true;
package.get_builder().apply_profile_template(*this, get_option("profile").value);
- freeze_mtime=false;
+ freeze_mtime = false;
load();
}
IO::print(out, "%s\n", profile);
}
- freeze_mtime=true;
+ freeze_mtime = true;
package.get_builder().apply_profile_template(*this, profile);
- freeze_mtime=false;
+ freeze_mtime = false;
load();
}
bool Config::update(const StringMap &opts)
{
- bool changed=false;
+ bool changed = false;
for(StringMap::const_iterator i=opts.begin(); i!=opts.end(); ++i)
{
if(set_option(i->first, i->second) && i->first!="profile")
- changed=true;
+ changed = true;
}
if(changed && !freeze_mtime)
- mtime=Time::now();
+ mtime = Time::now();
return changed;
}
{
for(unsigned n=0; n<20; ++n)
{
- bool changed=false;
+ bool changed = false;
for(OptionMap::iterator i=options.begin(); i!=options.end(); ++i)
{
- Option &opt=i->second;
- string::size_type dollar=0;
- while((dollar=opt.value.find('$', dollar))!=string::npos)
+ Option &opt = i->second;
+ string::size_type dollar = 0;
+ while((dollar = opt.value.find('$', dollar))!=string::npos)
{
string::size_type end;
string var;
if(opt.value[dollar+1]=='{')
{
- end=opt.value.find('}', dollar+2);
+ end = opt.value.find('}', dollar+2);
if(end==string::npos)
throw Exception("Unterminated variable reference");
- var=opt.value.substr(dollar+2, end-dollar-2);
+ var = opt.value.substr(dollar+2, end-dollar-2);
++end;
}
else
{
for(end=dollar+1; (isalnum(opt.value[end]) && opt.value[end]!='_'); ++end) ;
- var=opt.value.substr(dollar+1, end-dollar-1);
+ var = opt.value.substr(dollar+1, end-dollar-1);
}
string value;
if(is_option(var))
- value=get_option(var).value;
+ value = get_option(var).value;
else if(var=="arch")
- value=package.get_builder().get_current_arch().get_name();
- else if(const char *ptr=getenv(var.c_str()))
- value=ptr;
+ value = package.get_builder().get_current_arch().get_name();
+ else if(const char *ptr = getenv(var.c_str()))
+ value = ptr;
opt.value.replace(dollar, end-dollar, value);
- dollar+=value.size();
- changed=true;
+ dollar += value.size();
+ changed = true;
}
}
void Config::save() const
{
- FS::Path fn=package.get_source()/".options";
+ FS::Path fn = package.get_source()/".options";
- OptionMap::const_iterator i=options.find("profile");
+ OptionMap::const_iterator i = options.find("profile");
if(i!=options.end())
- fn=package.get_source()/(".options."+i->second.value);
+ fn = package.get_source()/(".options."+i->second.value);
IO::BufferedFile out(fn.str(), IO::M_WRITE);
bool Config::set_option(const string &opt, const string &val)
{
- bool result=false;
+ bool result = false;
- OptionMap::iterator i=options.find(opt);
+ OptionMap::iterator i = options.find(opt);
if(i!=options.end())
{
if(i->second.value!=val)
- result=true;
- i->second.value=val;
+ result = true;
+ i->second.value = val;
}
return result;
void Config::load()
{
- FS::Path fn=package.get_source()/(".options."+get_option("profile").value);
+ FS::Path fn = package.get_source()/(".options."+get_option("profile").value);
try
{
IO::BufferedFile in(fn.str());
- mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
+ mtime = Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
DataFile::Parser parser(in, fn.str());
Loader loader(*this);
IO::print("%s -> %s\n", s, d);
if(!builder.get_dry_run())
- worker=new Worker(*this);
+ worker = new Worker(*this);
}
catch(const Exception &e)
{
IO::print(IO::cerr, "%s\n", e.what());
- done=error=true;
+ done = error = true;
return;
}
}
char buf[16384];
while(!in.eof())
{
- unsigned len=in.read(buf, sizeof(buf));
+ unsigned len = in.read(buf, sizeof(buf));
out.write(buf, len);
}
}
catch(const Exception &e)
{
IO::print(IO::cerr, "%s\n", e.what());
- done=error=true;
+ done = error = true;
return;
}
// Preserve file permissions
- struct stat st=FS::stat(copy.src);
+ struct stat st = FS::stat(copy.src);
chmod(copy.dest.str().c_str(), st.st_mode&0777);
- done=true;
+ done = true;
}
DataCompile::DataCompile(Builder &b, ::DataFile &dfile):
ExternalAction(b)
{
- const Component &comp=dfile.get_component();
+ const Component &comp = dfile.get_component();
- work_dir=comp.get_package().get_source();
+ work_dir = comp.get_package().get_source();
argv.push_back("mspdatatool");
argv.push_back("-c");
argv.push_back("-b");
- FS::Path opath=dfile.get_path();
+ FS::Path opath = dfile.get_path();
argv.push_back("-o");
argv.push_back(relative(opath, work_dir).str());
- FS::Path spath=dfile.get_source().get_path();
+ FS::Path spath = dfile.get_source().get_path();
argv.push_back(relative(spath, work_dir).str());
if(!builder.get_dry_run())
component(c),
source(s)
{
- buildable=true;
+ buildable = true;
add_depend(&source);
}
void DependencyCache::set_deps(const string &tgt, const StringList &d)
{
- deps[tgt]=d;
- changed=true;
+ deps[tgt] = d;
+ changed = true;
}
const StringList &DependencyCache::get_deps(const string &tgt) const
{
- DepsMap::const_iterator i=deps.find(tgt);
+ DepsMap::const_iterator i = deps.find(tgt);
if(i==deps.end())
throw KeyError("Unknown dependencies", tgt);
void DependencyCache::load()
{
- string fn=(package.get_source()/".deps").str();
+ string fn = (package.get_source()/".deps").str();
try
{
string line;
while(in.getline(line))
{
- vector<string> parts=split(line, '|');
- deps[parts[0]]=StringList(parts.begin()+1, parts.end());
+ vector<string> parts = split(line, '|');
+ deps[parts[0]] = StringList(parts.begin()+1, parts.end());
}
- mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
+ mtime = Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
}
catch(const IO::FileNotFound &)
{ }
IO::print("%s\n", join(argv.begin(), argv.end()));
if(builder.get_dry_run())
- pid=-1;
+ pid = -1;
else
{
- pid=fork();
+ pid = fork();
if(pid==0)
{
char *argv_[argv.size()+1];
- unsigned j=0;
+ unsigned j = 0;
for(StringList::iterator i=argv.begin(); i!=argv.end(); ++i)
- argv_[j++]=strdup(i->c_str());
- argv_[j]=0;
+ argv_[j++] = strdup(i->c_str());
+ argv_[j] = 0;
if(!work_dir.empty())
FS::chdir(work_dir);
exit(1);
}
else if(pid<0)
- pid=0;
+ pid = 0;
}
}
{
signal_done.emit();
if(WIFEXITED(status))
- exit_code=WEXITSTATUS(status);
+ exit_code = WEXITSTATUS(status);
else
- exit_code=254;
- pid=0;
+ exit_code = 254;
+ pid = 0;
return exit_code;
}
else
struct stat st;
if(!FS::stat(path, st))
{
- mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
- size=st.st_size;
+ mtime = Time::TimeStamp::from_unixtime(st.st_mtime);
+ size = st.st_size;
}
}
FileTarget(b, &p, generate_target_path(s, loc)),
source(s)
{
- buildable=true;
+ buildable = true;
add_depend(&source);
}
if(!tgt.get_package())
throw InvalidParameterValue("Can't install package-less targets");
- FS::Path base=tgt.get_package()->get_builder().get_prefix();
- string tgtname=FS::basename(tgt.get_path());
+ FS::Path base = tgt.get_package()->get_builder().get_prefix();
+ string tgtname = FS::basename(tgt.get_path());
string mid;
if(!loc.empty())
- mid=loc;
- else if(const Header *hdr=dynamic_cast<const Header *>(&tgt))
+ mid = loc;
+ else if(const Header *hdr = dynamic_cast<const Header *>(&tgt))
{
if(hdr->get_component()->get_type()!=Component::HEADERS)
throw Exception("Header install from non-header component?");
- mid="include/"+hdr->get_component()->get_name();
+ mid = "include/"+hdr->get_component()->get_name();
}
else if(dynamic_cast<const Executable *>(&tgt))
- mid="bin";
- else if(const SharedLibrary *shlib=dynamic_cast<const SharedLibrary *>(&tgt))
+ mid = "bin";
+ else if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&tgt))
{
- const Component &comp=shlib->get_component();
+ const Component &comp = shlib->get_component();
if(comp.get_type()==Component::LIBRARY)
- mid="lib";
+ mid = "lib";
else if(comp.get_type()==Component::MODULE)
- mid="lib/"+tgt.get_package()->get_name();
+ mid = "lib/"+tgt.get_package()->get_name();
}
else if(dynamic_cast<const StaticLibrary *>(&tgt))
- mid="lib";
+ mid = "lib";
else if(dynamic_cast<const PkgConfig *>(&tgt))
- mid="lib/pkgconfig";
+ mid = "lib/pkgconfig";
else if(dynamic_cast<const ::DataFile *>(&tgt))
- mid="share/"+tgt.get_package()->get_name();
+ mid = "share/"+tgt.get_package()->get_name();
if(mid.empty())
throw InvalidParameterValue("Don't know where to install "+tgtname);
Link::Link(Builder &b, const Binary &bin):
ExternalAction(b)
{
- const Component &comp=bin.get_component();
+ const Component &comp = bin.get_component();
- work_dir=comp.get_package().get_source();
+ work_dir = comp.get_package().get_source();
//XXX Determine whether to use g++ or gcc
- string tool="LXX";
+ string tool = "LXX";
argv.push_back(builder.get_current_arch().get_tool(tool));
if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
else if(comp.get_package().get_library_mode()==ALL_STATIC)
argv.push_back("-static");
- const BuildInfo &binfo=comp.get_build_info();
+ 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("-o");
argv.push_back(relative(bin.get_path(), work_dir).str());
- const TargetList &deps=bin.get_depends();
+ const TargetList &deps = bin.get_depends();
for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
{
- Target *tgt=*i;
- if(Install *inst=dynamic_cast<Install *>(tgt))
- tgt=&inst->get_source();
+ Target *tgt = *i;
+ if(Install *inst = dynamic_cast<Install *>(tgt))
+ tgt = &inst->get_source();
- if(ObjectFile *obj=dynamic_cast<ObjectFile *>(tgt))
+ if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
argv.push_back(relative(obj->get_path(), work_dir).str());
- else if(StaticLibrary *stlib=dynamic_cast<StaticLibrary *>(tgt))
+ else if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(tgt))
argv.push_back(stlib->get_path().str());
- else if(Library *lib=dynamic_cast<Library *>(tgt))
+ else if(Library *lib = dynamic_cast<Library *>(tgt))
argv.push_back("-l"+lib->get_libname());
}
- FS::Path binpath=bin.get_path();
+ FS::Path binpath = bin.get_path();
if(!builder.get_dry_run())
FS::mkpath(FS::dirname(binpath), 0755);
string result;
- pid_t pid=fork();
+ pid_t pid = fork();
if(pid==0)
{
char *argv_[argv.size()+1];
- unsigned j=0;
+ unsigned j = 0;
for(StringList::const_iterator i=argv.begin(); i!=argv.end(); ++i)
- argv_[j++]=strdup(i->c_str());
- argv_[j]=0;
+ argv_[j++] = strdup(i->c_str());
+ argv_[j] = 0;
close(pfd[0]);
dup2(pfd[1], 1);
close(pfd[1]);
- int devnull=open("/dev/null", O_WRONLY);
+ int devnull = open("/dev/null", O_WRONLY);
dup2(devnull, 2);
close(devnull);
while(1)
{
char buf[1024];
- int len=read(pfd[0], buf, sizeof(buf));
+ int len = read(pfd[0], buf, sizeof(buf));
if(len<=0)
{
int s;
if(status)
{
if(WIFEXITED(s))
- *status=WEXITSTATUS(s);
+ *status = WEXITSTATUS(s);
else
- *status=-1;
+ *status = -1;
}
break;
}
comp(c),
source(s)
{
- buildable=true;
+ buildable = true;
add_depend(&source);
}
{
for(TargetList::iterator i=new_deps.begin(); i!=new_deps.end();)
{
- Target *tgt=*i;
+ Target *tgt = *i;
if(tgt->get_depends_ready())
{
- i=new_deps.erase(i);
+ i = new_deps.erase(i);
find_depends(tgt);
}
else
++i;
}
- deps_ready=new_deps.empty();
+ deps_ready = new_deps.empty();
}
void ObjectFile::find_depends(Target *tgt)
{
- SourceFile *src=dynamic_cast<SourceFile *>(tgt);
- FileTarget *file=src;
+ SourceFile *src = dynamic_cast<SourceFile *>(tgt);
+ FileTarget *file = src;
if(!src)
{
- if(Install *inst=dynamic_cast<Install *>(tgt))
+ if(Install *inst = dynamic_cast<Install *>(tgt))
{
- file=inst;
- src=dynamic_cast<SourceFile *>(&inst->get_source());
+ file = inst;
+ src = dynamic_cast<SourceFile *>(&inst->get_source());
}
}
if(!src)
return;
- FS::Path spath=FS::dirname(file->get_path());
- const StringList &incpath=comp.get_build_info().incpath;
+ FS::Path spath = FS::dirname(file->get_path());
+ const StringList &incpath = comp.get_build_info().incpath;
- const list<string> &includes=src->get_includes();
+ const list<string> &includes = src->get_includes();
for(list<string>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
{
- Target *hdr2=builder.get_header(*i, spath, incpath);
+ Target *hdr2 = builder.get_header(*i, spath, incpath);
if(hdr2 && find(depends.begin(), depends.end(), hdr2)==depends.end())
add_depend(hdr2);
}
FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src)
{
- const SourcePackage &pkg=comp.get_package();
+ const SourcePackage &pkg = comp.get_package();
return pkg.get_temp_dir()/comp.get_name()/(FS::basepart(src)+".o");
}
result.push_back(this);
for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i)
{
- PackageList r=(*i)->collect_requires();
+ PackageList r = (*i)->collect_requires();
result.splice(result.end(), r);
}
create_build_info();
- conf_done=true;
+ conf_done = true;
}
void Package::Loader::require(const string &n)
{
- Package *req=pkg.builder.get_package(n);
+ Package *req = pkg.builder.get_package(n);
if(req)
pkg.requires.push_back(req);
}
PkgConfig::PkgConfig(Builder &b, const SourcePackage &p):
FileTarget(b, &p, p.get_source()/(p.get_name()+".pc"))
{
- buildable=true;
+ buildable = true;
}
Action *PkgConfig::create_action()
PkgConfigAction::PkgConfigAction(Builder &b, const PkgConfig &p):
Action(b)
{
- const SourcePackage &spkg=*static_cast<const SourcePackage *>(p.get_package());
+ const SourcePackage &spkg = *static_cast<const SourcePackage *>(p.get_package());
announce(spkg.get_name(), "PC", basename(p.get_path()));
IO::print(out, "Version: %s\n", spkg.get_version());
IO::print(out, "Requires:");
- const PackageList &reqs=spkg.get_requires();
+ const PackageList &reqs = spkg.get_requires();
for(PackageList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
if((*i)->get_use_pkgconfig())
IO::print(out, " %s", (*i)->get_name());
out.put('\n');
- const BuildInfo &binfo=spkg.get_exported_binfo();
+ const BuildInfo &binfo = spkg.get_exported_binfo();
IO::print(out, "Libs:");
for(StringList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
IO::print(out, " -L%s", *i);
{
if(!comp)
{
- deps_ready=true;
+ deps_ready = true;
return;
}
- const SourcePackage &spkg=comp->get_package();
- string relname=FS::relative(name, spkg.get_source()).str();
- DependencyCache &deps_cache=spkg.get_deps_cache();
- bool deps_found=false;
+ const SourcePackage &spkg = comp->get_package();
+ string relname = FS::relative(name, spkg.get_source()).str();
+ DependencyCache &deps_cache = spkg.get_deps_cache();
+ bool deps_found = false;
if(mtime<deps_cache.get_mtime())
{
try
{
- includes=deps_cache.get_deps(relname);
- deps_found=true;
+ includes = deps_cache.get_deps(relname);
+ deps_found = true;
}
catch(const KeyError &)
{ }
string line;
while(in.getline(line))
- if(RegMatch match=r_include.match(line))
+ if(RegMatch match = r_include.match(line))
includes.push_back(match[1].str);
deps_cache.set_deps(relname, includes);
}
}
- const StringList &incpath=comp->get_build_info().incpath;
+ const StringList &incpath = comp->get_build_info().incpath;
- FS::Path dir=FS::dirname(path);
+ FS::Path dir = FS::dirname(path);
for(list<string>::iterator i=includes.begin(); i!=includes.end(); ++i)
{
- Target *hdr=builder.get_header(*i, dir, incpath);
+ Target *hdr = builder.get_header(*i, dir, incpath);
if(hdr)
add_depend(hdr);
}
- deps_ready=true;
+ deps_ready = true;
}
FS::Path SourcePackage::get_out_dir() const
{
- const Architecture &arch=builder.get_current_arch();
+ const Architecture &arch = builder.get_current_arch();
if(arch.is_native())
return source/config.get_option("outdir").value;
else
unsigned SourcePackage::get_install_flags()
{
- unsigned flags=0;
+ unsigned flags = 0;
for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
if(i->get_install())
{
if(i->get_type()==Component::PROGRAM)
- flags|=BIN;
+ flags |= BIN;
else if(i->get_type()==Component::LIBRARY || i->get_type()==Component::MODULE)
- flags|=LIB;
+ flags |= LIB;
else if(i->get_type()==Component::HEADERS)
- flags|=INCLUDE;
+ flags |= INCLUDE;
}
return flags;
LibMode SourcePackage::get_library_mode() const
{
- const string &mode=config.get_option("staticlibs").value;
+ const string &mode = config.get_option("staticlibs").value;
if(mode=="all")
return ALL_STATIC;
else if(mode=="local")
{
init_config();
- StringMap::const_iterator prof=opts.find("profile");
+ StringMap::const_iterator prof = opts.find("profile");
if(prof!=opts.end() && flag)
config.select_profile(prof->second);
else
for(ConditionList::iterator i=conditions.begin(); i!=conditions.end(); ++i)
if(i->eval())
{
- const StringList &reqs=i->get_requires();
+ const StringList &reqs = i->get_requires();
for(StringList::const_iterator j=reqs.begin(); j!=reqs.end(); ++j)
- if(Package *pkg=builder.get_package(*j))
+ if(Package *pkg = builder.get_package(*j))
requires.push_back(pkg);
}
- base_reqs=requires;
+ base_reqs = requires;
for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
{
- const PackageList &reqs=i->get_requires();
+ const PackageList &reqs = i->get_requires();
requires.insert(requires.end(), reqs.begin(), reqs.end());
}
for(PackageList::iterator i=requires.begin(); i!=requires.end(); ++i)
{
- BinaryPackage *bpkg=dynamic_cast<BinaryPackage *>(*i);
+ BinaryPackage *bpkg = dynamic_cast<BinaryPackage *>(*i);
if(bpkg && bpkg->get_need_path())
bpkg->set_path(config.get_option(bpkg->get_name()+"_path").value);
}
for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i)
{
- BinaryPackage *bpkg=dynamic_cast<BinaryPackage *>(*i);
+ BinaryPackage *bpkg = dynamic_cast<BinaryPackage *>(*i);
if(bpkg && bpkg->get_need_path())
config.add_option(bpkg->get_name()+"_path", "/usr", "Path for "+bpkg->get_name());
}
{
for(PackageList::iterator i=base_reqs.begin(); i!=base_reqs.end(); ++i)
{
- const BuildInfo &ebi=(*i)->get_exported_binfo();
+ const BuildInfo &ebi = (*i)->get_exported_binfo();
build_info.add(ebi);
export_binfo.cflags.insert(export_binfo.cflags.end(), ebi.cflags.begin(), ebi.cflags.end());
}
// XXX Currently, a package-specific settings will override cmdline. This might or might not be desirable.
- const StringList &warnings=builder.get_warnings();
+ const StringList &warnings = builder.get_warnings();
build_info.warnings.insert(build_info.warnings.begin(), warnings.begin(), warnings.end());
- unsigned flags=get_install_flags();
+ unsigned flags = get_install_flags();
build_info.incpath.push_back((builder.get_prefix()/"include").str());
build_info.libpath.push_back((builder.get_prefix()/"lib").str());
if(flags&LIB)
export_binfo.libpath.push_back((builder.get_prefix()/"lib").str());
- string optimize=config.get_option("optimize").value;
+ string optimize = config.get_option("optimize").value;
if(lexical_cast<unsigned>(optimize))
{
build_info.cflags.push_back("-O"+optimize);
build_info.ldflags.push_back("-O"+optimize);
- string cpu=config.get_option("cpu").value;
+ string cpu = config.get_option("cpu").value;
if(cpu!="none")
build_info.cflags.push_back("-march="+cpu);
}
void SourcePackage::Loader::finish()
{
- SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
+ SourcePackage &spkg = static_cast<SourcePackage &>(pkg);
spkg.components.sort(component_sort);
}
void SourcePackage::Loader::condition(const string &c)
{
- SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
+ SourcePackage &spkg = static_cast<SourcePackage &>(pkg);
Condition cond(spkg, c);
load_sub(cond);
spkg.conditions.push_back(cond);
template<Component::Type t>
void SourcePackage::Loader::component(const string &n)
{
- SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
+ SourcePackage &spkg = static_cast<SourcePackage &>(pkg);
Component comp(spkg, t, n);
load_sub(comp);
spkg.components.push_back(comp);
void SourcePackage::Loader::tarball(const string &n)
{
- SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
+ SourcePackage &spkg = static_cast<SourcePackage &>(pkg);
if(n=="@src")
{
for(ComponentList::iterator i=spkg.components.begin(); i!=spkg.components.end(); ++i)
void SourcePackage::Loader::tar_file(const string &f)
{
IO::print("%s: Note: tar_file is deprecated\n", get_source());
- SourcePackage &spkg=static_cast<SourcePackage &>(pkg);
+ SourcePackage &spkg = static_cast<SourcePackage &>(pkg);
for(ComponentList::iterator i=spkg.components.begin(); i!=spkg.components.end(); ++i)
if(i->get_type()==Component::TARBALL && i->get_name()=="@src")
const_cast<PathList &>(i->get_sources()).push_back(spkg.source/f);
public:
enum InstallFlags
{
- INCLUDE=1,
- BIN=2,
- LIB=4,
- DATA=8
+ INCLUDE = 1,
+ BIN = 2,
+ LIB = 4,
+ DATA = 8
};
class Loader: public Package::Loader
Library(b, package, path, c.get_name()),
comp(c)
{
- buildable=true;
+ buildable = true;
for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
add_depend(*i);
}
string SystemLibrary::extract_libname(const FS::Path &p)
{
- string result=FS::basepart(FS::basename(p));
+ string result = FS::basepart(FS::basename(p));
if(!result.compare(0, 3, "lib"))
result.erase(0, 3);
return result;
InternalAction(b),
tarball(t)
{
- string basename=FS::basename(tarball.get_path());
+ string basename = FS::basename(tarball.get_path());
announce(tarball.get_package()->get_name(), "TAR ", basename);
if(builder.get_verbose()>=2)
IO::print("Create %s\n", basename);
if(!builder.get_dry_run())
- worker=new Worker(*this);
+ worker = new Worker(*this);
}
void Tar::Worker::main()
{
- const FS::Path &pkg_src=tar.tarball.get_package()->get_source();
- FS::Path basedir=FS::basepart(FS::basename(tar.tarball.get_path()));
+ const FS::Path &pkg_src = tar.tarball.get_package()->get_source();
+ FS::Path basedir = FS::basepart(FS::basename(tar.tarball.get_path()));
IO::File out(tar.tarball.get_path().str(), IO::M_WRITE);
- const TargetList &deps=tar.tarball.get_depends();
+ const TargetList &deps = tar.tarball.get_depends();
for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
{
- FileTarget *ft=dynamic_cast<FileTarget *>(*i);
+ FileTarget *ft = dynamic_cast<FileTarget *>(*i);
if(!ft)
continue;
char buf[4096];
memset(buf, 0, 512);
- string rel_path=(basedir/relative(ft->get_path(), pkg_src)).str();
+ string rel_path = (basedir/relative(ft->get_path(), pkg_src)).str();
if(rel_path.size()>99)
{
IO::print("Can't store %s in tar archive - too long name\n", rel_path);
- error=true;
+ error = true;
break;
}
memcpy(buf, rel_path.data(), rel_path.size());
- struct stat st=FS::stat(ft->get_path());
+ struct stat st = FS::stat(ft->get_path());
store_number(buf+100, st.st_mode, 7);
store_number(buf+108, st.st_uid, 7);
store_number(buf+116, st.st_gid, 7);
store_number(buf+124, st.st_size, 11);
store_number(buf+136, st.st_mtime, 11);
- buf[156]='0';
+ buf[156] = '0';
memset(buf+148, ' ', 8);
- unsigned chk=0;
+ unsigned chk = 0;
for(unsigned j=0; j<512; ++j)
- chk+=static_cast<unsigned char>(buf[j]);
+ chk += static_cast<unsigned char>(buf[j]);
store_number(buf+148, chk, 7);
- buf[155]=0;
+ buf[155] = 0;
out.write(buf, 512);
IO::File in(ft->get_path().str());
for(int j=0; j<st.st_size; j+=4096)
{
- unsigned len=in.read(buf, 4096);
- len+=((~len)+1)&0777;
+ unsigned len = in.read(buf, 4096);
+ len += ((~len)+1)&0777;
out.write(buf, len);
}
}
- done=true;
+ done = true;
}
void Tar::Worker::store_number(char *buf, unsigned value, unsigned length)
{
for(unsigned i=length; i--;)
{
- buf[i]='0'+value%8;
- value/=8;
+ buf[i] = '0'+value%8;
+ value /= 8;
}
}
TarBall::TarBall(Builder &b, const SourcePackage &p, const string &n):
FileTarget(b, &p, p.get_source()/(n+".tar"))
{
- buildable=true;
+ buildable = true;
}
const SourcePackage *TarBall::get_package() const
if(!rebuild)
return 0;
- bool self_ok=!building;
+ bool self_ok = !building;
for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
{
- Target *tgt=(*i)->get_buildable_target();
+ Target *tgt = (*i)->get_buildable_target();
if(tgt)
return tgt;
else if((*i)->get_rebuild())
- self_ok=false;
+ self_ok = false;
}
if(self_ok)
return;
}
- preparing=true;
+ preparing = true;
for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
(*i)->prepare();
check_rebuild();
- preparing=false;
- prepared=true;
+ preparing = false;
+ prepared = true;
}
Action *Target::build()
{
if(!buildable)
{
- rebuild=false;
+ rebuild = false;
return 0;
}
- if(FileTarget *ft=dynamic_cast<FileTarget *>(this))
+ if(FileTarget *ft = dynamic_cast<FileTarget *>(this))
if(!builder.get_dry_run() && FS::exists(ft->get_path()))
FS::unlink(ft->get_path());
- Action *action=create_action();
+ Action *action = create_action();
if(action)
{
action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
- building=true;
+ building = true;
}
return action;
void Target::touch()
{
- mtime=Time::now();
+ mtime = Time::now();
}
void Target::mark_rebuild(const std::string &reason)
{
- rebuild=true;
- rebuild_reason=reason;
+ rebuild = true;
+ rebuild_reason = reason;
}
void Target::check_rebuild()
}
}
- const SourcePackage *spkg=dynamic_cast<const SourcePackage *>(package);
+ const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
mark_rebuild("Package options changed");
}
void Target::build_done()
{
- building=false;
- rebuild=false;
+ building = false;
+ rebuild = false;
}
public:
virtual ~Target() { }
- virtual const char *get_type() const=0;
+ virtual const char *get_type() const = 0;
const std::string &get_name() const { return name; }
const Package *get_package() const { return package; }
const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
Finds dependencies for the target. When all dependencies have been found,
the function should set deps_ready to true.
*/
- virtual void find_depends() { deps_ready=true; }
+ virtual void find_depends() { deps_ready = true; }
/**
Prepares the target by recursively preparing dependencies, then checking
Unlink::Unlink(Builder &b, const FileTarget &t):
Action(b)
{
- const SourcePackage &spkg=*static_cast<const SourcePackage *>(t.get_package());
+ const SourcePackage &spkg = *static_cast<const SourcePackage *>(t.get_package());
announce(spkg.get_name(), "RM", relative(t.get_path(), spkg.get_source()).str());