From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA11075; Tue, 14 Aug 2001 21:11:15 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA11036 for ; Tue, 14 Aug 2001 21:11:14 +0200 (MET DST) Received: from postoffice.mail.cornell.edu (postoffice.mail.cornell.edu [132.236.56.7]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f7EJBD123899 for ; Tue, 14 Aug 2001 21:11:14 +0200 (MET DST) Received: from milhouse.cs.cornell.edu.cs.cornell.edu (dhcp99-208.cs.cornell.edu [128.84.99.208]) by postoffice.mail.cornell.edu (8.9.3/8.9.3) with ESMTP id PAA04090 for ; Tue, 14 Aug 2001 15:11:12 -0400 (EDT) To: caml-list@inria.fr Subject: [Caml-list] Patch that adds -pp option to ocamldep From: Paul Stodghill Date: 14 Aug 2001 15:11:12 -0400 Message-ID: User-Agent: Gnus/5.090003 (Oort Gnus v0.03) XEmacs/21.4 (Artificial Intelligence) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Enjoy. Please let me know if you find any bugs in this. --- tools/ocamldep.ml.ORIG Fri Mar 23 11:57:45 2001 +++ tools/ocamldep.ml Tue Aug 14 15:06:03 2001 @@ -319,7 +319,28 @@ let error_occurred = ref false -let file_dependencies source_file = +let preprocessor = ref None + +let preprocess sourcefile = + match !preprocessor with + None -> sourcefile + | Some pp -> + let tmpfile = Filename.temp_file "camlpp" "" in + let comm = Printf.sprintf "%s %s > %s" pp sourcefile tmpfile in + if Sys.command comm <> 0 then begin + Misc.remove_file tmpfile; + Printf.eprintf "Preprocessing error\n"; + exit 2 + end; + tmpfile + +let remove_preprocessed inputfile = + match !preprocessor with + None -> () + | Some _ -> Misc.remove_file inputfile + +let file_dependencies raw_source_file = + let source_file = preprocess raw_source_file in Location.input_name := source_file; if Sys.file_exists source_file then begin try @@ -327,9 +348,9 @@ let ic = open_in_bin source_file in try let lb = Lexing.from_channel ic in - if Filename.check_suffix source_file ".ml" then begin + if Filename.check_suffix raw_source_file ".ml" then begin add_use_file StringSet.empty (Parse.use_file lb); - let basename = Filename.chop_suffix source_file ".ml" in + let basename = Filename.chop_suffix raw_source_file ".ml" in let init_deps = if Sys.file_exists (basename ^ ".mli") then let cmi_name = basename ^ ".cmi" in ([cmi_name], [cmi_name]) @@ -339,17 +360,17 @@ print_dependencies (basename ^ ".cmo") byt_deps; print_dependencies (basename ^ ".cmx") opt_deps end else - if Filename.check_suffix source_file ".mli" then begin + if Filename.check_suffix raw_source_file ".mli" then begin add_signature StringSet.empty (Parse.interface lb); - let basename = Filename.chop_suffix source_file ".mli" in + let basename = Filename.chop_suffix raw_source_file ".mli" in let (byt_deps, opt_deps) = StringSet.fold find_dependency !free_structure_names ([], []) in print_dependencies (basename ^ ".cmi") byt_deps end else (); - close_in ic + close_in ic; remove_preprocessed source_file with x -> - close_in ic; raise x + close_in ic; remove_preprocessed source_file; raise x with x -> let report_err = function | Lexer.Error(err, start, stop) -> @@ -375,6 +396,8 @@ Arg.parse [ "-I", Arg.String(fun dir -> load_path := !load_path @ [dir]), " Add to the list of include directories"; + "-pp", Arg.String(fun cmd -> preprocessor := Some(cmd)), + " Pipe sources through preprocessor "; "-native", Arg.Set native_only, " Generate dependencies for a pure native-code project (no .cmo files)" ] file_dependencies usage; milhouse$ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr