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