Project

General

Profile

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

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

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

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

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

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

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

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

    
56

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

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

    
82
end
83

    
84
(* Local Variables: *)
85
(* compile-command:"make -C ../../.." *)
86
(* End: *)
(6-6/9)