1
##########################################################################
5
# Fran�ois Pottier and Yann R�gis-Gianas, INRIA Rocquencourt #
7
# Copyright 2005 Institut National de Recherche en Informatique et #
8
# en Automatique. All rights reserved. This file is distributed #
9
# under the terms of the Q Public License version 1.0, with the #
10
# change described in file LICENSE. #
12
##########################################################################
14
# This OMakefile is designed for projects that use Objective Caml,
15
# ocamllex, menhir, and alphaCaml.
17
# This OMakefile is meant to be included within a host OMakefile
18
# that defines the following variables:
20
# GENERATED : a list of the source (.ml and .mli) files
21
# that are generated (by invoking ocamllex
24
# MODULES : a list of the modules (without extension)
25
# that should be linked into the executable
26
# program. Order is significant.
28
# EXECUTABLE : the base name of the executables that should
29
# be produced. Suffixes $(BSUFFIX) and $(OSUFFIX)
30
# will be added to distinguish the bytecode and
31
# native code versions.
33
# -------------------------------------------------------------------------
35
# The host OMakefile can override the following default settings.
37
# Include directives for compilation and for linking.
39
if $(not $(defined INCLUDE))
43
# Bytecode compilation flags.
45
if $(not $(defined BFLAGS))
49
# Native code compilation flags.
51
if $(not $(defined OFLAGS))
55
# Bytecode link-time flags.
57
if $(not $(defined BLNKFLAGS))
61
# Native code link-time flags.
63
if $(not $(defined OLNKFLAGS))
67
# Lexer generation flags.
69
if $(not $(defined LGFLAGS))
73
# Parser generation flags.
75
if $(not $(defined PGFLAGS))
79
# Suffix appended to the name of the bytecode executable.
81
if $(not $(defined BSUFFIX))
85
# Suffix appended to the name of the native code executable.
87
if $(not $(defined OSUFFIX))
91
# Access paths for the tools.
93
if $(not $(defined OCAML))
97
if $(not $(defined OCAMLC))
99
OCAMLC = ocamlfind ocamlc
101
elseif $(which ocamlc.opt)
109
if $(not $(defined OCAMLOPT))
110
if $(which ocamlfind)
111
OCAMLOPT = ocamlfind ocamlopt
113
elseif $(which ocamlopt.opt)
114
OCAMLOPT = ocamlopt.opt
121
if $(not $(defined OCAMLDEP))
122
if $(which ocamlfind)
123
OCAMLDEP = ocamlfind ocamldep
125
elseif $(which ocamldep.opt)
126
OCAMLDEP = ocamldep.opt
133
if $(not $(defined OCAMLDEPWRAPPER))
134
OCAMLDEPWRAPPER = ./ocamldep.wrapper
137
if $(not $(defined OCAMLLEX))
141
if $(not $(defined MENHIR))
145
if $(not $(defined ALPHACAML))
146
ALPHACAML = alphaCaml
149
# ----------------------------------------------------------------
151
# Define an ocamldep wrapper that creates fake generated files so that
152
# ocamldep can see that these files exist (or are supposed to exist).
153
# This is required to work around ocamldep's brokenness.
155
WrapScanner(command) =
156
$(OCAML) $(OCAMLDEPWRAPPER) $(GENERATED) - $(command)
158
# ----------------------------------------------------------------
162
.SCANNER: %.cmi: %.mli
163
WrapScanner($(OCAMLDEP) $<)
165
.SCANNER: %.cmx %.cmo %.o: %.ml
166
WrapScanner($(OCAMLDEP) $<)
168
# ----------------------------------------------------------------
173
$(OCAMLC) $(INCLUDE) $(BFLAGS) -c $<
176
$(OCAMLC) $(INCLUDE) $(BFLAGS) -c $<
179
$(OCAMLOPT) $(INCLUDE) $(OFLAGS) -c $<
182
$(OCAMLLEX) $(LGFLAGS) $<
187
# ----------------------------------------------------------------
191
$(EXECUTABLE)$(OSUFFIX): $(addsuffix .cmx, $(MODULES))
192
$(OCAMLOPT) -o $@ $(INCLUDE) $(OLNKFLAGS) $+
194
$(EXECUTABLE)$(BSUFFIX): $(addsuffix .cmo, $(MODULES))
195
$(OCAMLC) -o $@ $(INCLUDE) $(BLNKFLAGS) $+
197
# ----------------------------------------------------------------
199
# Menhir: multiple file projects.
201
MenhirMulti(target, sources, options) =
202
TARGETS = $(file $(target).ml $(target).mli)
203
SOURCES = $(file $(sources))
204
$(TARGETS): $(SOURCES)
205
$(MENHIR) --ocamlc "$(OCAMLC)" $(PGFLAGS) --base $(target) $(options) $(SOURCES)
206
.SCANNER: $(TARGETS): $(SOURCES)
207
WrapScanner($(MENHIR) --ocamldep "$(OCAMLDEP)" --depend --base $(target) $(options) $(SOURCES))
209
# Menhir: single file projects.
211
MenhirMono(target, options) =
212
MenhirMulti($(target), $(target).mly, $(options))
214
# Menhir: automatic single file projects.
215
# This causes every .mly file to be viewed as a single file project.
218
foreach (target, $(glob *.mly))
219
MenhirMono($(removesuffix $(target)), $(EMPTY))
221
# ----------------------------------------------------------------
226
/bin/rm -f $(EXECUTABLE)$(BSUFFIX) $(EXECUTABLE)$(OSUFFIX) $(GENERATED)
227
/bin/rm -f *.cmi *.cmx *.cmo *.o *~ .*~ *.automaton *.conflicts *.annot