Coccinelle release 1.0.0-rc13
[bpt/coccinelle.git] / bundles / menhirLib / menhir-20120123 / demos / OMakefile.shared
1 # This OMakefile is designed for projects that use Objective Caml,
2 # ocamllex, menhir, and alphaCaml.
3
4 # This OMakefile is meant to be included within a host OMakefile
5 # that defines the following variables:
6 #
7 # GENERATED : a list of the source (.ml and .mli) files
8 # that are generated (by invoking ocamllex
9 # or menhir)
10 #
11 # MODULES : a list of the modules (without extension)
12 # that should be linked into the executable
13 # program. Order is significant.
14 #
15 # EXECUTABLE : the base name of the executables that should
16 # be produced. Suffixes $(BSUFFIX) and $(OSUFFIX)
17 # will be added to distinguish the bytecode and
18 # native code versions.
19
20 # -------------------------------------------------------------------------
21
22 # The host OMakefile can override the following default settings.
23
24 # Menhir.
25
26 if $(not $(defined MENHIR))
27 MENHIR = menhir
28 export
29
30 # Parser generation flags.
31
32 if $(not $(defined MENHIR_FLAGS))
33 MENHIR_FLAGS = --infer -v
34 export
35
36 # Include directives for compilation and for linking.
37
38 if $(not $(defined PREFIXED_OCAMLINCLUDES))
39 PREFIXED_OCAMLINCLUDES =
40 export
41
42 # Bytecode compilation flags.
43
44 if $(not $(defined BFLAGS))
45 BFLAGS = -dtypes -g
46 export
47
48 # Native code compilation flags.
49
50 if $(not $(defined OFLAGS))
51 OFLAGS = -dtypes
52 export
53
54 # Menhir-suggested compilation flags.
55 if $(not $(defined SUGG_FLAGS))
56 SUGG_FLAGS = $(shell $(MENHIR) $(MENHIR_FLAGS) --suggest-comp-flags 2>/dev/null)
57 export
58
59 # Bytecode link-time flags.
60
61 if $(not $(defined BLNKFLAGS))
62 BLNKFLAGS = -g
63 export
64
65 # Menhir-suggested bytecode link-time flags.
66 if $(not $(defined SUGG_BLNKFLAGS))
67 SUGG_BLNKFLAGS = $(shell $(MENHIR) $(MENHIR_FLAGS) --suggest-link-flags-byte 2>/dev/null)
68 export
69
70 # Native code link-time flags.
71
72 if $(not $(defined OLNKFLAGS))
73 OLNKFLAGS =
74 export
75
76 # Menhir-suggested native code link-time flags.
77 if $(not $(defined SUGG_OLNKFLAGS))
78 SUGG_OLNKFLAGS = $(shell $(MENHIR) $(MENHIR_FLAGS) --suggest-link-flags-opt 2>/dev/null)
79 export
80
81 # Lexer generation flags.
82
83 if $(not $(defined LGFLAGS))
84 LGFLAGS =
85 export
86
87 # Suffix appended to the name of the bytecode executable.
88
89 if $(not $(defined BSUFFIX))
90 BSUFFIX = .byte
91 export
92
93 # Suffix appended to the name of the native code executable.
94
95 if $(not $(defined OSUFFIX))
96 OSUFFIX =
97 export
98
99 # Access paths for the tools.
100
101 if $(not $(defined OCAML))
102 OCAML = ocaml
103 export
104
105 if $(not $(defined OCAMLC))
106 if $(which ocamlfind)
107 OCAMLC = ocamlfind ocamlc
108 export
109 elseif $(which ocamlc.opt)
110 OCAMLC = ocamlc.opt
111 export
112 else
113 OCAMLC = ocamlc
114 export
115 export
116
117 if $(not $(defined OCAMLOPT))
118 if $(which ocamlfind)
119 OCAMLOPT = ocamlfind ocamlopt
120 export
121 elseif $(which ocamlopt.opt)
122 OCAMLOPT = ocamlopt.opt
123 export
124 else
125 OCAMLOPT = ocamlopt
126 export
127 export
128
129 if $(not $(defined OCAMLDEP))
130 if $(which ocamlfind)
131 OCAMLDEP = ocamlfind ocamldep
132 export
133 elseif $(which ocamldep.opt)
134 OCAMLDEP = ocamldep.opt
135 export
136 else
137 OCAMLDEP = ocamldep
138 export
139 export
140
141 if $(not $(defined OCAMLDEPWRAPPER))
142 OCAMLDEPWRAPPER = ./ocamldep.wrapper
143 export
144
145 if $(not $(defined OCAMLLEX))
146 OCAMLLEX = ocamllex
147 export
148
149 if $(not $(defined ALPHACAML))
150 ALPHACAML = alphaCaml
151 export
152
153 # ----------------------------------------------------------------
154
155 # Define an ocamldep wrapper that creates fake generated files so that
156 # ocamldep can see that these files exist (or are supposed to exist).
157 # This is required to work around ocamldep's brokenness.
158
159 WrapScanner(command) =
160 $(OCAML) $(OCAMLDEPWRAPPER) $(GENERATED) - $(command)
161
162 # ----------------------------------------------------------------
163
164 # Dependencies.
165
166 .SCANNER: %.cmi: %.mli
167 WrapScanner($(OCAMLDEP) $<)
168
169 .SCANNER: %.cmx %.cmo %.o: %.ml
170 WrapScanner($(OCAMLDEP) $<)
171
172 # ----------------------------------------------------------------
173
174 # Compilation.
175
176 %.cmi: %.mli
177 $(OCAMLC) $(PREFIXED_OCAMLINCLUDES) $(BFLAGS) $(SUGG_FLAGS) -c $<
178
179 %.cmo: %.ml
180 $(OCAMLC) $(PREFIXED_OCAMLINCLUDES) $(BFLAGS) $(SUGG_FLAGS) -c $<
181
182 %.cmx %.o: %.ml
183 $(OCAMLOPT) $(PREFIXED_OCAMLINCLUDES) $(OFLAGS) $(SUGG_FLAGS) -c $<
184
185 %.ml: %.mll
186 $(OCAMLLEX) $(LGFLAGS) $<
187
188 %.ml %.mli: %.mla
189 $(ALPHACAML) $<
190
191 # ----------------------------------------------------------------
192
193 # Linking.
194
195 $(EXECUTABLE)$(OSUFFIX): $(addsuffix .cmx, $(MODULES))
196 $(OCAMLOPT) -o $@ $(PREFIXED_OCAMLINCLUDES) $(OLNKFLAGS) $(SUGG_FLAGS) $(SUGG_OLNKFLAGS) $+
197
198 $(EXECUTABLE)$(BSUFFIX): $(addsuffix .cmo, $(MODULES))
199 $(OCAMLC) -o $@ $(PREFIXED_OCAMLINCLUDES) $(BLNKFLAGS) $(SUGG_FLAGS) $(SUGG_BLNKFLAGS) $+
200
201 # ----------------------------------------------------------------
202
203 # Menhir: multiple file projects.
204
205 MenhirMulti(target, sources, options) =
206 TARGETS = $(file $(target).ml $(target).mli)
207 SOURCES = $(file $(sources))
208 $(TARGETS): $(SOURCES)
209 $(MENHIR) --ocamlc "$(OCAMLC) $(PREFIXED_OCAMLINCLUDES) $(BFLAGS)" $(MENHIR_FLAGS) --base $(target) $(options) $(SOURCES)
210 .SCANNER: $(TARGETS): $(SOURCES)
211 WrapScanner($(MENHIR) --ocamldep "$(OCAMLDEP)" --depend --base $(target) $(options) $(SOURCES))
212
213 # Menhir: single file projects.
214
215 MenhirMono(target, options) =
216 MenhirMulti($(target), $(target).mly, $(options))
217
218 # Menhir: automatic single file projects.
219 # This causes every .mly file to be viewed as a single file project.
220
221 MenhirAuto() =
222 foreach (target, $(glob *.mly))
223 MenhirMono($(removesuffix $(target)), $(EMPTY))
224
225 # ----------------------------------------------------------------
226
227 .PHONY: clean
228
229 clean:
230 /bin/rm -f $(EXECUTABLE)$(BSUFFIX) $(EXECUTABLE)$(OSUFFIX) $(GENERATED)
231 /bin/rm -f *.cmi *.cmx *.cmo *.o *~ .*~ *.automaton *.conflicts *.annot