//#bb ldlibs := -lpthread #include #include #include "BBParser.h" #include "parallel.h" #include "toolchain.h" #include "globals.h" #include "logger.h" #include "sys.h" #include "build.h" int main(int argc, char **argv) { std::string outDir = "bbbuild"; int jobs = parallel::coreCount(); std::string workDir = ""; std::string target = ""; const char *shortopts = "hvo:j:C:cp"; const struct option opts[] = { { "help", no_argument, NULL, 'h' }, { "verbose", no_argument, NULL, 'v' }, { "output", required_argument, NULL, 'o' }, { "jobs", required_argument, NULL, 'j' }, { "directory", required_argument, NULL, 'C' }, { "target", required_argument, NULL, 't' }, {}, }; const char usage[] = "Usage: bbbuild [options...] [sources]\n" "\n" " -h, --help " "Show this help text.\n" " -v, --verbose " "Show every command as it's executing.\n" " -o, --output " "Set output directory. Default: bbbuild\n" " -j, --jobs " "Set the number of jobs run simultaneously. " "Default: the number of cores in the machine.\n" " -C, --directory " "Change directory before doing anything else.\n"; // Parse options from argv while (1) { int optidx; int c = getopt_long(argc, argv, shortopts, opts, &optidx); if (c < 0) { break; } switch (c) { case 'h': puts(usage); return 0; case 'v': global::verbose += 1; break; case 'o': outDir = optarg; break; case 'j': jobs = atoi(optarg); if (jobs <= 0) { fprintf(stderr, "Can't run %i jobs.\n", jobs); return 1; } break; case 'C': workDir = optarg; break; default: printf("Unknown option: '%c'.\n%s", (char)c, usage); return 1; } } logger::LogContext logCtx = logger::init(); parallel::ParallelContext par = parallel::init(jobs); // Change directory? if (workDir.size() > 0) { fprintf(stderr, "Entering directory '%s'\n", workDir.c_str()); sys::chdir(workDir); } // Read everything related to the build configuration, // finding all source files and reading their configs std::vector args; while (optind < argc) { args.push_back(argv[optind++]); } // TODO: Parse variables from CLI BBVariables vars; std::unique_ptr root = buildDepTree(outDir, vars); if (root == nullptr) { logger::log("No source files."); } else if (root->hasChanged(outDir)) { root->build(outDir); } else { logger::log("Nothing to do."); } }