Commits

ysulsky committed b8af308

core: build fixes

Comments (0)

Files changed (3)

base/core/extended/oasis.sh

 EOF
 
 make_myocamlbuild "$HERE/myocamlbuild.ml" <<EOF
-let endswith x s =
-  let len_x = String.length x and len_s = String.length s in
-  (len_x <= len_s) && x = String.sub s (len_s - len_x) len_x
-
-let select_files dir ext =
-  List.map (Pathname.concat dir)
-    (List.filter (endswith ext)
-      (Array.to_list (Sys.readdir dir)))
-
-let mlh_files = select_files "lib/" ".mlh"
+$useful_ocaml_functions
 
 let dispatch = function
   | After_rules as e ->
-    dep  ["ocaml"; "ocamldep"; "mlh"] mlh_files;
-    List.iter (fun tag ->
-      flag ["mlh"; "ocaml"; tag] (S[A"-ppopt"; A"-Ilib/"]))
-      ["ocamldep"; "compile"];
+
+    dep  ["ocaml"; "ocamldep"; "mlh"] (select_files "lib/" ".mlh");
+
+    flag ["mlh"; "ocaml"; "ocamldep"] (S[A"-ppopt"; A"-Ilib/"]);
+    flag ["mlh"; "ocaml"; "compile"]  (S[A"-ppopt"; A"-Ilib/"]);
+
+    begin match getconf "LFS64_CFLAGS" with
+    | None -> ()
+    | Some flags -> flag ["compile"; "c"] (S[A"-ccopt"; A flags])
+    end;
+
     dispatch_default e
   | e -> dispatch_default e
 
 EOF
 
 make_setup_ml "$HERE/setup.ml" <<EOF
-let test cmd =
-  match Sys.command (cmd ^ " 2>/dev/null") with
-  | 0 -> true
-  | 1 -> false
-  | _ -> failwith ("command '"^cmd^"' failed.")
-
-let getconf var =
-  let f_exit_code = ignore in
-  let ctxt = !BaseContext.default in
-  OASISExec.run_read_output ~f_exit_code ~ctxt "getconf" [var]
+$useful_ocaml_functions
 
 let linux_possible = test "uname | grep -q -i linux"
 let timers_possible =
   match getconf "_POSIX_TIMERS" with
-  | [x] -> (try int_of_string x >= 200112 with _ -> false)
-  |  _  -> false
+  | None   -> false
+  | Some x -> (try int_of_string x >= 200112 with _ -> false)
 
 let map_section = function
   | Flag (cs, flag) when cs.cs_name = "linux" ->

base/core/oasis.sh

   Modules:            Install_printers
   XMETARequires:      core
   XMETADescription:   Toplevel printers for Core
+  BuildDepends:       core
 
 Executable test_runner
   Path:               lib_test
 EOF
 
 make_myocamlbuild "$HERE/myocamlbuild.ml" <<EOF
-let endswith x s =
-  let len_x = String.length x and len_s = String.length s in
-  (len_x <= len_s) && x = String.sub s (len_s - len_x) len_x
-
-let select_files dir ext =
-  List.map (Pathname.concat dir)
-    (List.filter (endswith ext)
-      (Array.to_list (Sys.readdir dir)))
-
-let mlh_files = select_files "lib/" ".mlh"
+$useful_ocaml_functions
 
 let dispatch = function
   | After_rules as e ->
-    dep  ["ocaml"; "ocamldep"; "mlh"] mlh_files;
-    List.iter (fun tag ->
-      flag ["mlh"; "ocaml"; tag] (S[A"-ppopt"; A"-Ilib/"]))
-      ["ocamldep"; "compile"];
+
+    dep  ["ocaml"; "ocamldep"; "mlh"] (select_files "lib/" ".mlh");
+
+    flag ["mlh"; "ocaml"; "ocamldep"] (S[A"-ppopt"; A"-Ilib/"]);
+    flag ["mlh"; "ocaml"; "compile"]  (S[A"-ppopt"; A"-Ilib/"]);
+
+    begin match getconf "LFS64_CFLAGS" with
+    | None -> ()
+    | Some flags -> flag ["compile"; "c"] (S[A"-ccopt"; A flags])
+    end;
+
+    if test "ld -lrt -shared -o /dev/null 2>/dev/null" then begin
+      flag ["ocamlmklib"; "c"]                      (S[A"-lrt"]);
+      flag ["use_libcore_stubs"; "link"] (S[A"-cclib"; A"-lrt"]);
+    end;
+
     dispatch_default e
   | e -> dispatch_default e
 
 EOF
 
 make_setup_ml "$HERE/setup.ml" <<EOF
-let test cmd =
-  match Sys.command (cmd ^ " 2>/dev/null") with
-  | 0 -> true
-  | 1 -> false
-  | _ -> failwith ("command '"^cmd^"' failed.")
+$useful_ocaml_functions
 
-let getconf var =
-  let f_exit_code = ignore in
-  let ctxt = !BaseContext.default in
-  OASISExec.run_read_output ~f_exit_code ~ctxt "getconf" [var]
-
-let use_librt = test "ld -lrt -shared -o /dev/null"
 let linux_possible = test "uname | grep -q -i linux"
 let timers_possible =
   match getconf "_POSIX_TIMERS" with
-  | [x] -> (try int_of_string x >= 200112 with _ -> false)
-  |  _  -> false
-
-let cc_libs =
-  if use_librt then ["-lrt"] else []
-
-let cc_opts =
-  getconf "LFS64_CFLAGS"
+  | None   -> false
+  | Some x -> (try int_of_string x >= 200112 with _ -> false)
 
 let map_section = function
-  | Library (cs, bs, libs) when cs.cs_name = "core" ->
-    Library (cs, { bs with
-                   bs_ccopt     = [(OASISExpr.EBool true, cc_opts)];
-                   bs_cclib     = [(OASISExpr.EBool true, cc_libs)]; },
-             libs)
   | Flag (cs, flag) when cs.cs_name = "linux" ->
     Flag (cs, { flag with
                 flag_default = [OASISExpr.EBool true,      linux_possible;
 EOF
 }
 
+useful_ocaml_functions='
+let protectx x ~f ~finally =
+  let r = try f x with exn -> finally x; raise exn in
+  finally x; r
+
+let read_lines ic =
+  let rec loop acc =
+    match try Some (input_line ic) with End_of_file -> None with
+    | Some line -> loop (line :: acc)
+    | None -> List.rev acc
+  in loop []
+
+let test cmd =
+  match Sys.command cmd with
+  | 0 -> true
+  | 1 -> false
+  | _ -> failwith ("command '"^cmd^"' failed.")
+
+let sh_lines cmd =
+  protectx (Filename.temp_file "ocamlbuild_cmd" ".txt")
+    ~f:(fun fn ->
+      ignore (Sys.command ("(" ^ cmd ^ ") >" ^ fn) : int);
+      protectx (open_in fn) ~f:read_lines ~finally:close_in)
+    ~finally:Sys.remove
+
+let getconf var =
+  let cmd = Printf.sprintf "getconf %S" var in
+  match sh_lines cmd with
+  | []  -> None
+  | [x] -> Some x
+  | _   -> failwith ("`"^cmd^"` returned multiple lines")
+
+let endswith x s =
+  let len_x = String.length x and len_s = String.length s in
+  (len_x <= len_s) && x = String.sub s (len_s - len_x) len_x
+
+let select_files dir ext =
+  List.map (Filename.concat dir)
+    (List.filter (endswith ext)
+      (Array.to_list (Sys.readdir dir)))
+'
+
 HERE=$(dirname -- "$0")
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.