diff --git a/tools/qfcc/include/options.h b/tools/qfcc/include/options.h index e59581313..1b2fa9138 100644 --- a/tools/qfcc/include/options.h +++ b/tools/qfcc/include/options.h @@ -65,6 +65,7 @@ typedef struct { qboolean traditional; // behave more like qcc qboolean compile; // serparate compilation mode qboolean partial_link; // partial linking + qboolean preprocess_only;// only run cpp, don't ocmpile int strip_path; // number of leading path elements to strip // from source file names const char *output_file; diff --git a/tools/qfcc/source/cpp.c b/tools/qfcc/source/cpp.c index a67c41765..437ddc1fb 100644 --- a/tools/qfcc/source/cpp.c +++ b/tools/qfcc/source/cpp.c @@ -131,9 +131,12 @@ build_cpp_args (const char *in_name, const char *out_name) } else if (!strcmp (cpp_arg->arg, "%i")) { *arg++ = in_name; } else if (!strcmp (cpp_arg->arg, "%o")) { - *arg++ = out_name; + if (!options.preprocess_only) { + *arg++ = out_name; + } } else { - *arg++ = cpp_arg->arg; + if (!options.preprocess_only || strcmp (cpp_arg->arg, "-o") != 0) + *arg++ = cpp_arg->arg; } } *arg = 0; @@ -220,6 +223,8 @@ preprocess_file (const char *filename) } } + if (options.preprocess_only) + return 0; return fopen (tempname->str, "rt"); #else if (!options.save_temps) @@ -268,7 +273,9 @@ preprocess_file (const char *filename) exit (1); } } - if (options.save_temps) + if (options.preprocess_only) + return 0; + else if (options.save_temps) return fopen (tempname->str, "rt"); else return fdopen (tempfd, "r+t"); diff --git a/tools/qfcc/source/options.c b/tools/qfcc/source/options.c index 27608f5a4..b975885e1 100644 --- a/tools/qfcc/source/options.c +++ b/tools/qfcc/source/options.c @@ -344,9 +344,16 @@ DecodeArgs (int argc, char **argv) } break; case 'M': - add_cpp_def (nva ("-M%s", optarg)); - if (strchr ("FQT", optarg[0])) - add_cpp_def (argv[optind++]); + if (optarg) { + add_cpp_def (nva ("-M%s", optarg)); + if (!strchr (optarg, 'D')) + options.preprocess_only = 1; + if (strchr ("FQT", optarg[0])) + add_cpp_def (argv[optind++]); + } else { + options.preprocess_only = 1; + add_cpp_def (nva ("-M")); + } break; default: usage (1); diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 7c92e0bef..d0dcb5b1e 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -463,6 +463,8 @@ compile_to_obj (const char *file, const char *obj) int err; yyin = preprocess_file (file); + if (!yyin) + return !options.preprocess_only; InitData (); clear_frame_macros (); @@ -478,7 +480,7 @@ compile_to_obj (const char *file, const char *obj) pr.source_file = ReuseString (strip_path (file)); err = yyparse () || pr.error_count; fclose (yyin); - if (cpp_name && (!options.save_temps)) { + if (cpp_name && !options.save_temps) { if (unlink (tempname->str)) { perror ("unlink"); exit (1); @@ -623,6 +625,8 @@ progs_src_compile (void) printf ("compiling %s\n", filename->str); yyin = preprocess_file (filename->str); + if (!yyin) + return !options.preprocess_only; pr.source_file = ReuseString (strip_path (filename->str)); pr.source_line = 1;