diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/src/main.cpp b/src/main.cpp index 79d4d9d..0f20ea0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,21 @@ void usage() exit(1); } +void usageBuild() +{ + printf("Usage: sibs build [project_path] [--debug|--release]\n\n"); + printf("Build a sibs project\n\n"); + printf("Options:\n"); + printf(" project_path\t\t The directory containing a project.conf file - Optional (default: current working directory)\n"); + printf(" --debug|--release\t\tOptimization level to build project and dependencies with (if not a system package) - Optional (default: --debug)\n"); + printf("Examples:\n"); + printf(" sibs build\n"); + printf(" sibs build dirA/dirB\n"); + printf(" sibs build --release\n"); + printf(" sibs build dirA --release\n"); + exit(1); +} + void usageNew() { printf("Usage: sibs new <project_name> <--exec|--static|--dynamic>\n\n"); @@ -100,17 +115,50 @@ bool isPathSubPathOf(const string &path, const string &subPathOf) int buildProject(int argc, const char **argv) { - if(argc > 1) + if(argc > 2) + usageBuild(); + + OptimizationLevel optimizationLevel = OPT_LEV_NONE; + string projectPath; + + for(int i = 0; i < argc; ++i) { - cerr << "Expected 'build' command to only be followed by one argument which is the path to a directory that contains a project.conf file, "; - cerr << "or none; in which case build would use the working directory as target directory" << endl << endl; - usage(); + const char *arg = argv[i]; + if(strcmp(arg, "--debug") == 0) + { + if(optimizationLevel != OPT_LEV_NONE) + { + fprintf(stderr, "Error: Optimization level defined more than once. First defined as %s then as %s\n", asString(optimizationLevel), "debug"); + usageBuild(); + } + optimizationLevel = OPT_LEV_DEBUG; + } + else if(strcmp(arg, "--release") == 0) + { + if(optimizationLevel != OPT_LEV_NONE) + { + fprintf(stderr, "Error: Optimization level defined more than once. First defined as %s then as %s\n", asString(optimizationLevel), "debug"); + usageBuild(); + } + optimizationLevel = OPT_LEV_RELEASE; + } + else + { + if(!projectPath.empty()) + { + fprintf(stderr, "Error: Project path was defined more than once. First defined as %s then as %s\n", projectPath.c_str(), arg); + usageBuild(); + } + projectPath = arg; + } } - // TODO: If argc == 0 and working directory does not contain project.conf, then search every parent directory until one is found - string projectPath = "."; - if(argc == 1) - projectPath = argv[0]; + if(optimizationLevel == OPT_LEV_NONE) + optimizationLevel = OPT_LEV_DEBUG; + + // TODO: If projectPath is not defined and working directory does not contain project.conf, then search every parent directory until one is found + if(projectPath.empty()) + projectPath = "."; validateDirectoryPath(projectPath.c_str()); if(projectPath.back() != '/') @@ -128,7 +176,7 @@ int buildProject(int argc, const char **argv) projectConfFilePath += "/project.conf"; validateFilePath(projectConfFilePath.c_str()); - SibsConfig sibsConfig(projectPath); + SibsConfig sibsConfig(projectPath, optimizationLevel); Result<bool> result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig); if(result.isErr()) { @@ -186,8 +234,18 @@ int buildProject(int argc, const char **argv) }; walkDir(projectPath.c_str(), collectSourceFiles); - string debugBuildPath = projectPath + "/sibs-build/debug"; - Result<bool> buildFileResult = ninja.build(sibsConfig, debugBuildPath.c_str()); + string buildPath = projectPath + "/sibs-build/"; + switch(sibsConfig.getOptimizationLevel()) + { + case OPT_LEV_DEBUG: + buildPath += "debug"; + break; + case OPT_LEV_RELEASE: + buildPath += "release"; + break; + } + + Result<bool> buildFileResult = ninja.build(sibsConfig, buildPath.c_str()); if(buildFileResult.isErr()) { cerr << "Failed to build ninja file: " << buildFileResult.getErrMsg() << endl; |