/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
using namespace std;
-/**
-Annouces the action by printing out the package name, tool and target name.
-*/
void Action::announce(const string &pkg, const string &tool, const string &tgt)
{
ostringstream line;
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/// Emitted when the action has finished
sigc::signal<void> signal_done;
- /**
- Checks whether the action is done and emits signal_done if it is.
+protected:
+ Builder &builder;
+
+ Action(Builder &b): builder(b) { }
+public:
+ virtual ~Action() { }
- @return 0 on successful completion, 1 on error, -1 if the action is still
- executing
+ /**
+ Checks whether the action is done and emits signal_done if it is. Returns 0
+ if the action has completed successfully, 1 if an error was encountered and
+ -1 if it is still executing.
*/
virtual int check()=0;
- virtual ~Action() { }
protected:
- Builder &builder;
-
- Action(Builder &b): builder(b) { }
+ /**
+ Annouces the action by printing out the package name, tool and target name.
+ */
void announce(const std::string &, const std::string &, const std::string &);
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
full_paths(false)
{ }
-/**
-Performs the analysis and prints out the resulting dependency tree.
-*/
void Analyzer::analyze()
{
TableRow row;
print_table();
}
-/**
-Adds rows to the table for the given target and it' dependencies.
-
-@param tgt Target to be processed
-@param depth Recursion level of the target (top level is 0)
-*/
void Analyzer::build_depend_table(Target &tgt, unsigned depth)
{
if(mode!=REBUILD && mode!=ALLDEPS)
}
else if(mode==REBUILD && !tgt.get_rebuild())
/* All targets that depend on to-be-built targets will be rebuilt
- themselves, so we cn stop here. */
+ themselves, so we cn stop here. */
return;
TableRow row;
}
}
-/**
-Prints out the table that resulted from the analysis.
-*/
void Analyzer::print_table() const
{
vector<unsigned> col_width;
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
public:
enum Mode
{
- DEPS, /// Skip over "trivial" targets such as Install and Compile
- ALLDEPS, /// Print out absolutely every target
- REBUILD, /// Print targets that are going to be rebuilt
- RDEPS /// Print targets that depend on the given targets (NYI)
+ DEPS, //< Skip over "trivial" targets such as Install and Compile
+ ALLDEPS, //< Print out absolutely every target
+ REBUILD, //< Print targets that are going to be rebuilt
+ RDEPS //< Print targets that depend on the given targets (NYI)
};
- 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 analyze();
private:
typedef std::vector<std::string> TableRow;
typedef std::list<TableRow> Table;
- Builder &builder;
- Mode mode;
- Table table;
+ Builder &builder;
+ Mode mode;
+ Table table;
unsigned max_depth;
- bool full_paths;
+ bool full_paths;
+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; }
+
+ /**
+ Performs the analysis and prints out the resulting dependency tree.
+ */
+ void analyze();
+
+private:
+ /**
+ Adds rows to the table for the given target and its dependencies.
+ */
void build_depend_table(Target &, unsigned);
+
+ /**
+ Prints out the table that resulted from the analysis.
+ */
void print_table() const;
static bool target_order(Target *, Target *);
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
public:
class Loader: public Msp::DataFile::Loader
{
+ private:
+ Architecture &arch;
+
public:
Loader(Architecture &);
Architecture &get_object() { return arch; }
private:
- Architecture &arch;
-
void tool(const std::string &t, const std::string &p);
};
+private:
+ Builder &builder;
+ std::string name;
+ bool native;
+ std::string prefix;
+ StringMap tools;
+
+public:
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; }
bool is_native() const { return native; }
const std::string &get_prefix() const { return prefix; }
-private:
- Builder &builder;
- std::string name;
- bool native;
- std::string prefix;
- StringMap tools;
};
typedef std::map<std::string, Architecture> ArchMap;
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
use_pkgconfig=false;
}
-/**
-Sets the path where the package files were installed. This is only useful if
-the package doesn't use pkg-config.
-*/
void BinaryPackage::set_path(const Msp::FS::Path &p)
{
path=builder.get_cwd()/p;
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
void build_info();
};
+private:
+ bool need_path;
+ Msp::FS::Path path;
+
+public:
BinaryPackage(Builder &, const std::string &);
+
+ /**
+ Sets the path where the package's files were installed. This is only useful
+ if the package doesn't use pkg-config.
+ */
void set_path(const Msp::FS::Path &);
+
bool get_need_path() const { return need_path; }
static BinaryPackage *from_pkgconfig(Builder &, const std::string &);
private:
- bool need_path;
- Msp::FS::Path path;
-
virtual void create_build_info();
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
using namespace std;
using namespace Msp;
+namespace {
+
+void update_hash(string &hash, const string &value)
+{
+ for(unsigned i=0; i<value.size(); ++i)
+ hash[i%hash.size()]^=value[i];
+}
+
+}
+
+
Builder::Builder(int argc, char **argv):
main_pkg(0),
analyzer(0),
build_all(false),
create_makefile(false)
{
- string analyze_mode;
- string work_dir;
- bool full_paths=false;
+ string analyze_mode;
+ string work_dir;
+ bool full_paths=false;
unsigned max_depth=5;
StringList cmdline_warn;
- string prfx;
- string arch;
+ string prfx;
+ string arch;
GetOpt getopt;
getopt.add_option('a', "analyze", analyze_mode, GetOpt::REQUIRED_ARG);
pkg_path.push_back(cwd/"..");
}
-/**
-Gets a package by name, possibly creating it.
+Builder::~Builder()
+{
+ for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
+ delete i->second;
+ for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
+ delete i->second;
+ delete analyzer;
+}
-@param name Package name
+int Builder::main()
+{
+ if(load_build_file(cwd/build_file))
+ {
+ cerr<<"No build info here.\n";
+ return 1;
+ }
+
+ main_pkg->configure(cmdline_options, conf_all?2:1);
+
+ if(help)
+ {
+ usage(0, "builder", false);
+ cout<<'\n';
+ package_help();
+ return 0;
+ }
+
+ if(!conf_only && create_targets())
+ return 1;
+
+ PackageList all_reqs=main_pkg->collect_requires();
+
+ if(conf_only)
+ return 0;
+
+ if(verbose>=2)
+ cout<<"Building on "<<native_arch->get_name()<<", for "<<current_arch->get_name()<<'\n';
+ if(verbose>=1)
+ cout<<all_reqs.size()<<" active packages, "<<targets.size()<<" targets\n";
+ if(verbose>=2)
+ {
+ for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
+ {
+ cout<<' '<<(*i)->get_name();
+ if(dynamic_cast<SourcePackage *>(*i))
+ cout<<'*';
+ unsigned count=0;
+ unsigned ood_count=0;
+ for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
+ if(j->second->get_package()==*i)
+ {
+ ++count;
+ if(j->second->get_rebuild())
+ ++ood_count;
+ }
+ if(count)
+ {
+ cout<<" ("<<count<<" targets";
+ if(ood_count)
+ cout<<", "<<ood_count<<" out-of-date";
+ cout<<')';
+ }
+ cout<<'\n';
+ }
+ }
+
+ 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)
+ exit_code=do_clean();
+ else if(build)
+ exit_code=do_build();
+
+ return exit_code;
+}
-@return Pointer to the package, or 0 if the package could not be located
-*/
Package *Builder::get_package(const string &name)
{
PackageMap::iterator i=packages.find(format("%s/%s", name, current_arch->get_name()));
return pkg;
}
-/**
-Returns the target with the given name, or 0 if no such target exists.
-*/
Target *Builder::get_target(const string &n) const
{
TargetMap::const_iterator i=targets.find(n);
return 0;
}
-/**
-Tries to locate a header included from a given location and with a given include
-path. Considers known targets as well as existing files. If a matching target
-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 &from, const list<string> &path)
{
string hash(8, 0);
return tgt;
}
-/**
-Tries to locate a library with the given library path. Considers known targets
-as well as existing files. If a matching target is not found but a file exists,
-a new SystemLibrary target will be created and returned.
-
-@param lib Name of the library to get (without "lib" prefix or extension)
-@param path List of paths to search for the library
-@param mode Shared / static mode
-
-@return Some kind of library target, if a match was found
-*/
Target *Builder::get_library(const string &lib, const list<string> &path, LibMode mode)
{
string hash(8, 0);
problems.push_back(Problem(p, d));
}
-/**
-Adds a target to both the target map and the new target queue. Called from
-Target constructor.
-*/
void Builder::add_target(Target *t)
{
targets.insert(TargetMap::value_type(t->get_name(), t));
new_tgts.push_back(t);
}
-int Builder::main()
-{
- if(load_build_file(cwd/build_file))
- {
- cerr<<"No build info here.\n";
- return 1;
- }
-
- main_pkg->configure(cmdline_options, conf_all?2:1);
-
- if(help)
- {
- usage(0, "builder", false);
- cout<<'\n';
- package_help();
- return 0;
- }
-
- if(!conf_only && create_targets())
- return 1;
-
- PackageList all_reqs=main_pkg->collect_requires();
-
- if(conf_only)
- return 0;
-
- if(verbose>=2)
- cout<<"Building on "<<native_arch->get_name()<<", for "<<current_arch->get_name()<<'\n';
- if(verbose>=1)
- cout<<all_reqs.size()<<" active packages, "<<targets.size()<<" targets\n";
- if(verbose>=2)
- {
- for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
- {
- cout<<' '<<(*i)->get_name();
- if(dynamic_cast<SourcePackage *>(*i))
- cout<<'*';
- unsigned count=0;
- unsigned ood_count=0;
- for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
- if(j->second->get_package()==*i)
- {
- ++count;
- if(j->second->get_rebuild())
- ++ood_count;
- }
- if(count)
- {
- cout<<" ("<<count<<" targets";
- if(ood_count)
- cout<<", "<<ood_count<<" out-of-date";
- cout<<')';
- }
- cout<<'\n';
- }
- }
-
- 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)
- exit_code=do_clean();
- else if(build)
- exit_code=do_build();
-
- return exit_code;
-}
-
-Builder::~Builder()
-{
- for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
- delete i->second;
- for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
- delete i->second;
- delete analyzer;
-}
-
void Builder::usage(const char *reason, const char *argv0, bool brief)
{
if(reason)
}
}
-/**
-Determines the source directory of a package. pkg-config is consulted first,
-and if it fails, the package path is searched for matches.
-*/
FS::Path Builder::get_package_location(const string &name)
{
if(verbose>=3)
return FS::Path();
}
-/**
-Loads the given build file.
-
-@param fn Path to the file
-
-@return 0 on success, -1 if the file could not be opened
-*/
int Builder::load_build_file(const FS::Path &fn)
{
try
return 0;
}
-/**
-Creates targets for all packages and prepares them for building.
-
-@return 0 if everything went ok, -1 if something bad happened and a build
- shouldn't be attempted
-*/
int Builder::create_targets()
{
Target *world=new VirtualTarget(*this, "world");
}
/* If world is to be built, prepare cmdline. If not, add cmdline to world
- and prepare world. I don't really like this, but it keeps the graph
- acyclic. */
+ and prepare world. I don't really like this, but it keeps the graph
+ acyclic.
+
+ XXX Could we skip preparing targets we are not interested in? */
if(build_world)
cmdline->prepare();
else
return 0;
}
-/**
-Check if a header exists, either as a target or a file. Either an existing
-target or a new SystemHeader target will be returned.
-*/
Target *Builder::get_header(const Msp::FS::Path &fn)
{
Target *tgt=get_target(fn.str());
return 0;
}
-/**
-Updates a hash with a string. This is used from get_header and get_library.
-*/
-void Builder::update_hash(string &hash, const string &value)
-{
- for(unsigned i=0; i<value.size(); ++i)
- hash[i%hash.size()]^=value[i];
-}
-
-/**
-This function supervises the build process, starting new actions when slots
-become available.
-*/
int Builder::do_build()
{
Target *cmdline=get_target("cmdline");
return fail?1:0;
}
-/**
-Cleans buildable targets. If clean is 1, cleans only this package. If
-clean is 2 or greater, cleans all buildable packages.
-*/
int Builder::do_clean()
{
// Cleaning doesn't care about ordering, so a simpler method can be used
return 0;
}
-/**
-Prints out information about the default package.
-*/
void Builder::package_help()
{
const Config &config=main_pkg->get_config();
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class Builder: public Msp::Application
{
-public:
- Builder(int, char **);
- unsigned get_verbose() const { return verbose; }
- bool get_dry_run() const { return dry_run; }
- bool get_build_all() const { return build_all; }
- Package *get_package(const std::string &);
- SourcePackage *get_main_package() const { return main_pkg; }
- Target *get_target(const std::string &) const;
- const TargetMap &get_targets() const { return targets; }
- Target *get_header(const std::string &, const std::string &, const StringList &);
- Target *get_library(const std::string &, const StringList &, LibMode);
- const Msp::FS::Path &get_cwd() const { return cwd; }
- const Architecture &get_architecture(const std::string &) const;
- const Architecture &get_current_arch() const { return *current_arch; }
- const Architecture &get_native_arch() const { return *native_arch; }
- const Msp::FS::Path &get_prefix() const { return prefix; }
- const StringList &get_warnings() const { return warnings; }
- void apply_profile_template(Config &, const std::string &) const;
- void add_target(Target *);
- void problem(const std::string &, const std::string &);
- int main();
- ~Builder();
-
- static void usage(const char *, const char *, bool);
private:
class Loader: public Msp::DataFile::Loader
{
- public:
- Loader(Builder &, const Msp::FS::Path &);
private:
- Builder &bld;
+ Builder &bld;
Msp::FS::Path src;
+ public:
+ Loader(Builder &, const Msp::FS::Path &);
+ private:
void architecture(const std::string &);
void binpkg(const std::string &);
void profile(const std::string &);
class ProfileLoader: public Msp::DataFile::Loader
{
- public:
- ProfileLoader(StringMap &);
private:
StringMap &profile;
+ public:
+ ProfileLoader(StringMap &);
+ private:
void option(const std::string &, const std::string &);
};
- typedef std::list<Package *> PackageList;
- typedef std::map<std::string, Package *> PackageMap;
- typedef std::map<std::string, StringMap> ProfileTemplateMap;
+ typedef std::list<Package *> PackageList;
+ typedef std::map<std::string, Package *> PackageMap;
+ typedef std::map<std::string, StringMap> ProfileTemplateMap;
- StringList cmdline_targets;
- StringMap cmdline_options;
+ StringList cmdline_targets;
+ StringMap cmdline_options;
Msp::FS::Path cwd;
- PackageMap packages;
+ PackageMap packages;
SourcePackage *main_pkg;
- PathList pkg_path;
- PathList pkg_dirs;
+ PathList pkg_path;
+ PathList pkg_dirs;
- TargetMap targets;
- TargetList new_tgts;
- TargetMap includes;
- TargetMap libraries;
+ TargetMap targets;
+ TargetList new_tgts;
+ TargetMap includes;
+ TargetMap libraries;
- ArchMap archs;
+ ArchMap archs;
Architecture *native_arch;
const Architecture *current_arch;
ProfileTemplateMap profile_tmpl;
- ProblemList problems;
- Analyzer *analyzer;
- bool build;
- unsigned clean;
- bool dry_run;
- bool help;
- unsigned verbose;
- bool show_progress;
- std::string build_file;
- unsigned jobs;
- StringList what_if;
- bool conf_all;
- bool conf_only;
- bool build_all;
- bool create_makefile;
- Msp::FS::Path prefix;
- StringList warnings;
+ ProblemList problems;
+ Analyzer *analyzer;
+ bool build;
+ unsigned clean;
+ bool dry_run;
+ bool help;
+ unsigned verbose;
+ bool show_progress;
+ std::string build_file;
+ unsigned jobs;
+ StringList what_if;
+ bool conf_all;
+ bool conf_only;
+ bool build_all;
+ bool create_makefile;
+ Msp::FS::Path prefix;
+ StringList warnings;
+
+ static Msp::Application::RegApp<Builder> reg;
+
+public:
+ Builder(int, char **);
+ ~Builder();
+
+ int main();
+ unsigned get_verbose() const { return verbose; }
+ bool get_dry_run() const { return dry_run; }
+ bool get_build_all() const { return build_all; }
+
+ /** Gets a package by name, possibly creating it. Returns 0 if the package
+ could not be located. */
+ Package *get_package(const std::string &);
+
+ SourcePackage *get_main_package() const { return main_pkg; }
+
+ /** Looks up a target by name. Returns 0 if no such target exists. */
+ Target *get_target(const std::string &) const;
+
+ const TargetMap &get_targets() const { return targets; }
+
+ /** Tries to locate a header based on location of including file and include
+ path. Considers known targets as well as existing files. If a matching
+ target is not found but a file exists, a new SystemHeader target will be
+ created and returned. */
+ Target *get_header(const std::string &, const std::string &, const StringList &);
+ /** Tries to locate a library in a library path. The library name should be
+ the same as would be given to the linker with -l, i.e. without the "lib"
+ prefix or extension. Considers known targets as well as existing files. If
+ a matching target is not found but a file exists, a new SystemLibrary target
+ will be created and returned. */
+ Target *get_library(const std::string &, const StringList &, LibMode);
+
+ const Msp::FS::Path &get_cwd() const { return cwd; }
+ const Architecture &get_architecture(const std::string &) const;
+ const Architecture &get_current_arch() const { return *current_arch; }
+ const Architecture &get_native_arch() const { return *native_arch; }
+ const Msp::FS::Path &get_prefix() const { return prefix; }
+ const StringList &get_warnings() const { return warnings; }
+ void apply_profile_template(Config &, const std::string &) const;
+
+ /** Adds a target to both the target map and the new target queue. Called
+ from Target constructor. */
+ void add_target(Target *);
+
+ void problem(const std::string &, const std::string &);
+
+ static void usage(const char *, const char *, bool);
+
+private:
+ /** Determines the source directory of a package. Pkg-config is consulted
+ first, and if it fails, the package path is searched for matches. */
Msp::FS::Path get_package_location(const std::string &);
- int load_build_file(const Msp::FS::Path &);
- int create_targets();
+
+ /** Loads a build file. Returns 0 on success or -1 if the file could not be
+ opened. */
+ int load_build_file(const Msp::FS::Path &);
+
+ /** Creates targets for all packages and prepares them for building.
+ Returns 0 if everything went ok, -1 if something bad happened and a build
+ shouldn't be attempted. */
+ int create_targets();
+
+ /**
+ Check if a header exists, either as a target or a file. Returns an existing
+ target of one was found, or a new SystemHeader target if there was no known
+ target but the file exists.
+ */
Target *get_header(const Msp::FS::Path &);
+
Target *get_library(const std::string &, const Msp::FS::Path &, LibMode);
- void update_hash(std::string &, const std::string &);
- int do_build();
- int do_clean();
- int do_create_makefile();
- void package_help();
- static Msp::Application::RegApp<Builder> reg;
+ /** Supervises the build process, starting new actions when slots become
+ available. */
+ int do_build();
+
+ /** Cleans buildable targets. If clean is 1, cleans only the default
+ package. If clean is 2 or greater, cleans all buildable packages.
+ */
+ int do_clean();
+
+ int do_create_makefile();
+
+ /** Prints out information about the default package. */
+ void package_help();
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
using namespace std;
using namespace Msp;
-/**
-Adds another BuildInfo to the end of this one.
-*/
+namespace {
+
+/** Removes any duplicate entries from a list, leaving only the first one. The
+order of other elements is preserved. O(n²) efficiency. */
+void unique(StringList &l)
+{
+ for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
+ for(StringList::iterator j=i; j!=l.end();)
+ {
+ if(j!=i && *j==*i)
+ j=l.erase(j);
+ else
+ ++j;
+ }
+}
+
+}
+
+
void BuildInfo::add(const BuildInfo &bi)
{
cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end());
warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end());
}
-/**
-Makes sure there are no duplicate entries in the lists.
-*/
void BuildInfo::unique()
{
- unique(cflags);
- unique(defines);
- unique(incpath);
- unique(ldflags);
- unique(libpath);
- unique(libs);
+ ::unique(cflags);
+ ::unique(defines);
+ ::unique(incpath);
+ ::unique(ldflags);
+ ::unique(libpath);
+ ::unique(libs);
for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i)
{
}
}
-/**
-Removes any duplicate entries from a list, leaving only the first one. The
-order of other elements is preserved. O(n²) efficiency.
-*/
-void BuildInfo::unique(StringList &l)
-{
- for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
- for(StringList::iterator j=i; j!=l.end();)
- {
- if(j!=i && *j==*i)
- j=l.erase(j);
- else
- ++j;
- }
-}
BuildInfo::Loader::Loader(BuildInfo &bi):
binfo(bi)
add("warning", &Loader::warning);
}
+void BuildInfo::Loader::cflag(const std::string &s)
+{
+ binfo.cflags.push_back(s);
+}
+
+void BuildInfo::Loader::incpath(const std::string &s)
+{
+ binfo.incpath.push_back(s);
+}
+
+void BuildInfo::Loader::define(const std::string &s)
+{
+ binfo.defines.push_back(s);
+}
+void BuildInfo::Loader::ldflag(const std::string &s)
+{
+ binfo.ldflags.push_back(s);
+}
+
+void BuildInfo::Loader::libpath(const std::string &s)
+{
+ binfo.libpath.push_back(s);
+}
+
+void BuildInfo::Loader::library(const std::string &s)
+{
+ binfo.libs.push_back(s);
+}
+
+void BuildInfo::Loader::warning(const std::string &s)
+{
+ binfo.warnings.push_back(s);
+}
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
public:
class Loader: public Msp::DataFile::Loader
{
- public:
- Loader(BuildInfo &);
private:
BuildInfo &binfo;
- void cflag(const std::string &s) { binfo.cflags.push_back(s); }
- void incpath(const std::string &s) { binfo.incpath.push_back(s); }
- void define(const std::string &s) { binfo.defines.push_back(s); }
- void ldflag(const std::string &s) { binfo.ldflags.push_back(s); }
- void libpath(const std::string &s) { binfo.libpath.push_back(s); }
- void library(const std::string &s) { binfo.libs.push_back(s); }
- void warning(const std::string &s) { binfo.warnings.push_back(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 libpath(const std::string &);
+ void library(const std::string &);
+ void warning(const std::string &);
};
StringList cflags;
StringList libs;
StringList warnings;
+ /** Adds another BuildInfo to the end of this one. */
void add(const BuildInfo &);
+
+ /** Makes sure there are no duplicate entries in the lists. For warnings,
+ contradicting flags are eliminated and the last one stays in effect. */
void unique();
-private:
- void unique(StringList &);
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
deflt(true)
{ }
-/**
-Prepares the build information for building.
-*/
void Component::create_build_info()
{
build_info.add(pkg.get_build_info());
build_info.unique();
}
-/**
-Creates all targets needed for building this component.
-*/
void Component::create_targets() const
{
Builder &builder=pkg.get_builder();
if(build_exe)
{
- Executable *exe=0;
+ Executable *exe=0;
StaticLibrary *slib=0;
if(type==LIBRARY)
{
inst_tgt->add_depend(new Install(builder, pkg, **i));
}
-/**
-Collects all files belonging to the component.
-*/
PathList Component::collect_source_files() const
{
PathList files;
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
class Component
{
public:
- /// Loads a Component from file. Used from Package::Loader.
class Loader: public Msp::DataFile::Loader
{
+ private:
+ Component ∁
+
public:
Loader(Component &);
Component &get_object() { return comp; }
private:
- Component ∁
-
void source(const std::string &);
void require(const std::string &);
void modular();
HEADERS
};
- Component(SourcePackage &, Type, const std::string &);
- const SourcePackage &get_package() const { return pkg; }
- Type get_type() const { return type; }
- const std::string &get_name() const { return name; }
- const PathList &get_sources() const { return sources; }
- const BuildInfo &get_build_info() const { return build_info; }
- bool get_install() const { return install; }
- const std::string &get_install_headers() const { return install_headers; }
- bool get_modular() const { return modular; }
- const PackageList &get_requires() const { return requires; }
- bool get_default() const { return deflt; }
- void create_build_info();
- void create_targets() const;
protected:
SourcePackage &pkg;
- Type type;
+ Type type;
std::string name;
- PathList sources;
- bool install;
+ PathList sources;
+ bool install;
std::string install_headers;
const Component *module_host;
- bool modular;
- BuildInfo build_info;
+ bool modular;
+ BuildInfo build_info;
PackageList requires;
- bool deflt;
+ bool deflt;
- PathList collect_source_files() const;
+public:
+ Component(SourcePackage &, Type, const std::string &);
+ const SourcePackage &get_package() const { return pkg; }
+ Type get_type() const { return type; }
+ const std::string &get_name() const { return name; }
+ const PathList &get_sources() const { return sources; }
+ const BuildInfo &get_build_info() const { return build_info; }
+ bool get_install() const { return install; }
+ const std::string &get_install_headers() const { return install_headers; }
+ bool get_modular() const { return modular; }
+ const PackageList &get_requires() const { return requires; }
+ bool get_default() const { return deflt; }
+
+ /** Prepares the build information for building. Pulls build info from the
+ parent and dependency packages, and adds any component-specific flags. */
+ void create_build_info();
+
+ void create_targets() const;
+
+protected:
+ /** Returns a list of all source files for the component. */
+ PathList collect_source_files() const;
};
+
typedef std::list<Component> ComponentList;
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
public:
class Loader: public Msp::DataFile::Loader
{
- public:
- Loader(Condition &);
private:
Condition &cond;
+ public:
+ Loader(Condition &);
+ private:
void require(const std::string &);
void build_info();
};
- Condition(SourcePackage &, const std::string &);
- const StringList &get_requires() const { return requires; }
- const BuildInfo &get_build_info() const { return build_info; }
- bool eval();
private:
SourcePackage &pkg;
- StringMap expression;
+ StringMap expression;
StringList requires;
- BuildInfo build_info;
+ BuildInfo build_info;
+
+public:
+ Condition(SourcePackage &, const std::string &);
+ const StringList &get_requires() const { return requires; }
+ const BuildInfo &get_build_info() const { return build_info; }
+ bool eval();
};
typedef std::list<Condition> ConditionList;
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
freeze_mtime(false)
{ }
-/**
-Adds a configuration option.
-
-@param n Option name
-@param v Default value
-@param d Description
-*/
void Config::add_option(const string &n, const string &v, const string &d)
{
options.insert(OptionMap::value_type(n, Option(n, v, d)));
}
-/**
-Gets the given option from the configuration. If the option doesn't exist,
-an Exception is thrown.
-*/
const Config::Option &Config::get_option(const string &name) const
{
OptionMap::const_iterator i=options.find(name);
return i->second;
}
-/**
-Checks whether an option with the given name exists.
-*/
bool Config::is_option(const string &name) const
{
return options.count(name);
}
-/**
-Selects the last profile used. If the profile cache file is not present, the
-default profile is assumed.
-*/
void Config::select_last_profile()
{
try
load();
}
-/**
-Selects the given profile. The profile cache file is updated as well, unless
---dry-run was given.
-*/
void Config::select_profile(const string &profile)
{
set_option("profile", profile);
load();
}
-/**
-Processes options from the given raw option map. Nonexistent options are
-ignored. If any options were changed, the mtime of the configuration is updated
-to the current time.
-
-@param opts A map to process options from
-
-@return Whether any option values were changed
-*/
bool Config::update(const StringMap &opts)
{
bool changed=false;
return changed;
}
-/**
-Expands any variable references in options.
-*/
void Config::finish()
{
for(unsigned n=0; n<20; ++n)
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
class Config
{
public:
- /**
- A single configuration option.
- */
+ /** A single configuration option. */
struct Option
{
std::string name;
Option(const std::string &, const std::string &, const std::string &);
};
+
typedef std::map<std::string, Option> OptionMap;
- Config(SourcePackage &);
- void add_option(const std::string &, const std::string &, const std::string &);
- const Option &get_option(const std::string &) const;
- const OptionMap &get_options() const { return options; }
- const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
- bool is_option(const std::string &) const;
- void select_last_profile();
- void select_profile(const std::string &);
- bool update(const StringMap &);
- void finish();
- void save() const;
private:
class Loader: public Msp::DataFile::Loader
{
- public:
- Loader(Config &);
private:
Config &conf;
+ public:
+ Loader(Config &);
+ private:
void option(const std::string &, const std::string &);
};
- SourcePackage &package;
- OptionMap options;
+ SourcePackage &package;
+ OptionMap options;
Msp::Time::TimeStamp mtime;
bool freeze_mtime;
+public:
+ Config(SourcePackage &);
+
+ /** Adds a configuration option with name, default value and description. */
+ void add_option(const std::string &, const std::string &, const std::string &);
+
+ /** Gets a configuration option by name. */
+ const Option &get_option(const std::string &) const;
+
+ const OptionMap &get_options() const { return options; }
+ const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
+
+ /** Checks whether an option exists. */
+ bool is_option(const std::string &) const;
+
+ /** Selects the last profile used. If the profile cache file is not
+ present, the default profile is assumed. */
+ void select_last_profile();
+
+ /** Selects a profile. The profile cache file is updated, unless doing a
+ dry run. */
+ void select_profile(const std::string &);
+
+ /** Processes options from the given raw option map. Nonexistent options
+ are ignored. If any options were changed, the mtime of the configuration is
+ updated to the current time. Return value indicates whether any options
+ were changed. */
+ bool update(const StringMap &);
+
+ /** Expands any variable references in options. */
+ void finish();
+
+ void save() const;
+private:
bool set_option(const std::string &, const std::string &);
void load();
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class Copy: public InternalAction
{
-public:
- Copy(Builder &, const Package &, const Msp::FS::Path &, const Msp::FS::Path &);
private:
/**
A worker thread that actually does the data transfer.
Msp::FS::Path src;
Msp::FS::Path dest;
+
+public:
+ Copy(Builder &, const Package &, const Msp::FS::Path &, const Msp::FS::Path &);
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
changed(false)
{ }
+void DependencyCache::set_deps(const string &tgt, const StringList &d)
+{
+ deps[tgt]=d;
+ changed=true;
+}
+
const StringList &DependencyCache::get_deps(const string &tgt) const
{
DepsMap::const_iterator i=deps.find(tgt);
return i->second;
}
-void DependencyCache::set_deps(const string &tgt, const StringList &d)
-{
- deps[tgt]=d;
- changed=true;
-}
-
-/**
-Saves the depencency cache. If there are no cached dependencies or they
-haven't been changed, does nothing.
-*/
void DependencyCache::save() const
{
if(deps.empty() || !changed || package.get_builder().get_dry_run())
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class DependencyCache
{
-public:
- DependencyCache(SourcePackage &p);
- void set_deps(const std::string &tgt, const StringList &d);
- const StringList &get_deps(const std::string &tgt) const;
- const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
- void load();
- void save() const;
private:
typedef std::map<std::string, StringList> DepsMap;
DepsMap deps;
Msp::Time::TimeStamp mtime;
bool changed;
+
+public:
+ DependencyCache(SourcePackage &p);
+ void set_deps(const std::string &tgt, const StringList &d);
+ const StringList &get_deps(const std::string &tgt) const;
+ const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
+ void load();
+
+ /**
+ Saves the depencency cache. Does nothing if the cache is empty or nothing
+ has changed. */
+ void save() const;
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
add_depend(*i);
}
-/**
-Finds and adds any required libraries to the dependencies.
-*/
void Executable::find_depends()
{
LibMode libmode=comp.get_package().get_library_mode();
return new Link(builder, *this);
}
-/**
-Returns the name for the executable. We can't do this in the constructor since
-we need to pass the value to the Target c'tor.
-*/
string Executable::generate_target_name(const Component &c)
{
const SourcePackage &pkg=c.get_package();
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class Executable: public Target
{
+private:
+ const Component ∁
+
public:
Executable(Builder &, const Component &, const std::list<ObjectFile *> &);
- const char *get_type() const { return "Executable"; }
+ virtual const char *get_type() const { return "Executable"; }
const Component &get_component() const { return comp; }
- void find_depends();
+ virtual void find_depends();
private:
- const Component ∁
-
- virtual Action *create_action();
+ virtual Action *create_action();
+ /** Returns the name for the executable. We can't do this in the
+ constructor since we need to pass the value to the Target c'tor. */
static std::string generate_target_name(const Component &);
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
using namespace std;
using namespace Msp;
-int ExternalAction::check()
-{
- if(builder.get_dry_run())
- {
- signal_done.emit();
- return 0;
- }
-
- if(!pid)
- return exit_code;
-
- int status;
- if(waitpid(pid, &status, WNOHANG)==pid)
- {
- signal_done.emit();
- if(WIFEXITED(status))
- exit_code=WEXITSTATUS(status);
- else
- exit_code=254;
- pid=0;
- return exit_code;
- }
- else
- return -1;
-}
-
-/**
-Starts the external program. Fill in argv before calling this.
-*/
void ExternalAction::launch()
{
if(builder.get_verbose()>=2)
pid=0;
}
}
+
+int ExternalAction::check()
+{
+ if(builder.get_dry_run())
+ {
+ signal_done.emit();
+ return 0;
+ }
+
+ if(!pid)
+ return exit_code;
+
+ int status;
+ if(waitpid(pid, &status, WNOHANG)==pid)
+ {
+ signal_done.emit();
+ if(WIFEXITED(status))
+ exit_code=WEXITSTATUS(status);
+ else
+ exit_code=254;
+ pid=0;
+ return exit_code;
+ }
+ else
+ return -1;
+}
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class ExternalAction: public Action
{
-public:
- int check();
protected:
StringList argv;
- Msp::FS::Path work_dir;
- int pid;
- int exit_code;
+ Msp::FS::Path work_dir;
+ int pid;
+ int exit_code;
ExternalAction(Builder &b): Action(b), pid(0), exit_code(0) { }
+
+ /** Starts the external program. Fill in argv before calling this. */
void launch();
+
+public:
+ virtual int check();
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
Feature(const std::string &n, const std::string &d): name(n), descr(d) { }
};
+
typedef std::list<Feature> FeatureList;
#endif
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
File(Builder &, const std::string &);
virtual const char *get_type() const { return "File"; }
private:
- virtual Action *create_action() { return 0; }
+ virtual Action *create_action() { return 0; }
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
class Header: public SourceFile
{
public:
- Header(Builder &b, const Component *c, const std::string &f): SourceFile(b,c,f) { }
- const char *get_type() const { return "Header"; }
+ Header(Builder &b, const Component *c, const std::string &f): SourceFile(b, c, f) { }
+ virtual const char *get_type() const { return "Header"; }
};
/**
class SystemHeader: public Header
{
public:
- SystemHeader(Builder &b, const std::string &f): Header(b,0,f) { }
- const char *get_type() const { return "SystemHeader"; }
- void find_depends() { deps_ready=true; }
+ SystemHeader(Builder &b, const std::string &f): Header(b, 0, f) { }
+ virtual const char *get_type() const { return "SystemHeader"; }
+ virtual void find_depends() { deps_ready=true; }
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
{
public:
Install(Builder &, const SourcePackage &, Target &);
- const char *get_type() const { return "Install"; }
- void check_rebuild();
+ virtual const char *get_type() const { return "Install"; }
private:
+ virtual void check_rebuild();
virtual Action *create_action();
static std::string generate_target_name(const Target &);
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#include "internalaction.h"
+InternalAction::InternalAction(Builder &b):
+ Action(b),
+ worker(0)
+{ }
+
InternalAction::~InternalAction()
{
delete worker;
return -1;
}
-InternalAction::InternalAction(Builder &b):
- Action(b),
- worker(0)
-{ }
-
InternalAction::Worker::Worker():
done(false),
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
class InternalAction: public Action
{
-public:
- virtual ~InternalAction();
-
- virtual int check();
protected:
class Worker: public Msp::Thread
{
public:
- bool get_done() const { return done; }
+ bool get_done() const { return done; }
bool get_error() const { return error; }
protected:
bool done;
Worker *worker;
InternalAction(Builder &);
+public:
+ virtual ~InternalAction();
+
+ virtual int check();
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
using namespace std;
using namespace Msp;
-/**
-Runs a command and returns its output as a string. The exit status of the
-command is lost.
-*/
string run_command(const StringList &argv)
{
int pfd[2];
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
DYNAMIC
};
-typedef std::list<std::string> StringList;
+typedef std::list<std::string> StringList;
typedef std::list<Msp::FS::Path> PathList;
typedef std::map<std::string, std::string> StringMap;
+/** Runs a command and returns its output as a string. The exit status of the
+command is lost. */
std::string run_command(const StringList &);
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
add_depend(&src);
}
-/**
-Processes as many new dependences as possible. Some may be left unprocessed
-if their own dependencies are not ready, requiring another call to this
-function. Use the get_deps_ready() function to determine whether this is the
-case.
-*/
void ObjectFile::find_depends()
{
for(TargetList::iterator i=new_deps.begin(); i!=new_deps.end();)
}
-/**
-Recursively looks for header targets and adds them as dependencies.
-*/
void ObjectFile::find_depends(Target *tgt)
{
const string &tname=tgt->get_name();
}
}
-/**
-Adds a target to the dependency list as well as the new dependencies list.
-*/
void ObjectFile::add_depend(Target *tgt)
{
Target::add_depend(tgt);
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class ObjectFile: public Target
{
+private:
+ const Component ∁
+ TargetList new_deps;
+
public:
ObjectFile(Builder &, const Component &, SourceFile &);
- const char *get_type() const { return "ObjectFile"; }
+ virtual const char *get_type() const { return "ObjectFile"; }
const Component &get_component() const { return comp; }
- void find_depends();
+
+ /** Processes as many new dependences as possible. Some may be created on
+ the fly and can't be processed until their own dependencies are ready. In
+ such cases this function needs to be called again. */
+ virtual void find_depends();
+
private:
- const Component ∁
- TargetList new_deps;
-
+ /** Recursively looks for header targets and adds them as dependencies. */
void find_depends(Target *);
+
+ /** Adds a target to the dependency list as well as the new dependencies
+ list. */
void add_depend(Target *);
- virtual Action *create_action();
+ virtual Action *create_action();
static std::string generate_target_name(const Component &, const std::string &);
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#include <iostream>
-/**
-Creates a buildable package.
-*/
Package::Package(Builder &b, const string &n):
builder(b),
name(n),
use_pkgconfig(true)
{ }
-/**
-Collects all directly and indirectly required packages, including the package
-itself.
-*/
PackageList Package::collect_requires()
{
PackageList result;
return result;
}
-/**
-Processes configuration options that were most likely obtained from the command
-line.
-*/
void Package::configure(const StringMap &opts, unsigned flag)
{
if(conf_done)
conf_done=true;
}
-/*** private ***/
Package::Loader::Loader(Package &p):
pkg(p)
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
void require(const std::string &);
};
- const std::string &get_name() const { return name; }
- Builder &get_builder() const { return builder; }
- const PackageList &get_requires() const { return requires; }
- PackageList collect_requires();
- const BuildInfo &get_exported_binfo() const { return export_binfo; }
+protected:
+ Builder &builder;
- /// Indicates whether or not this package supports pkg-config
- bool get_use_pkgconfig() const { return use_pkgconfig; }
+ std::string name;
+
+ PackageList requires;
+ BuildInfo export_binfo;
+ bool conf_done;
- void configure(const StringMap &, unsigned);
+ bool use_pkgconfig;
+
+ Package(Builder &, const std::string &);
+public:
virtual ~Package() { }
-protected:
- Builder &builder;
- std::string name;
+ const std::string &get_name() const { return name; }
+ Builder &get_builder() const { return builder; }
+ const PackageList &get_requires() const { return requires; }
- PackageList requires;
- BuildInfo export_binfo;
- bool conf_done;
+ /** Returns a list of all directly and indirectly required packages,
+ including the package itself. */
+ PackageList collect_requires();
- bool use_pkgconfig;
+ const BuildInfo &get_exported_binfo() const { return export_binfo; }
- Package(Builder &, const std::string &);
+ /// Indicates whether or not this package supports pkg-config
+ bool get_use_pkgconfig() const { return use_pkgconfig; }
+
+ /** Processes configuration options that were most likely obtained from the
+ command line. */
+ void configure(const StringMap &, unsigned);
+protected:
virtual void do_configure(const StringMap &, unsigned) { }
virtual void create_build_info() { }
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class PkgConfig: public Target
{
-public:
- PkgConfig(Builder &, const SourcePackage &);
- const char *get_type() const { return "PkgConfig"; }
private:
const Package &pkg;
+public:
+ PkgConfig(Builder &, const SourcePackage &);
+ virtual const char *get_type() const { return "PkgConfig"; }
+private:
virtual Action *create_action();
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
{
public:
PkgConfigAction(Builder &, const PkgConfig &);
- int check();
+ virtual int check();
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class SharedLibrary: public Executable
{
+private:
+ std::string libname;
+
public:
SharedLibrary(Builder &, const Component &, const std::list<ObjectFile *> &);
- const char *get_type() const { return "SharedLibrary"; }
+ virtual const char *get_type() const { return "SharedLibrary"; }
const std::string &get_libname() const { return libname; }
-private:
- std::string libname;
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
comp(c)
{ }
-/**
-Parses include directives from the file and looks up the appropriate targets
-from Builder.
-*/
void SourceFile::find_depends()
{
if(!comp)
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class SourceFile: public Target
{
+private:
+ const Component *comp;
+ StringList includes;
+
public:
SourceFile(Builder &, const Component *, const std::string &);
+ virtual const char *get_type() const { return "SourceFile"; }
const StringList &get_includes() const { return includes; }
- const char *get_type() const { return "SourceFile"; }
- const Component *get_component() const { return comp; }
- void find_depends();
+ const Component *get_component() const { return comp; }
+ virtual void find_depends();
private:
- const Component *comp;
- StringList includes;
-
- virtual Action *create_action() { return 0; }
+ virtual Action *create_action() { return 0; }
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
using namespace std;
using namespace Msp;
-/**
-Creates a buildable package.
-*/
SourcePackage::SourcePackage(Builder &b, const string &n, const FS::Path &s):
Package(b, n),
source(s),
return source/arch.get_name()/config.get_option("outdir").value;
}
-/**
-Checks which kinds of things the components of this package install.
-
-@return A bitmask of installed things
-*/
unsigned SourcePackage::get_install_flags()
{
unsigned flags=0;
throw Exception("Unknown library mode");
}
-/*** private ***/
-
-/**
-Processes configuration options that were most likely obtained from the command
-line.
-*/
void SourcePackage::do_configure(const StringMap &opts, unsigned flag)
{
init_config();
(*i)->configure(opts, flag&2);*/
}
-/**
-Initializes configuration options.
-*/
void SourcePackage::init_config()
{
config.add_option("profile", "default", "Configuration profile");
}
}
-/**
-Fills in build info based on configuration. All required packages must be
-configured when this is called.
-*/
void SourcePackage::create_build_info()
{
for(PackageList::iterator i=base_reqs.begin(); i!=base_reqs.end(); ++i)
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
DATA=8
};
- /// Loads a package from a file.
class Loader: public Package::Loader
{
public:
void tar_file(const std::string &);
};
- SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
- const std::string &get_name() const { return name; }
- const std::string &get_version() const { return version; }
- const std::string &get_description() const { return description; }
- const Msp::FS::Path &get_source() const { return source; }
- Msp::FS::Path get_temp_dir() const;
- Msp::FS::Path get_out_dir() const;
- const ComponentList &get_components() const { return components; }
- const Config &get_config() const { return config; }
- const BuildInfo &get_build_info() const { return build_info; }
- const BuildInfo &get_exported_binfo() const { return export_binfo; }
- Builder &get_builder() const { return builder; }
- unsigned get_install_flags();
- LibMode get_library_mode() const;
- const PathList &get_tar_files() const { return tar_files; }
- DependencyCache &get_deps_cache() const { return deps_cache; }
private:
- std::string version;
- std::string description;
+ std::string version;
+ std::string description;
Msp::FS::Path source;
- PackageList base_reqs;
- FeatureList features;
- BuildInfo build_info;
+ PackageList base_reqs;
+ FeatureList features;
+ BuildInfo build_info;
ConditionList conditions;
ComponentList components;
- Config config;
- bool conf_done;
+ Config config;
+ bool conf_done;
mutable DependencyCache deps_cache;
- PathList tar_files;
+ PathList tar_files;
+
+public:
+ SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
+ const std::string &get_name() const { return name; }
+ const std::string &get_version() const { return version; }
+ const std::string &get_description() const { return description; }
+ const Msp::FS::Path &get_source() const { return source; }
+ Msp::FS::Path get_temp_dir() const;
+ Msp::FS::Path get_out_dir() const;
+ const ComponentList &get_components() const { return components; }
+ const Config &get_config() const { return config; }
+ const BuildInfo &get_build_info() const { return build_info; }
+ const BuildInfo &get_exported_binfo() const { return export_binfo; }
+ Builder &get_builder() const { return builder; }
- //Package(Builder &, const std::string &, const std::vector<std::string> &);
+ /** Returns a bitmask indicating which kinds of things the components of
+ this package install. */
+ unsigned get_install_flags();
+
+ LibMode get_library_mode() const;
+ const PathList &get_tar_files() const { return tar_files; }
+ DependencyCache &get_deps_cache() const { return deps_cache; }
+private:
virtual void do_configure(const StringMap &, unsigned);
- void init_config();
+
+ /** Initializes configuration options. */
+ void init_config();
+
+ /** Fills in build info based on configuration. All required packages must be
+ configured when this is called. */
virtual void create_build_info();
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class StaticLibrary: public Target
{
+private:
+ const Component ∁
+
public:
StaticLibrary(Builder &, const Component &, const std::list<ObjectFile *> &);
- const char *get_type() const { return "StaticLibrary"; }
+ virtual const char *get_type() const { return "StaticLibrary"; }
const Component &get_component() const { return comp; }
private:
- const Component ∁
-
- virtual Action *create_action();
+ virtual Action *create_action();
- std::string generate_target_name(const Component &);
+ static std::string generate_target_name(const Component &);
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class SystemLibrary: public Target
{
+private:
+ std::string libname;
+
public:
SystemLibrary(Builder &, const std::string &);
- const char *get_type() const { return "SystemLibrary"; }
+ virtual const char *get_type() const { return "SystemLibrary"; }
const std::string &get_libname() const { return libname; }
private:
- std::string libname;
-
- virtual Action *create_action() { return 0; }
+ virtual Action *create_action() { return 0; }
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
class Tar: public InternalAction
{
-public:
- Tar(Builder &, const TarBall &);
private:
class Worker: public InternalAction::Worker
{
const TarBall &tarball;
StringList files;
+
+public:
+ Tar(Builder &, const TarBall &);
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
class TarBall: public Target
{
+private:
+ std::string tarname;
+
public:
TarBall(Builder &, const SourcePackage &, const std::string & =std::string());
virtual const char *get_type() const { return "TarBall"; }
const SourcePackage *get_package() const;
virtual void find_depends();
private:
- std::string tarname;
-
virtual Action *create_action();
static std::string create_target_name(const SourcePackage &, const std::string &);
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
using namespace std;
using namespace Msp;
-/**
-Tries to locate a target that will help getting this target built. If all
-dependencies are up-to-date, returns this target. If there are no targets
-ready to be built (maybe because they are being built right now), returns 0.
-*/
+Target::Target(Builder &b, const Package *p, const string &n):
+ builder(b),
+ package(p),
+ name(n),
+ buildable(false),
+ building(false),
+ rebuild(false),
+ deps_ready(false),
+ prepared(false),
+ counted(false)
+{
+ builder.add_target(this);
+
+ struct stat st;
+ if(!FS::stat(name, st))
+ mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
+}
+
Target *Target::get_buildable_target()
{
if(!rebuild)
dep->rdepends.push_back(this);
}
-/**
-Prepares the target by recursively preparing dependencies, then checking
-whether rebuilding is needed. A flag is used to prevent unnecessary
-executions.
-*/
void Target::prepare()
{
if(prepared)
return action;
}
-/**
-Returns the number of targets that need to be rebuilt in order to get this
-target up-to-date.
-*/
unsigned Target::count_rebuild()
{
if(counted)
return count;
}
-/**
-Changes the mtime of the target to the current time.
-*/
void Target::touch()
{
mtime=Time::now();
}
-Target::Target(Builder &b, const Package *p, const string &n):
- builder(b),
- package(p),
- name(n),
- buildable(false),
- building(false),
- rebuild(false),
- deps_ready(false),
- prepared(false),
- counted(false)
-{
- builder.add_target(this);
-
- struct stat st;
- if(!FS::stat(name, st))
- mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
-}
-
void Target::mark_rebuild(const std::string &reason)
{
rebuild=true;
rebuild_reason=reason;
}
-/**
-Checks if this target needs to be rebuilt and why.
-*/
void Target::check_rebuild()
{
if(!buildable)
mark_rebuild("Package options changed");
}
-/**
-Handles for the build_done signal of Action.
-*/
void Target::build_done()
{
building=false;
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
*/
class Target
{
+protected:
+ Builder &builder;
+ const Package *package;
+ std::string name;
+ Msp::Time::TimeStamp mtime;
+
+ bool buildable;
+ bool building;
+ bool rebuild;
+ std::string rebuild_reason;
+
+ TargetList depends;
+ TargetList rdepends;
+ bool deps_ready;
+
+ bool prepared;
+ bool counted;
+
+ Target(Builder &, const Package *, const std::string &);
public:
- const std::string &get_name() const { return name; }
- Target *get_buildable_target();
- bool get_buildable() const { return buildable; }
- bool get_rebuild() const { return rebuild; }
- const std::string &get_rebuild_reason() const { return rebuild_reason; }
- const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
+ virtual ~Target() { }
+
virtual const char *get_type() const=0;
- const TargetList &get_depends() const { return depends; }
- const Package *get_package() const { return package; }
- bool get_depends_ready() const { return deps_ready; }
- void add_depend(Target *);
- virtual void prepare();
+ const std::string &get_name() const { return name; }
+ const Package *get_package() const { return package; }
+ const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
+
+ /**
+ Tries to locate a target that will help getting this target built. If all
+ dependencies are up-to-date, returns this target. If there are no targets
+ ready to be built (maybe because they are being built right now), returns 0.
+ */
+ Target *get_buildable_target();
+
+ bool get_buildable() const { return buildable; }
+ bool get_rebuild() const { return rebuild; }
+ const std::string &get_rebuild_reason() const { return rebuild_reason; }
+ void add_depend(Target *);
+ const TargetList &get_depends() const { return depends; }
+ bool get_depends_ready() const { return deps_ready; }
/**
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; }
/**
- Creates and returns an Action suitable for building this target.
+ Prepares the target by recursively preparing dependencies, then checking
+ whether rebuilding is needed. A flag is used to prevent unnecessary
+ executions.
*/
- Action *build();
+ virtual void prepare();
- void reset_count() { counted=false; }
- virtual unsigned count_rebuild();
- void touch();
- virtual ~Target() { }
-protected:
- Builder &builder;
- const Package *package;
- std::string name;
- Msp::Time::TimeStamp mtime;
+ /**
+ Starts building the target. Returns the Action used for building.
+ */
+ Action *build();
- bool buildable;
- bool building;
- bool rebuild;
- std::string rebuild_reason;
+ void reset_count() { counted=false; }
- TargetList depends;
- TargetList rdepends;
- bool deps_ready;
+ /**
+ Returns the number of targets that need to be rebuilt in order to get this
+ target up-to-date.
+ */
+ virtual unsigned count_rebuild();
- bool prepared;
- bool counted;
+ /**
+ Changes the mtime of the target to the current time.
+ */
+ void touch();
+protected:
+ void mark_rebuild(const std::string &);
- Target(Builder &, const Package *, const std::string &);
- void mark_rebuild(const std::string &);
+ /**
+ Checks if the target needs to be rebuilt and why.
+ */
virtual void check_rebuild();
+
+ /**
+ Creates and returns an Action suitable for building this target.
+ */
virtual Action *create_action() =0;
+
+ /**
+ Handles for the build_done signal of Action.
+ */
virtual void build_done();
};
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
{
public:
Unlink(Builder &, const Target &);
- int check();
+ virtual int check();
};
#endif
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
using namespace std;
using namespace Msp;
-/**
-Virtual targets are only rebuilt if their dependencies need rebuilding.
-*/
void VirtualTarget::check_rebuild()
{
+ // Virtual targets are only rebuilt if their dependencies need rebuilding.
for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
if((*i)->get_rebuild())
mark_rebuild(FS::basename((*i)->get_name())+" needs rebuilding");
}
-/**
-Don't count virtual targets since "building" them causes no action.
-*/
unsigned VirtualTarget::count_rebuild()
{
+ // Don't count virtual targets since "building" them causes no action.
return Target::count_rebuild()-rebuild;
}
/* $Id$
This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
{
public:
VirtualTarget(Builder &b, const std::string &n): Target(b, 0, n) { }
- const char *get_type() const { return "VirtualTarget"; }
- unsigned count_rebuild();
+ virtual const char *get_type() const { return "VirtualTarget"; }
+ virtual unsigned count_rebuild();
private:
- void check_rebuild();
+ virtual void check_rebuild();
virtual Action *create_action() { return 0; }
};