diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-31 00:28:00 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-31 12:04:19 +0900 |
| commit | da65f1e21a24f0a173ee5ae08f00db91cba5ffda (patch) | |
| tree | 3ec802f40d7cd0bd9e162ea5b3e50b76f319a884 /src/main.c | |
| parent | a5ee9d944edf665c814bbfeded2849f2bb980ed8 (diff) | |
| download | ducc-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.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -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"); + } } |
