Project

General

Profile

Download (4.14 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
    []
37
    header
38

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

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

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

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

    
68
module EmptyMod : MODIFIERS_MKF = struct
69
  let other_targets _ _ _ _ = ()
70
end
71

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

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

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

    
126
(* Local Variables: *)
127
(* compile-command:"make -C ../../.." *)
128
(* End: *)
(3-3/18)