Browse thread
[Caml-list] Patch that adds -pp option to ocamldep
- Paul Stodghill
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Paul Stodghill <stodghil@c...> |
| Subject: | [Caml-list] Patch that adds -pp option to ocamldep |
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]),
"<dir> Add <dir> to the list of include directories";
+ "-pp", Arg.String(fun cmd -> preprocessor := Some(cmd)),
+ "<command> Pipe sources through preprocessor <command>";
"-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