- string analyze_mode;
- string work_dir;
- bool full_paths=false;
- unsigned max_depth=5;
- StringList cmdline_warn;
- string prfx;
- string arch;
-
- 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('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])+" [<target> ...]";
- helpmsg=getopt.generate_help();
- getopt(argc, argv);
-
- 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 UsageError("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)
- {
- unsigned 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();
-
- utsname un;
- string sysname="native";
- if(uname(&un)==0)
- sysname=tolower(un.sysname);
-
- native_arch=&archs.insert(ArchMap::value_type(sysname, Architecture(*this, sysname, true))).first->second;
- native_arch->set_tool("CC", "gcc");
- native_arch->set_tool("CXX", "g++");
- native_arch->set_tool("LD", "gcc");
- native_arch->set_tool("LXX", "g++");
- native_arch->set_tool("AR", "ar");
-
- load_build_file((FS::get_sys_data_dir(argv[0], "builder")/"builderrc").str());
- load_build_file((FS::get_home_dir()/".builderrc").str());
-
- if(arch.empty())
- current_arch=native_arch;
- else
- current_arch=&get_architecture(arch);
-
- 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());
- }
-
- pkg_path.push_back(cwd/".");
- pkg_path.push_back(cwd/"..");