Release coccinelle-0.2.3rc1
[bpt/coccinelle.git] / tools / generate_dependencies.ml
CommitLineData
5636bb2c
C
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
9f8e26f4 23(*
ae4735db 24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
9f8e26f4
C
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
485bce71 45open Common
34e49164
C
46
47(*****************************************************************************)
48(* Flags *)
49(*****************************************************************************)
50
ae4735db
C
51let generate_dependencies dir =
52 let c_info =
34e49164 53 Common.glob (Filename.concat dir "*.[c]")
ae4735db 54 +> List.map (fun file ->
34e49164
C
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
ae4735db 63 c_info +> List.iter (fun (file, used_defined) ->
34e49164
C
64 pr2 ("HANDLING : " ^ file);
65 C_info.print_entities used_defined.C_info.used;
66 );
67 C_info.check_no_duplicate_global_definitions global;
ae4735db 68 let g = C_info.build_graph c_info global
34e49164
C
69 (Filename.concat dir "depgraph.dot") in
70 C_info.generate_makefile g (Filename.concat dir "depcocci.dep")
71
72
73
74
75(*
ae4735db 76 let path =
34e49164
C
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
ae4735db
C
83 let dirs =
84 if dir
34e49164
C
85 then Common.cmd_to_list ("find " ^ path ^ " -type d") +> Kbuild.adjust_dirs
86 else [path]
87 in
ae4735db 88 dirs +> List.iter (fun dir ->
34e49164 89*)
ae4735db 90
34e49164
C
91
92(*
ae4735db 93let test_yyy () =
34e49164
C
94 Sys.chdir "/home/pad/kernels/git/linux-2.6";
95 let path="drivers/net" in
96
ae4735db 97 let c_info =
34e49164 98 Common.cmd_to_list ("find " ^ path ^ " -name \"*.c\" ")
ae4735db 99 +> List.map (fun file ->
34e49164
C
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
ae4735db 108 c_info +> List.iter (fun (file, used_defined) ->
34e49164
C
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");*)
ae4735db 114*)
34e49164
C
115
116
117(*****************************************************************************)
118(* Main entry point *)
119(*****************************************************************************)
120
ae4735db 121let main () =
34e49164
C
122 begin
123 let args = ref [] in
124 let options = [
125 ] in
ae4735db
C
126 let usage_msg =
127 "Usage: " ^ basename Sys.argv.(0) ^
34e49164
C
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
ae4735db 135 | [x] ->
34e49164 136 generate_dependencies x
ae4735db 137 | _ -> Arg.usage (Arg.align options) usage_msg;
34e49164
C
138 )
139 end
140
141(*****************************************************************************)
142let _ =
143 main ()
144