diff --git a/src/util/compilationDatabase.ml b/src/util/compilationDatabase.ml index 54a46e2bf8..ecd96f2d5c 100644 --- a/src/util/compilationDatabase.ml +++ b/src/util/compilationDatabase.ml @@ -72,6 +72,10 @@ let load_and_preprocess ~all_cppflags filename = | (o_i, _) -> begin match List.split_at o_i arguments with | (arguments_program :: arguments_init, _ :: o_file :: arguments_tl) -> + let arguments_init = match List.findi (fun i e -> e = "-MF") arguments_init with + | (mf_i,_) -> List.remove_at mf_i (List.remove_at mf_i arguments_init) + | exception Not_found -> arguments_init + in let preprocess_arguments = all_cppflags @ "-E" :: "-MMD" :: "-MT" :: file :: arguments_init @ "-o" :: preprocessed_file :: arguments_tl in Filename.quote_command arguments_program preprocess_arguments | _ -> diff --git a/src/util/makefileParser.mly b/src/util/makefileParser.mly index 6a2946a7d7..f17df95c20 100644 --- a/src/util/makefileParser.mly +++ b/src/util/makefileParser.mly @@ -3,14 +3,16 @@ %token NEWLINE %token EOF -%type deps +%type <(string list * string list) list> deps %start deps %% deps: - | IDENTIFIER COLON identifier_list NEWLINE EOF { ($1, $3) } + | identifier_nonempty_list COLON identifier_list NEWLINE deps { ($1, $3) :: $5 } + | NEWLINE identifier_nonempty_list COLON identifier_list NEWLINE deps { ($2, $4) :: $6 } + | EOF { [] } ; identifier_list: diff --git a/src/util/preprocessor.ml b/src/util/preprocessor.ml index 956bf390fc..8c1ec02ae9 100644 --- a/src/util/preprocessor.ml +++ b/src/util/preprocessor.ml @@ -42,7 +42,11 @@ let dependencies: (string, string list) Hashtbl.t = Hashtbl.create 3 let parse_makefile_deps makefile = BatFile.with_file_in makefile (fun input -> let lexbuf = Lexing.from_channel input in - let (rule, deps) = MakefileParser.deps MakefileLexer.token lexbuf in - let deps = List.remove deps rule in - Hashtbl.replace dependencies rule deps + let rules = MakefileParser.deps MakefileLexer.token lexbuf in + List.iter (fun (rule, deps) -> + List.iter (fun r -> + let deps = List.remove deps r in + Hashtbl.replace dependencies r deps + ) rule + ) rules )