Project

General

Profile

« Previous | Next » 

Revision d1baac41

Added by Xavier Thirioux over 10 years ago

corrected a bug that made an error silent, confusing users...

git-svn-id: https://cavale.enseeiht.fr/svn/lustrec/lustre_compiler/trunk@370 041b043f-8d7c-46b2-b46e-ef0dd855326e

View differences:

myocamlbuild.ml
1 1
(* OASIS_START *)
2
(* DO NOT EDIT (digest: 5a9a2168dcb86db37476d58b8c0e25b3) *)
2
(* DO NOT EDIT (digest: 72be793de58c2829edbc48dbc71bb938) *)
3 3
module OASISGettext = struct
4
(* # 22 "src/oasis/OASISGettext.ml" *)
5

  
4
(* # 21 "src/oasis/OASISGettext.ml" *)
6 5

  
7 6
  let ns_ str =
8 7
    str
9 8

  
10

  
11 9
  let s_ str =
12 10
    str
13 11

  
14

  
15
  let f_ (str: ('a, 'b, 'c, 'd) format4) =
12
  let f_ (str : ('a, 'b, 'c, 'd) format4) =
16 13
    str
17 14

  
18

  
19 15
  let fn_ fmt1 fmt2 n =
20 16
    if n = 1 then
21 17
      fmt1^^""
22 18
    else
23 19
      fmt2^^""
24 20

  
25

  
26 21
  let init =
27 22
    []
28 23

  
29

  
30 24
end
31 25

  
32 26
module OASISExpr = struct
33
(* # 22 "src/oasis/OASISExpr.ml" *)
34

  
35

  
27
(* # 21 "src/oasis/OASISExpr.ml" *)
36 28

  
37 29

  
38 30

  
39 31
  open OASISGettext
40 32

  
33
  type test = string 
41 34

  
42
  type test = string
43

  
44

  
45
  type flag = string
46

  
35
  type flag = string 
47 36

  
48 37
  type t =
49 38
    | EBool of bool
......
52 41
    | EOr of t * t
53 42
    | EFlag of flag
54 43
    | ETest of test * string
44
    
55 45

  
56

  
57

  
58
  type 'a choices = (t * 'a) list
59

  
46
  type 'a choices = (t * 'a) list 
60 47

  
61 48
  let eval var_get t =
62 49
    let rec eval' =
......
88 75
    in
89 76
      eval' t
90 77

  
91

  
92 78
  let choose ?printer ?name var_get lst =
93 79
    let rec choose_aux =
94 80
      function
......
125 111
    in
126 112
      choose_aux (List.rev lst)
127 113

  
128

  
129 114
end
130 115

  
131 116

  
132
# 132 "myocamlbuild.ml"
117
# 117 "myocamlbuild.ml"
133 118
module BaseEnvLight = struct
134
(* # 22 "src/base/BaseEnvLight.ml" *)
135

  
119
(* # 21 "src/base/BaseEnvLight.ml" *)
136 120

  
137 121
  module MapString = Map.Make(String)
138 122

  
139

  
140 123
  type t = string MapString.t
141 124

  
142

  
143 125
  let default_filename =
144 126
    Filename.concat
145 127
      (Sys.getcwd ())
146 128
      "setup.data"
147 129

  
148

  
149 130
  let load ?(allow_empty=false) ?(filename=default_filename) () =
150 131
    if Sys.file_exists filename then
151 132
      begin
......
203 184
             filename)
204 185
      end
205 186

  
206

  
207
  let rec var_expand str env =
208
    let buff =
209
      Buffer.create ((String.length str) * 2)
210
    in
211
      Buffer.add_substitute
212
        buff
213
        (fun var ->
214
           try
215
             var_expand (MapString.find var env) env
216
           with Not_found ->
217
             failwith
218
               (Printf.sprintf
219
                  "No variable %s defined when trying to expand %S."
220
                  var
221
                  str))
222
        str;
223
      Buffer.contents buff
224

  
225

  
226 187
  let var_get name env =
227
    var_expand (MapString.find name env) env
228

  
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)
229 207

  
230 208
  let var_choose lst env =
231 209
    OASISExpr.choose
......
234 212
end
235 213

  
236 214

  
237
# 237 "myocamlbuild.ml"
215
# 215 "myocamlbuild.ml"
238 216
module MyOCamlbuildFindlib = struct
239
(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
240

  
217
(* # 21 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
241 218

  
242
  (** OCamlbuild extension, copied from
219
  (** OCamlbuild extension, copied from 
243 220
    * http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
244 221
    * by N. Pouillard and others
245 222
    *
246 223
    * Updated on 2009/02/28
247 224
    *
248
    * Modified by Sylvain Le Gall
225
    * Modified by Sylvain Le Gall 
249 226
    *)
250 227
  open Ocamlbuild_plugin
251 228

  
252

  
253 229
  (* these functions are not really officially exported *)
254
  let run_and_read =
230
  let run_and_read = 
255 231
    Ocamlbuild_pack.My_unix.run_and_read
256 232

  
257

  
258
  let blank_sep_strings =
233
  let blank_sep_strings = 
259 234
    Ocamlbuild_pack.Lexers.blank_sep_strings
260 235

  
261

  
262
  let exec_from_conf exec =
263
    let exec =
264
      let env_filename = Pathname.basename BaseEnvLight.default_filename in
265
      let env = BaseEnvLight.load ~filename:env_filename ~allow_empty:true () in
266
      try
267
        BaseEnvLight.var_get exec env
268
      with Not_found ->
269
        Printf.eprintf "W: Cannot get variable %s\n" exec;
270
        exec
271
    in
272
    let fix_win32 str =
273
      if Sys.os_type = "Win32" then begin
274
        let buff = Buffer.create (String.length str) in
275
        (* Adapt for windowsi, ocamlbuild + win32 has a hard time to handle '\\'.
276
         *)
277
        String.iter
278
          (fun c -> Buffer.add_char buff (if c = '\\' then '/' else c))
279
          str;
280
        Buffer.contents buff
281
      end else begin
282
        str
283
      end
284
    in
285
      fix_win32 exec
286

  
287 236
  let split s ch =
288
    let buf = Buffer.create 13 in
289
    let x = ref [] in
290
    let flush () =
291
      x := (Buffer.contents buf) :: !x;
292
      Buffer.clear buf
237
    let x = 
238
      ref [] 
293 239
    in
294
      String.iter
295
        (fun c ->
296
           if c = ch then
297
             flush ()
298
           else
299
             Buffer.add_char buf c)
300
        s;
301
      flush ();
302
      List.rev !x
303

  
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
304 250

  
305 251
  let split_nl s = split s '\n'
306 252

  
307

  
308 253
  let before_space s =
309 254
    try
310 255
      String.before s (String.index s ' ')
311 256
    with Not_found -> s
312 257

  
313
  (* ocamlfind command *)
314
  let ocamlfind x = S[Sh (exec_from_conf "ocamlfind"); x]
315

  
316
  (* This lists all supported packages. *)
258
  (* this lists all supported packages *)
317 259
  let find_packages () =
318 260
    List.map before_space (split_nl & run_and_read "ocamlfind list")
319 261

  
320

  
321
  (* Mock to list available syntaxes. *)
262
  (* this is supposed to list available syntaxes, but I don't know how to do it. *)
322 263
  let find_syntaxes () = ["camlp4o"; "camlp4r"]
323 264

  
324

  
325
  let well_known_syntax = [
326
    "camlp4.quotations.o";
327
    "camlp4.quotations.r";
328
    "camlp4.exceptiontracer";
329
    "camlp4.extend";
330
    "camlp4.foldgenerator";
331
    "camlp4.listcomprehension";
332
    "camlp4.locationstripper";
333
    "camlp4.macro";
334
    "camlp4.mapgenerator";
335
    "camlp4.metagenerator";
336
    "camlp4.profiler";
337
    "camlp4.tracer"
338
  ]
339

  
265
  (* ocamlfind command *)
266
  let ocamlfind x = S[A"ocamlfind"; x]
340 267

  
341 268
  let dispatch =
342 269
    function
343
      | After_options ->
344
          (* By using Before_options one let command line options have an higher
345
           * priority on the contrary using After_options will guarantee to have
346
           * the higher priority override default commands by ocamlfind ones *)
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 *)
347 274
          Options.ocamlc     := ocamlfind & A"ocamlc";
348 275
          Options.ocamlopt   := ocamlfind & A"ocamlopt";
349 276
          Options.ocamldep   := ocamlfind & A"ocamldep";
350 277
          Options.ocamldoc   := ocamlfind & A"ocamldoc";
351
          Options.ocamlmktop := ocamlfind & A"ocamlmktop";
352
          Options.ocamlmklib := ocamlfind & A"ocamlmklib"
353

  
278
          Options.ocamlmktop := ocamlfind & A"ocamlmktop"
279
                                  
354 280
      | After_rules ->
355

  
356
          (* When one link an OCaml library/binary/package, one should use
357
           * -linkpkg *)
281
          
282
          (* When one link an OCaml library/binary/package, one should use -linkpkg *)
358 283
          flag ["ocaml"; "link"; "program"] & A"-linkpkg";
359

  
284
          
360 285
          (* For each ocamlfind package one inject the -package option when
361 286
           * compiling, computing dependencies, generating documentation and
362 287
           * linking. *)
363
          List.iter
288
          List.iter 
364 289
            begin fun pkg ->
365
              let base_args = [A"-package"; A pkg] in
366
              (* TODO: consider how to really choose camlp4o or camlp4r. *)
367
              let syn_args = [A"-syntax"; A "camlp4o"] in
368
              let args =
369
              (* Heuristic to identify syntax extensions: whether they end in
370
                 ".syntax"; some might not.
371
               *)
372
                if Filename.check_suffix pkg "syntax" ||
373
                   List.mem pkg well_known_syntax then
374
                  syn_args @ base_args
375
                else
376
                  base_args
377
              in
378
              flag ["ocaml"; "compile";  "pkg_"^pkg] & S args;
379
              flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args;
380
              flag ["ocaml"; "doc";      "pkg_"^pkg] & S args;
381
              flag ["ocaml"; "link";     "pkg_"^pkg] & S base_args;
382
              flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args;
383
            end
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 
384 296
            (find_packages ());
385 297

  
386 298
          (* Like -package but for extensions syntax. Morover -syntax is useless
......
389 301
          flag ["ocaml"; "compile";  "syntax_"^syntax] & S[A"-syntax"; A syntax];
390 302
          flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
391 303
          flag ["ocaml"; "doc";      "syntax_"^syntax] & S[A"-syntax"; A syntax];
392
          flag ["ocaml"; "infer_interface"; "syntax_"^syntax] &
393
                S[A"-syntax"; A syntax];
304
          flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
394 305
          end (find_syntaxes ());
395 306

  
396 307
          (* The default "thread" tag is not compatible with ocamlfind.
397 308
           * Indeed, the default rules add the "threads.cma" or "threads.cmxa"
398 309
           * options when using this tag. When using the "-linkpkg" option with
399 310
           * ocamlfind, this module will then be added twice on the command line.
400
           *
311
           *                        
401 312
           * To solve this, one approach is to add the "-thread" option when using
402 313
           * the "threads" package using the previous plugin.
403 314
           *)
404 315
          flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
405 316
          flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]);
406 317
          flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
407
          flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"]);
408
          flag ["ocaml"; "package(threads)"; "compile"] (S[A "-thread"]);
409
          flag ["ocaml"; "package(threads)"; "doc"] (S[A "-I"; A "+threads"]);
410
          flag ["ocaml"; "package(threads)"; "link"] (S[A "-thread"]);
411
          flag ["ocaml"; "package(threads)"; "infer_interface"] (S[A "-thread"]);
318
          flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
412 319

  
413
      | _ ->
320
      | _ -> 
414 321
          ()
322

  
415 323
end
416 324

  
417 325
module MyOCamlbuildBase = struct
418
(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
419

  
326
(* # 21 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
420 327

  
421 328
  (** Base functions for writing myocamlbuild.ml
422 329
      @author Sylvain Le Gall
......
424 331

  
425 332

  
426 333

  
427

  
428

  
429 334
  open Ocamlbuild_plugin
430 335
  module OC = Ocamlbuild_pack.Ocaml_compiler
431 336

  
337
  type dir = string 
338
  type file = string 
339
  type name = string 
340
  type tag = string 
432 341

  
433
  type dir = string
434
  type file = string
435
  type name = string
436
  type tag = string
437

  
438

  
439
(* # 62 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
440

  
342
(* # 56 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
441 343

  
442 344
  type t =
443 345
      {
444
        lib_ocaml: (name * dir list * string list) list;
445
        lib_c:     (name * dir * file list) list;
346
        lib_ocaml: (name * dir list) list;
347
        lib_c:     (name * dir * file list) list; 
446 348
        flags:     (tag list * (spec OASISExpr.choices)) list;
447 349
        (* Replace the 'dir: include' from _tags by a precise interdepends in
448 350
         * directory.
449 351
         *)
450
        includes:  (dir * dir list) list;
451
      }
452

  
352
        includes:  (dir * dir list) list; 
353
      } 
453 354

  
454 355
  let env_filename =
455
    Pathname.basename
356
    Pathname.basename 
456 357
      BaseEnvLight.default_filename
457 358

  
458

  
459 359
  let dispatch_combine lst =
460 360
    fun e ->
461
      List.iter
361
      List.iter 
462 362
        (fun dispatch -> dispatch e)
463
        lst
464

  
363
        lst 
465 364

  
466 365
  let tag_libstubs nm =
467 366
    "use_lib"^nm^"_stubs"
468 367

  
469

  
470 368
  let nm_libstubs nm =
471 369
    nm^"_stubs"
472 370

  
473

  
474
  let dispatch t e =
475
    let env =
476
      BaseEnvLight.load
477
        ~filename:env_filename
371
  let dispatch t e = 
372
    let env = 
373
      BaseEnvLight.load 
374
        ~filename:env_filename 
478 375
        ~allow_empty:true
479 376
        ()
480 377
    in
481
      match e with
378
      match e with 
482 379
        | Before_options ->
483 380
            let no_trailing_dot s =
484 381
              if String.length s >= 1 && s.[0] = '.' then
......
488 385
            in
489 386
              List.iter
490 387
                (fun (opt, var) ->
491
                   try
388
                   try 
492 389
                     opt := no_trailing_dot (BaseEnvLight.var_get var env)
493 390
                   with Not_found ->
494
                     Printf.eprintf "W: Cannot get variable %s\n" var)
391
                     Printf.eprintf "W: Cannot get variable %s" var)
495 392
                [
496 393
                  Options.ext_obj, "ext_obj";
497 394
                  Options.ext_lib, "ext_lib";
498 395
                  Options.ext_dll, "ext_dll";
499 396
                ]
500 397

  
501
        | After_rules ->
398
        | After_rules -> 
502 399
            (* Declare OCaml libraries *)
503
            List.iter
400
            List.iter 
504 401
              (function
505
                 | nm, [], intf_modules ->
506
                     ocaml_lib nm;
507
                     let cmis =
508
                       List.map (fun m -> (String.uncapitalize m) ^ ".cmi")
509
                                intf_modules in
510
                     dep ["ocaml"; "link"; "library"; "file:"^nm^".cma"] cmis
511
                 | nm, dir :: tl, intf_modules ->
402
                 | nm, [] ->
403
                     ocaml_lib nm
404
                 | nm, dir :: tl ->
512 405
                     ocaml_lib ~dir:dir (dir^"/"^nm);
513
                     List.iter
514
                       (fun dir ->
406
                     List.iter 
407
                       (fun dir -> 
515 408
                          List.iter
516 409
                            (fun str ->
517 410
                               flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir]))
518 411
                            ["compile"; "infer_interface"; "doc"])
519
                       tl;
520
                     let cmis =
521
                       List.map (fun m -> dir^"/"^(String.uncapitalize m)^".cmi")
522
                                intf_modules in
523
                     dep ["ocaml"; "link"; "library"; "file:"^dir^"/"^nm^".cma"]
524
                         cmis)
412
                       tl)
525 413
              t.lib_ocaml;
526 414

  
527 415
            (* Declare directories dependencies, replace "include" in _tags. *)
528
            List.iter
416
            List.iter 
529 417
              (fun (dir, include_dirs) ->
530 418
                 Pathname.define_context dir include_dirs)
531 419
              t.includes;
......
540 428

  
541 429
                   flag ["link"; "library"; "ocaml"; "native"; tag_libstubs lib]
542 430
                     (S[A"-cclib"; A("-l"^(nm_libstubs lib))]);
543

  
431
                        
544 432
                   flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib]
545 433
                     (S[A"-dllib"; A("dll"^(nm_libstubs lib))]);
546 434

  
......
555 443

  
556 444
                   (* TODO: be more specific about what depends on headers *)
557 445
                   (* Depends on .h files *)
558
                   dep ["compile"; "c"]
446
                   dep ["compile"; "c"] 
559 447
                     headers;
560 448

  
561 449
                   (* Setup search path for lib *)
562
                   flag ["link"; "ocaml"; "use_"^lib]
450
                   flag ["link"; "ocaml"; "use_"^lib] 
563 451
                     (S[A"-I"; P(dir)]);
564 452
              )
565 453
              t.lib_c;
......
567 455
              (* Add flags *)
568 456
              List.iter
569 457
              (fun (tags, cond_specs) ->
570
                 let spec = BaseEnvLight.var_choose cond_specs env in
571
                 let rec eval_specs =
572
                   function
573
                     | S lst -> S (List.map eval_specs lst)
574
                     | A str -> A (BaseEnvLight.var_expand str env)
575
                     | spec -> spec
458
                 let spec = 
459
                   BaseEnvLight.var_choose cond_specs env
576 460
                 in
577
                   flag tags & (eval_specs spec))
461
                   flag tags & spec)
578 462
              t.flags
579
        | _ ->
463
        | _ -> 
580 464
            ()
581 465

  
582

  
583 466
  let dispatch_default t =
584
    dispatch_combine
467
    dispatch_combine 
585 468
      [
586 469
        dispatch t;
587 470
        MyOCamlbuildFindlib.dispatch;
588 471
      ]
589 472

  
590

  
591 473
end
592 474

  
593 475

  
594
# 594 "myocamlbuild.ml"
476
# 476 "myocamlbuild.ml"
595 477
open Ocamlbuild_plugin;;
596 478
let package_default =
597 479
  {MyOCamlbuildBase.lib_ocaml = []; lib_c = []; flags = []; includes = []}
......
599 481

  
600 482
let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
601 483

  
602
# 603 "myocamlbuild.ml"
484
# 485 "myocamlbuild.ml"
603 485
(* OASIS_STOP *)
604 486
Ocamlbuild_plugin.dispatch dispatch_default;;

Also available in: Unified diff