Debian Codegraph @

test-suite/tools/coq_config_to_make.ml

raw symbols SCIP
1 (* Flags used to compile Coq but _not_ plugins (via rocq makefile) *)
2 module Prefs = struct
3 type t = { warn_error : bool }
4 let default = { warn_error = true }
5 end
6
7 let die fmt = Printf.kfprintf (fun _ -> exit 1) stderr (fmt^^"\n%!")
8
9 (** This Makefile is only used in the test-suite now, remove eventually. *)
10 let write_makefile coqprefix coqlibinstall best_compiler ocamlfind caml_flags coq_caml_flags o () =
11 let pr s = Printf.fprintf o s in
12 pr "###### Coq Test suite configuration ##############################\n";
13 pr "# #\n";
14 pr "# This file is generated by the script \"coq_config_to_make\" #\n";
15 pr "# DO NOT EDIT IT !! DO NOT EDIT IT !! DO NOT EDIT IT !! #\n";
16 pr "# #\n";
17 pr "##################################################################\n\n";
18
19 pr "# Paths where Coq is installed\n";
20 pr "COQPREFIX='%s'\n" coqprefix;
21 pr "COQLIBINSTALL='%s'\n\n" coqlibinstall;
22 pr "# The best compiler: native (=opt) or bytecode (=byte)\n";
23 pr "BEST=%s\n\n" best_compiler;
24 pr "# Findlib command\n";
25 pr "OCAMLFIND=%S\n" ocamlfind;
26 pr "# Caml flags\n";
27 pr "CAMLFLAGS=%s %s\n" caml_flags coq_caml_flags;
28 pr "# coqc was said to be '%s'\n" Sys.argv.(1);
29 pr "ARCH=%s\n" Coq_config.arch;
30 ()
31
32 let coq_warn_error (prefs : Prefs.t) =
33 if prefs.warn_error
34 then "-warn-error +a"
35 else ""
36
37 let canonical_path_name p =
38 let current = Sys.getcwd () in
39 try
40 Sys.chdir p;
41 let p' = Sys.getcwd () in
42 Sys.chdir current;
43 p'
44 with Sys_error _ ->
45 (* We give up to find a canonical name and just simplify it... *)
46 Filename.concat current p
47
48 let find_in_PATH f =
49 if Filename.basename f <> f then Some f
50 else match Sys.getenv_opt "PATH" with
51 | None -> None
52 | Some paths ->
53 let sep = if Coq_config.arch_is_win32 then ';' else ':' in
54 let paths = String.split_on_char sep paths in
55 paths |> List.map (fun path -> if path = "" then f else Filename.concat path f)
56 |> List.find_opt Sys.file_exists
57
58 let main () =
59 if Array.length Sys.argv < 2 then die "usage: %s ROCQ_EXE [OUT_FILE]" Sys.argv.(0);
60 let coqc = Sys.argv.(1) in
61
62 let coqc = match find_in_PATH coqc with
63 | Some f -> f
64 | None -> die "Could not find %s in PATH." coqc
65 in
66
67 let coqbin = canonical_path_name (Filename.dirname coqc) in
68 let coqroot = Filename.dirname coqbin in
69
70 let relocate = function
71 | Coq_config.NotRelocatable p -> p
72 | Coq_config.Relocatable p -> Filename.concat coqroot p
73 in
74
75 let prefs = Prefs.default in
76 let coqprefix = relocate Coq_config.install_prefix in
77 let coqlibinstall = relocate Coq_config.coqlib in
78 (* EJGA: Good enough approximation *)
79 let best_compiler = if Coq_config.has_natdynlink then "opt" else "byte" in
80 let ocamlfind = Coq_config.ocamlfind in
81 let caml_flags = Coq_config.caml_flags in
82 let coq_caml_flags = coq_warn_error prefs in
83 let out = if Array.length Sys.argv = 2 then stdout
84 else open_out Sys.argv.(2)
85 in
86 Printf.fprintf out "%a\n%!"
87 (write_makefile coqprefix coqlibinstall best_compiler ocamlfind caml_flags coq_caml_flags) ();
88 ()
89
90 let () = main ()