-
Notifications
You must be signed in to change notification settings - Fork 5
/
discover.ml
75 lines (65 loc) · 2.96 KB
/
discover.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
module C = Configurator.V1
(* Keep the order of "type r2r_kind" in fftw3SD.ml in sync with
fftw3.h values. *)
let check_r2r_kind ?c_flags c =
let v = C.C_define.(import c ?c_flags ~includes:["fftw3.h"]
["FFTW_R2HC", Type.Int;
"FFTW_HC2R", Type.Int;
"FFTW_DHT", Type.Int;
"FFTW_REDFT00", Type.Int;
"FFTW_REDFT01", Type.Int;
"FFTW_REDFT10", Type.Int;
"FFTW_REDFT11", Type.Int;
"FFTW_RODFT00", Type.Int;
"FFTW_RODFT01", Type.Int;
"FFTW_RODFT10", Type.Int;
"FFTW_RODFT11", Type.Int; ]) in
let get name = match List.assoc name v with
| C.C_define.Value.Int i -> i
| exception _ -> C.die "Cannot find %S in the header file <fftw3.h>. \
Contact the authors." name
| _ -> C.die "Macro %S does not have an integer value. Contact the \
authors." name in
get "FFTW_R2HC" = 0 && get "FFTW_HC2R" = 1 && get "FFTW_DHT" = 2
&& get "FFTW_REDFT00" = 3 && get "FFTW_REDFT01" = 4 && get "FFTW_REDFT10" = 5
&& get "FFTW_REDFT11" = 6 && get "FFTW_RODFT00" = 7 && get "FFTW_RODFT01" = 8
&& get "FFTW_RODFT10" = 9 && get "FFTW_RODFT11" = 10
let ocaml_version c =
let v = C.ocaml_config_var_exn c "version" in
let is_word_char c = '0' <= c && c <= '9' in
match C.Flags.extract_words ~is_word_char v with
| major :: minor :: _ -> (int_of_string major, int_of_string minor)
| _ -> assert false
let get_cflags ?(default=[]) conf =
match conf with Some c -> c.C.Pkg_config.cflags
| None -> default
let get_libs ?(default=[]) conf =
match conf with Some c -> c.C.Pkg_config.libs
| None -> default
let discover c =
let module P = C.Pkg_config in
let fftw3 = match P.get c with
| Some p -> P.query p ~package:"fftw3"
| None -> None in
let fftw3f = match P.get c with
| Some p -> P.query p ~package:"fftw3f"
| None -> None in
let c_flags =
match Sys.getenv "FFTW3_CFLAGS" with
| exception Not_found -> get_cflags fftw3 @ get_cflags fftw3f
| alt_cflags -> C.Flags.extract_blank_separated_words alt_cflags in
let libs =
match Sys.getenv "FFTW3_LIBS" with
| exception Not_found -> get_libs fftw3 ~default:["-lfftw3"]
@ get_libs fftw3f ~default:["-lfftw3f"]
| alt_libs -> "-lm" :: C.Flags.extract_blank_separated_words alt_libs in
let c_flags = if fftw3f = None then c_flags
else "-DFFTW3F_EXISTS" :: c_flags in
if not(check_r2r_kind ~c_flags c) then
C.die "The values of the fields FFTW_R2HC,... in fftw3.h have \
changed.\n Please use a newer version of the OCaml-fftw3 \
library or report the issue.";
C.Flags.write_sexp "c_flags.sexp" c_flags;
C.Flags.write_sexp "c_library_flags.sexp" libs
let () =
C.main ~name:"fftw3" discover