Commits

Anonymous committed 722f204

.

Comments (0)

Files changed (9)

+~$
+^_build/
+name="ocaml_monad_io"
+version=""
+requires=""
+description="Monadic input-output with OCaml"
+
+package "lwt" (
+requires+="unix, lwt, lwt.unix"
+archive(byte)="iO_Lwt.cma"
+archive(native)="iO_Lwt.cmxa"
+)
+PKG=monad_io
+VERSION=0.1
+
+
+FILES=iO_Types.cmi iO_Lwt.cma iO_Lwt.cmxa
+
+all :
+	ocamlbuild $(FILES) \
+	  compile_tests.cmo
+
+install : all
+	ocamlfind install \
+	  -patch-version $(VERSION) \
+	  $(PKG) META \
+	  $(addprefix _build/,$(FILES)) \
+
+uninstall :
+	ocamlfind remove $(PKG)
+<**/*> : camlp4r
+
+<iO_Lwt.ml> : pkg_lwt, pkg_lwt.unix
+open IO_Types;
+module Test_Lwt_Pure = (IO_Lwt : IO_Pure);
+module Test_Lwt_PureError = (IO_Lwt : IO_PureError);
+type m +'a = Lwt.t 'a;
+
+value return = Lwt.return;
+
+value bind = Lwt.(=<<);
+
+value bind_rev = Lwt.bind;
+
+value error = Lwt.fail;
+
+value catch = Lwt.catch;
+IO_Lwt
+module type IO_Pure
+ =
+  sig
+
+    type m +'a;
+
+    value return : 'a -> m 'a;
+    value bind : ('a -> m 'b) -> m 'a -> m 'b;
+    value bind_rev : m 'a -> ('a -> m 'b) -> m 'b;
+
+  end
+;
+
+
+module type IO_PureError
+ =
+  sig
+
+    type m +'a;
+
+    value return : 'a -> m 'a;
+    value bind : ('a -> m 'b) -> m 'a -> m 'b;
+    value bind_rev : m 'a -> ('a -> m 'b) -> m 'b;
+
+    value error : exn -> m 'a;
+    value catch : (unit -> m 'a) -> (exn -> m 'a) -> m 'a;
+
+  end
+;
+open Ocamlbuild_plugin;;
+
+
+
+(**********************)
+
+(* these functions are not really officially exported *)
+let run_and_read = Ocamlbuild_pack.My_unix.run_and_read
+let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings
+
+let split s ch =
+  let x = ref [] in
+  let rec go s =
+    let pos = String.index s ch in
+    x := (String.before s pos)::!x;
+    go (String.after s (pos + 1))
+  in
+  try
+    go s
+  with Not_found -> !x
+
+let split_nl s = split s '\n'
+
+let before_space s =
+  try
+    String.before s (String.index s ' ')
+  with Not_found -> s
+
+(* this lists all supported packages *)
+let find_packages () =
+  List.map before_space (split_nl & run_and_read "ocamlfind list")
+
+(* this is supposed to list available syntaxes,
+   but I don't know how to do it. *)
+let find_syntaxes () = ["camlp4o"; "camlp4r"]
+
+(* ocamlfind command *)
+let ocamlfind x = S[A"ocamlfind"; x]
+;;
+
+let disp_ocamlfind = begin function
+   | Before_options ->
+       (* by using Before_options one let command line options have an higher priority *)
+       (* on the contrary using After_options will guarantee to have the higher priority *)
+
+       (* override default commands by ocamlfind ones *)
+       Options.ocamlc     := ocamlfind & A"ocamlc";
+       Options.ocamlopt   := ocamlfind & A"ocamlopt";
+       Options.ocamldep   := ocamlfind & A"ocamldep" (* S[A"ocamldep"; A"-verbose"] *) ;
+       Options.ocamldoc   := ocamlfind & A"ocamldoc";
+       Options.ocamlmktop := ocamlfind & A"ocamlmktop"
+
+   | After_rules ->
+
+       (* When one link an OCaml library/binary/package, one should use -linkpkg *)
+       flag ["ocaml"; "link"] & A"-linkpkg";
+
+       (* For each ocamlfind package one inject the -package option when
+       	* compiling, computing dependencies, generating documentation and
+       	* linking. *)
+       List.iter begin fun pkg ->
+         flag ["ocaml"; "compile";  "pkg_"^pkg] & S[A"-package"; A pkg];
+         flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
+         flag ["ocaml"; "doc";      "pkg_"^pkg] & S[A"-package"; A pkg];
+         flag ["ocaml"; "link";     "pkg_"^pkg] & S[A"-package"; A pkg];
+         flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
+       end (find_packages ());
+
+       (* Like -package but for extensions syntax. Morover -syntax is useless
+       	* when linking. *)
+       List.iter begin fun syntax ->
+         flag ["ocaml"; "compile";  "syntax_"^syntax] & S[A"-syntax"; A syntax];
+         flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+         flag ["ocaml"; "doc";      "syntax_"^syntax] & S[A"-syntax"; A syntax];
+         flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
+       end (find_syntaxes ());
+       
+       (* The default "thread" tag is not compatible with ocamlfind.
+          Indeed, the default rules add the "threads.cma" or "threads.cmxa"
+          options when using this tag. When using the "-linkpkg" option with
+          ocamlfind, this module will then be added twice on the command line.
+       
+          To solve this, one approach is to add the "-thread" option when using
+          the "threads" package using the previous plugin.
+        *)
+       flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
+       flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
+       flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
+       
+   | _ -> ()
+end
+
+(**********************)
+
+
+
+(*
+List.iter begin fun class_name ->
+  flag ["ocaml"; "pp"; "classes"^class_name] (S[A"-classes"; A class_name])
+end ["Show"; "Typeable"]
+;;
+*)
+
+let libdir = !Ocamlbuild_pack.Ocamlbuild_where.libdir
+;;
+
+(*
+Printf.printf "%!\n\n\nlibdir: %S\n\n\n%!"
+   !Ocamlbuild_pack.Ocamlbuild_where.libdir
+   !libdir
+   !Ocamlbuild_where.libdir
+   !Myocamlbuild_config.libdir
+   !Ocamlbuild_Myocamlbuild_config.libdir
+*)
+
+let stdlib_dir = Ocamlbuild_pack.Ocaml_utils.stdlib_dir;;
+
+
+let str_replace_char str cfrom cto =
+  let str = String.copy str in
+  let () =
+    for i = 0 to String.length str - 1 do
+      ( if str.[i] = cfrom
+        then str.[i] <- cto
+        else ()
+      )
+      done
+  in
+  str
+;;
+
+
+let disp_deriving = (function
+| After_rules ->
+    let stdlib_dir = Lazy.force stdlib_dir in
+    let syn_dir = stdlib_dir / "deriving" / "syntax" in
+(*
+    let syn_dir =
+      if Sys.os_type = "Win32"
+      then str_replace_char syn_dir '/' '\\'
+      else syn_dir
+    in
+*)
+    ( flag ["ocaml"; "pp"; "deriving"]
+        (S[A"-I"; P(syn_dir);
+          S(List.map
+              (fun m -> A(m^".cmo"))
+              ["utils"; "type"; "base"; "id"; "extend"; "show_class"]
+           )
+          ]
+        )
+    ; flag ["ocaml"; "compile"; "deriving"]
+        (S[A"-I"; P("+deriving" / "lib")])
+    ; flag ["ocaml"; "link"; "deriving"; "byte"]
+        (S[A"-I"; P("+deriving" / "lib"); A"deriving.cma"])
+    ; flag ["ocaml"; "link"; "deriving"; "native"]
+        (S[A"-I"; P("+deriving" / "lib"); A"deriving.cmxa"])
+    )
+|  _ -> ()
+);;
+
+
+dispatch
+(fun x -> (disp_ocamlfind x; disp_deriving x))
+;;