Project

General

Profile

« Previous | Next » 

Revision ca7ff3f7

Added by LĂ©lio Brun 7 months ago

reformatting

View differences:

src/backends/C/c_backend_cmake.ml
14 14
open Corelang
15 15

  
16 16
let header_has_code header =
17
  List.exists 
18
    (fun top -> 
17
  List.exists
18
    (fun top ->
19 19
      match top.top_decl_desc with
20
      | Const _ -> true 
21
      | ImportedNode nd -> nd.nodei_in_lib = []
22
      | _ -> false
23
    )
20
      | Const _ ->
21
        true
22
      | ImportedNode nd ->
23
        nd.nodei_in_lib = []
24
      | _ ->
25
        false)
24 26
    header
25 27

  
26 28
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
    
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
33 37

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

  
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) =
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) =
42 48
  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))
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)
50 60

  
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
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
54 64
end
55 65

  
56
module EmptyMod =
57
(struct
66
module EmptyMod : MODIFIERS_MKF = struct
58 67
  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;
68
end
74 69

  
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 "@.";
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;
81 86

  
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 "@.";
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 "@.";
102 93

  
103
end
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
104 117

  
105 118
(* Local Variables: *)
106 119
(* compile-command:"make -C ../../.." *)

Also available in: Unified diff