~ubuntu-branches/ubuntu/trusty/sexplib310/trusty

« back to all changes in this revision

Viewing changes to myocamlbuild.ml

  • Committer: Package Import Robot
  • Author(s): Stéphane Glondu
  • Date: 2013-12-03 21:36:45 UTC
  • mfrom: (11.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20131203213645-h1if1c6hxual8p11
Tags: 109.20.00-2
* Team upload
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
(* OASIS_START *)
2
 
(* DO NOT EDIT (digest: 6a36af2626fc8bc901ff0b729583bf22) *)
 
2
(* DO NOT EDIT (digest: f445332011b20e926cbe52b8fd37e91b) *)
3
3
module OASISGettext = struct
4
 
# 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc2/src/oasis/OASISGettext.ml"
5
 
  
 
4
(* # 21 "/home/ysulsky/local/opam-full/4.00.1/build/oasis.0.3.0/src/oasis/OASISGettext.ml" *)
 
5
 
6
6
  let ns_ str =
7
7
    str
8
 
  
 
8
 
9
9
  let s_ str =
10
10
    str
11
 
  
 
11
 
12
12
  let f_ (str : ('a, 'b, 'c, 'd) format4) =
13
13
    str
14
 
  
 
14
 
15
15
  let fn_ fmt1 fmt2 n =
16
16
    if n = 1 then
17
17
      fmt1^^""
18
18
    else
19
19
      fmt2^^""
20
 
  
 
20
 
21
21
  let init =
22
22
    []
23
 
  
 
23
 
24
24
end
25
25
 
26
26
module OASISExpr = struct
27
 
# 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc2/src/oasis/OASISExpr.ml"
28
 
  
29
 
  
30
 
  
 
27
(* # 21 "/home/ysulsky/local/opam-full/4.00.1/build/oasis.0.3.0/src/oasis/OASISExpr.ml" *)
 
28
 
 
29
 
 
30
 
31
31
  open OASISGettext
32
 
  
 
32
 
33
33
  type test = string 
34
 
  
 
34
 
35
35
  type flag = string 
36
 
  
 
36
 
37
37
  type t =
38
38
    | EBool of bool
39
39
    | ENot of t
42
42
    | EFlag of flag
43
43
    | ETest of test * string
44
44
    
45
 
  
 
45
 
46
46
  type 'a choices = (t * 'a) list 
47
 
  
 
47
 
48
48
  let eval var_get t =
49
49
    let rec eval' =
50
50
      function
51
51
        | EBool b ->
52
52
            b
53
 
  
 
53
 
54
54
        | ENot e ->
55
55
            not (eval' e)
56
 
  
 
56
 
57
57
        | EAnd (e1, e2) ->
58
58
            (eval' e1) && (eval' e2)
59
 
  
 
59
 
60
60
        | EOr (e1, e2) ->
61
61
            (eval' e1) || (eval' e2)
62
 
  
 
62
 
63
63
        | EFlag nm ->
64
64
            let v =
65
65
              var_get nm
66
66
            in
67
67
              assert(v = "true" || v = "false");
68
68
              (v = "true")
69
 
  
 
69
 
70
70
        | ETest (nm, vl) ->
71
71
            let v =
72
72
              var_get nm
74
74
              (v = vl)
75
75
    in
76
76
      eval' t
77
 
  
 
77
 
78
78
  let choose ?printer ?name var_get lst =
79
79
    let rec choose_aux =
80
80
      function
110
110
                         str_lst)
111
111
    in
112
112
      choose_aux (List.rev lst)
113
 
  
 
113
 
114
114
end
115
115
 
116
116
 
 
117
# 117 "myocamlbuild.ml"
117
118
module BaseEnvLight = struct
118
 
# 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc2/src/base/BaseEnvLight.ml"
119
 
  
 
119
(* # 21 "/home/ysulsky/local/opam-full/4.00.1/build/oasis.0.3.0/src/base/BaseEnvLight.ml" *)
 
120
 
120
121
  module MapString = Map.Make(String)
121
 
  
 
122
 
122
123
  type t = string MapString.t
123
 
  
 
124
 
124
125
  let default_filename =
125
126
    Filename.concat
126
127
      (Sys.getcwd ())
127
128
      "setup.data"
128
 
  
 
129
 
129
130
  let load ?(allow_empty=false) ?(filename=default_filename) () =
130
131
    if Sys.file_exists filename then
131
132
      begin
182
183
             "Unable to load environment, the file '%s' doesn't exist."
183
184
             filename)
184
185
      end
185
 
  
 
186
 
186
187
  let var_get name env =
187
188
    let rec var_expand str =
188
189
      let buff =
203
204
        Buffer.contents buff
204
205
    in
205
206
      var_expand (MapString.find name env)
206
 
  
 
207
 
207
208
  let var_choose lst env =
208
209
    OASISExpr.choose
209
210
      (fun nm -> var_get nm env)
211
212
end
212
213
 
213
214
 
 
215
# 215 "myocamlbuild.ml"
214
216
module MyOCamlbuildFindlib = struct
215
 
# 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc2/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml"
216
 
  
 
217
(* # 21 "/home/ysulsky/local/opam-full/4.00.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
 
218
 
217
219
  (** OCamlbuild extension, copied from 
218
220
    * http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
219
221
    * by N. Pouillard and others
223
225
    * Modified by Sylvain Le Gall 
224
226
    *)
225
227
  open Ocamlbuild_plugin
226
 
  
 
228
 
227
229
  (* these functions are not really officially exported *)
228
230
  let run_and_read = 
229
231
    Ocamlbuild_pack.My_unix.run_and_read
230
 
  
 
232
 
231
233
  let blank_sep_strings = 
232
234
    Ocamlbuild_pack.Lexers.blank_sep_strings
233
 
  
 
235
 
234
236
  let split s ch =
235
237
    let x = 
236
238
      ref [] 
245
247
      try
246
248
        go s
247
249
      with Not_found -> !x
248
 
  
 
250
 
249
251
  let split_nl s = split s '\n'
250
 
  
 
252
 
251
253
  let before_space s =
252
254
    try
253
255
      String.before s (String.index s ' ')
254
256
    with Not_found -> s
255
 
  
 
257
 
256
258
  (* this lists all supported packages *)
257
259
  let find_packages () =
258
260
    List.map before_space (split_nl & run_and_read "ocamlfind list")
259
 
  
 
261
 
260
262
  (* this is supposed to list available syntaxes, but I don't know how to do it. *)
261
263
  let find_syntaxes () = ["camlp4o"; "camlp4r"]
262
 
  
 
264
 
263
265
  (* ocamlfind command *)
264
266
  let ocamlfind x = S[A"ocamlfind"; x]
265
 
  
 
267
 
266
268
  let dispatch =
267
269
    function
268
270
      | Before_options ->
292
294
              flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
293
295
            end 
294
296
            (find_packages ());
295
 
  
 
297
 
296
298
          (* Like -package but for extensions syntax. Morover -syntax is useless
297
299
           * when linking. *)
298
300
          List.iter begin fun syntax ->
301
303
          flag ["ocaml"; "doc";      "syntax_"^syntax] & S[A"-syntax"; A syntax];
302
304
          flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
303
305
          end (find_syntaxes ());
304
 
  
 
306
 
305
307
          (* The default "thread" tag is not compatible with ocamlfind.
306
308
           * Indeed, the default rules add the "threads.cma" or "threads.cmxa"
307
309
           * options when using this tag. When using the "-linkpkg" option with
314
316
          flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]);
315
317
          flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
316
318
          flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
317
 
  
 
319
 
318
320
      | _ -> 
319
321
          ()
320
 
  
 
322
 
321
323
end
322
324
 
323
325
module MyOCamlbuildBase = struct
324
 
# 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc2/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
325
 
  
 
326
(* # 21 "/home/ysulsky/local/opam-full/4.00.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
 
327
 
326
328
  (** Base functions for writing myocamlbuild.ml
327
329
      @author Sylvain Le Gall
328
330
    *)
329
 
  
330
 
  
331
 
  
 
331
 
 
332
 
 
333
 
332
334
  open Ocamlbuild_plugin
333
 
  
 
335
  module OC = Ocamlbuild_pack.Ocaml_compiler
 
336
 
334
337
  type dir = string 
335
338
  type file = string 
336
339
  type name = string 
337
340
  type tag = string 
338
 
  
339
 
# 55 "/Users/mmottl/Downloads/oasis-0.3.0~rc2/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
340
 
  
 
341
 
 
342
(* # 56 "/home/ysulsky/local/opam-full/4.00.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
 
343
 
341
344
  type t =
342
345
      {
343
346
        lib_ocaml: (name * dir list) list;
344
347
        lib_c:     (name * dir * file list) list; 
345
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; 
346
353
      } 
347
 
  
 
354
 
348
355
  let env_filename =
349
356
    Pathname.basename 
350
357
      BaseEnvLight.default_filename
351
 
  
 
358
 
352
359
  let dispatch_combine lst =
353
360
    fun e ->
354
361
      List.iter 
355
362
        (fun dispatch -> dispatch e)
356
363
        lst 
357
 
  
 
364
 
 
365
  let tag_libstubs nm =
 
366
    "use_lib"^nm^"_stubs"
 
367
 
 
368
  let nm_libstubs nm =
 
369
    nm^"_stubs"
 
370
 
358
371
  let dispatch t e = 
359
372
    let env = 
360
373
      BaseEnvLight.load 
381
394
                  Options.ext_lib, "ext_lib";
382
395
                  Options.ext_dll, "ext_dll";
383
396
                ]
384
 
  
 
397
 
385
398
        | After_rules -> 
386
399
            (* Declare OCaml libraries *)
387
400
            List.iter 
388
401
              (function
389
 
                 | lib, [] ->
390
 
                     ocaml_lib lib;
391
 
                 | lib, dir :: tl ->
392
 
                     ocaml_lib ~dir:dir lib;
 
402
                 | nm, [] ->
 
403
                     ocaml_lib nm
 
404
                 | nm, dir :: tl ->
 
405
                     ocaml_lib ~dir:dir (dir^"/"^nm);
393
406
                     List.iter 
394
407
                       (fun dir -> 
395
 
                          flag 
396
 
                            ["ocaml"; "use_"^lib; "compile"] 
397
 
                            (S[A"-I"; P dir]))
 
408
                          List.iter
 
409
                            (fun str ->
 
410
                               flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir]))
 
411
                            ["compile"; "infer_interface"; "doc"])
398
412
                       tl)
399
413
              t.lib_ocaml;
400
 
  
 
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
 
401
421
            (* Declare C libraries *)
402
422
            List.iter
403
423
              (fun (lib, dir, headers) ->
404
424
                   (* Handle C part of library *)
405
 
                   flag ["link"; "library"; "ocaml"; "byte"; "use_lib"^lib]
406
 
                     (S[A"-dllib"; A("-l"^lib); A"-cclib"; A("-l"^lib)]);
407
 
  
408
 
                   flag ["link"; "library"; "ocaml"; "native"; "use_lib"^lib]
409
 
                     (S[A"-cclib"; A("-l"^lib)]);
 
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))]);
410
431
                        
411
 
                   flag ["link"; "program"; "ocaml"; "byte"; "use_lib"^lib]
412
 
                     (S[A"-dllib"; A("dll"^lib)]);
413
 
  
 
432
                   flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib]
 
433
                     (S[A"-dllib"; A("dll"^(nm_libstubs lib))]);
 
434
 
414
435
                   (* When ocaml link something that use the C library, then one
415
436
                      need that file to be up to date.
416
437
                    *)
417
 
                   dep  ["link"; "ocaml"; "program"; "use_lib"^lib]
418
 
                     [dir/"lib"^lib^"."^(!Options.ext_lib)];
419
 
  
420
 
                   dep  ["compile"; "ocaml"; "program"; "use_lib"^lib]
421
 
                     [dir/"lib"^lib^"."^(!Options.ext_lib)];
422
 
  
 
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
 
423
444
                   (* TODO: be more specific about what depends on headers *)
424
445
                   (* Depends on .h files *)
425
446
                   dep ["compile"; "c"] 
426
447
                     headers;
427
 
  
 
448
 
428
449
                   (* Setup search path for lib *)
429
450
                   flag ["link"; "ocaml"; "use_"^lib] 
430
451
                     (S[A"-I"; P(dir)]);
431
452
              )
432
453
              t.lib_c;
433
 
  
 
454
 
434
455
              (* Add flags *)
435
456
              List.iter
436
457
              (fun (tags, cond_specs) ->
441
462
              t.flags
442
463
        | _ -> 
443
464
            ()
444
 
  
 
465
 
445
466
  let dispatch_default t =
446
467
    dispatch_combine 
447
468
      [
448
469
        dispatch t;
449
470
        MyOCamlbuildFindlib.dispatch;
450
471
      ]
451
 
  
 
472
 
452
473
end
453
474
 
454
475
 
 
476
# 476 "myocamlbuild.ml"
455
477
open Ocamlbuild_plugin;;
456
478
let package_default =
457
479
  {
458
480
     MyOCamlbuildBase.lib_ocaml =
459
481
       [
460
 
          ("lib/sexplib", ["lib"]);
461
 
          ("syntax/pa_sexp_conv", ["syntax"]);
462
 
          ("top/sexplib_top", ["top"])
 
482
          ("sexplib", ["lib"]);
 
483
          ("pa_sexp_conv", ["syntax"]);
 
484
          ("sexplib_top", ["top"])
463
485
       ];
464
486
     lib_c = [];
465
487
     flags = [];
 
488
     includes = [("lib_test", ["lib"; "syntax"])];
466
489
     }
467
490
  ;;
468
491
 
469
492
let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
470
493
 
471
 
# 472 "myocamlbuild.ml"
 
494
# 495 "myocamlbuild.ml"
472
495
(* OASIS_STOP *)
473
496
 
474
 
Ocamlbuild_plugin.dispatch 
475
 
  begin
476
 
    function
477
 
      | After_rules as e ->
478
 
 
479
 
          flag ["ocamldep"; "ocaml"; "use_pa_sexp_conv"]
480
 
            (S[A"-ppopt"; P"syntax/pa_sexp_conv.cma"]);
481
 
 
482
 
          flag ["compile"; "ocaml"; "use_pa_sexp_conv"]
483
 
            (S[A"-ppopt"; P"syntax/pa_sexp_conv.cma"]);
484
 
 
485
 
          dispatch_default e
486
 
      | e ->
487
 
          dispatch_default e 
488
 
  end
489
 
;;
 
497
let dispatch = function
 
498
  | After_rules ->
 
499
    pflag ["ocaml"; "compile"] "I" (fun x -> S [A "-I"; A x]);
 
500
    flag ["ocamldep"; "ocaml"; "use_pa_sexp_conv"]
 
501
      (S [A "-ppopt"; P "syntax/pa_sexp_conv.cma"]);
 
502
    flag ["compile"; "ocaml"; "use_pa_sexp_conv"]
 
503
      (S [A "-ppopt"; P "syntax/pa_sexp_conv.cma"])
 
504
  | _ ->
 
505
    ()
 
506
 
 
507
let () = Ocamlbuild_plugin.dispatch (fun hook -> dispatch hook; dispatch_default hook)