Project

General

Profile

Download (3.38 KB) Statistics
| Branch: | Tag: | Revision:
1 b38ffff3 ploc
(********************************************************************)
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 522938b5 ploc
open Format
13 0038002e ploc
open LustreSpec
14 522938b5 ploc
open Corelang
15
16
let header_has_code header =
17
  List.exists 
18
    (fun top -> 
19
      match top.top_decl_desc with
20 70e1006b xthirioux
      | Const _ -> true 
21 522938b5 ploc
      | 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 e95470b3 ploc
36
let compiled_dependencies dep = 
37 830de634 ploc
  List.filter (fun (Dep (_, _, header, _)) -> header_has_code header) dep
38 e95470b3 ploc
39
let lib_dependencies dep = 
40
  List.fold_left 
41 830de634 ploc
    (fun accu (Dep (_, _, header, _)) -> Utils.list_union (header_libs header) accu) [] dep
42 e95470b3 ploc
    
43 830de634 ploc
let fprintf_dependencies fmt (dep: dep_t list) =
44 e95470b3 ploc
  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 830de634 ploc
	   (fun (Dep (local, s, _, _)) -> 
50 5ae8db15 ploc
	     (if local then s else Version.include_path ^ "/" ^ s) ^ ".c")
51 e95470b3 ploc
	   compiled_dep))
52
53
module type MODIFIERS_MKF =
54 830de634 ploc
sig (* dep was (bool * ident * top_decl list) *)
55
  val other_targets: Format.formatter -> string -> string -> dep_t list -> unit
56 e95470b3 ploc
end
57
58
module EmptyMod =
59 830de634 ploc
(struct
60 e95470b3 ploc
  let other_targets _ _ _ _ = ()
61 830de634 ploc
end: MODIFIERS_MKF)
62 e95470b3 ploc
63
module Main = functor (Mod: MODIFIERS_MKF) -> 
64
struct
65
66
67 830de634 ploc
let print_makefile basename nodename (dependencies:  dep_t list) fmt =
68 522938b5 ploc
  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 e95470b3 ploc
74
  (* Main binary *)
75 8eee42de Ploc
  fprintf fmt "%s_%s: %s.c %s_main.c@." basename nodename basename basename;
76 e95470b3 ploc
  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 830de634 ploc
    (Utils.fprintf_list ~sep:" " (fun fmt (Dep (_, s, _, _)) -> Format.fprintf fmt "%s.o" s)) 
81
    (compiled_dependencies dependencies)
82 e95470b3 ploc
    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 522938b5 ploc
    ;
86
 fprintf fmt "@.";
87
 fprintf fmt "clean:@.";
88 e95470b3 ploc
 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 713176a4 ploc
end
94 522938b5 ploc
95
(* Local Variables: *)
96
(* compile-command:"make -C ../../.." *)
97
(* End: *)