aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.c')
-rw-r--r--src/cli.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/cli.c b/src/cli.c
index c8bb60c..ccc64b9 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -1,13 +1,10 @@
-struct CliArgs {
- const char* input_filename;
- const char* output_filename;
- BOOL output_executable;
-};
-typedef struct CliArgs CliArgs;
+#include "cli.h"
+#include "common.h"
CliArgs* parse_cli_args(int argc, char** argv) {
const char* output_filename = NULL;
int positional_arguments_start = -1;
+ BOOL only_compile = FALSE;
for (int i = 1; i < argc; ++i) {
if (argv[i][0] != '-') {
@@ -27,6 +24,8 @@ CliArgs* parse_cli_args(int argc, char** argv) {
}
output_filename = argv[i + 1];
++i;
+ } else if (c == 'c') {
+ only_compile = TRUE;
} else {
fatal_error("unknown option: %s", argv[i]);
}
@@ -38,6 +37,26 @@ CliArgs* parse_cli_args(int argc, char** argv) {
CliArgs* a = calloc(1, sizeof(CliArgs));
a->input_filename = argv[positional_arguments_start];
a->output_filename = output_filename;
- a->output_executable = output_filename && !str_ends_with(output_filename, ".s");
+ a->output_assembly = !output_filename || str_ends_with(output_filename, ".s");
+ a->only_compile = only_compile;
+ a->totally_deligate_to_gcc = FALSE;
+ a->gcc_command = NULL;
+
+ if (!a->only_compile && str_ends_with(a->input_filename, ".o")) {
+ a->totally_deligate_to_gcc = TRUE;
+ StrBuilder builder;
+ strbuilder_init(&builder);
+ strbuilder_append_string(&builder, "gcc ");
+ for (int i = 1; i < argc; ++i) {
+ strbuilder_append_char(&builder, '\'');
+ strbuilder_append_string(&builder, argv[i]);
+ strbuilder_append_char(&builder, '\'');
+ if (i != argc - 1) {
+ strbuilder_append_char(&builder, ' ');
+ }
+ }
+ a->gcc_command = builder.buf;
+ }
+
return a;
}