|
|
@@ -42,7 +42,7 @@ static void readDir(std::string dir, std::vector<SourceFile> &sources, |
|
|
|
std::vector<std::string> files; |
|
|
|
bool hasFiles = false; |
|
|
|
|
|
|
|
// Parse $dir/build.bbb, specifies a 'files' value |
|
|
|
// Parse $dir/build.bbb, see if it specifies a 'files' value. |
|
|
|
if (buildFile.good()) { |
|
|
|
BBBParser parser(buildFile, BBBParser::FLAG_NONE); |
|
|
|
parser.parse(vars); |
|
|
@@ -109,7 +109,8 @@ static bool compile(const std::vector<SourceFile> &sources, const std::string &o |
|
|
|
|
|
|
|
static void link( |
|
|
|
const std::vector<SourceFile> &sources, |
|
|
|
const std::string &outDir, const std::string &name) { |
|
|
|
const std::string &outDir, const std::string &name, |
|
|
|
toolchain::TargetType targetType) { |
|
|
|
std::cerr << "Link " << outDir << '/' << name << '\n'; |
|
|
|
|
|
|
|
std::vector<std::string> ldFlags; |
|
|
@@ -155,7 +156,20 @@ static void link( |
|
|
|
|
|
|
|
flags.clear(); |
|
|
|
|
|
|
|
toolchain::link(name, ldFlags, ldLibs, type, objects, outDir); |
|
|
|
toolchain::link(name, ldFlags, ldLibs, type, targetType, objects, outDir); |
|
|
|
} |
|
|
|
|
|
|
|
static bool compileAndLink( |
|
|
|
const std::vector<SourceFile> &sources, const std::string &outDir, |
|
|
|
int jobs, const std::string &target, toolchain::TargetType targetType) { |
|
|
|
std::string targetPath = toolchain::targetFilePath(targetType, target, outDir); |
|
|
|
|
|
|
|
if (compile(sources, outDir, jobs) || !sys::fileExists(targetPath)) { |
|
|
|
link(sources, outDir, target, targetType); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char **argv) { |
|
|
@@ -163,19 +177,21 @@ int main(int argc, char **argv) { |
|
|
|
std::string outDir = "bbbuild"; |
|
|
|
int jobs = parallel::coreCount(); |
|
|
|
std::string workDir = ""; |
|
|
|
std::string target = ""; |
|
|
|
|
|
|
|
enum class Action { |
|
|
|
BUILD, PRINT_STATE, |
|
|
|
}; |
|
|
|
Action action = Action::BUILD; |
|
|
|
|
|
|
|
const char *shortopts = "hvo:j:C:p"; |
|
|
|
const char *shortopts = "hvo:j:C:t:p"; |
|
|
|
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' }, |
|
|
|
{ "print-state", no_argument, NULL, 'p' }, |
|
|
|
{}, |
|
|
|
}; |
|
|
@@ -194,6 +210,8 @@ int main(int argc, char **argv) { |
|
|
|
"Default: the number of cores in the machine.\n" |
|
|
|
" -C, --directory <dir> " |
|
|
|
"Change directory before doing anything else.\n" |
|
|
|
" -t, --target <name> " |
|
|
|
"Set the name of the executable.\n" |
|
|
|
" -p, --print-state " |
|
|
|
"Print the state instead of building.\n"; |
|
|
|
|
|
|
@@ -231,6 +249,10 @@ int main(int argc, char **argv) { |
|
|
|
workDir = optarg; |
|
|
|
break; |
|
|
|
|
|
|
|
case 't': |
|
|
|
target = optarg; |
|
|
|
break; |
|
|
|
|
|
|
|
case 'p': |
|
|
|
action = Action::PRINT_STATE; |
|
|
|
break; |
|
|
@@ -253,6 +275,11 @@ int main(int argc, char **argv) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: Read this from build.bbb |
|
|
|
if (target.size() == 0) { |
|
|
|
target = "target"; |
|
|
|
} |
|
|
|
|
|
|
|
// Parse non-opt argv as source dirs |
|
|
|
if (optind < argc) { |
|
|
|
while (optind < argc) { |
|
|
@@ -268,17 +295,12 @@ int main(int argc, char **argv) { |
|
|
|
readDir(dir, sources, {}); |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: Get this from somewhere |
|
|
|
std::string target = "target"; |
|
|
|
|
|
|
|
switch (action) { |
|
|
|
case Action::BUILD: |
|
|
|
if (compile(sources, outDir, jobs)) { |
|
|
|
link(sources, outDir, target); |
|
|
|
} else { |
|
|
|
// TODO: Support more types than BINARY |
|
|
|
if (!compileAndLink(sources, outDir, jobs, target, toolchain::TargetType::BINARY)) { |
|
|
|
std::cerr << "Nothing to do.\n"; |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case Action::PRINT_STATE: |