Skip to content

Commit

Permalink
Build profile handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Dec 16, 2023
1 parent c06c1c3 commit 06bf4a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
27 changes: 22 additions & 5 deletions src/Cmd/Build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,32 @@ void build(const Vec<String>& args) {
std::filesystem::create_directory("poac-out");
}

bool debug = true;
if (!args.empty()) {
if (args[0] == "-d" || args[0] == "--debug") {
debug = true;
} else if (args[0] == "-r" || args[0] == "--release") {
debug = false;
} else {
Logger::error(
"invalid option: `", args[0], "`", "\n\n",
" run `poac help build` for a list of options"
);
return;
}
}

BuildConfig config;

// Compiler settings
config.defineVariable("CC", "clang++");
config.defineVariable("DEBUG_FLAGS", "-g -O0 -DDEBUG");
config.defineVariable("RELEASE_FLAGS", "-O3 -DNDEBUG");
config.defineVariable(
"CFLAGS", "-Wall -Wextra -fdiagnostics-color -pedantic-errors -std=c++20"
);
const String baseCflags =
"-Wall -Wextra -fdiagnostics-color -pedantic-errors -std=c++20 ";
if (debug) {
config.defineVariable("CFLAGS", baseCflags + "-g -O0 -DDEBUG");
} else {
config.defineVariable("CFLAGS", baseCflags + "-O3 -DNDEBUG");
}
config.defineVariable("LDFLAGS", "-L.");
// Directories
config.defineVariable("SRC_DIR", "../src");
Expand Down
21 changes: 12 additions & 9 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ void help(const Vec<String>& args) {

StringRef subcommand = args[0];
if (helps.count(subcommand) == 0) {
Logger::error("no such subcommand: `", subcommand, "`");
std::cerr << '\n';
std::cerr << " run `poac help` for a list of subcommands" << '\n';
Logger::error(
"no such subcommand: `", subcommand, "`", "\n\n",
" run `poac help` for a list of subcommands"
);
return;
}

Expand All @@ -63,9 +64,10 @@ int main(int argc, char* argv[]) {
}

if (args.empty()) {
Logger::error("no subcommand provided");
std::cerr << '\n';
std::cerr << " run `poac help` for a list of commands" << '\n';
Logger::error(
"no subcommand provided", "\n\n",
" run `poac help` for a list of commands"
);
return 1;
}

Expand All @@ -75,9 +77,10 @@ int main(int argc, char* argv[]) {

StringRef subcommand = args[0];
if (cmds.count(subcommand) == 0) {
Logger::error("no such command: `", subcommand, "`");
std::cerr << '\n';
std::cerr << " run `poac help` for a list of commands" << '\n';
Logger::error(
"no such command: `", subcommand, "`", "\n\n",
" run `poac help` for a list of commands"
);
return 1;
}

Expand Down

0 comments on commit 06bf4a4

Please sign in to comment.