preprocessising fixes, including detecting when to stop at the preprocessing

stage.
This commit is contained in:
Bill Currie 2002-08-13 22:02:07 +00:00
parent 8474f145d1
commit 53b257c918
4 changed files with 26 additions and 7 deletions

View file

@ -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;

View file

@ -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");

View file

@ -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);

View file

@ -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;