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