Project

General

Profile

Download (3.35 KB) Statistics
| Branch: | Tag: | Revision:
1
(********************************************************************)
2
(*                                                                  *)
3
(*  The LustreC compiler toolset   /  The LustreC Development Team  *)
4
(*  Copyright 2012 -    --   ONERA - CNRS - INPT                    *)
5
(*                                                                  *)
6
(*  LustreC is free software, distributed WITHOUT ANY WARRANTY      *)
7
(*  under the terms of the GNU Lesser General Public License        *)
8
(*  version 2.1.                                                    *)
9
(*                                                                  *)
10
(********************************************************************)
11

    
12
open Format
13
open LustreSpec
14
open Corelang
15

    
16
let header_has_code header =
17
  List.exists 
18
    (fun top -> 
19
      match top.top_decl_desc with
20
      | Const _ -> true 
21
      | ImportedNode nd -> nd.nodei_in_lib = None
22
      | _ -> false
23
    )
24
    header
25

    
26
let header_libs header =
27
  List.fold_left (fun accu top ->
28
    match top.top_decl_desc with
29
      | ImportedNode nd -> (match nd.nodei_in_lib with 
30
	| None -> accu 
31
	| Some lib -> Utils.list_union [lib] accu)
32
      | _ -> accu 
33
  ) [] header 
34
    
35

    
36
let compiled_dependencies dep = 
37
  List.filter (fun (Dep (_, _, header, _)) -> header_has_code header) dep
38

    
39
let lib_dependencies dep = 
40
  List.fold_left 
41
    (fun accu (Dep (_, _, header, _)) -> Utils.list_union (header_libs header) accu) [] dep
42
    
43
let fprintf_dependencies fmt (dep: dep_t list) =
44
  let compiled_dep = compiled_dependencies dep in
45
  List.iter (fun s -> (* Format.eprintf "Adding dependency: %s@." s;  *)
46
    fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
47
    (("${INC}/io_frontend.c"):: (* IO functions when a main function is computed *)
48
	(List.map 
49
	   (fun (Dep (local, s, _, _)) -> 
50
	     (if local then s else Version.include_path ^ "/" ^ s) ^ ".c")
51
	   compiled_dep))
52

    
53
module type MODIFIERS_MKF =
54
sig (* dep was (bool * ident * top_decl list) *)
55
  val other_targets: Format.formatter -> string -> string -> dep_t list -> unit
56
end
57

    
58
module EmptyMod =
59
(struct
60
  let other_targets _ _ _ _ = ()
61
end: MODIFIERS_MKF)
62

    
63
module Main = functor (Mod: MODIFIERS_MKF) -> 
64
struct
65

    
66

    
67
let print_makefile basename nodename (dependencies:  dep_t list) fmt =
68
  fprintf fmt "GCC=gcc@.";
69
  fprintf fmt "LUSTREC=%s@." Sys.executable_name;
70
  fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
71
  fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
72
  fprintf fmt "@.";
73

    
74
  (* Main binary *)
75
  fprintf fmt "%s_%s:@." basename nodename;
76
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;  
77
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s_main.c@." basename;   
78
  fprintf_dependencies fmt dependencies;    
79
  fprintf fmt "\t${GCC} -o %s_%s io_frontend.o %a %s.o %s_main.o %a@." basename nodename 
80
    (Utils.fprintf_list ~sep:" " (fun fmt (Dep (_, s, _, _)) -> Format.fprintf fmt "%s.o" s)) 
81
    (compiled_dependencies dependencies)
82
    basename (* library .o *)
83
    basename (* main function . o *) 
84
    (Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib)) (lib_dependencies dependencies)
85
    ;
86
 fprintf fmt "@.";
87
 fprintf fmt "clean:@.";
88
 fprintf fmt "\t\\rm -f *.o %s_%s@." basename nodename;
89
 fprintf fmt "@.";
90
 Mod.other_targets fmt basename nodename dependencies;
91
 fprintf fmt "@.";
92

    
93
end
94

    
95
(* Local Variables: *)
96
(* compile-command:"make -C ../../.." *)
97
(* End: *)
(5-5/7)