Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / backends / C / c_backend_makefile.ml @ 45f0f48d

History | View | Annotate | Download (3.41 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 = []
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 -> Utils.list_union nd.nodei_in_lib accu
30
      | _ -> accu 
31
  ) [] header 
32
    
33

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

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

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

    
56
module EmptyMod =
57
(struct
58
  let other_targets _ _ _ _ = ()
59
end: MODIFIERS_MKF)
60

    
61
module Main = functor (Mod: MODIFIERS_MKF) -> 
62
struct
63

    
64

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

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