Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / backends / C / c_backend_makefile.ml @ 70e1006b

History | View | Annotate | Download (3.26 KB)

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 (_, _, header) -> header_has_code header) dep
38

    
39
let lib_dependencies dep = 
40
  List.fold_left 
41
    (fun accu (_, _, header) -> Utils.list_union (header_libs header) accu) [] dep
42
    
43
let fprintf_dependencies fmt dep =
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 (local, s, _) -> 
50
	     (if local then s else Version.prefix ^ "/include/lustrec/" ^ s) ^ ".c")
51
	   compiled_dep))
52

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

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

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

    
66

    
67
let print_makefile basename nodename dependencies 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 (_, s, _) -> Format.fprintf fmt "%s.o" s)) (compiled_dependencies dependencies)
81
    basename (* library .o *)
82
    basename (* main function . o *) 
83
    (Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib)) (lib_dependencies dependencies)
84
    ;
85
 fprintf fmt "@.";
86
 fprintf fmt "clean:@.";
87
 fprintf fmt "\t\\rm -f *.o %s_%s@." basename nodename;
88
 fprintf fmt "@.";
89
 Mod.other_targets fmt basename nodename dependencies;
90
 fprintf fmt "@.";
91

    
92
end
93

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