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.
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.
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.
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/>.
22 * The authors reserve the right to distribute this or future versions of
23 * Coccinelle under other licenses.
29 (*****************************************************************************)
31 (*****************************************************************************)
33 let generate_dependencies dir
=
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}
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;
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")
60 | [] -> "/home/pad/kernels/git/linux-2.6/drivers/net"
62 | _ -> failwith "too much path"
67 then Common.cmd_to_list ("find " ^ path ^ " -type d") +> Kbuild.adjust_dirs
70 dirs +> List.iter (fun dir ->
76 Sys.chdir "/home/pad/kernels/git/linux-2.6";
77 let path="drivers/net" in
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}
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;
94 check_no_duplicate_global_definitions global
95 (*build_graph c_info global (Filename.concat dir "depgraph.dot");*)
99 (*****************************************************************************)
100 (* Main entry point *)
101 (*****************************************************************************)
109 "Usage: " ^ basename
Sys.argv
.(0) ^
110 " <dir> [options]" ^
"\n" ^
"Options are:"
113 Arg.parse
(Arg.align
options) (fun x -> args := x::!args) usage_msg;
114 args := List.rev
!args;
118 generate_dependencies x
119 | _
-> Arg.usage
(Arg.align
options) usage_msg;
123 (*****************************************************************************)