Blame 0004-Detect-OCaml-version-used-for-the-ocaml-bridge-in-th.patch

fd4fc68
From 07fef81c576b3c94d13acd1880538b8140767a19 Mon Sep 17 00:00:00 2001
fd4fc68
From: =?UTF-8?q?Kim=20Nguy=E1=BB=85n?= <kn@lri.fr>
fd4fc68
Date: Sat, 2 Aug 2014 23:02:56 +0200
fab6100
Subject: [PATCH 04/11] Detect OCaml version used for the ocaml bridge in the
fd4fc68
 configure script.
fd4fc68
fd4fc68
---
fd4fc68
 configure.ml | 84 ++++++++++++++++++++++++++++++++++--------------------------
fd4fc68
 1 file changed, 48 insertions(+), 36 deletions(-)
fd4fc68
fd4fc68
diff --git a/configure.ml b/configure.ml
fd4fc68
index 3e60372..4860dfe 100644
fd4fc68
--- a/configure.ml
fd4fc68
+++ b/configure.ml
fd4fc68
@@ -29,7 +29,7 @@ Optional features:
fd4fc68
  expat                 support for the expat XML parser
fd4fc68
  curl                  support for the libcurl library
fd4fc68
  netclient             support for the netclient library
fd4fc68
- cgi                   support for the cgi library 
fd4fc68
+ cgi                   support for the cgi library
fd4fc68
 
fd4fc68
 OCaml/CDuce interface:
fd4fc68
  --mliface=DIR         build the interface with the OCaml sources in DIR
fd4fc68
@@ -44,11 +44,11 @@ if not_distrib then print_string "
fd4fc68
  --wprefix=WPREFIX     root directory of the web-server [/var/www]
fd4fc68
  --cgidir=DIR          install the cgi-bin interpreter in DIR [WPREFIX/cgi-bin]
fd4fc68
  --htmldir=DIR         install the website in DIR [WPREFIX/html]
fd4fc68
- --sessiondir=DIR      store the open sessions of the cgi-bin in DIR 
fd4fc68
+ --sessiondir=DIR      store the open sessions of the cgi-bin in DIR
fd4fc68
                        [/tmp/cduce_sessions]
fd4fc68
 "
fd4fc68
 
fd4fc68
-let features = 
fd4fc68
+let features =
fd4fc68
   [ "ocamlopt", ref `auto;
fd4fc68
     "mliface", ref `auto;
fd4fc68
     "pxp", ref `auto;
fd4fc68
@@ -57,8 +57,8 @@ let features =
fd4fc68
     "netclient", ref `auto;
fd4fc68
     "cgi", ref `auto;
fd4fc68
     "pxp_wlex", ref `no ]
fd4fc68
-  
fd4fc68
-let vars = 
fd4fc68
+
fd4fc68
+let vars =
fd4fc68
   [ "prefix", ref "/usr/local";
fd4fc68
     "bindir", ref "";
fd4fc68
     "mandir", ref "";
fd4fc68
@@ -74,7 +74,7 @@ let vars =
fd4fc68
 
fd4fc68
 
fd4fc68
 let src_dirs = ["/usr/src"; "/usr/local/src"; "/tmp"]
fd4fc68
-	
fd4fc68
+
fd4fc68
 let fatal s = printf "*** Fatal error: %s\n" s; exit 1
fd4fc68
 let warning s = printf "* Warning: %s\n" s
fd4fc68
 
fd4fc68
@@ -93,7 +93,7 @@ let start_with s p =
fd4fc68
   let ls = String.length s and lp = String.length p in
fd4fc68
   if (ls >= lp) && (String.sub s 0 lp = p)
fd4fc68
   then Some (String.sub s lp (ls - lp)) else None
fd4fc68
-    
fd4fc68
+
fd4fc68
 let parse_arg s =
fd4fc68
   if s = "--help" then (usage (); exit 0)
fd4fc68
   else
fd4fc68
@@ -121,20 +121,20 @@ let print s = print_string s; flush stdout
fd4fc68
 let check_feature f p =
fd4fc68
   printf "%s: " f;
fd4fc68
   match !(List.assoc f features) with
fd4fc68
-    | `no -> 
fd4fc68
+    | `no ->
fd4fc68
 	print "disabled\n"; false
fd4fc68
-    | `yes -> 
fd4fc68
+    | `yes ->
fd4fc68
 	print "checking... ";
fd4fc68
-	if p () 
fd4fc68
-	then (print "ok\n"; true) 
fd4fc68
+	if p ()
fd4fc68
+	then (print "ok\n"; true)
fd4fc68
 	else (print "failed !\n"; fatal "Required feature is not available")
fd4fc68
-    | `auto -> 
fd4fc68
+    | `auto ->
fd4fc68
 	print "autodetecting... ";
fd4fc68
-	if p () 
fd4fc68
+	if p ()
fd4fc68
 	then (print "enabled\n"; true)
fd4fc68
 	else (print "disabled\n"; false)
fd4fc68
 
fd4fc68
-let native = 
fd4fc68
+let native =
fd4fc68
   check_feature "ocamlopt" (fun () -> command "ocamlfind ocamlopt")
fd4fc68
 
fd4fc68
 let check_pkg p () =
fd4fc68
@@ -142,8 +142,8 @@ let check_pkg p () =
fd4fc68
 (*    ignore (Findlib.package_property
fd4fc68
       [ (if native then "native" else "bytecode") ]
fd4fc68
       p "archive"); *)
fd4fc68
-    command 
fd4fc68
-      (sprintf 
fd4fc68
+    command
fd4fc68
+      (sprintf
fd4fc68
 	 "ocamlfind ocaml%s -package %s -linkpkg -o configure.try && rm -f configure.try"
fd4fc68
 	 (if native then "opt" else "c")
fd4fc68
 	 p)
fd4fc68
@@ -151,32 +151,42 @@ let check_pkg p () =
fd4fc68
 
fd4fc68
 let need_pkg p =
fd4fc68
   printf "Checking for package %s... " p; flush stdout;
fd4fc68
-  if not (check_pkg p ()) 
fd4fc68
+  if not (check_pkg p ())
fd4fc68
   then (print "failed !\n"; fatal "Required package is not available")
fd4fc68
   else (print "ok\n")
fd4fc68
 
fd4fc68
-let dir ?def d = 
fd4fc68
+let dir ?def d =
fd4fc68
   let s = !(List.assoc d vars) in
fd4fc68
   if s <> "" then s
fd4fc68
-  else match def with 
fd4fc68
-    | Some x -> x 
fd4fc68
+  else match def with
fd4fc68
+    | Some x -> x
fd4fc68
     | None -> fatal (sprintf "%s cannot be empty" d)
fd4fc68
 
fd4fc68
 
fd4fc68
-let exe = match Sys.os_type with 
fd4fc68
+let exe = match Sys.os_type with
fd4fc68
   | "Win32" ->
fd4fc68
-      print "Win32 detected... executable will have .exe extension\n"; ".exe" 
fd4fc68
+      print "Win32 detected... executable will have .exe extension\n"; ".exe"
fd4fc68
   | "Cygwin" ->
fd4fc68
-      print "Cygwin detected... executable will have .exe extension\n"; ".exe" 
fd4fc68
+      print "Cygwin detected... executable will have .exe extension\n"; ".exe"
fd4fc68
   | _ -> ""
fd4fc68
 
fd4fc68
-let add_icon = match Sys.os_type with 
fd4fc68
+let add_icon = match Sys.os_type with
fd4fc68
   | "Win32" | "Cygwin" -> true
fd4fc68
   | _ -> false
fd4fc68
 
fd4fc68
 let check_mliface dir =
fd4fc68
 (*  Sys.file_exists (Filename.concat dir "typing/types.ml") *)
fd4fc68
-  Sys.file_exists (Filename.concat dir "typing/types.ml") 
fd4fc68
+  List.for_all (fun f ->
fd4fc68
+    Sys.file_exists (Filename.concat dir f))
fd4fc68
+    [ "typing/types.ml"; "VERSION" ]
fd4fc68
+
fd4fc68
+let mliface_version dir =
fd4fc68
+  let ic = open_in (Filename.concat dir "VERSION") in
fd4fc68
+  let s = input_line ic in
fd4fc68
+  close_in ic;
fd4fc68
+  if s < "4" then "3.x"
fd4fc68
+  else if s < "4.02" then "4.01"
fd4fc68
+  else "4.02"
fd4fc68
 
fd4fc68
 let ocaml_stdlib () =
fd4fc68
   if (Sys.command "ocamlc -where > ocaml_stdlib" <> 0) then
fd4fc68
@@ -188,25 +198,27 @@ let ocaml_stdlib () =
fd4fc68
   s
fd4fc68
 
fd4fc68
 let make_absolute dir =
fd4fc68
-  if Filename.is_relative dir 
fd4fc68
+  if Filename.is_relative dir
fd4fc68
   then Filename.concat (Sys.getcwd ()) dir
fd4fc68
   else dir
fd4fc68
 
fd4fc68
-let ml_interface = 
fd4fc68
+let ml_interface, mliface_version =
fd4fc68
   let dir1 = !(List.assoc "mliface" vars) in
fd4fc68
   let dirs = if dir1 = "" then [] else [ make_absolute dir1 ] in
fd4fc68
   print "ocaml sources... ";
fd4fc68
   let rec loop = function
fd4fc68
-    | [] -> 
fd4fc68
+    | [] ->
fd4fc68
 	print "not found (the interface will not be built)\n";
fd4fc68
-	None
fd4fc68
+	None, ""
fd4fc68
     | d::dirs ->
fd4fc68
 	if check_mliface d then
fd4fc68
-	  (print ("found: " ^ d ^ "\n"); Some d)
fd4fc68
+          let version = mliface_version d in
fd4fc68
+	  (print ("found: " ^ d ^ ", version " ^ version ^ "\n");
fd4fc68
+           Some d, version)
fd4fc68
 	else loop dirs
fd4fc68
   in
fd4fc68
   loop dirs
fd4fc68
-  
fd4fc68
+
fd4fc68
 let pxp = check_feature "pxp" (check_pkg "pxp")
fd4fc68
 let expat = check_feature "expat" (check_pkg "expat")
fd4fc68
 let curl = check_feature "curl" (check_pkg "curl")
fd4fc68
@@ -222,9 +234,9 @@ let cgidir = dir ~def:(wprefix^"/cgi-bin") "cgidir"
fd4fc68
 let htmldir = dir ~def:(wprefix^"/html") "htmldir"
fd4fc68
 let sessiondir = dir "sessiondir"
fd4fc68
 
fd4fc68
-let curl,netclient = 
fd4fc68
+let curl,netclient =
fd4fc68
   match curl,netclient with
fd4fc68
-    | true,true -> 
fd4fc68
+    | true,true ->
fd4fc68
 	warning "Both netclient and curl are available. Will use curl.";
fd4fc68
 	true,false
fd4fc68
     | false,false ->
fd4fc68
@@ -232,9 +244,9 @@ let curl,netclient =
fd4fc68
 	false,false
fd4fc68
     | c,n -> c,n
fd4fc68
 
fd4fc68
-let pxp,expat = 
fd4fc68
+let pxp,expat =
fd4fc68
   match pxp,expat with
fd4fc68
-    | true,true -> 
fd4fc68
+    | true,true ->
fd4fc68
 	warning "Both PXP and expat are available. Will build both and use expat by default.";
fd4fc68
 	true,true
fd4fc68
     | false,false ->
fd4fc68
@@ -282,7 +294,7 @@ let () =
fd4fc68
   fprintf out "# This file has been generated by the configure script\n";
fd4fc68
   fprintf out "NATIVE=%b\n" native;
fd4fc68
   (match ml_interface with
fd4fc68
-    | Some d -> fprintf out "ML_INTERFACE=true\nOCAML_SRC=%s\n" d
fd4fc68
+    | Some d -> fprintf out "ML_INTERFACE=true\nOCAML_SRC=%s\nML_INTERFACE_VERSION=%s\n" d mliface_version
fd4fc68
     | None -> fprintf out "ML_INTERFACE=false\n");
fd4fc68
   fprintf out "PXP=%b\n" pxp;
fd4fc68
   fprintf out "EXPAT=%b\n" expat;
fd4fc68
-- 
fd4fc68
1.9.3
fd4fc68