Skip to content

Commit

Permalink
Merge pull request #51 from anmonteiro/anmonteiro/fix-x-compilation
Browse files Browse the repository at this point in the history
discover: read `$PKG_CONFIG` to fix cross-compilation
  • Loading branch information
mmottl authored Dec 9, 2024
2 parents e828f1c + c5d6270 commit 5059766
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions src/config/discover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,34 @@ let major_minor_from_pgconfig () =
in
Fun.protect ~finally:(fun () -> close_in ic) (fun () -> pg_major_minor ic)

let major_minor_from_pkg_config () =
let ic = Unix.open_process_in "pkg-config --modversion libpq" in
Fun.protect ~finally:(fun () -> close_in ic) @@ fun () ->
let version_line = input_line ic in
(* Typically something like "14.1" *)
match String.split_on_char '.' version_line with
| major :: minor :: _ ->
("-DPG_OCAML_MAJOR_VERSION=" ^ major, "-DPG_OCAML_MINOR_VERSION=" ^ minor)
| _ ->
eprintf "Unable to parse libpq version: %s" version_line;
exit 1
let major_minor_from_pkg_config =
let pkg_config_prefix () =
let pkg_config_args =
match Sys.getenv "PKG_CONFIG_ARGN" with
| s -> String.split_on_char ' ' s
| exception Not_found -> []
in
let bin =
match Sys.getenv "PKG_CONFIG" with
| s -> s
| exception Not_found -> "pkg-config"
in
Format.asprintf "%s %s " bin (String.concat " " pkg_config_args)
in
fun () ->
let ic =
Unix.open_process_in (pkg_config_prefix () ^ " --modversion libpq")
in
Fun.protect ~finally:(fun () -> close_in ic) @@ fun () ->
let version_line = input_line ic in
(* Typically something like "14.1" *)
match String.split_on_char '.' version_line with
| major :: minor :: _ ->
( "-DPG_OCAML_MAJOR_VERSION=" ^ major,
"-DPG_OCAML_MINOR_VERSION=" ^ minor )
| _ ->
eprintf "Unable to parse libpq version: %s" version_line;
exit 1

let from_pgconfig () =
let cmd = "pg_config --includedir --libdir --version" in
Expand Down

0 comments on commit 5059766

Please sign in to comment.