2 * Copyright 2005-2009, 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.
25 (*****************************************************************************)
27 (*****************************************************************************)
29 let generate_dependencies dir
=
31 Common.glob
(Filename.concat dir
"*.[c]")
32 +> List.map
(fun file
->
33 let (x
,_
) = Parse_c.parse_cache file
in
34 let defined = C_info.defined_stuff x
in
35 let used = C_info.used_stuff x
in
36 let extra = C_info.extra_stuff x
in
37 C_info.adjust_used_only_external
used defined;
38 file
, { C_info.used = used; defined = defined; is_module
= extra}
40 let global = C_info.mk_global_definitions_index
c_info in
41 c_info +> List.iter
(fun (file
, used_defined
) ->
42 pr2
("HANDLING : " ^ file
);
43 C_info.print_entities used_defined
.C_info.used;
45 C_info.check_no_duplicate_global_definitions
global;
46 let g = C_info.build_graph
c_info global
47 (Filename.concat dir
"depgraph.dot") in
48 C_info.generate_makefile
g (Filename.concat dir
"depcocci.dep")
56 | [] -> "/home/pad/kernels/git/linux-2.6/drivers/net"
58 | _ -> failwith "too much path"
63 then Common.cmd_to_list ("find " ^ path ^ " -type d") +> Kbuild.adjust_dirs
66 dirs +> List.iter (fun dir ->
72 Sys.chdir "/home/pad/kernels/git/linux-2.6";
73 let path="drivers/net" in
76 Common.cmd_to_list ("find " ^ path ^ " -name \"*.c\" ")
77 +> List.map (fun file ->
78 let x = cprogram_of_file_cached file in
79 let defined = defined_stuff x in
80 let used = used_stuff x in
81 let extra = extra_stuff x in
82 adjust_used_only_external used defined;
83 file, { used = used; defined = defined; is_module = extra}
85 let global = mk_global_definitions_index c_info in
86 c_info +> List.iter (fun (file, used_defined) ->
87 pr2 ("HANDLING : " ^ file);
88 print_entities used_defined.used;
90 check_no_duplicate_global_definitions global
91 (*build_graph c_info global (Filename.concat dir "depgraph.dot");*)
95 (*****************************************************************************)
96 (* Main entry point *)
97 (*****************************************************************************)
105 "Usage: " ^ basename
Sys.argv
.(0) ^
106 " <dir> [options]" ^
"\n" ^
"Options are:"
109 Arg.parse
(Arg.align
options) (fun x -> args := x::!args) usage_msg;
110 args := List.rev
!args;
114 generate_dependencies x
115 | _
-> Arg.usage
(Arg.align
options) usage_msg;
119 (*****************************************************************************)