Project

General

Profile

Download (3.92 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

    
65
  let print_cmake basename nodename (dependencies:  dep_t list) fmt =
66

    
67
    (* Printing the basic file CMakeLists.txt *)
68
    let fmt_CMakeLists_txt = formatter_of_out_channel (open_out (!Options.dest_dir ^ "/CMakeLists.txt")) in
69
    fprintf fmt_CMakeLists_txt "cmake_minimum_required(VERSION 3.0)@.";
70
    fprintf fmt_CMakeLists_txt "project(%s C)@." basename;
71
    fprintf mt_CMakeLists_txt "@.";
72
    fprintf mt_CMakeLists_txt "set(LUSTREC_DEFINE_TARGETS ON)@.";
73
    fprintf mt_CMakeLists_txt "include(lustrec-%s.cmake)" basename;
74

    
75
    
76
    fprintf fmt "GCC=gcc@.";
77
    fprintf fmt "LUSTREC=%s@." Sys.executable_name;
78
    fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
79
    fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
80
    fprintf fmt "@.";
81

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

    
103
end
104

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