File: discover.ml

package info (click to toggle)
ocaml-eio 1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,548 kB
  • sloc: ml: 14,608; ansic: 1,237; makefile: 25
file content (57 lines) | stat: -rw-r--r-- 1,930 bytes parent folder | download
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
module C = Configurator.V1

let optional_flags = [
  "O_DSYNC";
  "O_RESOLVE_BENEATH";
  "O_PATH";
  "ENOTCAPABLE";
]

let () =
  C.main ~name:"discover" (fun c ->
      let c_flags = ["-D_LARGEFILE64_SOURCE"; "-D_XOPEN_SOURCE=700"; "-D_DARWIN_C_SOURCE"; "-D_GNU_SOURCE"; "-D_BSD_SOURCE"; "-D__BSD_VISIBLE"] in
      let includes = ["errno.h"; "sys/types.h"; "sys/stat.h"; "fcntl.h"; "limits.h"] in
      let extra_flags, missing_defs =
        C.C_define.import c ~c_flags ~includes
          C.C_define.Type.(List.map (fun name -> name, Switch) optional_flags)
        |> List.partition_map (function
            | name, C.C_define.Value.Switch true -> Left (name, C.C_define.Type.Int)
            | name, Switch false ->
              Right (Printf.sprintf "let %s = None" (String.lowercase_ascii name))
            | _ -> assert false
          )
      in
      let present_defs =
        C.C_define.import c ~c_flags ~includes
          C.C_define.Type.(extra_flags @ [
            "O_RDONLY", Int;
            "O_RDWR", Int;
            "O_WRONLY", Int;

            "O_APPEND", Int;
            "O_CLOEXEC", Int;
            "O_CREAT", Int;
            "O_DIRECTORY", Int;
            "O_EXCL", Int;
            "O_NOCTTY", Int;
            "O_NOFOLLOW", Int;
            "O_NONBLOCK", Int;
            "O_SYNC", Int;
            "O_TRUNC", Int;

            "AT_FDCWD", Int;
            "AT_SYMLINK_NOFOLLOW", Int;

            "IOV_MAX", Int;
          ])
        |> List.map (function
            | name, C.C_define.Value.Int v when List.mem name optional_flags ->
              Printf.sprintf "let %s = Some 0x%x" (String.lowercase_ascii name) v
            | name, C.C_define.Value.Int v ->
              Printf.sprintf "let %s = 0x%x" (String.lowercase_ascii name) v
            | _ -> assert false
          )
      in
      let defs = present_defs @ missing_defs in
      C.Flags.write_lines "config.ml" defs
    )