Add -MT option

This commit is contained in:
Rui Ueyama 2020-08-18 12:38:21 +09:00
parent 57c1d4ec02
commit db850f37a2
2 changed files with 17 additions and 2 deletions

13
main.c
View File

@ -17,6 +17,7 @@ static bool opt_c;
static bool opt_cc1; static bool opt_cc1;
static bool opt_hash_hash_hash; static bool opt_hash_hash_hash;
static char *opt_MF; static char *opt_MF;
static char *opt_MT;
static char *opt_o; static char *opt_o;
static StringArray ld_extra_args; static StringArray ld_extra_args;
@ -33,7 +34,7 @@ static void usage(int status) {
} }
static bool take_arg(char *arg) { static bool take_arg(char *arg) {
char *x[] = {"-o", "-I", "-idirafter", "-include", "-x", "-MF"}; char *x[] = {"-o", "-I", "-idirafter", "-include", "-x", "-MF", "-MT"};
for (int i = 0; i < sizeof(x) / sizeof(*x); i++) for (int i = 0; i < sizeof(x) / sizeof(*x); i++)
if (!strcmp(arg, x[i])) if (!strcmp(arg, x[i]))
@ -194,6 +195,14 @@ static void parse_args(int argc, char **argv) {
continue; continue;
} }
if (!strcmp(argv[i], "-MT")) {
if (opt_MT == NULL)
opt_MT = argv[++i];
else
opt_MT = format("%s %s", opt_MT, argv[++i]);
continue;
}
if (!strcmp(argv[i], "-cc1-input")) { if (!strcmp(argv[i], "-cc1-input")) {
base_file = argv[++i]; base_file = argv[++i];
continue; continue;
@ -357,7 +366,7 @@ static void print_dependencies(void) {
path = "-"; path = "-";
FILE *out = open_file(path); FILE *out = open_file(path);
fprintf(out, "%s:", replace_extn(base_file, ".o")); fprintf(out, "%s:", opt_MT ? opt_MT : replace_extn(base_file, ".o"));
File **files = get_input_files(); File **files = get_input_files();

View File

@ -240,4 +240,10 @@ check -MP
grep -q '^.*/out3.h:' $tmp/mp grep -q '^.*/out3.h:' $tmp/mp
check -MP check -MP
# -MT
$chibicc -MT foo -M -I$tmp $tmp/out.c | grep -q '^foo:'
check -MT
$chibicc -MT foo -MT bar -M -I$tmp $tmp/out.c | grep -q '^foo bar:'
check -MT
echo OK echo OK