aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-08-31 00:28:00 +0900
committernsfisis <nsfisis@gmail.com>2025-08-31 12:04:19 +0900
commitda65f1e21a24f0a173ee5ae08f00db91cba5ffda (patch)
tree3ec802f40d7cd0bd9e162ea5b3e50b76f319a884 /src/main.c
parenta5ee9d944edf665c814bbfeded2849f2bb980ed8 (diff)
downloadducc-da65f1e21a24f0a173ee5ae08f00db91cba5ffda.tar.gz
ducc-da65f1e21a24f0a173ee5ae08f00db91cba5ffda.tar.zst
ducc-da65f1e21a24f0a173ee5ae08f00db91cba5ffda.zip
feat: support -MMD flag
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 5704367..b064f39 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,6 +2,7 @@
#include "cli.h"
#include "codegen.h"
#include "common.h"
+#include "fs.h"
#include "io.h"
#include "parse.h"
#include "preprocess.h"
@@ -16,7 +17,11 @@ int main(int argc, char** argv) {
}
InFile* source = infile_open(cli_args->input_filename);
- TokenArray* pp_tokens = preprocess(source);
+
+ StrArray included_files;
+ strings_init(&included_files);
+
+ TokenArray* pp_tokens = preprocess(source, &included_files);
TokenArray* tokens = tokenize(pp_tokens);
Program* prog = parse(tokens);
@@ -45,4 +50,18 @@ int main(int argc, char** argv) {
fatal_error("gcc failed: %d", result);
}
}
+
+ if (cli_args->generate_deps && cli_args->only_compile && cli_args->output_filename) {
+ const char* dep_filename = replace_extension(cli_args->output_filename, ".d");
+
+ FILE* dep_file = fopen(dep_filename, "w");
+ if (!dep_file) {
+ fatal_error("Cannot open dependency file: %s", dep_filename);
+ }
+ fprintf(dep_file, "%s:", cli_args->output_filename);
+ for (size_t i = 0; i < included_files.len; ++i) {
+ fprintf(dep_file, " \\\n %s", included_files.data[i]);
+ }
+ fprintf(dep_file, "\n");
+ }
}