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 exception WrongArguments
27 (* could do via a List.filter because cpp flags are simple as it's
28 * "-I/usr/include" not ["-I";"/usr/include"] like in ocaml so no
29 * need to look multiple args.
31 let rec cpp_flags_filter xs
=
36 | s
when x
=~
"-D.*" ->
37 s
::cpp_flags_filter xs
38 | s
when s
=~
"-I.*" ->
39 s
::cpp_flags_filter xs
44 let is_compile_command xs
=
48 xs
+> List.filter
(fun s
-> s
=~
".*\\.c$")
50 let rec fix_args args file
=
57 hd
::fix_args tail file
59 let rec get_outputfile args
=
64 let (hd'
,tail'
) = match tail
with
65 hd'
::tail'
-> (hd'
,tail'
)
66 | _
-> raise WrongArguments
70 let (ntail
, out
) = get_outputfile tail
in
74 let args = List.tl
(Array.to_list
Sys.argv
) in
75 (*args +> List.iter pr2;*)
76 if is_compile_command args
78 let file = source_file args in
81 let cpp_flags = cpp_flags_filter args in
83 (spf
"cpp %s %s > %s.i"
84 (Common.join
" " cpp_flags)
89 let ret2 = Sys.command
cmd2 in
90 if ret2 > 0 then exit
ret2;
91 let sp_args = fix_args args file in
92 let cmd = "spatch " ^
(Common.join
" " sp_args) in
94 let ret = Sys.command
cmd in
97 | [] -> failwith
"could not find name of source file"
98 | x
::y
::xs
-> failwith
"multiple source files"
103 let (nargs
, outfile
) = get_outputfile args in
106 (Common.join
" " nargs
)