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.
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.
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.
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/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
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.
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.
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.
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/>.
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
47 (*****************************************************************************)
49 (*****************************************************************************)
51 let generate_dependencies dir
=
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}
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;
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")
78 | [] -> "/home/pad/kernels/git/linux-2.6/drivers/net"
80 | _ -> failwith "too much path"
85 then Common.cmd_to_list ("find " ^ path ^ " -type d") +> Kbuild.adjust_dirs
88 dirs +> List.iter (fun dir ->
94 Sys.chdir "/home/pad/kernels/git/linux-2.6";
95 let path="drivers/net" in
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}
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;
112 check_no_duplicate_global_definitions global
113 (*build_graph c_info global (Filename.concat dir "depgraph.dot");*)
117 (*****************************************************************************)
118 (* Main entry point *)
119 (*****************************************************************************)
127 "Usage: " ^ basename
Sys.argv
.(0) ^
128 " <dir> [options]" ^
"\n" ^
"Options are:"
131 Arg.parse
(Arg.align
options) (fun x -> args := x::!args) usage_msg;
132 args := List.rev
!args;
136 generate_dependencies x
137 | _
-> Arg.usage
(Arg.align
options) usage_msg;
141 (*****************************************************************************)