*/
static int compile_preprocessed_source_code;
+/* Whether the output is a precompiled header */
+static int output_is_precompiled_header = 0;
+
/* How long (in microseconds) to wait before breaking a stale lock. */
unsigned lock_staleness_limit = 2000000;
/* When using the preprocessor, some arguments don't contribute
to the hash. The theory is that these arguments will change
the output of -E if they are going to have any effect at
- all. */
- if (!direct_mode) {
+ all. For precompiled headers this might not be the case. */
+ if (!direct_mode && !output_is_precompiled_header) {
if (i < args->argc-1) {
if (str_eq(args->argv[i], "-D") ||
str_eq(args->argv[i], "-I") ||
int found_c_opt = 0;
int found_S_opt = 0;
int found_arch_opt = 0;
- int output_is_precompiled_header = 0;
+ int found_pch = 0;
const char *explicit_language = NULL; /* As specified with -x. */
const char *file_language; /* As deduced from file extension. */
const char *actual_language; /* Language to actually use. */
};
int j;
char *relpath;
+ char *pchpath;
for (j = 0; opts[j]; j++) {
if (str_eq(argv[i], opts[j])) {
if (i == argc-1) {
args_add(stripped_args, argv[i]);
relpath = make_relative_path(x_strdup(argv[i+1]));
args_add(stripped_args, relpath);
+
+ /* Try to be smart about detecting precompiled headers */
+ pchpath = format("%s.gch", argv[i+1]);
+ if (stat(pchpath, &st) == 0 && S_ISDIR(st.st_mode)) {
+ found_pch = 1;
+ }
+
+ free(pchpath);
free(relpath);
i++;
break;
if (input_charset) {
args_add(*preprocessor_args, input_charset);
}
+ if (found_pch) {
+ cc_log("Use of precompiled header detected, adding -fpch-preprocess");
+ args_add(*preprocessor_args, "-fpch-preprocess");
+ }
if (explicit_language) {
args_add(*preprocessor_args, "-x");
args_add(*preprocessor_args, explicit_language);