<commit_before>(********************************************************************)
(*                                                                  *)
(*  The LustreC compiler toolset   /  The LustreC Development Team  *)
(*  Copyright 2012 -    --   ONERA - CNRS - INPT                    *)
(*                                                                  *)
(*  LustreC is free software, distributed WITHOUT ANY WARRANTY      *)
(*  under the terms of the GNU Lesser General Public License        *)
(*  version 2.1.                                                    *)
(*                                                                  *)
(********************************************************************)

open Format
open LustreSpec
open Corelang

let header_has_code header =
  List.exists 
    (fun top -> 
      match top.top_decl_desc with
      | Const _ -> true 
      | ImportedNode nd -> nd.nodei_in_lib = None
      | _ -> false
    )
    header

let header_libs header =
  List.fold_left (fun accu top ->
    match top.top_decl_desc with
      | ImportedNode nd -> (match nd.nodei_in_lib with 
	| None -> accu 
	| Some lib -> Utils.list_union [lib] accu)
      | _ -> accu 
  ) [] header 
    

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

let lib_dependencies dep = 
  List.fold_left 
    (fun accu (Dep (_, _, header, _)) -> Utils.list_union (header_libs header) accu) [] dep
    
let fprintf_dependencies fmt (dep: dep_t list) =
  let compiled_dep = compiled_dependencies dep in
  List.iter (fun s -> (* Format.eprintf "Adding dependency: %s@." s;  *)
    fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
    (("${INC}/io_frontend.c"):: (* IO functions when a main function is computed *)
	(List.map 
	   (fun (Dep (local, s, _, _)) -> 
	     (if local then s else Version.include_path ^ "/" ^ s) ^ ".c")
	   compiled_dep))

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

module EmptyMod =
(struct
  let other_targets _ _ _ _ = ()
end: MODIFIERS_MKF)

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


let print_makefile basename nodename (dependencies:  dep_t list) fmt =
  fprintf fmt "GCC=gcc@.";
  fprintf fmt "LUSTREC=%s@." Sys.executable_name;
  fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
  fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
  fprintf fmt "@.";

  (* Main binary *)
  fprintf fmt "%s_%s:@." basename nodename;
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;  
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s_main.c@." basename;   
  fprintf_dependencies fmt dependencies;    <commit_msg>Refined the dependencies in the generated makefile<commit_after>(********************************************************************)
(*                                                                  *)
(*  The LustreC compiler toolset   /  The LustreC Development Team  *)
(*  Copyright 2012 -    --   ONERA - CNRS - INPT                    *)
(*                                                                  *)
(*  LustreC is free software, distributed WITHOUT ANY WARRANTY      *)
(*  under the terms of the GNU Lesser General Public License        *)
(*  version 2.1.                                                    *)
(*                                                                  *)
(********************************************************************)

open Format
open LustreSpec
open Corelang

let header_has_code header =
  List.exists 
    (fun top -> 
      match top.top_decl_desc with
      | Const _ -> true 
      | ImportedNode nd -> nd.nodei_in_lib = None
      | _ -> false
    )
    header

let header_libs header =
  List.fold_left (fun accu top ->
    match top.top_decl_desc with
      | ImportedNode nd -> (match nd.nodei_in_lib with 
	| None -> accu 
	| Some lib -> Utils.list_union [lib] accu)
      | _ -> accu 
  ) [] header 
    

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

let lib_dependencies dep = 
  List.fold_left 
    (fun accu (Dep (_, _, header, _)) -> Utils.list_union (header_libs header) accu) [] dep
    
let fprintf_dependencies fmt (dep: dep_t list) =
  let compiled_dep = compiled_dependencies dep in
  List.iter (fun s -> (* Format.eprintf "Adding dependency: %s@." s;  *)
    fprintf fmt "\t${GCC} -I${INC} -c %s@." s)
    (("${INC}/io_frontend.c"):: (* IO functions when a main function is computed *)
	(List.map 
	   (fun (Dep (local, s, _, _)) -> 
	     (if local then s else Version.include_path ^ "/" ^ s) ^ ".c")
	   compiled_dep))

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

module EmptyMod =
(struct
  let other_targets _ _ _ _ = ()
end: MODIFIERS_MKF)

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


let print_makefile basename nodename (dependencies:  dep_t list) fmt =
  fprintf fmt "GCC=gcc@.";
  fprintf fmt "LUSTREC=%s@." Sys.executable_name;
  fprintf fmt "LUSTREC_BASE=%s@." (Filename.dirname (Filename.dirname Sys.executable_name));
  fprintf fmt "INC=${LUSTREC_BASE}/include/lustrec@.";
  fprintf fmt "@.";

  (* Main binary *)
  fprintf fmt "%s_%s: %s.c %s_main.c@." basename nodename basename basename;
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s.c@." basename;  
  fprintf fmt "\t${GCC} -I${INC} -I. -c %s_main.c@." basename;   
  fprintf_dependencies fmt dependencies;    
{'fraction_non_alphanumeric': 0.16714082503556188, 'fraction_numerical': 0.0021337126600284497, 'mean_word_length': 2.2420749279538903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3852150', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1678, 'n_words': 484}