@@ -5,57 +5,60 @@ let () =
5
5
let module C = Configurator in
6
6
C. main ~name: " postgresql" (fun _c ->
7
7
let cmd = " pg_config --includedir --libdir --version" in
8
- Exn. protectx (Unix. open_process_in cmd) ~finally: In_channel. close
9
- ~f: (fun ic ->
10
- let pgsql_includedir = " -I" ^ In_channel. input_line_exn ic in
11
- let pgsql_libdir = " -L" ^ In_channel. input_line_exn ic in
12
- let major, minor =
13
- let line = In_channel. input_line_exn ic in
14
- let print_fail () =
15
- eprintf " Unable to find versions from line '%s', cmd: '%s'" line cmd
8
+ let ic =
9
+ try Unix. open_process_in cmd
10
+ with exc -> eprintf " could not open pg_config, cmd: '%s'" cmd; raise exc
11
+ in
12
+ Exn. protectx ic ~finally: In_channel. close ~f: (fun ic ->
13
+ let pgsql_includedir = " -I" ^ In_channel. input_line_exn ic in
14
+ let pgsql_libdir = " -L" ^ In_channel. input_line_exn ic in
15
+ let major, minor =
16
+ let line = In_channel. input_line_exn ic in
17
+ let print_fail () =
18
+ eprintf " Unable to find versions from line '%s', cmd: '%s'" line cmd
19
+ in
20
+ try
21
+ let first_space = String. index_exn line ' ' in
22
+ let first_dot = String. index_exn line '.' in
23
+ let first_part =
24
+ let len = first_dot - first_space - 1 in
25
+ String. sub line ~pos: (first_space + 1 ) ~len
16
26
in
17
- try
18
- let first_space = String. index_exn line ' ' in
19
- let first_dot = String. index_exn line '.' in
20
- let first_part =
21
- let len = first_dot - first_space - 1 in
22
- String. sub line ~pos: (first_space + 1 ) ~len
23
- in
24
- let second_part =
25
- let len = String. length line - first_dot - 1 in
26
- String. sub line ~pos: (first_dot + 1 ) ~len
27
- in
28
- let search_version s =
29
- let version = ref " " in
30
- let stop = ref false in
31
- let check_car c =
32
- let ascii = Char. to_int c in
33
- if (ascii > = 48 && ascii < = 57 && not ! stop) then
34
- version := ! version ^ (String. make 1 c)
35
- else stop := true
36
- in
37
- let () = String. iter ~f: check_car s in
38
- ! version
27
+ let second_part =
28
+ let len = String. length line - first_dot - 1 in
29
+ String. sub line ~pos: (first_dot + 1 ) ~len
30
+ in
31
+ let search_version s =
32
+ let version = ref " " in
33
+ let stop = ref false in
34
+ let check_car c =
35
+ let ascii = Char. to_int c in
36
+ if (ascii > = 48 && ascii < = 57 && not ! stop) then
37
+ version := ! version ^ (String. make 1 c)
38
+ else stop := true
39
39
in
40
- let major = search_version first_part in
41
- let minor = search_version second_part in
42
- if String. (major <> " " && minor <> " " ) then
43
- " -DPG_OCAML_MAJOR_VERSION=" ^ major,
44
- " -DPG_OCAML_MINOR_VERSION=" ^ minor
45
- else begin
46
- print_fail () ;
47
- Caml. exit 1
48
- end
49
- with exn -> print_fail () ; raise exn
50
- in
51
- let conf = {
52
- C.Pkg_config.
53
- cflags = [pgsql_includedir; major; minor];
54
- libs = [pgsql_libdir; " -lpq" ];
55
- } in
56
- let write_sexp file sexp =
57
- Out_channel. write_all file ~data: (Sexp. to_string sexp)
58
- in
59
- write_sexp " c_flags.sexp" (sexp_of_list sexp_of_string conf.cflags);
60
- write_sexp " c_library_flags.sexp"
61
- (sexp_of_list sexp_of_string conf.libs)))
40
+ let () = String. iter ~f: check_car s in
41
+ ! version
42
+ in
43
+ let major = search_version first_part in
44
+ let minor = search_version second_part in
45
+ if String. (major <> " " && minor <> " " ) then
46
+ " -DPG_OCAML_MAJOR_VERSION=" ^ major,
47
+ " -DPG_OCAML_MINOR_VERSION=" ^ minor
48
+ else begin
49
+ print_fail () ;
50
+ Caml. exit 1
51
+ end
52
+ with exn -> print_fail () ; raise exn
53
+ in
54
+ let conf = {
55
+ C.Pkg_config.
56
+ cflags = [pgsql_includedir; major; minor];
57
+ libs = [pgsql_libdir; " -lpq" ];
58
+ } in
59
+ let write_sexp file sexp =
60
+ Out_channel. write_all file ~data: (Sexp. to_string sexp)
61
+ in
62
+ write_sexp " c_flags.sexp" (sexp_of_list sexp_of_string conf.cflags);
63
+ write_sexp " c_library_flags.sexp"
64
+ (sexp_of_list sexp_of_string conf.libs)))
0 commit comments