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