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 exception WrongArguments
31 (* could do via a List.filter because cpp flags are simple as it's
32 * "-I/usr/include" not ["-I";"/usr/include"] like in ocaml so no
33 * need to look multiple args.
35 let rec cpp_flags_filter xs
=
40 | s
when x
=~
"-D.*" ->
41 s
::cpp_flags_filter xs
42 | s
when s
=~
"-I.*" ->
43 s
::cpp_flags_filter xs
48 let is_compile_command xs
=
52 xs
+> List.filter
(fun s
-> s
=~
".*\\.c$")
54 let rec fix_args args file
=
61 hd
::fix_args tail file
63 let rec get_outputfile args
=
68 let (hd'
,tail'
) = match tail
with
69 hd'
::tail'
-> (hd'
,tail'
)
70 | _
-> raise WrongArguments
74 let (ntail
, out
) = get_outputfile tail
in
78 let args = List.tl
(Array.to_list
Sys.argv
) in
79 (*args +> List.iter pr2;*)
80 if is_compile_command args
82 let file = source_file args in
85 let cpp_flags = cpp_flags_filter args in
87 (spf
"cpp %s %s > %s.i"
88 (Common.join
" " cpp_flags)
93 let ret2 = Sys.command
cmd2 in
94 if ret2 > 0 then exit
ret2;
95 let sp_args = fix_args args file in
96 let cmd = "spatch " ^
(Common.join
" " sp_args) in
98 let ret = Sys.command
cmd in
101 | [] -> failwith
"could not find name of source file"
102 | x
::y
::xs
-> failwith
"multiple source files"
107 let (nargs
, outfile
) = get_outputfile args in
110 (Common.join
" " nargs
)