fd48de57f8fb1cf5284dd6129de16aaaacd4a407
[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 OCAMLCFLAGS ?= -g
32 OPTFLAGS ?= -g
33
34 LEXER_SOURCES = lexer_cocci.mll
35 CLI_LEXER_SOURCES = lexer_cli.mll
36 SCRIPT_LEXER_SOURCES = lexer_script.mll
37 PARSER_SOURCES = parser_cocci_menhir.mly
38 SOURCES = flag_parsing_cocci.ml type_cocci.ml ast_cocci.ml ast0_cocci.ml \
39 pretty_print_cocci.ml unparse_ast0.ml visitor_ast0_types.ml \
40 visitor_ast.ml visitor_ast0.ml compute_lines.ml comm_assoc.ml \
41 iso_pattern.ml iso_compile.ml single_statement.ml simple_assignments.ml \
42 get_metas.ml ast0toast.ml check_meta.ml top_level.ml type_infer.ml \
43 test_exps.ml unitary_ast0.ml arity.ml index.ml context_neg.ml \
44 adjust_pragmas.ml insert_plus.ml function_prototypes.ml \
45 unify_ast.ml semantic_cocci.ml data.ml free_vars.ml safe_for_multi_decls.ml \
46 parse_aux.ml disjdistr.ml \
47 $(LEXER_SOURCES:.mll=.ml) $(PARSER_SOURCES:.mly=.ml) \
48 $(CLI_LEXER_SOURCES:.mll=.ml) $(SCRIPT_LEXER_SOURCES:.mll=.ml) \
49 get_constants2.ml id_utils.ml adjacency.ml parse_cocci.ml command_line.ml
50
51 LIBS=../commons/commons.cma ../globals/globals.cma
52 SYSLIBS = str.cma unix.cma
53
54 INCLUDES = -I ../commons \
55 -I ../commons/ocamlextra \
56 -I ../globals \
57 -I $(MENHIRDIR)
58
59 MENHIRMOD=menhirLib.cmo
60 MENHIROMOD=menhirLib.cmx
61
62 # The Caml compilers.
63 OCAMLCFLAGS ?= -g -dtypes
64 EXEC=$(TARGET).byte
65 EXEC=$(TARGET)
66 LIB=$(TARGET).cma
67 OPTLIB=$(LIB:.cma=.cmxa)
68
69 GENERATED= $(LEXER_SOURCES:.mll=.ml) \
70 $(CLI_LEXER_SOURCES:.mll=.ml) $(SCRIPT_LEXER_SOURCES:.mll=.ml) \
71 $(PARSER_SOURCES:.mly=.ml) $(PARSER_SOURCES:.mly=.mli)
72 OBJS = $(SOURCES:.ml=.cmo)
73 OPTOBJS = $(OBJS:.cmo=.cmx)
74
75
76 all: $(LIB)
77 local: $(EXEC)
78
79 all.opt:
80 @$(MAKE) $(OPTLIB) BUILD_OPT=yes
81
82 $(LIB): $(GENERATED) $(OBJS)
83 $(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES) -I $(MENHIRDIR) -a -o $(LIB) $(MENHIRMOD) $(OBJS)
84
85
86 $(OPTLIB): $(GENERATED) $(OPTOBJS)
87 $(OCAMLOPT) $(OPTFLAGS) $(INCLUDES) -I $(MENHIRDIR) -a -o $(OPTLIB) $(MENHIROMOD) $(OPTOBJS)
88
89
90 $(EXEC): $(OBJS) main.cmo $(LIBS)
91 $(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES) -o $(EXEC) $(SYSLIBS) $(LIBS) $(OBJS) main.cmo
92
93 clean::
94 rm -f $(LIB)
95 rm -f $(OPTLIB) $(LIB:.cma=.a)
96 rm -f $(TARGET)
97
98
99 .SUFFIXES:
100 .SUFFIXES: .ml .mli .cmo .cmi .cmx
101
102 .ml.cmo:
103 $(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES) -c $<
104
105 .mli.cmi:
106 $(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES) -c $<
107
108 .ml.cmx:
109 $(OCAMLOPT) $(OPTFLAGS) $(INCLUDES) -c $<
110
111 $(LEXER_SOURCES:.mll=.ml) : $(LEXER_SOURCES)
112 $(OCAMLLEX) $(LEXER_SOURCES)
113
114 $(PARSER_SOURCES:.mly=.ml) $(PARSER_SOURCES:.mly=.mli) : $(PARSER_SOURCES)
115 $(MENHIR) --ocamlc "${OCAMLC}" --ocamldep "${OCAMLDEP}" --table --base parser_cocci_menhir $(PARSER_SOURCES)
116
117 $(CLI_LEXER_SOURCES:.mll=.ml): $(CLI_LEXER_SOURCES)
118 $(OCAMLLEX) $(CLI_LEXER_SOURCES)
119
120 $(SCRIPT_LEXER_SOURCES:.mll=.ml): $(SCRIPT_LEXER_SOURCES)
121 $(OCAMLLEX) $(SCRIPT_LEXER_SOURCES)
122
123 distclean:: clean
124 @echo cleaning generated parsers and lexers
125 rm -f $(GENERATED)
126
127 # clean rule for others files
128 clean::
129 rm -f *.cm[iox] *.o *.annot
130 rm -f *~ .*~ #*#
131 rm -f .depend
132
133
134 .PHONEY: depend
135 .depend depend: $(GENERATED)
136 $(OCAMLDEP) *.mli *.ml > .depend
137
138 lexer_cocci.ml: lexer_cocci.mll
139 parser_cocci_menhir.ml: parser_cocci_menhir.mly lexer_cocci.mll
140 parser_cocci_menhir.mli: parser_cocci_menhir.mly lexer_cocci.mll
141 lexer_script.ml: lexer_script.mll
142 lexer_cli.ml: lexer_cli.mll
143
144 ifneq ($(MAKECMDGOALS),clean)
145 ifneq ($(MAKECMDGOALS),distclean)
146 -include .depend
147 endif
148 endif
149
150 include ../Makefile.common