1
|
(* OASIS_START *)
|
2
|
(* DO NOT EDIT (digest: 00359f2e15a7ed8f31f1d7ce086345f9) *)
|
3
|
module OASISGettext = struct
|
4
|
(* # 21 "/build/buildd/oasis-0.3.0/src/oasis/OASISGettext.ml" *)
|
5
|
|
6
|
let ns_ str =
|
7
|
str
|
8
|
|
9
|
let s_ str =
|
10
|
str
|
11
|
|
12
|
let f_ (str : ('a, 'b, 'c, 'd) format4) =
|
13
|
str
|
14
|
|
15
|
let fn_ fmt1 fmt2 n =
|
16
|
if n = 1 then
|
17
|
fmt1^^""
|
18
|
else
|
19
|
fmt2^^""
|
20
|
|
21
|
let init =
|
22
|
[]
|
23
|
|
24
|
end
|
25
|
|
26
|
module OASISExpr = struct
|
27
|
(* # 21 "/build/buildd/oasis-0.3.0/src/oasis/OASISExpr.ml" *)
|
28
|
|
29
|
|
30
|
|
31
|
open OASISGettext
|
32
|
|
33
|
type test = string
|
34
|
|
35
|
type flag = string
|
36
|
|
37
|
type t =
|
38
|
| EBool of bool
|
39
|
| ENot of t
|
40
|
| EAnd of t * t
|
41
|
| EOr of t * t
|
42
|
| EFlag of flag
|
43
|
| ETest of test * string
|
44
|
|
45
|
|
46
|
type 'a choices = (t * 'a) list
|
47
|
|
48
|
let eval var_get t =
|
49
|
let rec eval' =
|
50
|
function
|
51
|
| EBool b ->
|
52
|
b
|
53
|
|
54
|
| ENot e ->
|
55
|
not (eval' e)
|
56
|
|
57
|
| EAnd (e1, e2) ->
|
58
|
(eval' e1) && (eval' e2)
|
59
|
|
60
|
| EOr (e1, e2) ->
|
61
|
(eval' e1) || (eval' e2)
|
62
|
|
63
|
| EFlag nm ->
|
64
|
let v =
|
65
|
var_get nm
|
66
|
in
|
67
|
assert(v = "true" || v = "false");
|
68
|
(v = "true")
|
69
|
|
70
|
| ETest (nm, vl) ->
|
71
|
let v =
|
72
|
var_get nm
|
73
|
in
|
74
|
(v = vl)
|
75
|
in
|
76
|
eval' t
|
77
|
|
78
|
let choose ?printer ?name var_get lst =
|
79
|
let rec choose_aux =
|
80
|
function
|
81
|
| (cond, vl) :: tl ->
|
82
|
if eval var_get cond then
|
83
|
vl
|
84
|
else
|
85
|
choose_aux tl
|
86
|
| [] ->
|
87
|
let str_lst =
|
88
|
if lst = [] then
|
89
|
s_ "<empty>"
|
90
|
else
|
91
|
String.concat
|
92
|
(s_ ", ")
|
93
|
(List.map
|
94
|
(fun (cond, vl) ->
|
95
|
match printer with
|
96
|
| Some p -> p vl
|
97
|
| None -> s_ "<no printer>")
|
98
|
lst)
|
99
|
in
|
100
|
match name with
|
101
|
| Some nm ->
|
102
|
failwith
|
103
|
(Printf.sprintf
|
104
|
(f_ "No result for the choice list '%s': %s")
|
105
|
nm str_lst)
|
106
|
| None ->
|
107
|
failwith
|
108
|
(Printf.sprintf
|
109
|
(f_ "No result for a choice list: %s")
|
110
|
str_lst)
|
111
|
in
|
112
|
choose_aux (List.rev lst)
|
113
|
|
114
|
end
|
115
|
|
116
|
|
117
|
# 117 "myocamlbuild.ml"
|
118
|
module BaseEnvLight = struct
|
119
|
(* # 21 "/build/buildd/oasis-0.3.0/src/base/BaseEnvLight.ml" *)
|
120
|
|
121
|
module MapString = Map.Make(String)
|
122
|
|
123
|
type t = string MapString.t
|
124
|
|
125
|
let default_filename =
|
126
|
Filename.concat
|
127
|
(Sys.getcwd ())
|
128
|
"setup.data"
|
129
|
|
130
|
let load ?(allow_empty=false) ?(filename=default_filename) () =
|
131
|
if Sys.file_exists filename then
|
132
|
begin
|
133
|
let chn =
|
134
|
open_in_bin filename
|
135
|
in
|
136
|
let st =
|
137
|
Stream.of_channel chn
|
138
|
in
|
139
|
let line =
|
140
|
ref 1
|
141
|
in
|
142
|
let st_line =
|
143
|
Stream.from
|
144
|
(fun _ ->
|
145
|
try
|
146
|
match Stream.next st with
|
147
|
| '\n' -> incr line; Some '\n'
|
148
|
| c -> Some c
|
149
|
with Stream.Failure -> None)
|
150
|
in
|
151
|
let lexer =
|
152
|
Genlex.make_lexer ["="] st_line
|
153
|
in
|
154
|
let rec read_file mp =
|
155
|
match Stream.npeek 3 lexer with
|
156
|
| [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] ->
|
157
|
Stream.junk lexer;
|
158
|
Stream.junk lexer;
|
159
|
Stream.junk lexer;
|
160
|
read_file (MapString.add nm value mp)
|
161
|
| [] ->
|
162
|
mp
|
163
|
| _ ->
|
164
|
failwith
|
165
|
(Printf.sprintf
|
166
|
"Malformed data file '%s' line %d"
|
167
|
filename !line)
|
168
|
in
|
169
|
let mp =
|
170
|
read_file MapString.empty
|
171
|
in
|
172
|
close_in chn;
|
173
|
mp
|
174
|
end
|
175
|
else if allow_empty then
|
176
|
begin
|
177
|
MapString.empty
|
178
|
end
|
179
|
else
|
180
|
begin
|
181
|
failwith
|
182
|
(Printf.sprintf
|
183
|
"Unable to load environment, the file '%s' doesn't exist."
|
184
|
filename)
|
185
|
end
|
186
|
|
187
|
let var_get name env =
|
188
|
let rec var_expand str =
|
189
|
let buff =
|
190
|
Buffer.create ((String.length str) * 2)
|
191
|
in
|
192
|
Buffer.add_substitute
|
193
|
buff
|
194
|
(fun var ->
|
195
|
try
|
196
|
var_expand (MapString.find var env)
|
197
|
with Not_found ->
|
198
|
failwith
|
199
|
(Printf.sprintf
|
200
|
"No variable %s defined when trying to expand %S."
|
201
|
var
|
202
|
str))
|
203
|
str;
|
204
|
Buffer.contents buff
|
205
|
in
|
206
|
var_expand (MapString.find name env)
|
207
|
|
208
|
let var_choose lst env =
|
209
|
OASISExpr.choose
|
210
|
(fun nm -> var_get nm env)
|
211
|
lst
|
212
|
end
|
213
|
|
214
|
|
215
|
# 215 "myocamlbuild.ml"
|
216
|
module MyOCamlbuildFindlib = struct
|
217
|
(* # 21 "/build/buildd/oasis-0.3.0/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
|
218
|
|
219
|
(** OCamlbuild extension, copied from
|
220
|
* http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
|
221
|
* by N. Pouillard and others
|
222
|
*
|
223
|
* Updated on 2009/02/28
|
224
|
*
|
225
|
* Modified by Sylvain Le Gall
|
226
|
*)
|
227
|
open Ocamlbuild_plugin
|
228
|
|
229
|
(* these functions are not really officially exported *)
|
230
|
let run_and_read =
|
231
|
Ocamlbuild_pack.My_unix.run_and_read
|
232
|
|
233
|
let blank_sep_strings =
|
234
|
Ocamlbuild_pack.Lexers.blank_sep_strings
|
235
|
|
236
|
let split s ch =
|
237
|
let x =
|
238
|
ref []
|
239
|
in
|
240
|
let rec go s =
|
241
|
let pos =
|
242
|
String.index s ch
|
243
|
in
|
244
|
x := (String.before s pos)::!x;
|
245
|
go (String.after s (pos + 1))
|
246
|
in
|
247
|
try
|
248
|
go s
|
249
|
with Not_found -> !x
|
250
|
|
251
|
let split_nl s = split s '\n'
|
252
|
|
253
|
let before_space s =
|
254
|
try
|
255
|
String.before s (String.index s ' ')
|
256
|
with Not_found -> s
|
257
|
|
258
|
(* this lists all supported packages *)
|
259
|
let find_packages () =
|
260
|
List.map before_space (split_nl & run_and_read "ocamlfind list")
|
261
|
|
262
|
(* this is supposed to list available syntaxes, but I don't know how to do it. *)
|
263
|
let find_syntaxes () = ["camlp4o"; "camlp4r"]
|
264
|
|
265
|
(* ocamlfind command *)
|
266
|
let ocamlfind x = S[A"ocamlfind"; x]
|
267
|
|
268
|
let dispatch =
|
269
|
function
|
270
|
| Before_options ->
|
271
|
(* by using Before_options one let command line options have an higher priority *)
|
272
|
(* on the contrary using After_options will guarantee to have the higher priority *)
|
273
|
(* override default commands by ocamlfind ones *)
|
274
|
Options.ocamlc := ocamlfind & A"ocamlc";
|
275
|
Options.ocamlopt := ocamlfind & A"ocamlopt";
|
276
|
Options.ocamldep := ocamlfind & A"ocamldep";
|
277
|
Options.ocamldoc := ocamlfind & A"ocamldoc";
|
278
|
Options.ocamlmktop := ocamlfind & A"ocamlmktop"
|
279
|
|
280
|
| After_rules ->
|
281
|
|
282
|
(* When one link an OCaml library/binary/package, one should use -linkpkg *)
|
283
|
flag ["ocaml"; "link"; "program"] & A"-linkpkg";
|
284
|
|
285
|
(* For each ocamlfind package one inject the -package option when
|
286
|
* compiling, computing dependencies, generating documentation and
|
287
|
* linking. *)
|
288
|
List.iter
|
289
|
begin fun pkg ->
|
290
|
flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg];
|
291
|
flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
|
292
|
flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg];
|
293
|
flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg];
|
294
|
flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
|
295
|
end
|
296
|
(find_packages ());
|
297
|
|
298
|
(* Like -package but for extensions syntax. Morover -syntax is useless
|
299
|
* when linking. *)
|
300
|
List.iter begin fun syntax ->
|
301
|
flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
|
302
|
flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
|
303
|
flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
|
304
|
flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
|
305
|
end (find_syntaxes ());
|
306
|
|
307
|
(* The default "thread" tag is not compatible with ocamlfind.
|
308
|
* Indeed, the default rules add the "threads.cma" or "threads.cmxa"
|
309
|
* options when using this tag. When using the "-linkpkg" option with
|
310
|
* ocamlfind, this module will then be added twice on the command line.
|
311
|
*
|
312
|
* To solve this, one approach is to add the "-thread" option when using
|
313
|
* the "threads" package using the previous plugin.
|
314
|
*)
|
315
|
flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
|
316
|
flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]);
|
317
|
flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
|
318
|
flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
|
319
|
|
320
|
| _ ->
|
321
|
()
|
322
|
|
323
|
end
|
324
|
|
325
|
module MyOCamlbuildBase = struct
|
326
|
(* # 21 "/build/buildd/oasis-0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
|
327
|
|
328
|
(** Base functions for writing myocamlbuild.ml
|
329
|
@author Sylvain Le Gall
|
330
|
*)
|
331
|
|
332
|
|
333
|
|
334
|
open Ocamlbuild_plugin
|
335
|
module OC = Ocamlbuild_pack.Ocaml_compiler
|
336
|
|
337
|
type dir = string
|
338
|
type file = string
|
339
|
type name = string
|
340
|
type tag = string
|
341
|
|
342
|
(* # 56 "/build/buildd/oasis-0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
|
343
|
|
344
|
type t =
|
345
|
{
|
346
|
lib_ocaml: (name * dir list) list;
|
347
|
lib_c: (name * dir * file list) list;
|
348
|
flags: (tag list * (spec OASISExpr.choices)) list;
|
349
|
(* Replace the 'dir: include' from _tags by a precise interdepends in
|
350
|
* directory.
|
351
|
*)
|
352
|
includes: (dir * dir list) list;
|
353
|
}
|
354
|
|
355
|
let env_filename =
|
356
|
Pathname.basename
|
357
|
BaseEnvLight.default_filename
|
358
|
|
359
|
let dispatch_combine lst =
|
360
|
fun e ->
|
361
|
List.iter
|
362
|
(fun dispatch -> dispatch e)
|
363
|
lst
|
364
|
|
365
|
let tag_libstubs nm =
|
366
|
"use_lib"^nm^"_stubs"
|
367
|
|
368
|
let nm_libstubs nm =
|
369
|
nm^"_stubs"
|
370
|
|
371
|
let dispatch t e =
|
372
|
let env =
|
373
|
BaseEnvLight.load
|
374
|
~filename:env_filename
|
375
|
~allow_empty:true
|
376
|
()
|
377
|
in
|
378
|
match e with
|
379
|
| Before_options ->
|
380
|
let no_trailing_dot s =
|
381
|
if String.length s >= 1 && s.[0] = '.' then
|
382
|
String.sub s 1 ((String.length s) - 1)
|
383
|
else
|
384
|
s
|
385
|
in
|
386
|
List.iter
|
387
|
(fun (opt, var) ->
|
388
|
try
|
389
|
opt := no_trailing_dot (BaseEnvLight.var_get var env)
|
390
|
with Not_found ->
|
391
|
Printf.eprintf "W: Cannot get variable %s" var)
|
392
|
[
|
393
|
Options.ext_obj, "ext_obj";
|
394
|
Options.ext_lib, "ext_lib";
|
395
|
Options.ext_dll, "ext_dll";
|
396
|
]
|
397
|
|
398
|
| After_rules ->
|
399
|
(* Declare OCaml libraries *)
|
400
|
List.iter
|
401
|
(function
|
402
|
| nm, [] ->
|
403
|
ocaml_lib nm
|
404
|
| nm, dir :: tl ->
|
405
|
ocaml_lib ~dir:dir (dir^"/"^nm);
|
406
|
List.iter
|
407
|
(fun dir ->
|
408
|
List.iter
|
409
|
(fun str ->
|
410
|
flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir]))
|
411
|
["compile"; "infer_interface"; "doc"])
|
412
|
tl)
|
413
|
t.lib_ocaml;
|
414
|
|
415
|
(* Declare directories dependencies, replace "include" in _tags. *)
|
416
|
List.iter
|
417
|
(fun (dir, include_dirs) ->
|
418
|
Pathname.define_context dir include_dirs)
|
419
|
t.includes;
|
420
|
|
421
|
(* Declare C libraries *)
|
422
|
List.iter
|
423
|
(fun (lib, dir, headers) ->
|
424
|
(* Handle C part of library *)
|
425
|
flag ["link"; "library"; "ocaml"; "byte"; tag_libstubs lib]
|
426
|
(S[A"-dllib"; A("-l"^(nm_libstubs lib)); A"-cclib";
|
427
|
A("-l"^(nm_libstubs lib))]);
|
428
|
|
429
|
flag ["link"; "library"; "ocaml"; "native"; tag_libstubs lib]
|
430
|
(S[A"-cclib"; A("-l"^(nm_libstubs lib))]);
|
431
|
|
432
|
flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib]
|
433
|
(S[A"-dllib"; A("dll"^(nm_libstubs lib))]);
|
434
|
|
435
|
(* When ocaml link something that use the C library, then one
|
436
|
need that file to be up to date.
|
437
|
*)
|
438
|
dep ["link"; "ocaml"; "program"; tag_libstubs lib]
|
439
|
[dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
|
440
|
|
441
|
dep ["compile"; "ocaml"; "program"; tag_libstubs lib]
|
442
|
[dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
|
443
|
|
444
|
(* TODO: be more specific about what depends on headers *)
|
445
|
(* Depends on .h files *)
|
446
|
dep ["compile"; "c"]
|
447
|
headers;
|
448
|
|
449
|
(* Setup search path for lib *)
|
450
|
flag ["link"; "ocaml"; "use_"^lib]
|
451
|
(S[A"-I"; P(dir)]);
|
452
|
)
|
453
|
t.lib_c;
|
454
|
|
455
|
(* Add flags *)
|
456
|
List.iter
|
457
|
(fun (tags, cond_specs) ->
|
458
|
let spec =
|
459
|
BaseEnvLight.var_choose cond_specs env
|
460
|
in
|
461
|
flag tags & spec)
|
462
|
t.flags
|
463
|
| _ ->
|
464
|
()
|
465
|
|
466
|
let dispatch_default t =
|
467
|
dispatch_combine
|
468
|
[
|
469
|
dispatch t;
|
470
|
MyOCamlbuildFindlib.dispatch;
|
471
|
]
|
472
|
|
473
|
end
|
474
|
|
475
|
|
476
|
# 476 "myocamlbuild.ml"
|
477
|
open Ocamlbuild_plugin;;
|
478
|
let package_default =
|
479
|
{MyOCamlbuildBase.lib_ocaml = []; lib_c = []; flags = []; includes = []; }
|
480
|
;;
|
481
|
|
482
|
let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
|
483
|
|
484
|
# 485 "myocamlbuild.ml"
|
485
|
(* OASIS_STOP *)
|
486
|
Ocamlbuild_plugin.dispatch dispatch_default;;
|