Use OCAML_STDLIB_DIR more often
authorStéphane Glondu <glondu@debian.org>
Sat, 3 Aug 2024 00:13:47 +0000 (02:13 +0200)
committerStéphane Glondu <glondu@debian.org>
Sat, 3 Aug 2024 00:55:50 +0000 (02:55 +0200)
debian/dispatch.ml
debian/rules

index 53009bdc6654f5d63ca9b5ca386d6c1c8ce1a7ee..c7c03981a14d3d0a9900a69f52fba3d409b70746 100644 (file)
@@ -3,6 +3,16 @@
   Copyright © 2019-2024 Stéphane Glondu <glondu@debian.org>
 *)
 
+let stdlib_dir =
+  match Sys.getenv_opt "OCAML_STDLIB_DIR" with
+  | Some x ->
+     let n = String.length x in
+     if n > 0 && x.[0] = '/' then
+       String.sub x 1 (n - 1)
+     else
+       failwith "OCAML_STDLIB_DIR does not start with /"
+  | None -> failwith "OCAML_STDLIB_DIR is missing"
+
 let read_lines fn =
   let ic = open_in fn in
   Fun.protect
@@ -50,10 +60,10 @@ let dev_stdlib = ref []
 let run_stdlib = ref []
 let dev_compiler_libs = ref []
 
-let ocaml_base = ref [ "debian/ld.conf usr/lib/ocaml" ]
+let ocaml_base = ref [ "debian/ld.conf " ^ stdlib_dir ]
 let ocaml =
   ref [
-      "debian/native-archs usr/lib/ocaml";
+      "debian/native-archs " ^ stdlib_dir;
     ]
 let ocaml_interp =
   ref [
@@ -101,20 +111,20 @@ let () =
       "usr/bin/ocamlmklib", ocaml;
       "usr/bin/ocamlprof", ocaml;
       "usr/bin/ocamlmktop", ocaml;
-      "usr/lib/ocaml/camlheader", ocaml;
-      "usr/lib/ocaml/camlheaderd", ocaml;
-      "usr/lib/ocaml/camlheaderi", ocaml;
-      "usr/lib/ocaml/eventlog_metadata", ocaml;
-      "usr/lib/ocaml/Makefile.config", ocaml;
-      "usr/lib/ocaml/extract_crc", ocaml;
-      "usr/lib/ocaml/camlheader_ur", ocaml;
-      "usr/lib/ocaml/expunge", ocaml;
-      "usr/lib/ocaml/VERSION", ocaml_base;
-      "usr/lib/ocaml/target_camlheaderd", ocaml;
-      "usr/lib/ocaml/objinfo_helper", ocaml;
-      "usr/lib/ocaml/target_camlheaderi", ocaml;
-      "usr/lib/ocaml/runtime-launch-info", ocaml;
-      "usr/lib/ocaml/sys.ml.in", ocaml;
+      stdlib_dir ^ "/camlheader", ocaml;
+      stdlib_dir ^ "/camlheaderd", ocaml;
+      stdlib_dir ^ "/camlheaderi", ocaml;
+      stdlib_dir ^ "/eventlog_metadata", ocaml;
+      stdlib_dir ^ "/Makefile.config", ocaml;
+      stdlib_dir ^ "/extract_crc", ocaml;
+      stdlib_dir ^ "/camlheader_ur", ocaml;
+      stdlib_dir ^ "/expunge", ocaml;
+      stdlib_dir ^ "/VERSION", ocaml_base;
+      stdlib_dir ^ "/target_camlheaderd", ocaml;
+      stdlib_dir ^ "/objinfo_helper", ocaml;
+      stdlib_dir ^ "/target_camlheaderi", ocaml;
+      stdlib_dir ^ "/runtime-launch-info", ocaml;
+      stdlib_dir ^ "/sys.ml.in", ocaml;
       "usr/bin/ocamlmklib.opt", ocaml;
       "usr/bin/ocamllex.byte", ocaml;
       "usr/bin/ocamldebug", ocaml;
@@ -165,7 +175,7 @@ let base_set = ref SSet.empty
 
 let () =
   List.iter (fun x ->
-      match chop_prefix ~prefix:"usr/lib/ocaml/stdlib__" x with
+      match chop_prefix ~prefix:(stdlib_dir ^ "/stdlib__") x with
       | None -> ()
       | Some x ->
          let i = String.index x '.' in
@@ -223,15 +233,15 @@ let remaining =
   installed_files
   |> move_all_to ocaml ((=) "usr/share/doc/ocaml/Changes")
   |> move_all_to ocaml ((=) "usr/share/doc/ocaml/README.adoc")
-  |> move_all_to ocaml (String.starts_with ~prefix:"usr/lib/ocaml/caml/")
-  |> move_all_to dev_stdlib (String.starts_with ~prefix:"usr/lib/ocaml/threads/")
-  |> move_all_to dev_stdlib (String.starts_with ~prefix:"usr/lib/ocaml/std_exit.")
-  |> move_all_to dev_stdlib (String.starts_with ~prefix:"usr/lib/ocaml/stdlib.")
-  |> move_all_to dev_stdlib (String.starts_with ~prefix:"usr/lib/ocaml/dynlink")
-  |> move_all_to dev_compiler_libs (String.starts_with ~prefix:"usr/lib/ocaml/topdirs.")
-  |> move_all_to dev_compiler_libs (String.starts_with ~prefix:"usr/lib/ocaml/compiler-libs/")
-  |> move_all_to dev_compiler_libs (String.starts_with ~prefix:"usr/lib/ocaml/ocamldoc/")
-  |> move_all_to dev_compiler_libs (String.starts_with ~prefix:"usr/lib/ocaml/runtime_events/")
+  |> move_all_to ocaml (String.starts_with ~prefix:(stdlib_dir ^ "/caml/"))
+  |> move_all_to dev_stdlib (String.starts_with ~prefix:(stdlib_dir ^ "/threads/"))
+  |> move_all_to dev_stdlib (String.starts_with ~prefix:(stdlib_dir ^ "/std_exit."))
+  |> move_all_to dev_stdlib (String.starts_with ~prefix:(stdlib_dir ^ "/stdlib."))
+  |> move_all_to dev_stdlib (String.starts_with ~prefix:(stdlib_dir ^ "/dynlink"))
+  |> move_all_to dev_compiler_libs (String.starts_with ~prefix:(stdlib_dir ^ "/topdirs."))
+  |> move_all_to dev_compiler_libs (String.starts_with ~prefix:(stdlib_dir ^ "/compiler-libs/"))
+  |> move_all_to dev_compiler_libs (String.starts_with ~prefix:(stdlib_dir ^ "/ocamldoc/"))
+  |> move_all_to dev_compiler_libs (String.starts_with ~prefix:(stdlib_dir ^ "/runtime_events/"))
   |> move_all_to ocaml_man (String.ends_with ~suffix:".3o")
   |> List.filter_map process_static
   |> List.filter_map process_file
index c18dc4574fd9bb6a35076d2fab65529e7f7222da..9c95a69f6e8b30be426d61c391becda3455de793 100755 (executable)
@@ -213,7 +213,7 @@ install-stamp:
        $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
 ifeq (,$(DEB_TEST_BUILD_PREFIX))
 # Remove Debian-specific file
-       rm -f $(INSTDIR)/lib/ocaml/ld.conf
+       rm -f debian/tmp$(OCAML_STDLIB_DIR)/ld.conf
 # Remove uninstalled files
        rm -f \
          $(INSTDIR)/share/man/man1/ocamlopt.opt.1 \
@@ -232,7 +232,7 @@ endif
          $(INSTDIR)/share/doc/ocaml/LICENSE
 # Dispatch files with dh_install
        find debian/tmp \( -type f -or -type l \) -printf '%P\n' > debian/installed-files
-       boot/ocamlrun ./ocaml -nostdlib -I debian/tmp/usr/lib/ocaml debian/dispatch.ml
+       boot/ocamlrun ./ocaml -nostdlib -I debian/tmp$(OCAML_STDLIB_DIR) debian/dispatch.ml
        dh_install
 endif
        touch $@