From bfad5d6af72693654162b41eb3a0dcd2cf0368c3 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Fri, 27 Feb 2015 16:48:24 +0100 Subject: Removed the recdepend again and replaced it by a builtin Make function. --- Makefile.extr | 14 ++-- tools/recdepend.ml | 206 ----------------------------------------------------- 2 files changed, 6 insertions(+), 214 deletions(-) delete mode 100644 tools/recdepend.ml diff --git a/Makefile.extr b/Makefile.extr index 372f5e32..67b2a604 100644 --- a/Makefile.extr +++ b/Makefile.extr @@ -61,12 +61,14 @@ endif OCAMLC=ocamlc$(DOTOPT) $(COMPFLAGS) OCAMLOPT=ocamlopt$(DOTOPT) $(COMPFLAGS) +OCAMLDEP=ocamldep$(DOTOPT) -slash $(INCLUDES) # Compilers used for Camlp4-preprocessed code. Note that we cannot # use the .opt compilers (because ocamlfind doesn't support them). OCAMLC_P4=ocamlfind ocamlc $(COMPFLAGS) $(BITSTRING) OCAMLOPT_P4=ocamlfind ocamlopt $(COMPFLAGS) $(BITSTRING) +OCAMLDEP_P4=ocamlfind ocamldep $(INCLUDES) $(BITSTRING) MENHIR=menhir --explain OCAMLLEX=ocamllex -q @@ -154,7 +156,6 @@ checklink/%.cmx: checklink/%.ml clean: rm -f $(EXECUTABLES) rm -f $(GENERATED) - rm -f tools/recdepend for d in $(ALLDIRS); do rm -f $$d/*.cm[iox] $$d/*.o; done cleansource: @@ -163,16 +164,13 @@ cleansource: # Generation of .depend.extr -tools/recdepend: tools/recdepend.ml - ocamlopt -o tools/recdepend unix.cmxa tools/recdepend.ml - -RECDEPEND=tools/recdepend - depend: $(GENERATED) tools/recdepend @echo "Analyzing OCaml dependencies" - @$(RECDEPEND) $(DIRS) -o .depend.extr -ifneq ($(strip $(DIRS_P4)),) + $(OCAMLDEP) $(foreach d,$(DIRS),$(wildcard $(d)/*.mli $(d)/*.ml)) >.depend.extr + $(OCAMLDEP) $(GENERATED) >> .depend.extr + ifneq ($(strip $(DIRS_P4)),) @$(RECDEPEND) -use-ocamlfind $(BITSTRING) $(INCLUDES) $(DIRS_P4) >> .depend.extr + $(OCAMLDEP_P4) $(foreach d,$(DIRS_P4),$(wildcard $(d)/*.mli $(d)/*.ml)) >>.depend.extr endif diff --git a/tools/recdepend.ml b/tools/recdepend.ml deleted file mode 100644 index 6ddebdd6..00000000 --- a/tools/recdepend.ml +++ /dev/null @@ -1,206 +0,0 @@ -(* *********************************************************************) -(* *) -(* The Compcert verified compiler *) -(* *) -(* Bernhard Schommer, AbstInt Angewandte Informatik GmbH *) -(* *) -(* Copyright AbstInt Angewandte Informatik GmbH. All rights reserved. *) -(* This file is distributed under the terms of the GNU General Public *) -(* License as published by the Free Software Foundation, either *) -(* version 2 of the License, or (at your option) any later version. *) -(* *) -(* *********************************************************************) - -(* Generate dependencies for directories by calling dependencie tool *) - -open Set - -module StringSet = Make(String) - -(* The tools *) -let ocamlfind = ref "ocamlfind" -let ocamldep = ref "ocamldep" -let menhir = ref "menhir" - -(* Some controling options *) -let use_ocamlfind = ref false -let use_menhir = ref false -let dirs_to_search = ref ([] : string list) -let target_file = ref (None: string option) -let error_occured = ref false - -(* Options for ocamldep *) -let include_dirs = ref (StringSet.empty) -let ml_synonyms = ref [".ml"] -let mli_synonyms = ref [".mli"] -let slash = ref false -let native_only = ref false -let raw_dependencies = ref false -let pp_command = ref (None: string option) -let ppx_command = ref ([] : string list) -let all_dependencies = ref false -let open_modules = ref ([] : string list) -let one_line = ref false -let ocamlfind_package = ref "" -let ocamlfind_syntax = ref "" -let ocamlfind_ppopt = ref ([] : string list) - -(* Helper functions for options *) -let add_to_list li s = - li := s :: !li - -let add_to_set set s = - set := StringSet.add s !set - -let add_to_synonym_list synonyms suffix = - if (String.length suffix) > 1 && (String.get suffix 0) = '.' then - add_to_list synonyms suffix - else - Printf.eprintf "Bad file suffix '%s'.\n" suffix - -let usage = "Usage: recdepend [options] \nOptions are:" - -type file_type = - | ML - | MLL - -(* Concats dir and name except for the case when dir is . or equivalent *) -let (^) dir name = - if dir = Filename.current_dir_name then - name - else - Filename.concat dir name - -let get_files () = - let rec files_of_dir acc dir = - let files = Sys.readdir dir in - let contains_files = ref false in - let acc = Array.fold_left (fun acc f_name -> - if Sys.is_directory (dir ^ f_name) then - files_of_dir acc (dir ^ f_name) - else - if List.exists (Filename.check_suffix f_name) (!ml_synonyms@ !mli_synonyms) then - begin - contains_files := true; - (ML,(dir ^ f_name))::acc - end - else if !use_menhir && (Filename.check_suffix f_name ".mll") then - begin - contains_files := true; - (MLL,(dir ^ f_name))::acc - end - else - acc) acc files in - if !contains_files && dir <> Filename.current_dir_name then - add_to_set include_dirs dir; - acc in - try - List.fold_left files_of_dir [] !dirs_to_search - with _ -> - error_occured := true; - [] - -let translate_arg_list acc name args = - List.fold_left (fun args s -> name::(s::args)) acc args - -let compute_dependencies files = - try let out_file = match !target_file with - | None -> Unix.stdout - | Some s -> Unix.openfile s [Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC] 0o666 in - let call_process args = - let argv = Array.of_list args in - let pid = Unix.create_process argv.(0) argv Unix.stdin out_file Unix.stderr in - let (_,status) = - Unix.waitpid [] pid in - let rc = (match status with - | Unix.WEXITED rc -> rc - | Unix.WSIGNALED _ - | Unix.WSTOPPED _ -> -1) in - error_occured := !error_occured || rc <> 0 in - let call_ocamldep file = - let args = StringSet.fold (fun s args -> "-I"::(s::args)) !include_dirs [file] in - let args = translate_arg_list args "-ml-synonym" (List.filter ((<>) ".ml") !ml_synonyms) in - let args = translate_arg_list args "-mli-synonym" (List.filter ((<>) ".mli") !mli_synonyms) in - let args = if !slash then "-slash"::args else args in - let args = if !native_only then "-native"::args else args in - let args = if !raw_dependencies then "-modules"::args else args in - let args = match !pp_command with - | None -> args - | Some s -> "-pp"::(s::args) in - let args = translate_arg_list args "-ppx" !ppx_command in - let args = if !all_dependencies then "-all"::args else args in - let args = translate_arg_list args "-open" !open_modules in - let args = if !one_line then "-one-line"::args else args in - let args = if !use_ocamlfind then - let args = if !ocamlfind_package <> "" then - "-package"::(!ocamlfind_package::args) - else - args in - let args = if !ocamlfind_syntax <> "" then - "-syntax"::(!ocamlfind_syntax::args) - else - args in - let args = translate_arg_list args "-ppopt" !ocamlfind_ppopt in - !ocamlfind::("ocamldep"::args) - else - !ocamldep :: args in - call_process args in - let call_menhir file = - let args = [!menhir;"--depend";"--ocamldep";!ocamldep] in - let args = if !raw_dependencies then args@["--raw-depend"] else args in - call_process args in - List.iter (fun (f_type,f_name) -> - match f_type with - | ML -> call_ocamldep f_name - | MLL -> if !use_menhir then call_menhir f_name) files; - if !target_file <> None then Unix.close out_file - with _ -> - error_occured := true - - -let _ = - Arg.parse [ - "-all", Arg.Set all_dependencies, - " Generate dependencies on all files"; - "-dep", Arg.Set_string ocamldep, - " Use instead of ocamldep"; - "-I", Arg.String (add_to_set include_dirs), - " Add to the list of include directories"; - "-menhir", Arg.String (fun s -> use_menhir:= true; menhir := s), - " Use instead of menhir"; - "-ml-synonym", Arg.String (add_to_synonym_list ml_synonyms), - " Consider as synonym of the .ml extension"; - "-mli-synonym", Arg.String (add_to_synonym_list mli_synonyms), - " Consider as synonym of the .mli extension"; - "-modules", Arg.Set raw_dependencies, - " Print module dependencies in raw form"; - "-native", Arg.Set native_only, - " Generate dependencies for native-code only"; - "-o", Arg.String (fun s -> target_file := Some s), - " Write the dependencies in file "; - "-ocamlfind", Arg.String (fun s -> use_ocamlfind := true; ocamlfind := s), - " Use instead of ocamlfind"; - "-one-line", Arg.Set one_line, - " Output only ine line per file, regardless of length"; - "-open", Arg.String (add_to_list open_modules), - " Opens the module before typing"; - "-package", Arg.Set_string ocamlfind_package, - "

Pass the package option

to ocamlfind"; - "-ppopt", Arg.String (add_to_list ocamlfind_ppopt), - "

Pass the camlp4 option

to ocamlfind"; - "-pp", Arg.String (fun s -> pp_command := Some s), - " Pipe sources through preprocessor "; - "-ppx", Arg.String (add_to_list ppx_command), - " Pipe abstract syntax trees through preprocessor "; - "-slash", Arg.Set slash, - " (Windows) Use foward slash / instead of backslash \\ in file paths"; - "-syntax", Arg.Set_string ocamlfind_syntax, - "

Pass the syntax option

to ocamlfind"; - "-use-menhir", Arg.Set use_menhir, - " Use menhir to callculate the dependencies of .mll files"; - "-use-ocamlfind", Arg.Set use_ocamlfind, - " Use ocamlfind as driver for ocamldepend";] - (add_to_list dirs_to_search) usage; - let files = get_files () in - compute_dependencies files; - exit (if !error_occured then 2 else 0) -- cgit