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