- string analyze_mode;
- string work_dir;
- bool full_paths = false;
- unsigned max_depth = 5;
- StringList cmdline_warn;
- string prfx;
- string arch;
- bool no_externals = false;
- unsigned verbose = 1;
- bool silent = false;
- list<string> log_channels;
-
- GetOpt getopt;
- 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('l', "log", log_channels, GetOpt::REQUIRED_ARG).set_help("Set log channels to be displayed.", "LIST");
- 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('s', "silent", silent, GetOpt::NO_ARG).set_help("Don't print any messages other than errors.");
- 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("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])+" [<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("packages");
- logger.enable_channel("commands");
- }
- if(verbose>=3)
- {
- logger.enable_channel("packagemgr");
- logger.enable_channel("configure");
- }
- if(verbose>=4)
- {
- logger.enable_channel("files");
- logger.enable_channel("auxcommands");
- }
- if(verbose>=5)
- {
- logger.enable_channel("tools");
- logger.enable_channel("vfs");
- }
- 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");
-
- analyzer->set_max_depth(max_depth);
- analyzer->set_full_paths(full_paths);
- }
- else if(!clean && !create_makefile)
- build = true;
-
- 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('=');
- if(equal!=string::npos)
- cmdline_options.insert(StringMap::value_type(i->substr(0, equal), i->substr(equal+1)));
- else
- cmdline_targets.push_back(*i);
- }
-
- if(cmdline_targets.empty())
- cmdline_targets.push_back("default");
-
- if(!work_dir.empty())
- FS::chdir(work_dir);
-
- cwd = FS::getcwd();
-
- package_manager.set_no_externals(no_externals);
-
- load_build_file((FS::get_sys_data_dir(argv[0], "builder")/"builderrc").str());
- load_build_file((FS::get_user_data_dir("builder")/"rc").str());
-
- if(arch.empty())
- current_arch = &native_arch;
- else
- current_arch = new Architecture(*this, arch);
-
- if(!current_arch->is_native())
- {
- for(StringMap::const_iterator i=cross_prefixes.begin(); i!=cross_prefixes.end(); ++i)
- if(current_arch->match_name(i->first))
- {
- current_arch->set_cross_prefix(i->second);
- break;
- }
- }
-
- toolchain.add_tool(new GnuCCompiler(*this, *current_arch));
- toolchain.add_tool(new GnuCxxCompiler(*this, *current_arch));
- toolchain.add_tool(new GnuLinker(*this, *current_arch));
- toolchain.add_tool(new GnuArchiver(*this, *current_arch));
- toolchain.add_tool(new Copy(*this));
- toolchain.add_tool(new Tar(*this));
- toolchain.add_tool(new PkgConfigGenerator(*this));
-
- if(prfx.empty())
- {
- if(current_arch->is_native())
- prefix = (FS::get_home_dir()/"local").str();
- else
- prefix = (FS::get_home_dir()/"local"/current_arch->get_name()).str();
- }
- else
- prefix = FS::getcwd()/prfx;
-
- warnings.push_back("all");
- warnings.push_back("extra");
- warnings.push_back("shadow");
- warnings.push_back("pointer-arith");
- warnings.push_back("error");
- for(StringList::iterator i=cmdline_warn.begin(); i!=cmdline_warn.end(); ++i)
- {
- vector<string> warns = split(*i, ',');
- warnings.insert(warnings.end(), warns.begin(), warns.end());
- }