- string analyze_mode;
- string work_dir;
- bool full_paths = false;
- unsigned max_depth = 4;
- string prfx;
- string temp_str;
- string arch;
- bool no_externals = false;
- unsigned verbose = 1;
- bool silent = false;
- list<string> log_channels;
- string build_type_name;
-
- GetOpt getopt;
- getopt.add_option('a', "analyze", analyze_mode, GetOpt::REQUIRED_ARG).set_help("Perform dependency analysis.", "MODE");
- getopt.add_option('b', "build", build, GetOpt::NO_ARG).set_help("Perform build even if also doing something else.");
- 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 build instructions from FILE.", "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 up to NUM tasks in parallel.", "NUM");
- getopt.add_option('l', "log", log_channels, GetOpt::REQUIRED_ARG).set_help("Enable listed log channels.", "LIST");
- getopt.add_option('n', "dry-run", dry_run, GetOpt::NO_ARG).set_help("Show what would be done without actually doing it.");
- getopt.add_option('s', "silent", silent, GetOpt::NO_ARG).set_help("Don't print any messages other than errors.");
- getopt.add_option('t', "build-type", build_type_name, GetOpt::REQUIRED_ARG).set_help("Set build type.", "TYPE");
- getopt.add_option('v', "verbose", verbose, GetOpt::NO_ARG).set_help("Print more information about what's going on.");
- getopt.add_option('x', "no-externals", no_externals, GetOpt::NO_ARG).set_help("Do not load external source packages.");
- 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("Build for architecture ARCH.", "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("Show up to NUM levels in analysis.", "NUM");
- getopt.add_option( "prefix", prfx, GetOpt::REQUIRED_ARG).set_help("Install things to DIR.", "DIR");
- getopt.add_option( "tempdir", temp_str, GetOpt::REQUIRED_ARG).set_help("Store temporary files in DIR.", "DIR");
- usagemsg = getopt.generate_usage(argv[0])+" [<target> ...]";
- helpmsg = getopt.generate_help();
- getopt(argc, argv);
-
- if(silent)
- --verbose;
- if(verbose>=1)
- {
- logger.enable_channel("summary");
- logger.enable_channel("tasks");
- }
- if(verbose>=2)
- {
- logger.enable_channel("environment");
- logger.enable_channel("packages");
- logger.enable_channel("commands");
- }
- if(verbose>=3)
- {
- logger.enable_channel("files");
- logger.enable_channel("auxcommands");
- }
- for(list<string>::const_iterator i=log_channels.begin(); i!=log_channels.end(); ++i)
- {
- vector<string> parts = split(*i, ',');
- for(vector<string>::const_iterator j=parts.begin(); j!=parts.end(); ++j)
- logger.enable_channel(*j);
- }
-
- if(!analyze_mode.empty())
- {
- analyzer = new Analyzer(*this);
-
- if(analyze_mode=="deps")
- analyzer->set_mode(Analyzer::DEPS);
- else if(analyze_mode=="alldeps")
- analyzer->set_mode(Analyzer::ALLDEPS);
- else if(analyze_mode=="rebuild")
- analyzer->set_mode(Analyzer::REBUILD);
- else if(analyze_mode=="rdeps")
- analyzer->set_mode(Analyzer::RDEPS);
- else
- throw usage_error("Invalid analyze mode");