X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbuilder.cpp;h=de8375919e17678de591cdff9452cc36bf25057e;hb=5622fc20f0be8bff0938d24f6f45d3ab384288ca;hp=cf335c1a93a6c0f7248e20b2f46cb19d3c4efafb;hpb=96e132661ec82c9347f9155d3f30cd99ea8eca47;p=builder.git diff --git a/source/builder.cpp b/source/builder.cpp index cf335c1..de83759 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -5,7 +5,6 @@ Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include #include #include #include @@ -17,6 +16,7 @@ Distributed under the LGPL #include #include #include +#include #include #include #include @@ -77,26 +77,27 @@ Builder::Builder(int argc, char **argv): string arch; GetOpt getopt; - getopt.add_option('a', "analyze", analyze_mode, GetOpt::REQUIRED_ARG); - getopt.add_option('b', "build", build, GetOpt::NO_ARG); - getopt.add_option('c', "clean", clean, GetOpt::NO_ARG); - getopt.add_option('f', "file", build_file, GetOpt::REQUIRED_ARG); - getopt.add_option('h', "help", help, GetOpt::NO_ARG); - getopt.add_option('j', "jobs", jobs, GetOpt::REQUIRED_ARG); - getopt.add_option('n', "dry-run", dry_run, GetOpt::NO_ARG); - getopt.add_option('v', "verbose", verbose, GetOpt::NO_ARG); - getopt.add_option('A', "conf-all", conf_all, GetOpt::NO_ARG); - getopt.add_option('B', "build-all", build_all, GetOpt::NO_ARG); - getopt.add_option('C', "chdir", work_dir, GetOpt::REQUIRED_ARG); - getopt.add_option('P', "progress", show_progress, GetOpt::NO_ARG); - getopt.add_option('W', "what-if", what_if, GetOpt::REQUIRED_ARG); - getopt.add_option( "arch", arch, GetOpt::REQUIRED_ARG); - getopt.add_option( "conf-only", conf_only, GetOpt::NO_ARG); - getopt.add_option( "full-paths", full_paths, GetOpt::NO_ARG); - //getopt.add_option( "makefile", create_makefile, GetOpt::NO_ARG); - getopt.add_option( "max-depth", max_depth, GetOpt::REQUIRED_ARG); - getopt.add_option( "prefix", prfx, GetOpt::REQUIRED_ARG); - getopt.add_option( "warnings", cmdline_warn, GetOpt::REQUIRED_ARG); + getopt.add_option('a', "analyze", analyze_mode, GetOpt::REQUIRED_ARG).set_help("Perform analysis. MODE can be deps, alldeps or rebuild.", "MODE"); + getopt.add_option('b', "build", build, GetOpt::NO_ARG).set_help("Perform build even if doing analysis."); + getopt.add_option('c', "clean", clean, GetOpt::NO_ARG).set_help("Clean buildable targets."); + getopt.add_option('f', "file", build_file, GetOpt::REQUIRED_ARG).set_help("Read info from FILE instead of Build.", "FILE"); + getopt.add_option('h', "help", help, GetOpt::NO_ARG).set_help("Print this message."); + getopt.add_option('j', "jobs", jobs, GetOpt::REQUIRED_ARG).set_help("Run NUM commands at once, whenever possible.", "NUM"); + getopt.add_option('n', "dry-run", dry_run, GetOpt::NO_ARG).set_help("Don't actually do anything, only show what would be done."); + getopt.add_option('v', "verbose", verbose, GetOpt::NO_ARG).set_help("Print more information about what's going on."); + getopt.add_option('A', "conf-all", conf_all, GetOpt::NO_ARG).set_help("Apply configuration to all packages."); + getopt.add_option('B', "build-all", build_all, GetOpt::NO_ARG).set_help("Build all targets unconditionally."); + getopt.add_option('C', "chdir", work_dir, GetOpt::REQUIRED_ARG).set_help("Change to DIR before doing anything else.", "DIR"); + getopt.add_option('P', "progress", show_progress, GetOpt::NO_ARG).set_help("Display progress while building."); + getopt.add_option('W', "what-if", what_if, GetOpt::REQUIRED_ARG).set_help("Pretend that FILE has changed.", "FILE"); + getopt.add_option( "arch", arch, GetOpt::REQUIRED_ARG).set_help("Architecture to build for.", "ARCH"); + getopt.add_option( "conf-only", conf_only, GetOpt::NO_ARG).set_help("Stop after configuring packages."); + getopt.add_option( "full-paths", full_paths, GetOpt::NO_ARG).set_help("Output full paths in analysis."); + 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])+" [ ...]"; + helpmsg=getopt.generate_help(); getopt(argc, argv); if(!analyze_mode.empty()) @@ -196,8 +197,16 @@ int Builder::main() { if(load_build_file(cwd/build_file)) { - cerr<<"No build info here.\n"; - return 1; + if(help) + { + usage(0, "builder", false); + return 0; + } + else + { + IO::print(IO::cerr, "No build info here.\n"); + return 1; + } } main_pkg->configure(cmdline_options, conf_all?2:1); @@ -205,7 +214,7 @@ int Builder::main() if(help) { usage(0, "builder", false); - cout<<'\n'; + IO::print("\n"); package_help(); return 0; } @@ -219,16 +228,16 @@ int Builder::main() return 0; if(verbose>=2) - cout<<"Building on "<get_name()<<", for "<get_name()<<'\n'; + IO::print("Building on %s, for %s\n", native_arch->get_name(), current_arch->get_name()); if(verbose>=1) - cout<=2) { for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i) { - cout<<' '<<(*i)->get_name(); + IO::print(" %s", (*i)->get_name()); if(dynamic_cast(*i)) - cout<<'*'; + IO::print("*"); unsigned count=0; unsigned ood_count=0; for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j) @@ -240,12 +249,12 @@ int Builder::main() } if(count) { - cout<<" ("<package<<": "<descr<<'\n'; - cerr<<"Please fix them and try again.\n"; + IO::print(IO::cerr, " %s: %s\n", i->package, i->descr); + IO::print(IO::cerr, "Please fix them and try again.\n"); return 1; } @@ -335,12 +344,12 @@ Target *Builder::get_header(const string &include, const FS::Path &from, const l cxx_ver.erase(dot); } if(verbose>=5) - cout<<"C++ version is "<=5) - cout<<"Looking for include "<is_native()) @@ -383,7 +392,7 @@ Target *Builder::get_library(const string &lib, const list &path, LibMod syspath.push_back("/usr/"+current_arch->get_prefix()+"/lib"); if(verbose>=5) - cout<<"Looking for library "< ...]\n"; + IO::print(IO::cerr, "Usage: %s\n", usagemsg); 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" - " -P, --progress Display progress while building.\n" - " -W, --what-if FILE Pretend that FILE has changed.\n" - " --arch ARCH Architecture to build for.\n" - " --conf-only Stop after configuring packages.\n" - " --full-paths Output full paths in analysis.\n" - //" --makefile Create a makefile for this package.\n" - " --max-depth NUM Maximum depth to show in analysis.\n" - " --prefix DIR Directory to install things to.\n" - " --warnings LIST Compiler warnings to use.\n"; + IO::print(IO::cerr, "Usage: %s [options] [ ...]\n\n", argv0); + IO::print(IO::cerr, "Options:\n"); + IO::print(IO::cerr, helpmsg); } } FS::Path Builder::get_package_location(const string &name) { if(verbose>=3) - cout<<"Looking for package "< argv; @@ -477,7 +465,7 @@ FS::Path Builder::get_package_location(const string &name) argv.push_back("--variable=source"); argv.push_back(name); if(verbose>=4) - cout<<"Running "<=3) - cout<=3) - cout<<"Reading "<touch(); @@ -599,7 +587,7 @@ int Builder::create_targets() tgt=get_target((cwd/ *i).str()); if(!tgt) { - cerr<<"I don't know anything about "<<*i<<'\n'; + IO::print("I don't know anything about %s\n", *i); return -1; } if(tgt==world) @@ -697,11 +685,11 @@ int Builder::do_build() unsigned total=cmdline->count_rebuild(); if(!total) { - cout<<"Already up to date\n"; + IO::print("Already up to date\n"); return 0; } if(verbose>=1) - cout<<"Will build "< actions; @@ -722,10 +710,7 @@ int Builder::do_build() actions.push_back(action); if(show_progress) - { - cout<get_config(); const Config::OptionMap &options=config.get_options(); - cout<<"Required packages:\n "; + IO::print("Required packages:\n "); const PackageList &requires=main_pkg->get_requires(); for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i) { if(i!=requires.begin()) - cout<<", "; - cout<<(*i)->get_name(); + IO::print(", "); + IO::print((*i)->get_name()); } - cout<<"\n\n"; - cout<<"Package configuration:\n"; + IO::print("\n\nPackage configuration:\n"); for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i) { const Config::Option &opt=i->second; - cout<<" "< Builder::reg; +string Builder::usagemsg; +string Builder::helpmsg; Builder::Loader::Loader(Builder &b, const FS::Path &s):