Project

General

Profile

Download (4.09 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 _ ->
21
        true
22
      | ImportedNode nd ->
23
        nd.nodei_in_lib = []
24
      | _ ->
25
        false)
26
    header
27

    
28
let header_libs header =
29
  List.fold_left
30
    (fun accu top ->
31
      match top.top_decl_desc with
32
      | ImportedNode nd ->
33
        Utils.list_union nd.nodei_in_lib accu
34
      | _ ->
35
        accu)
36
    [] header
37

    
38
let compiled_dependencies dep =
39
  List.filter (fun (Dep (_, _, header, _)) -> header_has_code header) dep
40

    
41
let lib_dependencies dep =
42
  List.fold_left
43
    (fun accu (Dep (_, _, header, _)) ->
44
      Utils.list_union (header_libs header) accu)
45
    [] dep
46

    
47
let fprintf_dependencies fmt (dep : dep_t list) =
48
  let compiled_dep = compiled_dependencies dep in
49
  List.iter
50
    (fun s ->
51
      (* Format.eprintf "Adding dependency: %s@." s; *)
52
      fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
53
    ("${INC}/io_frontend.c"
54
     ::
55
     (* IO functions when a main function is computed *)
56
     List.map
57
       (fun (Dep (local, s, _, _)) ->
58
         (if local then s else Version.include_path ^ "/" ^ s) ^ ".c")
59
       compiled_dep)
60

    
61
module type MODIFIERS_MKF = sig
62
  (* dep was (bool * ident * top_decl list) *)
63
  val other_targets : Format.formatter -> string -> string -> dep_t list -> unit
64
end
65

    
66
module EmptyMod : MODIFIERS_MKF = struct
67
  let other_targets _ _ _ _ = ()
68
end
69

    
70
module Main =
71
functor
72
  (Mod : MODIFIERS_MKF)
73
  ->
74
  struct
75
    let print_cmake basename nodename (dependencies : dep_t list) fmt =
76
      (* Printing the basic file CMakeLists.txt *)
77
      let fmt_CMakeLists_txt =
78
        formatter_of_out_channel
79
          (open_out (!Options.dest_dir ^ "/CMakeLists.txt"))
80
      in
81
      fprintf fmt_CMakeLists_txt "cmake_minimum_required(VERSION 3.0)@.";
82
      fprintf fmt_CMakeLists_txt "project(%s C)@." basename;
83
      fprintf mt_CMakeLists_txt "@.";
84
      fprintf mt_CMakeLists_txt "set(LUSTREC_DEFINE_TARGETS ON)@.";
85
      fprintf mt_CMakeLists_txt "include(lustrec-%s.cmake)" basename;
86

    
87
      fprintf fmt "GCC=gcc@.";
88
      fprintf fmt "LUSTREC=%s@." Sys.executable_name;
89
      fprintf fmt "LUSTREC_BASE=%s@."
90
        (Filename.dirname (Filename.dirname Sys.executable_name));
91
      fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
92
      fprintf fmt "@.";
93

    
94
      (* Main binary *)
95
      fprintf fmt "%s_%s: %s.c %s_main.c@." basename nodename basename basename;
96
      fprintf fmt "\t${GCC} -O0 -I${INC} -I. -c %s.c@." basename;
97
      fprintf fmt "\t${GCC} -O0 -I${INC} -I. -c %s_main.c@." basename;
98
      fprintf_dependencies fmt dependencies;
99
      fprintf fmt "\t${GCC} -O0 -o %s_%s io_frontend.o %a %s.o %s_main.o %a@."
100
        basename nodename
101
        (Utils.fprintf_list ~sep:" " (fun fmt (Dep (_, s, _, _)) ->
102
             Format.fprintf fmt "%s.o" s))
103
        (compiled_dependencies dependencies)
104
        basename (* library .o *) basename
105
        (* main function . o *)
106
        (Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib))
107
        (lib_dependencies dependencies);
108
      fprintf fmt "@.";
109
      fprintf fmt "clean:@.";
110
      fprintf fmt "\t\\rm -f *.o %s_%s@." basename nodename;
111
      fprintf fmt "@.";
112
      fprintf fmt ".PHONY: %s_%s@." basename nodename;
113
      fprintf fmt "@.";
114
      Mod.other_targets fmt basename nodename dependencies;
115
      fprintf fmt "@."
116
  end
117

    
118
(* Local Variables: *)
119
(* compile-command:"make -C ../../.." *)
120
(* End: *)
(2-2/9)