1 #**************************************************************************
2 #* *
3 #* OCaml *
4 #* *
5 #* Sebastien Hinderer, projet Gallium, INRIA Paris *
6 #* *
7 #* Copyright 2016 Institut National de Recherche en Informatique et *
8 #* en Automatique. *
9 #* *
10 #* All rights reserved. This file is distributed under the terms of *
11 #* the GNU Lesser General Public License version 2.1, with the *
12 #* special exception on linking described in the file LICENSE. *
13 #* *
14 #**************************************************************************
15
16 # The Makefile for ocamltest
17
18 ROOTDIR = ..
19
20 include $(ROOTDIR)/Makefile.config
21 include $(ROOTDIR)/Makefile.common
22 include $(ROOTDIR)/Makefile.best_binaries
23
24 ifeq "$(filter str,$(OTHERLIBRARIES))" ""
25 str := false
26 else
27 str := true
28 endif
29
30 ifeq "$(filter systhreads,$(OTHERLIBRARIES))" ""
31 systhreads := false
32 else
33 systhreads := true
34 endif
35
36 ifeq "$(filter $(UNIXLIB),$(OTHERLIBRARIES))" ""
37 unix := None
38 else
39 ifeq "$(UNIX_OR_WIN32)" "win32"
40 unix := Some false
41 else
42 unix := Some true
43 endif
44 endif
45
46 ifeq "$(UNIX_OR_WIN32)" "win32"
47 ocamlsrcdir := $(shell echo "$(abspath $(shell pwd)/..)"|cygpath -w -f - \
48 | sed 's/\\/\\\\\\\\/g')
49 mkexe := $(MKEXE_ANSI) -link $(OC_LDFLAGS)
50 else
51 ocamlsrcdir := $(abspath $(shell pwd)/..)
52 mkexe := $(MKEXE)
53 endif
54
55 ifeq "$(TOOLCHAIN)" "msvc"
56 CPP := $(CPP) 2> nul
57 CSC := csc
58 ifeq "$(HOST)" "i686-pc-windows"
59 CSCFLAGS := /platform:x86
60 else
61 CSCFLAGS :=
62 endif
63 CSCFLAGS += /nologo /nowarn:1668
64 else
65 CSC :=
66 CSCFLAGS :=
67 endif
68
69 ifeq "$(WITH_OCAMLDOC)" "ocamldoc"
70 WITH_OCAMLDOC := true
71 else
72 WITH_OCAMLDOC := false
73 endif
74
75 ifeq "$(WITH_DEBUGGER)" "ocamldebugger"
76 WITH_OCAMLDEBUG := true
77 else
78 WITH_OCAMLDEBUG := false
79 endif
80
81 OC_CPPFLAGS += -I$(ROOTDIR)/runtime -DCAML_INTERNALS
82
83 run := run_$(UNIX_OR_WIN32)
84
85 # List of source files from which ocamltest is compiled
86 # (all the different sorts of files are derived from this)
87
88 # ocamltest has two components: its core and the OCaml "plugin"
89 # which is actually built into the tool but clearly separated from its core
90
91 core := \
92 $(run).c \
93 run_stubs.c \
94 ocamltest_stdlib_stubs.c \
95 ocamltest_config.mli ocamltest_config.ml.in \
96 ocamltest_stdlib.mli ocamltest_stdlib.ml \
97 run_command.mli run_command.ml \
98 filecompare.mli filecompare.ml \
99 variables.mli variables.ml \
100 environments.mli environments.ml \
101 result.mli result.ml \
102 actions.mli actions.ml \
103 tests.mli tests.ml \
104 strace.mli strace.ml \
105 tsl_ast.mli tsl_ast.ml \
106 tsl_parser.mly \
107 tsl_lexer.mli tsl_lexer.mll \
108 modifier_parser.mli modifier_parser.ml \
109 tsl_semantics.mli tsl_semantics.ml \
110 builtin_variables.mli builtin_variables.ml \
111 actions_helpers.mli actions_helpers.ml \
112 builtin_actions.mli builtin_actions.ml
113
114 ocaml_plugin := \
115 ocaml_backends.mli ocaml_backends.ml \
116 ocaml_filetypes.mli ocaml_filetypes.ml \
117 ocaml_variables.mli ocaml_variables.ml \
118 ocaml_modifiers.mli ocaml_modifiers.ml \
119 ocaml_directories.mli ocaml_directories.ml \
120 ocaml_files.mli ocaml_files.ml \
121 ocaml_flags.mli ocaml_flags.ml \
122 ocaml_commands.mli ocaml_commands.ml \
123 ocaml_tools.mli ocaml_tools.ml \
124 ocaml_compilers.mli ocaml_compilers.ml \
125 ocaml_toplevels.mli ocaml_toplevels.ml \
126 ocaml_actions.mli ocaml_actions.ml \
127 ocaml_tests.mli ocaml_tests.ml
128
129 sources := $(core) $(ocaml_plugin) \
130 options.mli options.ml \
131 main.mli main.ml
132
133 # List of .ml files used for ocamldep and to get the list of modules
134
135 ml_files := \
136 $(filter %.ml, \
137 $(subst .ml.in,.ml,$(subst .mll,.ml,$(subst .mly,.ml,$(sources)))) \
138 )
139
140 cmo_files := $(ml_files:.ml=.cmo)
141
142 cmx_files := $(ml_files:.ml=.cmx)
143
144 ocaml_objects := $(ml_files:.ml=.$(O))
145
146 # List of .mli files for ocamldep
147 mli_files := \
148 $(filter %.mli,$(subst .mly,.mli,$(sources)))
149
150 cmi_files := $(mli_files:.mli=.cmi)
151
152 c_files := $(filter %.c, $(sources))
153
154 o_files := $(c_files:.c=.$(O))
155
156 lexers := $(filter %.mll,$(sources))
157
158 parsers := $(filter %.mly,$(sources))
159
160 config_files := $(filter %.ml.in,$(sources))
161
162 dependencies_generated_prereqs := \
163 $(config_files:.ml.in=.ml) \
164 $(lexers:.mll=.ml) \
165 $(parsers:.mly=.mli) $(parsers:.mly=.ml)
166
167 generated := $(dependencies_generated_prereqs) $(parsers:.mly=.output)
168
169 bytecode_modules := $(o_files) $(cmo_files)
170
171 native_modules := $(o_files) $(cmx_files)
172
173 directories := $(addprefix $(ROOTDIR)/,utils bytecomp parsing stdlib \
174 compilerlibs file_formats)
175
176 include_directories := $(addprefix -I , $(directories))
177
178 flags := -g -nostdlib $(include_directories) \
179 -strict-sequence -safe-string -strict-formats \
180 -w +a-4-9-41-42-44-45-48 -warn-error A
181
182 ocamlc := $(BEST_OCAMLC) $(flags)
183
184 ocamlopt := $(BEST_OCAMLOPT) $(flags)
185
186 ocamldep := $(BEST_OCAMLDEP)
187 depflags := -slash
188 depincludes :=
189
190 ocamllex := $(BEST_OCAMLLEX)
191
192 ocamlyacc := $(ROOTDIR)/yacc/ocamlyacc
193
194 ocamlcdefaultflags :=
195
196 ocamloptdefaultflags := $(shell ./getocamloptdefaultflags $(TARGET))
197
198 .SECONDARY: $(lexers:.mll=.ml) $(parsers:.mly=.mli) $(parsers:.mly=.ml)
199
200 .PHONY: all allopt opt.opt # allopt and opt.opt are synonyms
201 all: ocamltest$(EXE)
202 allopt: ocamltest.opt$(EXE)
203 opt.opt: allopt
204
205 ocamltest$(EXE): $(bytecode_modules)
206 $(ocamlc_cmd) -custom ocamlcommon.cma ocamlbytecomp.cma -o $@ $^
207
208 %.cmo: %.ml
209 $(ocamlc) -c $<
210
211 ocamltest.opt$(EXE): $(native_modules)
212 $(ocamlopt_cmd) ocamlcommon.cmxa ocamlbytecomp.cmxa -o $@ $^
213
214 %.cmx: %.ml
215 $(ocamlopt) -c $<
216
217 %.cmi: %.mli
218 $(ocamlc) -c $<
219
220 %.ml %.mli: %.mly
221 $(ocamlyacc) $<
222
223 %.ml: %.mll
224 $(ocamllex) $(OCAMLLEX_FLAGS) $<
225
226 ocamltest_config.ml: ocamltest_config.ml.in Makefile ../Makefile.config
227 sed \
228 -e 's|@@AFL_INSTRUMENT@@|$(AFL_INSTRUMENT)|' \
229 -e 's|@@ARCH@@|$(ARCH)|' \
230 -e 's|@@SHARED_LIBRARIES@@|$(SUPPORTS_SHARED_LIBRARIES)|' \
231 -e 's|@@UNIX@@|$(unix)|' \
232 -e 's|@@SYSTHREADS@@|$(systhreads)|' \
233 -e 's|@@STR@@|$(str)|' \
234 -e 's|@@SYSTEM@@|$(SYSTEM)|' \
235 -e 's|@@CPP@@|$(CPP)|' \
236 -e 's|@@OCAMLCDEFAULTFLAGS@@|$(ocamlcdefaultflags)|' \
237 -e 's|@@OCAMLOPTDEFAULTFLAGS@@|$(ocamloptdefaultflags)|' \
238 -e 's|@@OCAMLSRCDIR@@|$(ocamlsrcdir)|' \
239 -e 's|@@FLAMBDA@@|$(FLAMBDA)|' \
240 -e 's|@@SPACETIME@@|$(WITH_SPACETIME)|' \
241 -e 's|@@FORCE_SAFE_STRING@@|$(FORCE_SAFE_STRING)|' \
242 -e 's|@@FLAT_FLOAT_ARRAY@@|$(FLAT_FLOAT_ARRAY)|' \
243 -e 's|@@OCAMLDOC@@|$(WITH_OCAMLDOC)|' \
244 -e 's|@@OCAMLDEBUG@@|$(WITH_OCAMLDEBUG)|' \
245 -e 's|@@OBJEXT@@|$(O)|' \
246 -e 's|@@NATIVE_DYNLINK@@|$(NATDYNLINK)|' \
247 -e 's|@@SHARED_LIBRARY_CFLAGS@@|$(SHAREDLIB_CFLAGS)|' \
248 -e 's|@@SHAREDOBJEXT@@|$(SO)|' \
249 -e 's|@@CSC@@|$(CSC)|' \
250 -e 's|@@CSCFLAGS@@|$(CSCFLAGS)|' \
251 -e 's|@@MKDLL@@|$(MKDLL)|' \
252 -e 's|@@MKEXE@@|$(mkexe)|' \
253 -e 's|@@BYTECCLIBS@@|$(BYTECCLIBS)|' \
254 -e 's|@@NATIVECCLIBS@@|$(NATIVECCLIBS)|' \
255 -e 's|@@ASM@@|$(ASM)|' \
256 -e 's|@@CC@@|$(CC)|' \
257 -e 's|@@CFLAGS@@|$(OC_CFLAGS)|' \
258 -e 's|@@CCOMPTYPE@@|$(CCOMPTYPE)|' \
259 -e 's|@@WINDOWS_UNICODE@@|$(WINDOWS_UNICODE)|' \
260 -e 's|@@FUNCTION_SECTIONS@@|$(FUNCTION_SECTIONS)|' \
261 $< > $@
262
263 .PHONY: clean
264 clean:
265 rm -rf ocamltest$(EXE) ocamltest.opt$(EXE)
266 rm -rf $(o_files) $(ocaml_objects)
267 rm -rf $(cmi_files)
268 rm -rf $(cmo_files)
269 rm -rf $(cmx_files)
270 rm -rf $(generated)
271
272 ifneq "$(TOOLCHAIN)" "msvc"
273 .PHONY: depend
274 depend: $(dependencies_generated_prereqs)
275 $(CC) -MM $(OC_CPPFLAGS) $(c_files) \
276 | sed -e 's/\.o/.$$(O)/' > .depend
277 $(ocamldep) $(depflags) $(depincludes) $(mli_files) $(ml_files) \
278 >> .depend
279 endif
280
281 -include .depend
282