aboutsummaryrefslogtreecommitdiffhomepage
path: root/configure.ml
diff options
context:
space:
mode:
authorGravatar Vincent Laporte <Vincent.Laporte@gmail.com>2017-12-05 09:35:31 +0000
committerGravatar Vincent Laporte <Vincent.Laporte@gmail.com>2017-12-05 09:35:31 +0000
commit52a37c791a349f8580653c8b2f53025c583ee024 (patch)
treedf56d6659da4192b5f65137c7ee6d43373884dc2 /configure.ml
parent0dd793a14a0b0b593bff7d33c1f835fc5a38313e (diff)
[configure] adds a `select_command` function
Diffstat (limited to 'configure.ml')
-rw-r--r--configure.ml22
1 files changed, 15 insertions, 7 deletions
diff --git a/configure.ml b/configure.ml
index 1e729e97e..33387f4c6 100644
--- a/configure.ml
+++ b/configure.ml
@@ -178,6 +178,20 @@ let which prog =
let program_in_path prog =
try let _ = which prog in true with Not_found -> false
+(** Choose a command among a list of candidates
+ (command name, mandatory arguments, arguments for this test).
+ Chooses the first one whose execution outputs a non-empty (first) line.
+ Dies with message [msg] if none is found. *)
+
+let select_command msg canditates =
+ let rec search = function
+ | [] -> die msg
+ | (p, x, y) :: tl ->
+ if fst (tryrun p (x @ y)) <> ""
+ then List.fold_left (Printf.sprintf "%s %s") p x
+ else search tl
+ in search canditates
+
(** As per bug #4828, ocamlfind on Windows/Cygwin barfs if you pass it
a quoted path to camlpXo via -pp. So we only quote camlpXo on not
Windows, and warn on Windows if the path contains spaces *)
@@ -837,13 +851,7 @@ let strip =
(** * md5sum command *)
let md5sum =
- let rec loop = function
- | [] -> die "Don’t know how to compute MD5 checksums…"
- | (p, ma, a) :: tl ->
- if fst (tryrun p (ma @ a)) <> ""
- then List.fold_left (Printf.sprintf "%s %s") p ma
- else loop tl
- in loop [
+ select_command "Don’t know how to compute MD5 checksums…" [
"md5sum", [], [ "--version" ];
"md5", ["-q"], [ "-s" ; "''" ];
]