diff --git a/tools/qfcc/include/cpp.h b/tools/qfcc/include/cpp.h index ecdff9169..6bec02189 100644 --- a/tools/qfcc/include/cpp.h +++ b/tools/qfcc/include/cpp.h @@ -37,6 +37,7 @@ void parse_cpp_name (void); void add_cpp_undef (const char *arg); void add_cpp_def (const char *arg); +int cpp_depend (const char *opt, const char *arg); int cpp_include (const char *opt, const char *arg); void cpp_define (const char *arg); void cpp_undefine (const char *arg); diff --git a/tools/qfcc/source/cpp.c b/tools/qfcc/source/cpp.c index 97e57b27d..8020fc021 100644 --- a/tools/qfcc/source/cpp.c +++ b/tools/qfcc/source/cpp.c @@ -140,6 +140,102 @@ add_cpp_def (const char *arg) cpp_argc++; } +static int +cpp_depend_ (const char *opt, const char *arg) +{ + add_cpp_def ("-M"); + options.preprocess_only = 1; + return 0; +} + +static int +cpp_depend_D (const char *opt, const char *arg) +{ + add_cpp_def ("-MD"); + return 0; +} + +static int +cpp_depend_F (const char *opt, const char *arg) +{ + add_cpp_def ("-MF"); + add_cpp_def (arg); + return 1; +} + +static int +cpp_depend_G (const char *opt, const char *arg) +{ + add_cpp_def ("-MG"); + return 0; +} + +static int +cpp_depend_M (const char *opt, const char *arg) +{ + add_cpp_def ("-MM"); + options.preprocess_only = 1; + return 0; +} + +static int +cpp_depend_MD (const char *opt, const char *arg) +{ + add_cpp_def ("-MMD"); + return 0; +} + +static int +cpp_depend_P (const char *opt, const char *arg) +{ + add_cpp_def ("-MP"); + return 0; +} + +static int +cpp_depend_Q (const char *opt, const char *arg) +{ + add_cpp_def ("-MQ"); + add_cpp_def (arg); + return 1; +} + +static int +cpp_depend_T (const char *opt, const char *arg) +{ + add_cpp_def ("-MT"); + add_cpp_def (arg); + return 1; +} + +#define CPP_DEPEND(name) {#name, cpp_depend_##name} +int +cpp_depend (const char *opt, const char *arg) +{ + static cpp_func_t depend_funcs[] = { + CPP_DEPEND (), + CPP_DEPEND (D), + CPP_DEPEND (F), + CPP_DEPEND (G), + CPP_DEPEND (M), + CPP_DEPEND (MD), + CPP_DEPEND (P), + CPP_DEPEND (Q), + CPP_DEPEND (T), + {} + }; + if (!opt) { + opt = ""; + } + for (int i = 0; depend_funcs[i].name; i++) { + if (!strcmp (opt, depend_funcs[i].name)) { + return depend_funcs[i].func (opt, arg); + } + } + return -1; +} +#undef CPP_DEPEND + static int cpp_include_I (const char *opt, const char *arg) { diff --git a/tools/qfcc/source/options.c b/tools/qfcc/source/options.c index 59e33135e..a4f9eba73 100644 --- a/tools/qfcc/source/options.c +++ b/tools/qfcc/source/options.c @@ -770,16 +770,16 @@ DecodeArgs (int argc, char **argv) cpp_undefine (optarg); break; case 'M': - options.preprocess_only = 1; - if (optarg) { - add_cpp_def (nva ("-M%s", optarg)); - if (strchr (optarg, 'D')) + { + if (optarg && strchr (optarg, 'D')) { saw_MD = 1; - if (strchr ("FQT", optarg[0])) - add_cpp_def (argv[optind++]); - } else { - options.preprocess_only = 1; - add_cpp_def (nva ("-M")); + } + int o = cpp_depend (optarg, argv[optind]); + if (o < 0) { + usage (1); + } else { + optind += o; + } } break; case OPT_NO_DEFAULT_PATHS: