1 # This OMakefile is designed for projects that use Objective Caml,
2 # ocamllex, menhir, and alphaCaml.
4 # This OMakefile is meant to be included within a host OMakefile
5 # that defines the following variables:
7 # GENERATED : a list of the source (.ml and .mli) files
8 # that are generated (by invoking ocamllex
11 # MODULES : a list of the modules (without extension)
12 # that should be linked into the executable
13 # program. Order is significant.
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.
20 # -------------------------------------------------------------------------
22 # The host OMakefile can override the following default settings.
26 if $(not $(defined MENHIR))
30 # Parser generation flags.
32 if $(not $(defined MENHIR_FLAGS))
33 MENHIR_FLAGS = --infer -v
36 # Include directives for compilation and for linking.
38 if $(not $(defined PREFIXED_OCAMLINCLUDES))
39 PREFIXED_OCAMLINCLUDES =
42 # Bytecode compilation flags.
44 if $(not $(defined BFLAGS))
48 # Native code compilation flags.
50 if $(not $(defined OFLAGS))
54 # Menhir-suggested compilation flags.
55 if $(not $(defined SUGG_FLAGS))
56 SUGG_FLAGS = $(shell $(MENHIR) $(MENHIR_FLAGS) --suggest-comp-flags 2>/dev/null)
59 # Bytecode link-time flags.
61 if $(not $(defined BLNKFLAGS))
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)
70 # Native code link-time flags.
72 if $(not $(defined OLNKFLAGS))
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)
81 # Lexer generation flags.
83 if $(not $(defined LGFLAGS))
87 # Suffix appended to the name of the bytecode executable.
89 if $(not $(defined BSUFFIX))
93 # Suffix appended to the name of the native code executable.
95 if $(not $(defined OSUFFIX))
99 # Access paths for the tools.
101 if $(not $(defined OCAML))
105 if $(not $(defined OCAMLC))
106 if $(which ocamlfind)
107 OCAMLC = ocamlfind ocamlc
109 elseif $(which ocamlc.opt)
117 if $(not $(defined OCAMLOPT))
118 if $(which ocamlfind)
119 OCAMLOPT = ocamlfind ocamlopt
121 elseif $(which ocamlopt.opt)
122 OCAMLOPT = ocamlopt.opt
129 if $(not $(defined OCAMLDEP))
130 if $(which ocamlfind)
131 OCAMLDEP = ocamlfind ocamldep
133 elseif $(which ocamldep.opt)
134 OCAMLDEP = ocamldep.opt
141 if $(not $(defined OCAMLDEPWRAPPER))
142 OCAMLDEPWRAPPER = ./ocamldep.wrapper
145 if $(not $(defined OCAMLLEX))
149 if $(not $(defined ALPHACAML))
150 ALPHACAML = alphaCaml
153 # ----------------------------------------------------------------
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.
159 WrapScanner(command) =
160 $(OCAML) $(OCAMLDEPWRAPPER) $(GENERATED) - $(command)
162 # ----------------------------------------------------------------
166 .SCANNER: %.cmi: %.mli
167 WrapScanner($(OCAMLDEP) $<)
169 .SCANNER: %.cmx %.cmo %.o: %.ml
170 WrapScanner($(OCAMLDEP) $<)
172 # ----------------------------------------------------------------
177 $(OCAMLC) $(PREFIXED_OCAMLINCLUDES) $(BFLAGS) $(SUGG_FLAGS) -c $<
180 $(OCAMLC) $(PREFIXED_OCAMLINCLUDES) $(BFLAGS) $(SUGG_FLAGS) -c $<
183 $(OCAMLOPT) $(PREFIXED_OCAMLINCLUDES) $(OFLAGS) $(SUGG_FLAGS) -c $<
186 $(OCAMLLEX) $(LGFLAGS) $<
191 # ----------------------------------------------------------------
195 $(EXECUTABLE)$(OSUFFIX): $(addsuffix .cmx, $(MODULES))
196 $(OCAMLOPT) -o $@ $(PREFIXED_OCAMLINCLUDES) $(OLNKFLAGS) $(SUGG_FLAGS) $(SUGG_OLNKFLAGS) $+
198 $(EXECUTABLE)$(BSUFFIX): $(addsuffix .cmo, $(MODULES))
199 $(OCAMLC) -o $@ $(PREFIXED_OCAMLINCLUDES) $(BLNKFLAGS) $(SUGG_FLAGS) $(SUGG_BLNKFLAGS) $+
201 # ----------------------------------------------------------------
203 # Menhir: multiple file projects.
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))
213 # Menhir: single file projects.
215 MenhirMono(target, options) =
216 MenhirMulti($(target), $(target).mly, $(options))
218 # Menhir: automatic single file projects.
219 # This causes every .mly file to be viewed as a single file project.
222 foreach (target, $(glob *.mly))
223 MenhirMono($(removesuffix $(target)), $(EMPTY))
225 # ----------------------------------------------------------------
230 /bin/rm -f $(EXECUTABLE)$(BSUFFIX) $(EXECUTABLE)$(OSUFFIX) $(GENERATED)
231 /bin/rm -f *.cmi *.cmx *.cmo *.o *~ .*~ *.automaton *.conflicts *.annot