Project

General

Profile

Download (2.05 KB) Statistics
| Branch: | Tag: | Revision:
1
open Format
2
open Corelang
3

    
4
module type MODIFIERS_MKF =
5
sig
6
end
7

    
8
module EmptyMod =
9
struct
10
end
11

    
12
module Main = functor (Mod: MODIFIERS_MKF) -> 
13
struct
14

    
15
let header_has_code header =
16
  List.exists 
17
    (fun top -> 
18
      match top.top_decl_desc with
19
      | Consts _ -> true 
20
      | ImportedNode nd -> nd.nodei_in_lib = None
21
      | _ -> false
22
    )
23
    header
24

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

    
66
(* Local Variables: *)
67
(* compile-command:"make -C ../../.." *)
68
(* End: *)
(5-5/7)