Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / backends / C / c_backend_makefile.ml @ cd670fe1

History | View | Annotate | Download (1.93 KB)

1
open Format
2
open Corelang
3

    
4
let header_has_code header =
5
  List.exists 
6
    (fun top -> 
7
      match top.top_decl_desc with
8
      | Consts _ -> true 
9
      | ImportedNode nd -> nd.nodei_in_lib = None
10
      | _ -> false
11
    )
12
    header
13

    
14
let header_libs header =
15
  List.fold_left (fun accu top ->
16
    match top.top_decl_desc with
17
      | ImportedNode nd -> (match nd.nodei_in_lib with 
18
	| None -> accu 
19
	| Some lib -> Utils.list_union [lib] accu)
20
      | _ -> accu 
21
  ) [] header 
22
    
23
let print_makefile basename nodename dependencies fmt =
24
  let compiled_dependencies = 
25
    List.filter (fun (_, _, header) -> header_has_code header) dependencies
26
  in
27
  let lib_dependencies = 
28
    List.fold_left 
29
      (fun accu (_, _, header) -> Utils.list_union (header_libs header) accu) [] dependencies 
30
  in
31
  fprintf fmt "GCC=gcc@.";
32
  fprintf fmt "LUSTREC=%s@." Sys.executable_name;
33
  fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
34
  fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
35
  fprintf fmt "@.";
36
  fprintf fmt "%s_%s:@." basename nodename;
37
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;    
38
  List.iter (fun s -> (* Format.eprintf "Adding dependency: %s@." s;  *)
39
    fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
40
    (("${INC}/io_frontend.c"):: (* IO functions when a main function is computed *)
41
	(List.map 
42
	   (fun (s, local, _) -> 
43
	     (if local then s else Version.prefix ^ "/include/lustrec/" ^ s) ^ ".c")
44
	   compiled_dependencies));    
45
  fprintf fmt "\t${GCC} -o %s_%s io_frontend.o %a %s.o %a@." basename nodename 
46
    (Utils.fprintf_list ~sep:" " (fun fmt (s, _, _) -> Format.fprintf fmt "%s.o" s)) compiled_dependencies 
47
    basename
48
    (Utils.fprintf_list ~sep:" " (fun fmt lib -> fprintf fmt "-l%s" lib)) lib_dependencies
49
    ;
50
 fprintf fmt "@.";
51
 fprintf fmt "clean:@.";
52
 fprintf fmt "\t\\rm -f *.o %s_%s@." basename nodename
53

    
54

    
55
(* Local Variables: *)
56
(* compile-command:"make -C ../../.." *)
57
(* End: *)