Debian Codegraph @

src/c/dune

raw
1 (* -*- tuareg -*- *)
2
3 (* To make this build verbose:
4
5 1. dune build -p luv -j 1 --verbose --no-buffer
6 2. Remove --silent and --enable-silent-rules from sh configure
7 3. Pass V=1 instead of V=0 to make
8 4. Remove --silent --no-warnings from sh libtool
9 5. Unwrap all the commands from (ignore-outputs ...) *)
10
11 let foreign_archives, uv_library_flag, include_dirs, i_option, install_h =
12 let use_system_libuv =
13 match Sys.getenv "LUV_USE_SYSTEM_LIBUV" with
14 | "yes" -> true
15 | _ -> false
16 | exception Not_found -> false
17 in
18
19 if use_system_libuv then
20 "",
21 "-luv",
22 "",
23 "",
24 false
25 else
26 "(foreign_archives uv)",
27 "",
28 "(include_dirs vendor/libuv/include)",
29 "-I .",
30 true
31
32 let () = Jbuild_plugin.V1.send @@ {|
33
34 ; The final FFI module, containing all the OCaml bits, and linked with libuv.
35 (library
36 (name luv_c)
37 (public_name luv.c)
38 (wrapped false)
39 (modules Luv_c_generated_functions)
40 (libraries ctypes luv_c_function_descriptions threads)
41 (foreign_stubs
42 (language c)
43 (names c_generated_functions helpers)
44 |}^ include_dirs ^{|)
45 |}^ foreign_archives ^{|
46 (c_library_flags |}^ uv_library_flag ^{| (:include extra_libs.sexp)))
47
48 |}^ (if not install_h then "" else {|
49
50 (rule
51 (deps (glob_files uv/*.h))
52 (action (copy vendor/libuv/include/uv.h uv.h)))
53
54 (install
55 (section lib)
56 (package luv)
57 (files
58 (uv.h as uv.h)
59 (uv/aix.h as uv/aix.h)
60 (uv/bsd.h as uv/bsd.h)
61 (uv/darwin.h as uv/darwin.h)
62 (uv/errno.h as uv/errno.h)
63 (uv/linux.h as uv/linux.h)
64 (uv/os390.h as uv/os390.h)
65 (uv/posix.h as uv/posix.h)
66 (uv/sunos.h as uv/sunos.h)
67 (uv/threadpool.h as uv/threadpool.h)
68 (uv/tree.h as uv/tree.h)
69 (uv/unix.h as uv/unix.h)
70 (uv/version.h as uv/version.h)
71 (uv/win.h as uv/win.h)))
72
73 |}) ^{|
74
75
76
77 ; The vendored libuv.
78 (rule
79 (targets libuv.a dlluv%{ext_dll})
80 (deps (source_tree vendor))
81 (action (progn
82 (bash "cp -r vendor/configure/* vendor/libuv/")
83 (chdir vendor/libuv (progn
84 (bash
85 "sh configure --host `ocamlc -config | awk '/^host:/ {print $NF}'` \
86 'CC=%{cc}' CFLAGS=-DNDEBUG --silent --enable-silent-rules")
87 (ignore-outputs (bash
88 "$([ '%{os_type}' = Unix ] && echo %{make} || echo make) V=0 -j 4 \
89 -o aclocal.m4 -o Makefile.in -o configure \
90 -o configure.status -o Makefile libuv.la"))
91 (ignore-outputs (bash
92 "sh libtool --silent --no-warnings --mode install cp libuv.la `pwd`"))))
93 (bash "cp vendor/libuv/libuv.a .")
94 (ignore-outputs (bash
95 "cp vendor/libuv/libuv.so.1.0.0 dlluv.so || \
96 cp vendor/libuv/libuv.1.dylib dlluv.so || \
97 cp vendor/bin/libuv-1.dll dlluv.dll")))))
98
99 (rule
100 (targets extra_libs.sexp)
101 (action (ignore-outputs (bash "\
102 if ocamlc -config | grep mingw; then \
103 echo '(-ldbghelp -liphlpapi -lole32 -lpsapi -luserenv)' > extra_libs.sexp; \
104 else \
105 echo '()' > extra_libs.sexp; \
106 fi"))))
107
108
109
110 ; Everything below is the bindings generation process using ctypes. It produces
111 ; two OCaml modules, Luv_c_generated_functions and Luv_c_generated_types.
112
113 ; Type bindings (Luv_c_generated_types).
114 (library
115 (name luv_c_type_descriptions)
116 (public_name luv.c_type_descriptions)
117 (modules Luv_c_type_descriptions)
118 (libraries ctypes))
119
120 (executable
121 (name generate_types_start)
122 (modules Generate_types_start)
123 (libraries ctypes.stubs luv_c_type_descriptions))
124
125 (rule
126 (with-stdout-to generate_types_step_2.c
127 (run ./generate_types_start.exe)))
128
129 ; Based partially on
130 ; https://github.com/avsm/ocaml-yaml/blob/master/types/stubgen/jbuild#L20
131 (rule
132 (targets generate_types_step_2.exe)
133 (deps (:c generate_types_step_2.c) helpers.h shims.h)
134 (action (bash "\
135 if [ '%{ocaml-config:ccomp_type}' = 'msvc' ]; then \
136 %{cc} %{c} \
137 -I '%{lib:ctypes:.}' \
138 -I '%{ocaml_where}' \
139 |}^ i_option ^{| /Fe\"%{targets}\"; \
140 else \
141 %{cc} %{c} \
142 -I '%{lib:ctypes:.}' \
143 -I '%{ocaml_where}' \
144 |}^ i_option ^{| -o %{targets}; \
145 fi")))
146
147 (rule
148 (with-stdout-to luv_c_generated_types.ml
149 (run ./generate_types_step_2.exe)))
150
151 ; Function bindings.
152 (library
153 (name luv_c_function_descriptions)
154 (public_name luv.c_function_descriptions)
155 (flags (:standard -w -9-16-27))
156 (wrapped false)
157 (modules Luv_c_generated_types Luv_c_function_descriptions Luv_c_types)
158 (libraries ctypes luv_c_type_descriptions))
159
160 (executable
161 (name generate_c_functions)
162 (modules Generate_c_functions)
163 (libraries ctypes.stubs luv_c_function_descriptions))
164
165 (executable
166 (name generate_ml_functions)
167 (modules Generate_ml_functions)
168 (libraries ctypes.stubs luv_c_function_descriptions))
169
170 (rule
171 (with-stdout-to c_generated_functions.c
172 (run ./generate_c_functions.exe luv_stub)))
173
174 (rule
175 (with-stdout-to luv_c_generated_functions.ml
176 (run ./generate_ml_functions.exe luv_stub)))
177
178 |}