lacaml / myocamlbuild.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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
(* OASIS_START *)
(* DO NOT EDIT (digest: bdaa21ca5cd1836a9ecc6178a820d370) *)
module OASISGettext = struct
(* # 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc5/src/oasis/OASISGettext.ml" *)
  
  let ns_ str =
    str
  
  let s_ str =
    str
  
  let f_ (str : ('a, 'b, 'c, 'd) format4) =
    str
  
  let fn_ fmt1 fmt2 n =
    if n = 1 then
      fmt1^^""
    else
      fmt2^^""
  
  let init =
    []
  
end

module OASISExpr = struct
(* # 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc5/src/oasis/OASISExpr.ml" *)
  
  
  
  open OASISGettext
  
  type test = string 
  
  type flag = string 
  
  type t =
    | EBool of bool
    | ENot of t
    | EAnd of t * t
    | EOr of t * t
    | EFlag of flag
    | ETest of test * string
    
  
  type 'a choices = (t * 'a) list 
  
  let eval var_get t =
    let rec eval' =
      function
        | EBool b ->
            b
  
        | ENot e ->
            not (eval' e)
  
        | EAnd (e1, e2) ->
            (eval' e1) && (eval' e2)
  
        | EOr (e1, e2) ->
            (eval' e1) || (eval' e2)
  
        | EFlag nm ->
            let v =
              var_get nm
            in
              assert(v = "true" || v = "false");
              (v = "true")
  
        | ETest (nm, vl) ->
            let v =
              var_get nm
            in
              (v = vl)
    in
      eval' t
  
  let choose ?printer ?name var_get lst =
    let rec choose_aux =
      function
        | (cond, vl) :: tl ->
            if eval var_get cond then
              vl
            else
              choose_aux tl
        | [] ->
            let str_lst =
              if lst = [] then
                s_ "<empty>"
              else
                String.concat
                  (s_ ", ")
                  (List.map
                     (fun (cond, vl) ->
                        match printer with
                          | Some p -> p vl
                          | None -> s_ "<no printer>")
                     lst)
            in
              match name with
                | Some nm ->
                    failwith
                      (Printf.sprintf
                         (f_ "No result for the choice list '%s': %s")
                         nm str_lst)
                | None ->
                    failwith
                      (Printf.sprintf
                         (f_ "No result for a choice list: %s")
                         str_lst)
    in
      choose_aux (List.rev lst)
  
end


# 117 "myocamlbuild.ml"
module BaseEnvLight = struct
(* # 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc5/src/base/BaseEnvLight.ml" *)
  
  module MapString = Map.Make(String)
  
  type t = string MapString.t
  
  let default_filename =
    Filename.concat
      (Sys.getcwd ())
      "setup.data"
  
  let load ?(allow_empty=false) ?(filename=default_filename) () =
    if Sys.file_exists filename then
      begin
        let chn =
          open_in_bin filename
        in
        let st =
          Stream.of_channel chn
        in
        let line =
          ref 1
        in
        let st_line =
          Stream.from
            (fun _ ->
               try
                 match Stream.next st with
                   | '\n' -> incr line; Some '\n'
                   | c -> Some c
               with Stream.Failure -> None)
        in
        let lexer =
          Genlex.make_lexer ["="] st_line
        in
        let rec read_file mp =
          match Stream.npeek 3 lexer with
            | [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] ->
                Stream.junk lexer;
                Stream.junk lexer;
                Stream.junk lexer;
                read_file (MapString.add nm value mp)
            | [] ->
                mp
            | _ ->
                failwith
                  (Printf.sprintf
                     "Malformed data file '%s' line %d"
                     filename !line)
        in
        let mp =
          read_file MapString.empty
        in
          close_in chn;
          mp
      end
    else if allow_empty then
      begin
        MapString.empty
      end
    else
      begin
        failwith
          (Printf.sprintf
             "Unable to load environment, the file '%s' doesn't exist."
             filename)
      end
  
  let var_get name env =
    let rec var_expand str =
      let buff =
        Buffer.create ((String.length str) * 2)
      in
        Buffer.add_substitute
          buff
          (fun var ->
             try
               var_expand (MapString.find var env)
             with Not_found ->
               failwith
                 (Printf.sprintf
                    "No variable %s defined when trying to expand %S."
                    var
                    str))
          str;
        Buffer.contents buff
    in
      var_expand (MapString.find name env)
  
  let var_choose lst env =
    OASISExpr.choose
      (fun nm -> var_get nm env)
      lst
end


# 215 "myocamlbuild.ml"
module MyOCamlbuildFindlib = struct
(* # 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc5/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
  
  (** OCamlbuild extension, copied from 
    * http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
    * by N. Pouillard and others
    *
    * Updated on 2009/02/28
    *
    * Modified by Sylvain Le Gall 
    *)
  open Ocamlbuild_plugin
  
  (* these functions are not really officially exported *)
  let run_and_read = 
    Ocamlbuild_pack.My_unix.run_and_read
  
  let blank_sep_strings = 
    Ocamlbuild_pack.Lexers.blank_sep_strings
  
  let split s ch =
    let x = 
      ref [] 
    in
    let rec go s =
      let pos = 
        String.index s ch 
      in
        x := (String.before s pos)::!x;
        go (String.after s (pos + 1))
    in
      try
        go s
      with Not_found -> !x
  
  let split_nl s = split s '\n'
  
  let before_space s =
    try
      String.before s (String.index s ' ')
    with Not_found -> s
  
  (* this lists all supported packages *)
  let find_packages () =
    List.map before_space (split_nl & run_and_read "ocamlfind list")
  
  (* this is supposed to list available syntaxes, but I don't know how to do it. *)
  let find_syntaxes () = ["camlp4o"; "camlp4r"]
  
  (* ocamlfind command *)
  let ocamlfind x = S[A"ocamlfind"; x]
  
  let dispatch =
    function
      | Before_options ->
          (* by using Before_options one let command line options have an higher priority *)
          (* on the contrary using After_options will guarantee to have the higher priority *)
          (* override default commands by ocamlfind ones *)
          Options.ocamlc     := ocamlfind & A"ocamlc";
          Options.ocamlopt   := ocamlfind & A"ocamlopt";
          Options.ocamldep   := ocamlfind & A"ocamldep";
          Options.ocamldoc   := ocamlfind & A"ocamldoc";
          Options.ocamlmktop := ocamlfind & A"ocamlmktop"
                                  
      | After_rules ->
          
          (* When one link an OCaml library/binary/package, one should use -linkpkg *)
          flag ["ocaml"; "link"; "program"] & A"-linkpkg";
          
          (* For each ocamlfind package one inject the -package option when
           * compiling, computing dependencies, generating documentation and
           * linking. *)
          List.iter 
            begin fun pkg ->
              flag ["ocaml"; "compile";  "pkg_"^pkg] & S[A"-package"; A pkg];
              flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
              flag ["ocaml"; "doc";      "pkg_"^pkg] & S[A"-package"; A pkg];
              flag ["ocaml"; "link";     "pkg_"^pkg] & S[A"-package"; A pkg];
              flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
            end 
            (find_packages ());
  
          (* Like -package but for extensions syntax. Morover -syntax is useless
           * when linking. *)
          List.iter begin fun syntax ->
          flag ["ocaml"; "compile";  "syntax_"^syntax] & S[A"-syntax"; A syntax];
          flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
          flag ["ocaml"; "doc";      "syntax_"^syntax] & S[A"-syntax"; A syntax];
          flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
          end (find_syntaxes ());
  
          (* The default "thread" tag is not compatible with ocamlfind.
           * Indeed, the default rules add the "threads.cma" or "threads.cmxa"
           * options when using this tag. When using the "-linkpkg" option with
           * ocamlfind, this module will then be added twice on the command line.
           *                        
           * To solve this, one approach is to add the "-thread" option when using
           * the "threads" package using the previous plugin.
           *)
          flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
          flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]);
          flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
          flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
  
      | _ -> 
          ()
  
end

module MyOCamlbuildBase = struct
(* # 21 "/Users/mmottl/Downloads/oasis-0.3.0~rc5/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
  
  (** Base functions for writing myocamlbuild.ml
      @author Sylvain Le Gall
    *)
  
  
  
  open Ocamlbuild_plugin
  module OC = Ocamlbuild_pack.Ocaml_compiler
  
  type dir = string 
  type file = string 
  type name = string 
  type tag = string 
  
(* # 56 "/Users/mmottl/Downloads/oasis-0.3.0~rc5/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
  
  type t =
      {
        lib_ocaml: (name * dir list) list;
        lib_c:     (name * dir * file list) list; 
        flags:     (tag list * (spec OASISExpr.choices)) list;
        (* Replace the 'dir: include' from _tags by a precise interdepends in
         * directory.
         *)
        includes:  (dir * dir list) list; 
      } 
  
  let env_filename =
    Pathname.basename 
      BaseEnvLight.default_filename
  
  let dispatch_combine lst =
    fun e ->
      List.iter 
        (fun dispatch -> dispatch e)
        lst 
  
  let tag_libstubs nm =
    "use_lib"^nm^"_stubs"
  
  let nm_libstubs nm =
    nm^"_stubs"
  
  let dispatch t e = 
    let env = 
      BaseEnvLight.load 
        ~filename:env_filename 
        ~allow_empty:true
        ()
    in
      match e with 
        | Before_options ->
            let no_trailing_dot s =
              if String.length s >= 1 && s.[0] = '.' then
                String.sub s 1 ((String.length s) - 1)
              else
                s
            in
              List.iter
                (fun (opt, var) ->
                   try 
                     opt := no_trailing_dot (BaseEnvLight.var_get var env)
                   with Not_found ->
                     Printf.eprintf "W: Cannot get variable %s" var)
                [
                  Options.ext_obj, "ext_obj";
                  Options.ext_lib, "ext_lib";
                  Options.ext_dll, "ext_dll";
                ]
  
        | Before_rules ->
          (* TODO: move this into its own file and conditionnaly include it, if
           * needed.
           *)
          (* OCaml cmxs rules: cmxs available in ocamlopt but not ocamlbuild.
             Copied from ocaml_specific.ml in ocamlbuild sources. *)
          let has_native_dynlink =
            try
              bool_of_string (BaseEnvLight.var_get "native_dynlink" env)
            with Not_found ->
              false
          in
          if has_native_dynlink && String.sub Sys.ocaml_version 0 4 = "3.11" then
            begin
              let ext_lib = !Options.ext_lib in
              let ext_obj = !Options.ext_obj in
              let ext_dll = !Options.ext_dll in
              let x_o = "%"-.-ext_obj in
              let x_a = "%"-.-ext_lib in
              let x_dll = "%"-.-ext_dll in
              let x_p_o = "%.p"-.-ext_obj in
              let x_p_a = "%.p"-.-ext_lib in
              let x_p_dll = "%.p"-.-ext_dll in
  
              rule "ocaml: mldylib & p.cmx* & p.o* -> p.cmxs & p.so"
                   ~tags:["ocaml"; "native"; "profile"; "shared"; "library"]
                   ~prods:["%.p.cmxs"; x_p_dll]
                   ~dep:"%.mldylib"
                   (OC.native_profile_shared_library_link_mldylib
                      "%.mldylib" "%.p.cmxs");
  
              rule "ocaml: mldylib & cmx* & o* -> cmxs & so"
                   ~tags:["ocaml"; "native"; "shared"; "library"]
                   ~prods:["%.cmxs"; x_dll]
                   ~dep:"%.mldylib"
                   (OC.native_shared_library_link_mldylib
                      "%.mldylib" "%.cmxs");
  
              rule "ocaml: p.cmx & p.o -> p.cmxs & p.so"
                   ~tags:["ocaml"; "native"; "profile"; "shared"; "library"]
                   ~prods:["%.p.cmxs"; x_p_dll]
                   ~deps:["%.p.cmx"; x_p_o]
                   (OC.native_shared_library_link ~tags:["profile"]
                                                  "%.p.cmx" "%.p.cmxs");
  
              rule "ocaml: p.cmxa & p.a -> p.cmxs & p.so"
                   ~tags:["ocaml"; "native"; "profile"; "shared"; "library"]
                   ~prods:["%.p.cmxs"; x_p_dll]
                   ~deps:["%.p.cmxa"; x_p_a]
                   (OC.native_shared_library_link ~tags:["profile"; "linkall"]
                                                  "%.p.cmxa" "%.p.cmxs");
  
              rule "ocaml: cmx & o -> cmxs"
                   ~tags:["ocaml"; "native"; "shared"; "library"]
                   ~prods:["%.cmxs"]
                   ~deps:["%.cmx"; x_o]
                   (OC.native_shared_library_link "%.cmx" "%.cmxs");
  
              rule "ocaml: cmx & o -> cmxs & so"
                   ~tags:["ocaml"; "native"; "shared"; "library"]
                   ~prods:["%.cmxs"; x_dll]
                   ~deps:["%.cmx"; x_o]
                   (OC.native_shared_library_link "%.cmx" "%.cmxs");
  
              rule "ocaml: cmxa & a -> cmxs & so"
                   ~tags:["ocaml"; "native"; "shared"; "library"]
                   ~prods:["%.cmxs"; x_dll]
                   ~deps:["%.cmxa"; x_a]
                   (OC.native_shared_library_link ~tags:["linkall"]
                                                  "%.cmxa" "%.cmxs");
            end
  
        | After_rules -> 
            (* Declare OCaml libraries *)
            List.iter 
              (function
                 | nm, [] ->
                     ocaml_lib nm
                 | nm, dir :: tl ->
                     ocaml_lib ~dir:dir (dir^"/"^nm);
                     List.iter 
                       (fun dir -> 
                          List.iter
                            (fun str ->
                               flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir]))
                            ["compile"; "infer_interface"; "doc"])
                       tl)
              t.lib_ocaml;
  
            (* Declare directories dependencies, replace "include" in _tags. *)
            List.iter 
              (fun (dir, include_dirs) ->
                 Pathname.define_context dir include_dirs)
              t.includes;
  
            (* Declare C libraries *)
            List.iter
              (fun (lib, dir, headers) ->
                   (* Handle C part of library *)
                   flag ["link"; "library"; "ocaml"; "byte"; tag_libstubs lib]
                     (S[A"-dllib"; A("-l"^(nm_libstubs lib)); A"-cclib";
                        A("-l"^(nm_libstubs lib))]);
  
                   flag ["link"; "library"; "ocaml"; "native"; tag_libstubs lib]
                     (S[A"-cclib"; A("-l"^(nm_libstubs lib))]);
                        
                   flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib]
                     (S[A"-dllib"; A("dll"^(nm_libstubs lib))]);
  
                   (* When ocaml link something that use the C library, then one
                      need that file to be up to date.
                    *)
                   dep  ["link"; "ocaml"; "program"; tag_libstubs lib]
                     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
  
                   dep  ["compile"; "ocaml"; "program"; tag_libstubs lib]
                     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
  
                   (* TODO: be more specific about what depends on headers *)
                   (* Depends on .h files *)
                   dep ["compile"; "c"] 
                     headers;
  
                   (* Setup search path for lib *)
                   flag ["link"; "ocaml"; "use_"^lib] 
                     (S[A"-I"; P(dir)]);
              )
              t.lib_c;
  
              (* Add flags *)
              List.iter
              (fun (tags, cond_specs) ->
                 let spec = 
                   BaseEnvLight.var_choose cond_specs env
                 in
                   flag tags & spec)
              t.flags
        | _ -> 
            ()
  
  let dispatch_default t =
    dispatch_combine 
      [
        dispatch t;
        MyOCamlbuildFindlib.dispatch;
      ]
  
end


# 548 "myocamlbuild.ml"
open Ocamlbuild_plugin;;
let package_default =
  {
     MyOCamlbuildBase.lib_ocaml =
       [("lacaml", ["lib"]); ("lacaml_top", ["lib"])];
     lib_c =
       [
          ("lacaml",
            "lib",
            ["lib/f2c.h"; "lib/lacaml_macros.h"; "lib/utils_c.h"])
       ];
     flags =
       [
          (["oasis_library_lacaml_ccopt"; "compile"],
            [
               (OASISExpr.EBool true,
                 S [A "-ccopt"; A "-O2"; A "-ccopt"; A "-DPIC"]);
               (OASISExpr.ETest ("system", "macosx"),
                 S
                   [
                      A "-ccopt";
                      A "-O2";
                      A "-ccopt";
                      A "-DPIC";
                      A "-ccopt";
                      A "-DEXTERNAL_EXP10";
                      A "-ccopt";
                      A "-framework";
                      A "-ccopt";
                      A "vecLib"
                   ]);
               (OASISExpr.ETest ("system", "mingw"),
                 S
                   [
                      A "-ccopt";
                      A "-O2";
                      A "-ccopt";
                      A "-DPIC";
                      A "-ccopt";
                      A "-DEXTERNAL_EXP10"
                   ])
            ]);
          (["oasis_library_lacaml_cclib"; "link"],
            [
               (OASISExpr.EBool true,
                 S [A "-cclib"; A "-lblas"; A "-cclib"; A "-llapack"]);
               (OASISExpr.ETest ("system", "macosx"),
                 S [A "-cclib"; A "-framework"; A "-cclib"; A "vecLib"])
            ]);
          (["oasis_library_lacaml_cclib"; "ocamlmklib"; "c"],
            [
               (OASISExpr.EBool true, S [A "-lblas"; A "-llapack"]);
               (OASISExpr.ETest ("system", "macosx"),
                 S [A "-framework"; A "vecLib"])
            ]);
          (["oasis_executable_blas_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_blas_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_eig_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_eig_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_sbev_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_sbev_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_sbgv_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_sbgv_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_lin_eq_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_lin_eq_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_gbsv_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_gbsv_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_lin_eq_comp_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_lin_eq_comp_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_lin_reg_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_lin_reg_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_qr_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_qr_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_svd_dllpath"; "link"; "byte"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])]);
          (["oasis_executable_svd_dllpath"; "ocamlmklib"; "c"],
            [(OASISExpr.EBool true, S [A "-dllpath"; P "../../lib"])])
       ];
     includes =
       [
          ("examples/svd", ["lib"]);
          ("examples/qr", ["lib"]);
          ("examples/lin_reg", ["lib"]);
          ("examples/lin_eq_comp", ["lib"]);
          ("examples/lin_eq", ["lib"]);
          ("examples/eig", ["lib"]);
          ("examples/blas", ["lib"])
       ];
     }
  ;;

let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;

# 661 "myocamlbuild.ml"
(* OASIS_STOP *)
# 502 "myocamlbuild.ml"

let rec split_on is_delim s i0 i i1 =
  if i >= i1 then [String.sub s i0 (i1 - i0)]
  else if is_delim s.[i] then
    String.sub s i0 (i - i0) :: skip is_delim s (i + 1) i1
  else
    split_on is_delim s i0 (i + 1) i1
and skip is_delim s i i1 =
  if i >= i1 then []
  else if is_delim s.[i] then skip is_delim s (i + 1) i1
  else split_on is_delim s i (i + 1) i1

let split_on_spaces s = skip (fun c -> c = ' ') s 0 (String.length s)
let split_on_tabs s = skip (fun c -> c = '\t') s 0 (String.length s)

let env = BaseEnvLight.load() (* setup.data *)
let ocamlfind = BaseEnvLight.var_get "ocamlfind" env
let stdlib = BaseEnvLight.var_get "standard_library" env

let a l = List.map (fun s -> A s) l
let conf_ccopt = a(split_on_tabs(BaseEnvLight.var_get "conf_ccopt" env))
let conf_cclib = a(split_on_tabs(BaseEnvLight.var_get "conf_cclib" env))

let replace1 want_tags spec ((tags, specs) as ts) =
  let all_tags = List.fold_left (fun a t -> a && List.mem t tags) true want_tags in
  if all_tags then (tags, [(OASISExpr.EBool true, S spec)])
  else ts

let replace tags spec l = List.map (replace1 tags spec) l

let prefix_each p l =
  List.fold_right (fun a l' -> p :: a :: l') l []

let package_default =
  (* Act on conf.ml *)
  let flags = package_default.MyOCamlbuildBase.flags in
  let flags = match conf_ccopt with
    | [] -> flags
    | _ -> replace ["oasis_library_lacaml_ccopt"]
                  (prefix_each (A "-ccopt") conf_ccopt) flags in
  let flags = match conf_cclib with
    | [] -> flags
    | _ ->
      let flags = replace ["oasis_library_lacaml_cclib"; "ocamlmklib"]
                          conf_cclib flags in
      replace ["oasis_library_lacaml_cclib"; "link"]
              (prefix_each (A "-cclib") conf_cclib) flags in
  { package_default with MyOCamlbuildBase.flags = flags }

let () =
  let additional_rules = function
    | After_rules ->
      flag
        ["compile"; "ocaml"] (S [A "-w"; A "@Aer"; A "-strict-sequence" ]);

      flag ["compile"; "ocaml"] (S [A "-I"; A "+compiler-libs"]);

      (* Files included, tailored with macros. *)
      dep ["compile"; "c"]
          ["lib"/"fold_col.c"; "lib"/"fold2_col.c";
           "lib"/"vec_map.c"; "lib"/"vec_combine.c"; "lib"/"vec_sort.c"];

      (* Special rules for precision dependent C code. *)
      let lacaml_cc desc ~prod ~dep flags =
        rule ("Lacaml: " ^ desc) ~prod ~dep
             (fun env _build ->
              let f = env dep and o = env prod in
              let tags = tags_of_pathname f ++ "compile" ++ "c"
                         ++ "oasis_library_lacaml_ccopt" in

              let add_ccopt f l = A"-ccopt" :: f :: l in
              let flags = List.fold_right add_ccopt flags [] in
              (* unfortunately -o is not respected for C files, use -ccopt. *)
              let cmd = [A ocamlfind; A"ocamlc"; A"-ccopt"; A("-o " ^ o)]
                        @ flags @ [T tags; A"-c"; P f] in
              Seq[Cmd(S(cmd))]
             ) in
      lacaml_cc "simple of SD" ~prod:"%2_S_c.o" ~dep:"%_SD_c.c" [];
      lacaml_cc "double of SD" ~prod:"%2_D_c.o" ~dep:"%_SD_c.c"
                [A"-DLACAML_DOUBLE"];
      lacaml_cc "simple of CZ" ~prod:"%2_C_c.o" ~dep:"%_CZ_c.c"
                [A"-DLACAML_COMPLEX"];
      lacaml_cc "double of CZ" ~prod:"%2_Z_c.o" ~dep:"%_CZ_c.c"
                [A"-DLACAML_COMPLEX"; A"-DLACAML_DOUBLE"];

      lacaml_cc "simple of SDCZ" ~prod:"%4_S_c.o" ~dep:"%_SDCZ_c.c" [];
      lacaml_cc "double of SDCZ" ~prod:"%4_D_c.o" ~dep:"%_SDCZ_c.c"
                [A"-DLACAML_DOUBLE"];
      lacaml_cc "complex32 of SDCZ" ~prod:"%4_C_c.o" ~dep:"%_SDCZ_c.c"
                [A"-DLACAML_COMPLEX"];
      lacaml_cc "complex64 of SDCZ" ~prod:"%4_Z_c.o" ~dep:"%_SDCZ_c.c"
                [A"-DLACAML_COMPLEX"; A"-DLACAML_DOUBLE"];

    | _ -> ()
  in
  dispatch
    (MyOCamlbuildBase.dispatch_combine [
         MyOCamlbuildBase.dispatch_default package_default;
         additional_rules ])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.