From b674653fa2d911b65a14062498a006e47f2a80ba Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 8 Jan 2026 02:06:19 +0900 Subject: feat: support -D flag --- src/cli.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/cli.c') diff --git a/src/cli.c b/src/cli.c index 7fe2119..56f6098 100644 --- a/src/cli.c +++ b/src/cli.c @@ -18,6 +18,8 @@ CliArgs* parse_cli_args(int argc, char** argv) { bool opt_MMD = false; StrArray include_dirs; strings_init(&include_dirs); + StrArray defines; + strings_init(&defines); for (int i = 1; i < argc; ++i) { if (argv[i][0] != '-') { @@ -46,6 +48,19 @@ CliArgs* parse_cli_args(int argc, char** argv) { fatal_error("-I requires directory"); } strings_push(&include_dirs, dir); + } else if (c == 'D') { + const char* def = NULL; + if (argv[i][2] != '\0') { + // -DFOO or -DFOO=value format + def = argv[i] + 2; + } else if (argc > i + 1) { + // -D FOO or -D FOO=value format + def = argv[i + 1]; + ++i; + } else { + fatal_error("-D requires macro definition"); + } + strings_push(&defines, def); } else if (c == 'o') { if (argc <= i + 1) { fatal_error("-o requires filename"); @@ -84,6 +99,7 @@ CliArgs* parse_cli_args(int argc, char** argv) { a->gcc_command = NULL; a->generate_deps = opt_MMD; a->include_dirs = include_dirs; + a->defines = defines; if (!a->only_compile && str_ends_with(a->input_filename, ".o")) { a->totally_deligate_to_gcc = true; -- cgit v1.2.3-70-g09d2