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 |
8446bf03
|
ploc
|
open Lustre_types
|
14 |
522938b5
|
ploc
|
open Corelang
|
15 |
|
|
|
16 |
0bca9d53
|
ploc
|
let pp_dep fmt (Dep(b,id,tops,stateful)) =
|
17 |
|
|
Format.fprintf fmt "%b, %s, {%a}, %b"
|
18 |
|
|
b id Printers.pp_prog tops stateful
|
19 |
|
|
|
20 |
|
|
let pp_deps fmt deps = Format.fprintf fmt "@[<v 0>%a@ @]" (Utils.fprintf_list ~sep:"@ ," pp_dep) deps
|
21 |
|
|
|
22 |
522938b5
|
ploc
|
let header_has_code header =
|
23 |
|
|
List.exists
|
24 |
|
|
(fun top ->
|
25 |
|
|
match top.top_decl_desc with
|
26 |
70e1006b
|
xthirioux
|
| Const _ -> true
|
27 |
53206908
|
xthirioux
|
| ImportedNode nd -> nd.nodei_in_lib = []
|
28 |
522938b5
|
ploc
|
| _ -> false
|
29 |
|
|
)
|
30 |
|
|
header
|
31 |
|
|
|
32 |
|
|
let header_libs header =
|
33 |
|
|
List.fold_left (fun accu top ->
|
34 |
|
|
match top.top_decl_desc with
|
35 |
53206908
|
xthirioux
|
| ImportedNode nd -> Utils.list_union nd.nodei_in_lib accu
|
36 |
522938b5
|
ploc
|
| _ -> accu
|
37 |
|
|
) [] header
|
38 |
|
|
|
39 |
e95470b3
|
ploc
|
|
40 |
|
|
let compiled_dependencies dep =
|
41 |
830de634
|
ploc
|
List.filter (fun (Dep (_, _, header, _)) -> header_has_code header) dep
|
42 |
e95470b3
|
ploc
|
|
43 |
|
|
let lib_dependencies dep =
|
44 |
|
|
List.fold_left
|
45 |
830de634
|
ploc
|
(fun accu (Dep (_, _, header, _)) -> Utils.list_union (header_libs header) accu) [] dep
|
46 |
e95470b3
|
ploc
|
|
47 |
830de634
|
ploc
|
let fprintf_dependencies fmt (dep: dep_t list) =
|
48 |
0bca9d53
|
ploc
|
(* Format.eprintf "Deps: %a@." pp_deps dep; *)
|
49 |
e95470b3
|
ploc
|
let compiled_dep = compiled_dependencies dep in
|
50 |
0bca9d53
|
ploc
|
(* Format.eprintf "Compiled Deps: %a@." pp_deps compiled_dep; *)
|
51 |
|
|
|
52 |
|
|
List.iter (fun s -> Format.eprintf "Adding dependency: %s@." s;
|
53 |
e95470b3
|
ploc
|
fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
|
54 |
|
|
(("${INC}/io_frontend.c"):: (* IO functions when a main function is computed *)
|
55 |
|
|
(List.map
|
56 |
830de634
|
ploc
|
(fun (Dep (local, s, _, _)) ->
|
57 |
5ae8db15
|
ploc
|
(if local then s else Version.include_path ^ "/" ^ s) ^ ".c")
|
58 |
e95470b3
|
ploc
|
compiled_dep))
|
59 |
|
|
|
60 |
|
|
module type MODIFIERS_MKF =
|
61 |
830de634
|
ploc
|
sig (* dep was (bool * ident * top_decl list) *)
|
62 |
|
|
val other_targets: Format.formatter -> string -> string -> dep_t list -> unit
|
63 |
e95470b3
|
ploc
|
end
|
64 |
|
|
|
65 |
|
|
module EmptyMod =
|
66 |
830de634
|
ploc
|
(struct
|
67 |
e95470b3
|
ploc
|
let other_targets _ _ _ _ = ()
|
68 |
830de634
|
ploc
|
end: MODIFIERS_MKF)
|
69 |
e95470b3
|
ploc
|
|
70 |
|
|
module Main = functor (Mod: MODIFIERS_MKF) ->
|
71 |
|
|
struct
|
72 |
|
|
|
73 |
f76eae4f
|
ploc
|
(* TODO: BEWARE OF THE BUG !! in case of very long nodename or maybe even
|
74 |
|
|
basename, the string basename_nodename exceed a limit length for files on linux
|
75 |
|
|
and prevent gcc to generate the binary of that name.
|
76 |
|
|
|
77 |
|
|
To be solved (later) with
|
78 |
|
|
- either the default name if it short
|
79 |
|
|
- a shorter version if it is long (md5?)
|
80 |
|
|
- a provided name given when calling the makefile so the user can control the
|
81 |
|
|
expected name of the binary
|
82 |
|
|
|
83 |
|
|
*)
|
84 |
e95470b3
|
ploc
|
|
85 |
6a078e8a
|
ploc
|
let print_makefile basename nodename (dependencies: dep_t list) fmt =
|
86 |
|
|
let binname =
|
87 |
|
|
let s = basename ^ "_" ^ nodename in
|
88 |
|
|
if String.length s > 100 (* seems that GCC fails from 144 characters and
|
89 |
|
|
on: File name too long collect2 ld error. *)
|
90 |
|
|
then
|
91 |
|
|
if String.length nodename > 100 then
|
92 |
|
|
basename ^ "_run" (* shorter version *)
|
93 |
|
|
else
|
94 |
|
|
nodename ^ "run"
|
95 |
|
|
else
|
96 |
|
|
s
|
97 |
|
|
in
|
98 |
|
|
fprintf fmt "BINNAME?=%s@." binname;
|
99 |
|
|
fprintf fmt "GCC=gcc -O0@.";
|
100 |
|
|
fprintf fmt "LUSTREC=%s@." Sys.executable_name;
|
101 |
|
|
fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
|
102 |
|
|
fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
|
103 |
|
|
fprintf fmt "@.";
|
104 |
e95470b3
|
ploc
|
|
105 |
6a078e8a
|
ploc
|
(* Main binary *)
|
106 |
|
|
fprintf fmt "%s_%s: %s.c %s_main.c@." basename "run"(*nodename*) basename basename;
|
107 |
|
|
fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;
|
108 |
|
|
fprintf fmt "\t${GCC} -I${INC} -I. -c %s_main.c@." basename;
|
109 |
|
|
fprintf_dependencies fmt dependencies;
|
110 |
|
|
fprintf fmt "\t${GCC} -o ${BINNAME} io_frontend.o %a %s.o %s_main.o %a@."
|
111 |
|
|
(Utils.fprintf_list ~sep:" " (fun fmt (Dep (_, s, _, _)) -> Format.fprintf fmt "%s.o" s))
|
112 |
|
|
(compiled_dependencies dependencies)
|
113 |
|
|
basename (* library .o *)
|
114 |
|
|
basename (* main function . o *)
|
115 |
|
|
(Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib)) (lib_dependencies dependencies)
|
116 |
522938b5
|
ploc
|
;
|
117 |
6a078e8a
|
ploc
|
fprintf fmt "@.";
|
118 |
|
|
fprintf fmt "clean:@.";
|
119 |
|
|
fprintf fmt "\t\\rm -f *.o ${BINNAME}@.";
|
120 |
|
|
fprintf fmt "@.";
|
121 |
|
|
Mod.other_targets fmt basename nodename dependencies;
|
122 |
|
|
fprintf fmt "@.";
|
123 |
e95470b3
|
ploc
|
|
124 |
713176a4
|
ploc
|
end
|
125 |
522938b5
|
ploc
|
|
126 |
|
|
(* Local Variables: *)
|
127 |
|
|
(* compile-command:"make -C ../../.." *)
|
128 |
|
|
(* End: *)
|