Coccinelle release 1.0.0-rc1
[bpt/coccinelle.git] / tools / generate_dependencies.ml
CommitLineData
f537ebc4
C
1(*
2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
7 *
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
11 *
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
22 *)
23
24
485bce71 25open Common
34e49164
C
26
27(*****************************************************************************)
28(* Flags *)
29(*****************************************************************************)
30
ae4735db
C
31let generate_dependencies dir =
32 let c_info =
34e49164 33 Common.glob (Filename.concat dir "*.[c]")
ae4735db 34 +> List.map (fun file ->
34e49164
C
35 let (x,_) = Parse_c.parse_cache file in
36 let defined = C_info.defined_stuff x in
37 let used = C_info.used_stuff x in
38 let extra = C_info.extra_stuff x in
39 C_info.adjust_used_only_external used defined;
40 file, { C_info.used = used; defined = defined; is_module = extra}
41 ) in
42 let global = C_info.mk_global_definitions_index c_info in
ae4735db 43 c_info +> List.iter (fun (file, used_defined) ->
34e49164
C
44 pr2 ("HANDLING : " ^ file);
45 C_info.print_entities used_defined.C_info.used;
46 );
47 C_info.check_no_duplicate_global_definitions global;
ae4735db 48 let g = C_info.build_graph c_info global
34e49164
C
49 (Filename.concat dir "depgraph.dot") in
50 C_info.generate_makefile g (Filename.concat dir "depcocci.dep")
51
52
53
54
55(*
ae4735db 56 let path =
34e49164
C
57 match xs with
58 | [] -> "/home/pad/kernels/git/linux-2.6/drivers/net"
59 | [x] -> x
60 | _ -> failwith "too much path"
61 in
62
ae4735db
C
63 let dirs =
64 if dir
34e49164
C
65 then Common.cmd_to_list ("find " ^ path ^ " -type d") +> Kbuild.adjust_dirs
66 else [path]
67 in
ae4735db 68 dirs +> List.iter (fun dir ->
34e49164 69*)
ae4735db 70
34e49164
C
71
72(*
ae4735db 73let test_yyy () =
34e49164
C
74 Sys.chdir "/home/pad/kernels/git/linux-2.6";
75 let path="drivers/net" in
76
ae4735db 77 let c_info =
34e49164 78 Common.cmd_to_list ("find " ^ path ^ " -name \"*.c\" ")
ae4735db 79 +> List.map (fun file ->
34e49164
C
80 let x = cprogram_of_file_cached file in
81 let defined = defined_stuff x in
82 let used = used_stuff x in
83 let extra = extra_stuff x in
84 adjust_used_only_external used defined;
85 file, { used = used; defined = defined; is_module = extra}
86 ) in
87 let global = mk_global_definitions_index c_info in
ae4735db 88 c_info +> List.iter (fun (file, used_defined) ->
34e49164
C
89 pr2 ("HANDLING : " ^ file);
90 print_entities used_defined.used;
91 );
92 check_no_duplicate_global_definitions global
93 (*build_graph c_info global (Filename.concat dir "depgraph.dot");*)
ae4735db 94*)
34e49164
C
95
96
97(*****************************************************************************)
98(* Main entry point *)
99(*****************************************************************************)
100
ae4735db 101let main () =
34e49164
C
102 begin
103 let args = ref [] in
104 let options = [
105 ] in
ae4735db
C
106 let usage_msg =
107 "Usage: " ^ basename Sys.argv.(0) ^
34e49164
C
108 " <dir> [options]" ^ "\n" ^ "Options are:"
109 in
110
111 Arg.parse (Arg.align options) (fun x -> args := x::!args) usage_msg;
112 args := List.rev !args;
113
114 (match (!args) with
ae4735db 115 | [x] ->
34e49164 116 generate_dependencies x
ae4735db 117 | _ -> Arg.usage (Arg.align options) usage_msg;
34e49164
C
118 )
119 end
120
121(*****************************************************************************)
122let _ =
123 main ()
124