X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbuilder.cpp;h=28d57d44012ce1465720185b1ea5d04c7558b910;hb=4fcc283a4bb1f695bd124006906bcdaba053193f;hp=bab8eb0af8701deb9a8f68e07491ca4eeed6fc2e;hpb=7e17b52f23dbbf06b425f69f4b8a84867e2f0597;p=builder.git diff --git a/source/builder.cpp b/source/builder.cpp index bab8eb0..28d57d4 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -17,6 +18,8 @@ #include "misc.h" #include "objectfile.h" #include "package.h" +#include "sharedlibrary.h" +#include "staticlibrary.h" #include "systemlibrary.h" #include "virtualtarget.h" @@ -25,7 +28,6 @@ using namespace Msp; Builder::Builder(int argc, char **argv): verbose(1), - cwd(Path::getcwd()), build_file("Build"), do_build(true), analyzer(0), @@ -33,21 +35,21 @@ Builder::Builder(int argc, char **argv): chrome(false) { GetOpt getopt; - getopt.add_option(GetOpt::Option('v', "verbose", GetOpt::NONE)); getopt.add_option(GetOpt::Option('a', "analyze", GetOpt::REQUIRED)); getopt.add_option(GetOpt::Option('b', "build", GetOpt::NONE)); - getopt.add_option(GetOpt::Option("max-depth", GetOpt::REQUIRED)); + getopt.add_option(GetOpt::Option('c', "clean", GetOpt::NONE)); + getopt.add_option(GetOpt::Option('f', "file", GetOpt::REQUIRED, "Build")); + getopt.add_option(GetOpt::Option('h', "help", GetOpt::NONE)); + getopt.add_option(GetOpt::Option('j', "jobs", GetOpt::REQUIRED, "1")); getopt.add_option(GetOpt::Option('n', "dry-run", GetOpt::NONE)); - getopt.add_option(GetOpt::Option('W', "what-if", GetOpt::REQUIRED)); + getopt.add_option(GetOpt::Option('v', "verbose", GetOpt::NONE)); + getopt.add_option(GetOpt::Option('A', "conf-all", GetOpt::NONE)); getopt.add_option(GetOpt::Option('B', "build-all", GetOpt::NONE)); getopt.add_option(GetOpt::Option('C', "chdir", GetOpt::REQUIRED)); - getopt.add_option(GetOpt::Option('j', "jobs", GetOpt::REQUIRED, "1")); - getopt.add_option(GetOpt::Option('h', "help", GetOpt::NONE)); - getopt.add_option(GetOpt::Option('c', "clean", GetOpt::NONE)); - getopt.add_option(GetOpt::Option('f', "file", GetOpt::REQUIRED, "Build")); + getopt.add_option(GetOpt::Option('W', "what-if", GetOpt::REQUIRED)); getopt.add_option(GetOpt::Option("chrome", GetOpt::NONE)); getopt.add_option(GetOpt::Option("full-paths", GetOpt::NONE)); - getopt.add_option(GetOpt::Option('A', "conf-all", GetOpt::NONE)); + getopt.add_option(GetOpt::Option("max-depth", GetOpt::REQUIRED)); int index=getopt(argc, argv); verbose+=getopt['v'].count(); @@ -77,18 +79,16 @@ Builder::Builder(int argc, char **argv): } dry_run=getopt['n']; - jobs=max(strtol(getopt['j'].arg()), 1L); - chrome=getopt["chrome"]; - conf_all=getopt['A']; + build_file=getopt['f'].arg(); + build_all=getopt['B']; + help=getopt['h']; if(getopt['C']) chdir(getopt['C'].arg().c_str()); - build_file=getopt['f'].arg(); - for(int i=index; i::const_iterator j=path.begin(); j!=path.end(); ++j) - if((tgt=check_header(Path::Path(*j)/fn))) + if((tgt=check_header(cwd/ *j/fn))) return tgt; return 0; @@ -213,7 +215,7 @@ Target *Builder::get_library(const string &lib, const list &path) string basename="lib"+lib+".so"; for(list::const_iterator j=path.begin(); j!=path.end(); ++j) { - string full=(Path::Path(*j)/basename).str(); + string full=(cwd/ *j/basename).str(); Target *tgt=get_target(full); if(tgt) return tgt; @@ -246,6 +248,14 @@ int Builder::main() pkg->resolve_refs(); } + if(help) + { + usage("builder", false); + cout<<'\n'; + package_help(); + return 0; + } + std::list missing; for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i) if(!i->second) @@ -275,10 +285,22 @@ int Builder::main() if(i->second->get_buildable()) cout<<'*'; unsigned count=0; + unsigned ood_count=0; for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j) if(j->second->get_package()==i->second) + { ++count; - cout<<" ("<second->get_rebuild()) + ++ood_count; + } + if(count) + { + cout<<" ("< ...]"; + else + { + cerr<< + "Usage: "< ...]\n" + "\n" + "Options:\n" + " -a, --analyze MODE Perform analysis. MODE can be deps, alldeps or rebuild.\n" + " -b, --build Perform build even if doing analysis.\n" + " -c, --clean Clean buildable targets.\n" + " -f, --file FILE Read info from FILE instead of Build.\n" + " -h, --help Print this message.\n" + " -j, --jobs NUM Run NUM commands at once, whenever possible.\n" + " -n, --dry-run Don't actually do anything, only show what would be done.\n" + " -v, --verbose Print more information about what's going on.\n" + " -A, --conf-all Apply configuration to all packages.\n" + " -B, --build-all Build all targets unconditionally.\n" + " -C, --chdir DIR Change to DIR before doing anything else.\n" + " -W, --what-if FILE Pretend that FILE has changed.\n" + " --chrome Use extra chrome to print status.\n" + " --full-paths Output full paths in analysis.\n" + " --max-depth NUM Maximum depth to show in analysis.\n"; + } +} + int Builder::load_build_file(const Path::Path &fn) { ifstream in(fn.str().c_str()); @@ -395,12 +445,28 @@ int Builder::create_targets() if(build_exe) { - Executable *exe=new Executable(*this, *j, objs); + Executable *exe=0; + StaticLibrary *slib=0; + if(j->get_type()==Component::LIBRARY) + { + exe=new SharedLibrary(*this, *j, objs); + slib=new StaticLibrary(*this, *j, objs); + add_target(slib); + } + else + exe=new Executable(*this, *j, objs); + add_target(exe); if(i->second==default_pkg) + { def_tgt->add_depend(exe); + if(slib) def_tgt->add_depend(slib); + } else + { world->add_depend(exe); + if(slib) world->add_depend(slib); + } if(j->get_install()) { @@ -414,6 +480,13 @@ int Builder::create_targets() Install *inst=new Install(*this, *i->second, *exe, (inst_base/inst_dir/Path::basename(exe->get_name())).str()); add_target(inst); install->add_depend(inst); + + if(slib) + { + inst=new Install(*this, *i->second, *slib, (inst_base/inst_dir/Path::basename(slib->get_name())).str()); + add_target(inst); + install->add_depend(inst); + } } } } @@ -560,6 +633,28 @@ int Builder::build() return fail?-1:0; } +void Builder::package_help() +{ + const Config &config=default_pkg->get_config(); + const Config::OptionMap &options=config.get_options(); + + cout<<"Required packages:\n "; + const list &requires=default_pkg->get_requires(); + for(list::const_iterator i=requires.begin(); i!=requires.end(); ++i) + { + if(i!=requires.begin()) + cout<<", "; + cout<get_name(); + } + cout<<"\n\n"; + cout<<"Package configuration:\n"; + for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i) + { + const Config::Option &opt=i->second; + cout<<" "< Builder::reg; Builder::Loader::Loader(Builder &b, const Path::Path &s):