Blob Blame History Raw
From 07fef81c576b3c94d13acd1880538b8140767a19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kim=20Nguy=E1=BB=85n?= <kn@lri.fr>
Date: Sat, 2 Aug 2014 23:02:56 +0200
Subject: [PATCH 04/11] Detect OCaml version used for the ocaml bridge in the
 configure script.

---
 configure.ml | 84 ++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 48 insertions(+), 36 deletions(-)

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