Project

General

Profile

Download (3.86 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 = []
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
(* TODO: BEWARE OF THE BUG !!  in case of very long nodename or maybe even
65
   basename, the string basename_nodename exceed a limit length for files on linux
66
   and prevent gcc to generate the binary of that name.
67

    
68
To be solved (later) with
69
- either the default name if it short
70
- a shorter version if it is long (md5?)
71
- a provided name given when calling the makefile so the user can control the 
72
  expected name of the binary
73

    
74
*)
75

    
76
let print_makefile basename nodename (dependencies:  dep_t list) fmt =
77
  fprintf fmt "GCC=gcc -O0@.";
78
  fprintf fmt "LUSTREC=%s@." Sys.executable_name;
79
  fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
80
  fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
81
  fprintf fmt "@.";
82

    
83
  (* Main binary *)
84
  fprintf fmt "%s_%s: %s.c %s_main.c@." basename "run"(*nodename*) basename basename;
85
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;  
86
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s_main.c@." basename;   
87
  fprintf_dependencies fmt dependencies;    
88
  fprintf fmt "\t${GCC} -o %s_%s io_frontend.o %a %s.o %s_main.o %a@." basename "run"(*nodename *)
89
    (Utils.fprintf_list ~sep:" " (fun fmt (Dep (_, s, _, _)) -> Format.fprintf fmt "%s.o" s)) 
90
    (compiled_dependencies dependencies)
91
    basename (* library .o *)
92
    basename (* main function . o *) 
93
    (Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib)) (lib_dependencies dependencies)
94
    ;
95
 fprintf fmt "@.";
96
 fprintf fmt "clean:@.";
97
 fprintf fmt "\t\\rm -f *.o %s_%s@." basename "run"(*nodename*);
98
 fprintf fmt "@.";
99
 fprintf fmt ".PHONY: %s_%s@." basename "run" (*nodename*);
100
 fprintf fmt "@.";
101
 Mod.other_targets fmt basename nodename dependencies;
102
 fprintf fmt "@.";
103

    
104
end
105

    
106
(* Local Variables: *)
107
(* compile-command:"make -C ../../.." *)
108
(* End: *)
(7-7/10)