Project

General

Profile

Download (2.56 KB) Statistics
| Branch: | Tag: | Revision:
1
open Format
2
open LustreSpec
3
open Corelang
4

    
5
let header_has_code header =
6
  List.exists 
7
    (fun top -> 
8
      match top.top_decl_desc with
9
      | Consts _ -> true 
10
      | ImportedNode nd -> nd.nodei_in_lib = None
11
      | _ -> false
12
    )
13
    header
14

    
15
let header_libs header =
16
  List.fold_left (fun accu top ->
17
    match top.top_decl_desc with
18
      | ImportedNode nd -> (match nd.nodei_in_lib with 
19
	| None -> accu 
20
	| Some lib -> Utils.list_union [lib] accu)
21
      | _ -> accu 
22
  ) [] header 
23
    
24

    
25
let compiled_dependencies dep = 
26
  List.filter (fun (_, _, header) -> header_has_code header) dep
27

    
28
let lib_dependencies dep = 
29
  List.fold_left 
30
    (fun accu (_, _, header) -> Utils.list_union (header_libs header) accu) [] dep
31
    
32
let fprintf_dependencies fmt dep =
33
  let compiled_dep = compiled_dependencies dep in
34
  List.iter (fun s -> (* Format.eprintf "Adding dependency: %s@." s;  *)
35
    fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
36
    (("${INC}/io_frontend.c"):: (* IO functions when a main function is computed *)
37
	(List.map 
38
	   (fun (s, local, _) -> 
39
	     (if local then s else Version.prefix ^ "/include/lustrec/" ^ s) ^ ".c")
40
	   compiled_dep))
41

    
42
module type MODIFIERS_MKF =
43
sig
44
  val other_targets: Format.formatter -> string -> string -> (string * bool * top_decl list) list -> unit
45
end
46

    
47
module EmptyMod =
48
struct
49
  let other_targets _ _ _ _ = ()
50
end
51

    
52
module Main = functor (Mod: MODIFIERS_MKF) -> 
53
struct
54

    
55

    
56
let print_makefile basename nodename dependencies fmt =
57
  fprintf fmt "GCC=gcc@.";
58
  fprintf fmt "LUSTREC=%s@." Sys.executable_name;
59
  fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
60
  fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
61
  fprintf fmt "@.";
62

    
63
  (* Main binary *)
64
  fprintf fmt "%s_%s:@." basename nodename;
65
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;  
66
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s_main.c@." basename;   
67
  fprintf_dependencies fmt dependencies;    
68
  fprintf fmt "\t${GCC} -o %s_%s io_frontend.o %a %s.o %s_main.o %a@." basename nodename 
69
    (Utils.fprintf_list ~sep:" " (fun fmt (s, _, _) -> Format.fprintf fmt "%s.o" s)) (compiled_dependencies dependencies)
70
    basename (* library .o *)
71
    basename (* main function . o *) 
72
    (Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib)) (lib_dependencies dependencies)
73
    ;
74
 fprintf fmt "@.";
75
 fprintf fmt "clean:@.";
76
 fprintf fmt "\t\\rm -f *.o %s_%s@." basename nodename;
77
 fprintf fmt "@.";
78
 Mod.other_targets fmt basename nodename dependencies;
79
 fprintf fmt "@.";
80

    
81
end
82

    
83
(* Local Variables: *)
84
(* compile-command:"make -C ../../.." *)
85
(* End: *)
(5-5/7)