caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Paul Stodghill <stodghil@cs.cornell.edu>
To: caml-list@inria.fr
Subject: [Caml-list] Patch that adds -pp option to ocamldep
Date: 14 Aug 2001 15:11:12 -0400	[thread overview]
Message-ID: <yz1wv46o3sf.fsf@milhouse.cs.cornell.edu> (raw)

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


             reply	other threads:[~2001-08-14 19:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-14 19:11 Paul Stodghill [this message]
2001-08-14 19:53 ` Daniel de Rauglaudre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yz1wv46o3sf.fsf@milhouse.cs.cornell.edu \
    --to=stodghil@cs.cornell.edu \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).