Commit | Line | Data |
---|---|---|
f537ebc4 | 1 | (* |
17ba0788 C |
2 | * Copyright 2012, INRIA |
3 | * Julia Lawall, Gilles Muller | |
4 | * Copyright 2010-2011, INRIA, University of Copenhagen | |
f537ebc4 C |
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 | ||
485bce71 | 27 | open Common |
34e49164 C |
28 | |
29 | (*****************************************************************************) | |
30 | (* Flags *) | |
31 | (*****************************************************************************) | |
32 | ||
ae4735db C |
33 | let generate_dependencies dir = |
34 | let c_info = | |
34e49164 | 35 | Common.glob (Filename.concat dir "*.[c]") |
ae4735db | 36 | +> List.map (fun file -> |
34e49164 C |
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 | |
ae4735db | 45 | c_info +> List.iter (fun (file, used_defined) -> |
34e49164 C |
46 | pr2 ("HANDLING : " ^ file); |
47 | C_info.print_entities used_defined.C_info.used; | |
48 | ); | |
49 | C_info.check_no_duplicate_global_definitions global; | |
ae4735db | 50 | let g = C_info.build_graph c_info global |
34e49164 C |
51 | (Filename.concat dir "depgraph.dot") in |
52 | C_info.generate_makefile g (Filename.concat dir "depcocci.dep") | |
53 | ||
54 | ||
55 | ||
56 | ||
57 | (* | |
ae4735db | 58 | let path = |
34e49164 C |
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 | ||
ae4735db C |
65 | let dirs = |
66 | if dir | |
34e49164 C |
67 | then Common.cmd_to_list ("find " ^ path ^ " -type d") +> Kbuild.adjust_dirs |
68 | else [path] | |
69 | in | |
ae4735db | 70 | dirs +> List.iter (fun dir -> |
34e49164 | 71 | *) |
ae4735db | 72 | |
34e49164 C |
73 | |
74 | (* | |
ae4735db | 75 | let test_yyy () = |
34e49164 C |
76 | Sys.chdir "/home/pad/kernels/git/linux-2.6"; |
77 | let path="drivers/net" in | |
78 | ||
ae4735db | 79 | let c_info = |
34e49164 | 80 | Common.cmd_to_list ("find " ^ path ^ " -name \"*.c\" ") |
ae4735db | 81 | +> List.map (fun file -> |
34e49164 C |
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 | |
ae4735db | 90 | c_info +> List.iter (fun (file, used_defined) -> |
34e49164 C |
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");*) | |
ae4735db | 96 | *) |
34e49164 C |
97 | |
98 | ||
99 | (*****************************************************************************) | |
100 | (* Main entry point *) | |
101 | (*****************************************************************************) | |
102 | ||
ae4735db | 103 | let main () = |
34e49164 C |
104 | begin |
105 | let args = ref [] in | |
106 | let options = [ | |
107 | ] in | |
ae4735db C |
108 | let usage_msg = |
109 | "Usage: " ^ basename Sys.argv.(0) ^ | |
34e49164 C |
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 | |
ae4735db | 117 | | [x] -> |
34e49164 | 118 | generate_dependencies x |
ae4735db | 119 | | _ -> Arg.usage (Arg.align options) usage_msg; |
34e49164 C |
120 | ) |
121 | end | |
122 | ||
123 | (*****************************************************************************) | |
124 | let _ = | |
125 | main () | |
126 |