@@ -55,34 +55,19 @@ let major_minor_from_pgconfig () =
5555 in
5656 Fun. protect ~finally: (fun () -> close_in ic) (fun () -> pg_major_minor ic)
5757
58- let major_minor_from_pkg_config =
59- let pkg_config_prefix () =
60- let pkg_config_args =
61- match Sys. getenv " PKG_CONFIG_ARGN" with
62- | s -> String. split_on_char ' ' s
63- | exception Not_found -> []
64- in
65- let bin =
66- match Sys. getenv " PKG_CONFIG" with
67- | s -> s
68- | exception Not_found -> " pkg-config"
69- in
70- Format. asprintf " %s %s " bin (String. concat " " pkg_config_args)
71- in
72- fun () ->
73- let ic =
74- Unix. open_process_in (pkg_config_prefix () ^ " --modversion libpq" )
75- in
76- Fun. protect ~finally: (fun () -> close_in ic) @@ fun () ->
77- let version_line = input_line ic in
78- (* Typically something like "14.1" *)
79- match String. split_on_char '.' version_line with
80- | major :: minor :: _ ->
81- ( " -DPG_OCAML_MAJOR_VERSION=" ^ major,
82- " -DPG_OCAML_MINOR_VERSION=" ^ minor )
83- | _ ->
84- eprintf " Unable to parse libpq version: %s" version_line;
85- exit 1
58+ let major_minor_from_pkg_config () =
59+ let bin = Sys. getenv_opt " PKG_CONFIG" |> Option. value ~default: " pkg-config" in
60+ let args = Sys. getenv_opt " PKG_CONFIG_ARGN" |> Option. value ~default: " " in
61+ let cmd = Format. asprintf " %s %s --modversion libpq" bin args in
62+ let ic = Unix. open_process_in cmd in
63+ Fun. protect ~finally: (fun () -> close_in ic) @@ fun () ->
64+ let version_line = input_line ic in
65+ match String. split_on_char '.' version_line with
66+ | major :: minor :: _ ->
67+ (" -DPG_OCAML_MAJOR_VERSION=" ^ major, " -DPG_OCAML_MINOR_VERSION=" ^ minor)
68+ | _ ->
69+ eprintf " Unable to parse libpq version: %s" version_line;
70+ exit 1
8671
8772let from_pgconfig () =
8873 let cmd = " pg_config --includedir --libdir --version" in
0 commit comments