ee96b84a6fb1d50957266b001736380c95194359
[bpt/coccinelle.git] / parsing_cocci / Makefile
1 # Copyright 2012, INRIA
2 # Julia Lawall, Gilles Muller
3 # Copyright 2010-2011, INRIA, University of Copenhagen
4 # Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
5 # Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
6 # Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
7 # This file is part of Coccinelle.
8 #
9 # Coccinelle is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, according to version 2 of the License.
12 #
13 # Coccinelle is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 #
21 # The authors reserve the right to distribute this or future versions of
22 # Coccinelle under other licenses.
23
24
25 ifneq ($(MAKECMDGOALS),distclean)
26 include ../Makefile.config
27 endif
28
29 TARGET=cocci_parser
30
31 LEXER_SOURCES = lexer_cocci.mll
32 CLI_LEXER_SOURCES = lexer_cli.mll
33 SCRIPT_LEXER_SOURCES = lexer_script.mll
34 PARSER_SOURCES = parser_cocci_menhir.mly
35 SOURCES = flag_parsing_cocci.ml type_cocci.ml ast_cocci.ml ast0_cocci.ml \
36 pretty_print_cocci.ml unparse_ast0.ml visitor_ast0_types.ml \
37 visitor_ast.ml visitor_ast0.ml compute_lines.ml comm_assoc.ml \
38 iso_pattern.ml iso_compile.ml single_statement.ml simple_assignments.ml \
39 get_metas.ml ast0toast.ml check_meta.ml top_level.ml type_infer.ml \
40 test_exps.ml unitary_ast0.ml arity.ml index.ml context_neg.ml \
41 adjust_pragmas.ml insert_plus.ml function_prototypes.ml \
42 unify_ast.ml semantic_cocci.ml data.ml free_vars.ml safe_for_multi_decls.ml \
43 parse_aux.ml disjdistr.ml \
44 $(LEXER_SOURCES:.mll=.ml) $(PARSER_SOURCES:.mly=.ml) \
45 $(CLI_LEXER_SOURCES:.mll=.ml) $(SCRIPT_LEXER_SOURCES:.mll=.ml) \
46 get_constants2.ml id_utils.ml adjacency.ml parse_cocci.ml command_line.ml
47
48 LIBS=../commons/commons.cma ../globals/globals.cma
49 SYSLIBS = str.cma unix.cma
50
51 INCLUDES = -I ../commons \
52 -I ../commons/ocamlextra \
53 -I ../globals \
54 -I $(MENHIRDIR)
55
56 MENHIRMOD=menhirLib.cmo
57 MENHIROMOD=menhirLib.cmx
58
59 # The Caml compilers.
60 OCAMLCFLAGS ?= -g -dtypes
61 EXEC=$(TARGET).byte
62 EXEC=$(TARGET)
63 LIB=$(TARGET).cma
64 OPTLIB=$(LIB:.cma=.cmxa)
65
66 GENERATED= $(LEXER_SOURCES:.mll=.ml) \
67 $(CLI_LEXER_SOURCES:.mll=.ml) $(SCRIPT_LEXER_SOURCES:.mll=.ml) \
68 $(PARSER_SOURCES:.mly=.ml) $(PARSER_SOURCES:.mly=.mli)
69 OBJS = $(SOURCES:.ml=.cmo)
70 OPTOBJS = $(OBJS:.cmo=.cmx)
71
72
73 all: $(LIB)
74 local: $(EXEC)
75
76 all.opt: $(OPTLIB)
77
78 $(LIB): $(GENERATED) $(OBJS)
79 $(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES) -I $(MENHIRDIR) -a -o $(LIB) $(MENHIRMOD) $(OBJS)
80
81
82 $(OPTLIB): $(GENERATED) $(OPTOBJS)
83 $(OCAMLOPT) $(OPTFLAGS) $(INCLUDES) -I $(MENHIRDIR) -a -o $(OPTLIB) $(MENHIROMOD) $(OPTOBJS)
84
85
86 $(EXEC): $(OBJS) main.cmo $(LIBS)
87 $(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES) -o $(EXEC) $(SYSLIBS) $(LIBS) $(OBJS) main.cmo
88
89 clean::
90 rm -f $(LIB)
91 rm -f $(OPTLIB) $(LIB:.cma=.a)
92 rm -f $(TARGET)
93
94
95 .SUFFIXES:
96 .SUFFIXES: .ml .mli .cmo .cmi .cmx
97
98 .ml.cmo:
99 $(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES) -c $<
100
101 .mli.cmi:
102 $(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES) -c $<
103
104 .ml.cmx:
105 $(OCAMLOPT) $(OPTFLAGS) $(INCLUDES) -c $<
106
107 $(LEXER_SOURCES:.mll=.ml) : $(LEXER_SOURCES)
108 $(OCAMLLEX) $(LEXER_SOURCES)
109
110 $(PARSER_SOURCES:.mly=.ml) $(PARSER_SOURCES:.mly=.mli) : $(PARSER_SOURCES)
111 $(MENHIR) --ocamlc "${OCAMLC}" --ocamldep "${OCAMLDEP}" --table --base parser_cocci_menhir $(PARSER_SOURCES)
112
113 $(CLI_LEXER_SOURCES:.mll=.ml): $(CLI_LEXER_SOURCES)
114 $(OCAMLLEX) $(CLI_LEXER_SOURCES)
115
116 $(SCRIPT_LEXER_SOURCES:.mll=.ml): $(SCRIPT_LEXER_SOURCES)
117 $(OCAMLLEX) $(SCRIPT_LEXER_SOURCES)
118
119 distclean:: clean
120 @echo cleaning generated parsers and lexers
121 rm -f $(GENERATED)
122
123 # clean rule for others files
124 clean::
125 rm -f *.cm[iox] *.o *.annot
126 rm -f *~ .*~ #*#
127 rm -f .depend
128
129
130 .PHONEY: depend
131 .depend depend: $(GENERATED)
132 $(OCAMLDEP) *.mli *.ml > .depend
133
134 lexer_cocci.ml: lexer_cocci.mll
135 parser_cocci_menhir.ml: parser_cocci_menhir.mly lexer_cocci.mll
136 parser_cocci_menhir.mli: parser_cocci_menhir.mly lexer_cocci.mll
137 lexer_script.ml: lexer_script.mll
138 lexer_cli.ml: lexer_cli.mll
139
140 ifneq ($(MAKECMDGOALS),clean)
141 ifneq ($(MAKECMDGOALS),distclean)
142 -include .depend
143 endif
144 endif